exception.S 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Low level routines for legacy iSeries support.
  3. *
  4. * Extracted from head_64.S
  5. *
  6. * PowerPC version
  7. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  8. *
  9. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  10. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  11. * Adapted for Power Macintosh by Paul Mackerras.
  12. * Low-level exception handlers and MMU support
  13. * rewritten by Paul Mackerras.
  14. * Copyright (C) 1996 Paul Mackerras.
  15. *
  16. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  17. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  18. *
  19. * This file contains the low-level support and setup for the
  20. * PowerPC-64 platform, including trap and interrupt dispatch.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License
  24. * as published by the Free Software Foundation; either version
  25. * 2 of the License, or (at your option) any later version.
  26. */
  27. #include <asm/reg.h>
  28. #include <asm/ppc_asm.h>
  29. #include <asm/asm-offsets.h>
  30. #include <asm/thread_info.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/cputable.h>
  33. #include <asm/mmu.h>
  34. #include "exception.h"
  35. .text
  36. .globl system_reset_iSeries
  37. system_reset_iSeries:
  38. bl .relative_toc
  39. mfspr r13,SPRN_SPRG3 /* Get alpaca address */
  40. LOAD_REG_ADDR(r23, alpaca)
  41. li r0,ALPACA_SIZE
  42. sub r23,r13,r23
  43. divdu r24,r23,r0 /* r24 has cpu number */
  44. cmpwi 0,r24,0 /* Are we processor 0? */
  45. bne 1f
  46. LOAD_REG_ADDR(r13, boot_paca)
  47. mtspr SPRN_SPRG_PACA,r13 /* Save it away for the future */
  48. mfmsr r23
  49. ori r23,r23,MSR_RI
  50. mtmsrd r23 /* RI on */
  51. b .__start_initialization_iSeries /* Start up the first processor */
  52. 1: mfspr r4,SPRN_CTRLF
  53. li r5,CTRL_RUNLATCH /* Turn off the run light */
  54. andc r4,r4,r5
  55. mtspr SPRN_CTRLT,r4
  56. /* Spin on __secondary_hold_spinloop until it is updated by the boot cpu. */
  57. /* In the UP case we'll yield() later, and we will not access the paca anyway */
  58. #ifdef CONFIG_SMP
  59. iSeries_secondary_wait_paca:
  60. HMT_LOW
  61. LOAD_REG_ADDR(r23, __secondary_hold_spinloop)
  62. ld r23,0(r23)
  63. cmpdi 0,r23,0
  64. bne 2f /* go on when the master is ready */
  65. /* Keep poking the Hypervisor until we're released */
  66. /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
  67. lis r3,0x8002
  68. rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
  69. li r0,-1 /* r0=-1 indicates a Hypervisor call */
  70. sc /* Invoke the hypervisor via a system call */
  71. b iSeries_secondary_wait_paca
  72. 2:
  73. HMT_MEDIUM
  74. sync
  75. LOAD_REG_ADDR(r3, nr_cpu_ids) /* get number of pacas allocated */
  76. lwz r3,0(r3) /* nr_cpus= or NR_CPUS can limit */
  77. cmpld 0,r24,r3 /* is our cpu number allocated? */
  78. bge iSeries_secondary_yield /* no, yield forever */
  79. /* Load our paca now that it's been allocated */
  80. LOAD_REG_ADDR(r13, paca)
  81. ld r13,0(r13)
  82. mulli r0,r24,PACA_SIZE
  83. add r13,r13,r0
  84. mtspr SPRN_SPRG_PACA,r13 /* Save it away for the future */
  85. mfmsr r23
  86. ori r23,r23,MSR_RI
  87. mtmsrd r23 /* RI on */
  88. iSeries_secondary_smp_loop:
  89. lbz r23,PACAPROCSTART(r13) /* Test if this processor
  90. * should start */
  91. cmpwi 0,r23,0
  92. bne 3f /* go on when we are told */
  93. HMT_LOW
  94. /* Let the Hypervisor know we are alive */
  95. /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
  96. lis r3,0x8002
  97. rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
  98. li r0,-1 /* r0=-1 indicates a Hypervisor call */
  99. sc /* Invoke the hypervisor via a system call */
  100. mfspr r13,SPRN_SPRG_PACA /* Put r13 back ???? */
  101. b iSeries_secondary_smp_loop /* wait for signal to start */
  102. 3:
  103. HMT_MEDIUM
  104. sync
  105. LOAD_REG_ADDR(r3,current_set)
  106. sldi r28,r24,3 /* get current_set[cpu#] */
  107. ldx r3,r3,r28
  108. addi r1,r3,THREAD_SIZE
  109. subi r1,r1,STACK_FRAME_OVERHEAD
  110. b __secondary_start /* Loop until told to go */
  111. #endif /* CONFIG_SMP */
  112. iSeries_secondary_yield:
  113. /* Yield the processor. This is required for non-SMP kernels
  114. which are running on multi-threaded machines. */
  115. HMT_LOW
  116. lis r3,0x8000
  117. rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
  118. addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
  119. li r4,0 /* "yield timed" */
  120. li r5,-1 /* "yield forever" */
  121. li r0,-1 /* r0=-1 indicates a Hypervisor call */
  122. sc /* Invoke the hypervisor via a system call */
  123. mfspr r13,SPRN_SPRG_PACA /* Put r13 back ???? */
  124. b iSeries_secondary_yield /* If SMP not configured, secondaries
  125. * loop forever */
  126. /*** ISeries-LPAR interrupt handlers ***/
  127. STD_EXCEPTION_ISERIES(machine_check, PACA_EXMC)
  128. .globl data_access_iSeries
  129. data_access_iSeries:
  130. mtspr SPRN_SPRG_SCRATCH0,r13
  131. BEGIN_FTR_SECTION
  132. mfspr r13,SPRN_SPRG_PACA
  133. std r9,PACA_EXSLB+EX_R9(r13)
  134. std r10,PACA_EXSLB+EX_R10(r13)
  135. mfspr r10,SPRN_DAR
  136. mfspr r9,SPRN_DSISR
  137. srdi r10,r10,60
  138. rlwimi r10,r9,16,0x20
  139. mfcr r9
  140. cmpwi r10,0x2c
  141. beq .do_stab_bolted_iSeries
  142. ld r10,PACA_EXSLB+EX_R10(r13)
  143. std r11,PACA_EXGEN+EX_R11(r13)
  144. ld r11,PACA_EXSLB+EX_R9(r13)
  145. std r12,PACA_EXGEN+EX_R12(r13)
  146. mfspr r12,SPRN_SPRG_SCRATCH0
  147. std r10,PACA_EXGEN+EX_R10(r13)
  148. std r11,PACA_EXGEN+EX_R9(r13)
  149. std r12,PACA_EXGEN+EX_R13(r13)
  150. EXCEPTION_PROLOG_ISERIES_1
  151. FTR_SECTION_ELSE
  152. EXCEPTION_PROLOG_1(PACA_EXGEN)
  153. EXCEPTION_PROLOG_ISERIES_1
  154. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_SLB)
  155. b data_access_common
  156. .do_stab_bolted_iSeries:
  157. std r11,PACA_EXSLB+EX_R11(r13)
  158. std r12,PACA_EXSLB+EX_R12(r13)
  159. mfspr r10,SPRN_SPRG_SCRATCH0
  160. std r10,PACA_EXSLB+EX_R13(r13)
  161. EXCEPTION_PROLOG_ISERIES_1
  162. b .do_stab_bolted
  163. .globl data_access_slb_iSeries
  164. data_access_slb_iSeries:
  165. mtspr SPRN_SPRG_SCRATCH0,r13 /* save r13 */
  166. mfspr r13,SPRN_SPRG_PACA /* get paca address into r13 */
  167. std r3,PACA_EXSLB+EX_R3(r13)
  168. mfspr r3,SPRN_DAR
  169. std r9,PACA_EXSLB+EX_R9(r13)
  170. mfcr r9
  171. #ifdef __DISABLED__
  172. cmpdi r3,0
  173. bge slb_miss_user_iseries
  174. #endif
  175. std r10,PACA_EXSLB+EX_R10(r13)
  176. std r11,PACA_EXSLB+EX_R11(r13)
  177. std r12,PACA_EXSLB+EX_R12(r13)
  178. mfspr r10,SPRN_SPRG_SCRATCH0
  179. std r10,PACA_EXSLB+EX_R13(r13)
  180. ld r12,PACALPPACAPTR(r13)
  181. ld r12,LPPACASRR1(r12)
  182. b .slb_miss_realmode
  183. STD_EXCEPTION_ISERIES(instruction_access, PACA_EXGEN)
  184. .globl instruction_access_slb_iSeries
  185. instruction_access_slb_iSeries:
  186. mtspr SPRN_SPRG_SCRATCH0,r13 /* save r13 */
  187. mfspr r13,SPRN_SPRG_PACA /* get paca address into r13 */
  188. std r3,PACA_EXSLB+EX_R3(r13)
  189. ld r3,PACALPPACAPTR(r13)
  190. ld r3,LPPACASRR0(r3) /* get SRR0 value */
  191. std r9,PACA_EXSLB+EX_R9(r13)
  192. mfcr r9
  193. #ifdef __DISABLED__
  194. cmpdi r3,0
  195. bge slb_miss_user_iseries
  196. #endif
  197. std r10,PACA_EXSLB+EX_R10(r13)
  198. std r11,PACA_EXSLB+EX_R11(r13)
  199. std r12,PACA_EXSLB+EX_R12(r13)
  200. mfspr r10,SPRN_SPRG_SCRATCH0
  201. std r10,PACA_EXSLB+EX_R13(r13)
  202. ld r12,PACALPPACAPTR(r13)
  203. ld r12,LPPACASRR1(r12)
  204. b .slb_miss_realmode
  205. #ifdef __DISABLED__
  206. slb_miss_user_iseries:
  207. std r10,PACA_EXGEN+EX_R10(r13)
  208. std r11,PACA_EXGEN+EX_R11(r13)
  209. std r12,PACA_EXGEN+EX_R12(r13)
  210. mfspr r10,SPRG_SCRATCH0
  211. ld r11,PACA_EXSLB+EX_R9(r13)
  212. ld r12,PACA_EXSLB+EX_R3(r13)
  213. std r10,PACA_EXGEN+EX_R13(r13)
  214. std r11,PACA_EXGEN+EX_R9(r13)
  215. std r12,PACA_EXGEN+EX_R3(r13)
  216. EXCEPTION_PROLOG_ISERIES_1
  217. b slb_miss_user_common
  218. #endif
  219. MASKABLE_EXCEPTION_ISERIES(hardware_interrupt)
  220. STD_EXCEPTION_ISERIES(alignment, PACA_EXGEN)
  221. STD_EXCEPTION_ISERIES(program_check, PACA_EXGEN)
  222. STD_EXCEPTION_ISERIES(fp_unavailable, PACA_EXGEN)
  223. MASKABLE_EXCEPTION_ISERIES(decrementer)
  224. STD_EXCEPTION_ISERIES(trap_0a, PACA_EXGEN)
  225. STD_EXCEPTION_ISERIES(trap_0b, PACA_EXGEN)
  226. .globl system_call_iSeries
  227. system_call_iSeries:
  228. mr r9,r13
  229. mfspr r13,SPRN_SPRG_PACA
  230. EXCEPTION_PROLOG_ISERIES_1
  231. b system_call_common
  232. STD_EXCEPTION_ISERIES(single_step, PACA_EXGEN)
  233. STD_EXCEPTION_ISERIES(trap_0e, PACA_EXGEN)
  234. STD_EXCEPTION_ISERIES(performance_monitor, PACA_EXGEN)
  235. decrementer_iSeries_masked:
  236. /* We may not have a valid TOC pointer in here. */
  237. li r11,1
  238. ld r12,PACALPPACAPTR(r13)
  239. stb r11,LPPACADECRINT(r12)
  240. li r12,-1
  241. clrldi r12,r12,33 /* set DEC to 0x7fffffff */
  242. mtspr SPRN_DEC,r12
  243. /* fall through */
  244. hardware_interrupt_iSeries_masked:
  245. mtcrf 0x80,r9 /* Restore regs */
  246. ld r12,PACALPPACAPTR(r13)
  247. ld r11,LPPACASRR0(r12)
  248. ld r12,LPPACASRR1(r12)
  249. mtspr SPRN_SRR0,r11
  250. mtspr SPRN_SRR1,r12
  251. ld r9,PACA_EXGEN+EX_R9(r13)
  252. ld r10,PACA_EXGEN+EX_R10(r13)
  253. ld r11,PACA_EXGEN+EX_R11(r13)
  254. ld r12,PACA_EXGEN+EX_R12(r13)
  255. ld r13,PACA_EXGEN+EX_R13(r13)
  256. rfid
  257. b . /* prevent speculative execution */
  258. _INIT_STATIC(__start_initialization_iSeries)
  259. /* Clear out the BSS */
  260. LOAD_REG_ADDR(r11,__bss_stop)
  261. LOAD_REG_ADDR(r8,__bss_start)
  262. sub r11,r11,r8 /* bss size */
  263. addi r11,r11,7 /* round up to an even double word */
  264. rldicl. r11,r11,61,3 /* shift right by 3 */
  265. beq 4f
  266. addi r8,r8,-8
  267. li r0,0
  268. mtctr r11 /* zero this many doublewords */
  269. 3: stdu r0,8(r8)
  270. bdnz 3b
  271. 4:
  272. LOAD_REG_ADDR(r1,init_thread_union)
  273. addi r1,r1,THREAD_SIZE
  274. li r0,0
  275. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  276. bl .iSeries_early_setup
  277. bl .early_setup
  278. /* relocation is on at this point */
  279. b .start_here_common