head_64.S 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  6. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Adapted for Power Macintosh by Paul Mackerras.
  8. * Low-level exception handlers and MMU support
  9. * rewritten by Paul Mackerras.
  10. * Copyright (C) 1996 Paul Mackerras.
  11. *
  12. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  13. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  14. *
  15. * This file contains the low-level support and setup for the
  16. * PowerPC-64 platform, including trap and interrupt dispatch.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #include <linux/threads.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/mmu.h>
  27. #include <asm/ppc_asm.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/bug.h>
  30. #include <asm/cputable.h>
  31. #include <asm/setup.h>
  32. #include <asm/hvcall.h>
  33. #include <asm/iseries/lpar_map.h>
  34. #include <asm/thread_info.h>
  35. #include <asm/firmware.h>
  36. #include <asm/page_64.h>
  37. #include <asm/exception.h>
  38. #define DO_SOFT_DISABLE
  39. /*
  40. * We layout physical memory as follows:
  41. * 0x0000 - 0x00ff : Secondary processor spin code
  42. * 0x0100 - 0x2fff : pSeries Interrupt prologs
  43. * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
  44. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  45. * 0x7000 - 0x7fff : FWNMI data area
  46. * 0x8000 - : Early init and support code
  47. */
  48. /*
  49. * SPRG Usage
  50. *
  51. * Register Definition
  52. *
  53. * SPRG0 reserved for hypervisor
  54. * SPRG1 temp - used to save gpr
  55. * SPRG2 temp - used to save gpr
  56. * SPRG3 virt addr of paca
  57. */
  58. /*
  59. * Entering into this code we make the following assumptions:
  60. * For pSeries:
  61. * 1. The MMU is off & open firmware is running in real mode.
  62. * 2. The kernel is entered at __start
  63. *
  64. * For iSeries:
  65. * 1. The MMU is on (as it always is for iSeries)
  66. * 2. The kernel is entered at system_reset_iSeries
  67. */
  68. .text
  69. .globl _stext
  70. _stext:
  71. _GLOBAL(__start)
  72. /* NOP this out unconditionally */
  73. BEGIN_FTR_SECTION
  74. b .__start_initialization_multiplatform
  75. END_FTR_SECTION(0, 1)
  76. /* Catch branch to 0 in real mode */
  77. trap
  78. /* Secondary processors spin on this value until it goes to 1. */
  79. .globl __secondary_hold_spinloop
  80. __secondary_hold_spinloop:
  81. .llong 0x0
  82. /* Secondary processors write this value with their cpu # */
  83. /* after they enter the spin loop immediately below. */
  84. .globl __secondary_hold_acknowledge
  85. __secondary_hold_acknowledge:
  86. .llong 0x0
  87. #ifdef CONFIG_PPC_ISERIES
  88. /*
  89. * At offset 0x20, there is a pointer to iSeries LPAR data.
  90. * This is required by the hypervisor
  91. */
  92. . = 0x20
  93. .llong hvReleaseData-KERNELBASE
  94. #endif /* CONFIG_PPC_ISERIES */
  95. . = 0x60
  96. /*
  97. * The following code is used to hold secondary processors
  98. * in a spin loop after they have entered the kernel, but
  99. * before the bulk of the kernel has been relocated. This code
  100. * is relocated to physical address 0x60 before prom_init is run.
  101. * All of it must fit below the first exception vector at 0x100.
  102. */
  103. _GLOBAL(__secondary_hold)
  104. mfmsr r24
  105. ori r24,r24,MSR_RI
  106. mtmsrd r24 /* RI on */
  107. /* Grab our physical cpu number */
  108. mr r24,r3
  109. /* Tell the master cpu we're here */
  110. /* Relocation is off & we are located at an address less */
  111. /* than 0x100, so only need to grab low order offset. */
  112. std r24,__secondary_hold_acknowledge@l(0)
  113. sync
  114. /* All secondary cpus wait here until told to start. */
  115. 100: ld r4,__secondary_hold_spinloop@l(0)
  116. cmpdi 0,r4,1
  117. bne 100b
  118. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  119. LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
  120. mtctr r4
  121. mr r3,r24
  122. bctr
  123. #else
  124. BUG_OPCODE
  125. #endif
  126. /* This value is used to mark exception frames on the stack. */
  127. .section ".toc","aw"
  128. exception_marker:
  129. .tc ID_72656773_68657265[TC],0x7265677368657265
  130. .text
  131. /*
  132. * This is the start of the interrupt handlers for pSeries
  133. * This code runs with relocation off.
  134. */
  135. . = 0x100
  136. .globl __start_interrupts
  137. __start_interrupts:
  138. STD_EXCEPTION_PSERIES(0x100, system_reset)
  139. . = 0x200
  140. _machine_check_pSeries:
  141. HMT_MEDIUM
  142. mtspr SPRN_SPRG1,r13 /* save r13 */
  143. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  144. . = 0x300
  145. .globl data_access_pSeries
  146. data_access_pSeries:
  147. HMT_MEDIUM
  148. mtspr SPRN_SPRG1,r13
  149. BEGIN_FTR_SECTION
  150. mtspr SPRN_SPRG2,r12
  151. mfspr r13,SPRN_DAR
  152. mfspr r12,SPRN_DSISR
  153. srdi r13,r13,60
  154. rlwimi r13,r12,16,0x20
  155. mfcr r12
  156. cmpwi r13,0x2c
  157. beq do_stab_bolted_pSeries
  158. mtcrf 0x80,r12
  159. mfspr r12,SPRN_SPRG2
  160. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  161. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
  162. . = 0x380
  163. .globl data_access_slb_pSeries
  164. data_access_slb_pSeries:
  165. HMT_MEDIUM
  166. mtspr SPRN_SPRG1,r13
  167. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  168. std r3,PACA_EXSLB+EX_R3(r13)
  169. mfspr r3,SPRN_DAR
  170. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  171. mfcr r9
  172. #ifdef __DISABLED__
  173. /* Keep that around for when we re-implement dynamic VSIDs */
  174. cmpdi r3,0
  175. bge slb_miss_user_pseries
  176. #endif /* __DISABLED__ */
  177. std r10,PACA_EXSLB+EX_R10(r13)
  178. std r11,PACA_EXSLB+EX_R11(r13)
  179. std r12,PACA_EXSLB+EX_R12(r13)
  180. mfspr r10,SPRN_SPRG1
  181. std r10,PACA_EXSLB+EX_R13(r13)
  182. mfspr r12,SPRN_SRR1 /* and SRR1 */
  183. b .slb_miss_realmode /* Rel. branch works in real mode */
  184. STD_EXCEPTION_PSERIES(0x400, instruction_access)
  185. . = 0x480
  186. .globl instruction_access_slb_pSeries
  187. instruction_access_slb_pSeries:
  188. HMT_MEDIUM
  189. mtspr SPRN_SPRG1,r13
  190. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  191. std r3,PACA_EXSLB+EX_R3(r13)
  192. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  193. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  194. mfcr r9
  195. #ifdef __DISABLED__
  196. /* Keep that around for when we re-implement dynamic VSIDs */
  197. cmpdi r3,0
  198. bge slb_miss_user_pseries
  199. #endif /* __DISABLED__ */
  200. std r10,PACA_EXSLB+EX_R10(r13)
  201. std r11,PACA_EXSLB+EX_R11(r13)
  202. std r12,PACA_EXSLB+EX_R12(r13)
  203. mfspr r10,SPRN_SPRG1
  204. std r10,PACA_EXSLB+EX_R13(r13)
  205. mfspr r12,SPRN_SRR1 /* and SRR1 */
  206. b .slb_miss_realmode /* Rel. branch works in real mode */
  207. MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
  208. STD_EXCEPTION_PSERIES(0x600, alignment)
  209. STD_EXCEPTION_PSERIES(0x700, program_check)
  210. STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
  211. MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
  212. STD_EXCEPTION_PSERIES(0xa00, trap_0a)
  213. STD_EXCEPTION_PSERIES(0xb00, trap_0b)
  214. . = 0xc00
  215. .globl system_call_pSeries
  216. system_call_pSeries:
  217. HMT_MEDIUM
  218. mr r9,r13
  219. mfmsr r10
  220. mfspr r13,SPRN_SPRG3
  221. mfspr r11,SPRN_SRR0
  222. clrrdi r12,r13,32
  223. oris r12,r12,system_call_common@h
  224. ori r12,r12,system_call_common@l
  225. mtspr SPRN_SRR0,r12
  226. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  227. mfspr r12,SPRN_SRR1
  228. mtspr SPRN_SRR1,r10
  229. rfid
  230. b . /* prevent speculative execution */
  231. STD_EXCEPTION_PSERIES(0xd00, single_step)
  232. STD_EXCEPTION_PSERIES(0xe00, trap_0e)
  233. /* We need to deal with the Altivec unavailable exception
  234. * here which is at 0xf20, thus in the middle of the
  235. * prolog code of the PerformanceMonitor one. A little
  236. * trickery is thus necessary
  237. */
  238. . = 0xf00
  239. b performance_monitor_pSeries
  240. STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
  241. #ifdef CONFIG_CBE_RAS
  242. HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
  243. #endif /* CONFIG_CBE_RAS */
  244. STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
  245. #ifdef CONFIG_CBE_RAS
  246. HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
  247. #endif /* CONFIG_CBE_RAS */
  248. STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
  249. #ifdef CONFIG_CBE_RAS
  250. HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
  251. #endif /* CONFIG_CBE_RAS */
  252. . = 0x3000
  253. /*** pSeries interrupt support ***/
  254. /* moved from 0xf00 */
  255. STD_EXCEPTION_PSERIES(., performance_monitor)
  256. /*
  257. * An interrupt came in while soft-disabled; clear EE in SRR1,
  258. * clear paca->hard_enabled and return.
  259. */
  260. masked_interrupt:
  261. stb r10,PACAHARDIRQEN(r13)
  262. mtcrf 0x80,r9
  263. ld r9,PACA_EXGEN+EX_R9(r13)
  264. mfspr r10,SPRN_SRR1
  265. rldicl r10,r10,48,1 /* clear MSR_EE */
  266. rotldi r10,r10,16
  267. mtspr SPRN_SRR1,r10
  268. ld r10,PACA_EXGEN+EX_R10(r13)
  269. mfspr r13,SPRN_SPRG1
  270. rfid
  271. b .
  272. .align 7
  273. do_stab_bolted_pSeries:
  274. mtcrf 0x80,r12
  275. mfspr r12,SPRN_SPRG2
  276. EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
  277. /*
  278. * We have some room here we use that to put
  279. * the peries slb miss user trampoline code so it's reasonably
  280. * away from slb_miss_user_common to avoid problems with rfid
  281. *
  282. * This is used for when the SLB miss handler has to go virtual,
  283. * which doesn't happen for now anymore but will once we re-implement
  284. * dynamic VSIDs for shared page tables
  285. */
  286. #ifdef __DISABLED__
  287. slb_miss_user_pseries:
  288. std r10,PACA_EXGEN+EX_R10(r13)
  289. std r11,PACA_EXGEN+EX_R11(r13)
  290. std r12,PACA_EXGEN+EX_R12(r13)
  291. mfspr r10,SPRG1
  292. ld r11,PACA_EXSLB+EX_R9(r13)
  293. ld r12,PACA_EXSLB+EX_R3(r13)
  294. std r10,PACA_EXGEN+EX_R13(r13)
  295. std r11,PACA_EXGEN+EX_R9(r13)
  296. std r12,PACA_EXGEN+EX_R3(r13)
  297. clrrdi r12,r13,32
  298. mfmsr r10
  299. mfspr r11,SRR0 /* save SRR0 */
  300. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  301. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  302. mtspr SRR0,r12
  303. mfspr r12,SRR1 /* and SRR1 */
  304. mtspr SRR1,r10
  305. rfid
  306. b . /* prevent spec. execution */
  307. #endif /* __DISABLED__ */
  308. #ifdef CONFIG_PPC_PSERIES
  309. /*
  310. * Vectors for the FWNMI option. Share common code.
  311. */
  312. .globl system_reset_fwnmi
  313. .align 7
  314. system_reset_fwnmi:
  315. HMT_MEDIUM
  316. mtspr SPRN_SPRG1,r13 /* save r13 */
  317. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
  318. .globl machine_check_fwnmi
  319. .align 7
  320. machine_check_fwnmi:
  321. HMT_MEDIUM
  322. mtspr SPRN_SPRG1,r13 /* save r13 */
  323. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
  324. #endif /* CONFIG_PPC_PSERIES */
  325. /*** Common interrupt handlers ***/
  326. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  327. /*
  328. * Machine check is different because we use a different
  329. * save area: PACA_EXMC instead of PACA_EXGEN.
  330. */
  331. .align 7
  332. .globl machine_check_common
  333. machine_check_common:
  334. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  335. FINISH_NAP
  336. DISABLE_INTS
  337. bl .save_nvgprs
  338. addi r3,r1,STACK_FRAME_OVERHEAD
  339. bl .machine_check_exception
  340. b .ret_from_except
  341. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  342. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  343. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  344. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  345. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  346. STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
  347. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  348. #ifdef CONFIG_ALTIVEC
  349. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  350. #else
  351. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  352. #endif
  353. #ifdef CONFIG_CBE_RAS
  354. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  355. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  356. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  357. #endif /* CONFIG_CBE_RAS */
  358. /*
  359. * Here we have detected that the kernel stack pointer is bad.
  360. * R9 contains the saved CR, r13 points to the paca,
  361. * r10 contains the (bad) kernel stack pointer,
  362. * r11 and r12 contain the saved SRR0 and SRR1.
  363. * We switch to using an emergency stack, save the registers there,
  364. * and call kernel_bad_stack(), which panics.
  365. */
  366. bad_stack:
  367. ld r1,PACAEMERGSP(r13)
  368. subi r1,r1,64+INT_FRAME_SIZE
  369. std r9,_CCR(r1)
  370. std r10,GPR1(r1)
  371. std r11,_NIP(r1)
  372. std r12,_MSR(r1)
  373. mfspr r11,SPRN_DAR
  374. mfspr r12,SPRN_DSISR
  375. std r11,_DAR(r1)
  376. std r12,_DSISR(r1)
  377. mflr r10
  378. mfctr r11
  379. mfxer r12
  380. std r10,_LINK(r1)
  381. std r11,_CTR(r1)
  382. std r12,_XER(r1)
  383. SAVE_GPR(0,r1)
  384. SAVE_GPR(2,r1)
  385. SAVE_4GPRS(3,r1)
  386. SAVE_2GPRS(7,r1)
  387. SAVE_10GPRS(12,r1)
  388. SAVE_10GPRS(22,r1)
  389. lhz r12,PACA_TRAP_SAVE(r13)
  390. std r12,_TRAP(r1)
  391. addi r11,r1,INT_FRAME_SIZE
  392. std r11,0(r1)
  393. li r12,0
  394. std r12,0(r11)
  395. ld r2,PACATOC(r13)
  396. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  397. bl .kernel_bad_stack
  398. b 1b
  399. /*
  400. * Return from an exception with minimal checks.
  401. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  402. * If interrupts have been enabled, or anything has been
  403. * done that might have changed the scheduling status of
  404. * any task or sent any task a signal, you should use
  405. * ret_from_except or ret_from_except_lite instead of this.
  406. */
  407. fast_exc_return_irq: /* restores irq state too */
  408. ld r3,SOFTE(r1)
  409. ld r12,_MSR(r1)
  410. stb r3,PACASOFTIRQEN(r13) /* restore paca->soft_enabled */
  411. rldicl r4,r12,49,63 /* get MSR_EE to LSB */
  412. stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
  413. b 1f
  414. .globl fast_exception_return
  415. fast_exception_return:
  416. ld r12,_MSR(r1)
  417. 1: ld r11,_NIP(r1)
  418. andi. r3,r12,MSR_RI /* check if RI is set */
  419. beq- unrecov_fer
  420. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  421. andi. r3,r12,MSR_PR
  422. beq 2f
  423. ACCOUNT_CPU_USER_EXIT(r3, r4)
  424. 2:
  425. #endif
  426. ld r3,_CCR(r1)
  427. ld r4,_LINK(r1)
  428. ld r5,_CTR(r1)
  429. ld r6,_XER(r1)
  430. mtcr r3
  431. mtlr r4
  432. mtctr r5
  433. mtxer r6
  434. REST_GPR(0, r1)
  435. REST_8GPRS(2, r1)
  436. mfmsr r10
  437. rldicl r10,r10,48,1 /* clear EE */
  438. rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
  439. mtmsrd r10,1
  440. mtspr SPRN_SRR1,r12
  441. mtspr SPRN_SRR0,r11
  442. REST_4GPRS(10, r1)
  443. ld r1,GPR1(r1)
  444. rfid
  445. b . /* prevent speculative execution */
  446. unrecov_fer:
  447. bl .save_nvgprs
  448. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  449. bl .unrecoverable_exception
  450. b 1b
  451. /*
  452. * Here r13 points to the paca, r9 contains the saved CR,
  453. * SRR0 and SRR1 are saved in r11 and r12,
  454. * r9 - r13 are saved in paca->exgen.
  455. */
  456. .align 7
  457. .globl data_access_common
  458. data_access_common:
  459. mfspr r10,SPRN_DAR
  460. std r10,PACA_EXGEN+EX_DAR(r13)
  461. mfspr r10,SPRN_DSISR
  462. stw r10,PACA_EXGEN+EX_DSISR(r13)
  463. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  464. ld r3,PACA_EXGEN+EX_DAR(r13)
  465. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  466. li r5,0x300
  467. b .do_hash_page /* Try to handle as hpte fault */
  468. .align 7
  469. .globl instruction_access_common
  470. instruction_access_common:
  471. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  472. ld r3,_NIP(r1)
  473. andis. r4,r12,0x5820
  474. li r5,0x400
  475. b .do_hash_page /* Try to handle as hpte fault */
  476. /*
  477. * Here is the common SLB miss user that is used when going to virtual
  478. * mode for SLB misses, that is currently not used
  479. */
  480. #ifdef __DISABLED__
  481. .align 7
  482. .globl slb_miss_user_common
  483. slb_miss_user_common:
  484. mflr r10
  485. std r3,PACA_EXGEN+EX_DAR(r13)
  486. stw r9,PACA_EXGEN+EX_CCR(r13)
  487. std r10,PACA_EXGEN+EX_LR(r13)
  488. std r11,PACA_EXGEN+EX_SRR0(r13)
  489. bl .slb_allocate_user
  490. ld r10,PACA_EXGEN+EX_LR(r13)
  491. ld r3,PACA_EXGEN+EX_R3(r13)
  492. lwz r9,PACA_EXGEN+EX_CCR(r13)
  493. ld r11,PACA_EXGEN+EX_SRR0(r13)
  494. mtlr r10
  495. beq- slb_miss_fault
  496. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  497. beq- unrecov_user_slb
  498. mfmsr r10
  499. .machine push
  500. .machine "power4"
  501. mtcrf 0x80,r9
  502. .machine pop
  503. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  504. mtmsrd r10,1
  505. mtspr SRR0,r11
  506. mtspr SRR1,r12
  507. ld r9,PACA_EXGEN+EX_R9(r13)
  508. ld r10,PACA_EXGEN+EX_R10(r13)
  509. ld r11,PACA_EXGEN+EX_R11(r13)
  510. ld r12,PACA_EXGEN+EX_R12(r13)
  511. ld r13,PACA_EXGEN+EX_R13(r13)
  512. rfid
  513. b .
  514. slb_miss_fault:
  515. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  516. ld r4,PACA_EXGEN+EX_DAR(r13)
  517. li r5,0
  518. std r4,_DAR(r1)
  519. std r5,_DSISR(r1)
  520. b handle_page_fault
  521. unrecov_user_slb:
  522. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  523. DISABLE_INTS
  524. bl .save_nvgprs
  525. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  526. bl .unrecoverable_exception
  527. b 1b
  528. #endif /* __DISABLED__ */
  529. /*
  530. * r13 points to the PACA, r9 contains the saved CR,
  531. * r12 contain the saved SRR1, SRR0 is still ready for return
  532. * r3 has the faulting address
  533. * r9 - r13 are saved in paca->exslb.
  534. * r3 is saved in paca->slb_r3
  535. * We assume we aren't going to take any exceptions during this procedure.
  536. */
  537. _GLOBAL(slb_miss_realmode)
  538. mflr r10
  539. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  540. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  541. bl .slb_allocate_realmode
  542. /* All done -- return from exception. */
  543. ld r10,PACA_EXSLB+EX_LR(r13)
  544. ld r3,PACA_EXSLB+EX_R3(r13)
  545. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  546. #ifdef CONFIG_PPC_ISERIES
  547. BEGIN_FW_FTR_SECTION
  548. ld r11,PACALPPACAPTR(r13)
  549. ld r11,LPPACASRR0(r11) /* get SRR0 value */
  550. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  551. #endif /* CONFIG_PPC_ISERIES */
  552. mtlr r10
  553. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  554. beq- unrecov_slb
  555. .machine push
  556. .machine "power4"
  557. mtcrf 0x80,r9
  558. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  559. .machine pop
  560. #ifdef CONFIG_PPC_ISERIES
  561. BEGIN_FW_FTR_SECTION
  562. mtspr SPRN_SRR0,r11
  563. mtspr SPRN_SRR1,r12
  564. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  565. #endif /* CONFIG_PPC_ISERIES */
  566. ld r9,PACA_EXSLB+EX_R9(r13)
  567. ld r10,PACA_EXSLB+EX_R10(r13)
  568. ld r11,PACA_EXSLB+EX_R11(r13)
  569. ld r12,PACA_EXSLB+EX_R12(r13)
  570. ld r13,PACA_EXSLB+EX_R13(r13)
  571. rfid
  572. b . /* prevent speculative execution */
  573. unrecov_slb:
  574. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  575. DISABLE_INTS
  576. bl .save_nvgprs
  577. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  578. bl .unrecoverable_exception
  579. b 1b
  580. .align 7
  581. .globl hardware_interrupt_common
  582. .globl hardware_interrupt_entry
  583. hardware_interrupt_common:
  584. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  585. FINISH_NAP
  586. hardware_interrupt_entry:
  587. DISABLE_INTS
  588. BEGIN_FTR_SECTION
  589. bl .ppc64_runlatch_on
  590. END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
  591. addi r3,r1,STACK_FRAME_OVERHEAD
  592. bl .do_IRQ
  593. b .ret_from_except_lite
  594. #ifdef CONFIG_PPC_970_NAP
  595. power4_fixup_nap:
  596. andc r9,r9,r10
  597. std r9,TI_LOCAL_FLAGS(r11)
  598. ld r10,_LINK(r1) /* make idle task do the */
  599. std r10,_NIP(r1) /* equivalent of a blr */
  600. blr
  601. #endif
  602. .align 7
  603. .globl alignment_common
  604. alignment_common:
  605. mfspr r10,SPRN_DAR
  606. std r10,PACA_EXGEN+EX_DAR(r13)
  607. mfspr r10,SPRN_DSISR
  608. stw r10,PACA_EXGEN+EX_DSISR(r13)
  609. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  610. ld r3,PACA_EXGEN+EX_DAR(r13)
  611. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  612. std r3,_DAR(r1)
  613. std r4,_DSISR(r1)
  614. bl .save_nvgprs
  615. addi r3,r1,STACK_FRAME_OVERHEAD
  616. ENABLE_INTS
  617. bl .alignment_exception
  618. b .ret_from_except
  619. .align 7
  620. .globl program_check_common
  621. program_check_common:
  622. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  623. bl .save_nvgprs
  624. addi r3,r1,STACK_FRAME_OVERHEAD
  625. ENABLE_INTS
  626. bl .program_check_exception
  627. b .ret_from_except
  628. .align 7
  629. .globl fp_unavailable_common
  630. fp_unavailable_common:
  631. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  632. bne 1f /* if from user, just load it up */
  633. bl .save_nvgprs
  634. addi r3,r1,STACK_FRAME_OVERHEAD
  635. ENABLE_INTS
  636. bl .kernel_fp_unavailable_exception
  637. BUG_OPCODE
  638. 1: b .load_up_fpu
  639. .align 7
  640. .globl altivec_unavailable_common
  641. altivec_unavailable_common:
  642. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  643. #ifdef CONFIG_ALTIVEC
  644. BEGIN_FTR_SECTION
  645. bne .load_up_altivec /* if from user, just load it up */
  646. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  647. #endif
  648. bl .save_nvgprs
  649. addi r3,r1,STACK_FRAME_OVERHEAD
  650. ENABLE_INTS
  651. bl .altivec_unavailable_exception
  652. b .ret_from_except
  653. #ifdef CONFIG_ALTIVEC
  654. /*
  655. * load_up_altivec(unused, unused, tsk)
  656. * Disable VMX for the task which had it previously,
  657. * and save its vector registers in its thread_struct.
  658. * Enables the VMX for use in the kernel on return.
  659. * On SMP we know the VMX is free, since we give it up every
  660. * switch (ie, no lazy save of the vector registers).
  661. * On entry: r13 == 'current' && last_task_used_altivec != 'current'
  662. */
  663. _STATIC(load_up_altivec)
  664. mfmsr r5 /* grab the current MSR */
  665. oris r5,r5,MSR_VEC@h
  666. mtmsrd r5 /* enable use of VMX now */
  667. isync
  668. /*
  669. * For SMP, we don't do lazy VMX switching because it just gets too
  670. * horrendously complex, especially when a task switches from one CPU
  671. * to another. Instead we call giveup_altvec in switch_to.
  672. * VRSAVE isn't dealt with here, that is done in the normal context
  673. * switch code. Note that we could rely on vrsave value to eventually
  674. * avoid saving all of the VREGs here...
  675. */
  676. #ifndef CONFIG_SMP
  677. ld r3,last_task_used_altivec@got(r2)
  678. ld r4,0(r3)
  679. cmpdi 0,r4,0
  680. beq 1f
  681. /* Save VMX state to last_task_used_altivec's THREAD struct */
  682. addi r4,r4,THREAD
  683. SAVE_32VRS(0,r5,r4)
  684. mfvscr vr0
  685. li r10,THREAD_VSCR
  686. stvx vr0,r10,r4
  687. /* Disable VMX for last_task_used_altivec */
  688. ld r5,PT_REGS(r4)
  689. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  690. lis r6,MSR_VEC@h
  691. andc r4,r4,r6
  692. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  693. 1:
  694. #endif /* CONFIG_SMP */
  695. /* Hack: if we get an altivec unavailable trap with VRSAVE
  696. * set to all zeros, we assume this is a broken application
  697. * that fails to set it properly, and thus we switch it to
  698. * all 1's
  699. */
  700. mfspr r4,SPRN_VRSAVE
  701. cmpdi 0,r4,0
  702. bne+ 1f
  703. li r4,-1
  704. mtspr SPRN_VRSAVE,r4
  705. 1:
  706. /* enable use of VMX after return */
  707. ld r4,PACACURRENT(r13)
  708. addi r5,r4,THREAD /* Get THREAD */
  709. oris r12,r12,MSR_VEC@h
  710. std r12,_MSR(r1)
  711. li r4,1
  712. li r10,THREAD_VSCR
  713. stw r4,THREAD_USED_VR(r5)
  714. lvx vr0,r10,r5
  715. mtvscr vr0
  716. REST_32VRS(0,r4,r5)
  717. #ifndef CONFIG_SMP
  718. /* Update last_task_used_math to 'current' */
  719. subi r4,r5,THREAD /* Back to 'current' */
  720. std r4,0(r3)
  721. #endif /* CONFIG_SMP */
  722. /* restore registers and return */
  723. b fast_exception_return
  724. #endif /* CONFIG_ALTIVEC */
  725. /*
  726. * Hash table stuff
  727. */
  728. .align 7
  729. _GLOBAL(do_hash_page)
  730. std r3,_DAR(r1)
  731. std r4,_DSISR(r1)
  732. andis. r0,r4,0xa450 /* weird error? */
  733. bne- handle_page_fault /* if not, try to insert a HPTE */
  734. BEGIN_FTR_SECTION
  735. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  736. bne- do_ste_alloc /* If so handle it */
  737. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  738. /*
  739. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  740. * accessing a userspace segment (even from the kernel). We assume
  741. * kernel addresses always have the high bit set.
  742. */
  743. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  744. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  745. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  746. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  747. ori r4,r4,1 /* add _PAGE_PRESENT */
  748. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  749. /*
  750. * On iSeries, we soft-disable interrupts here, then
  751. * hard-enable interrupts so that the hash_page code can spin on
  752. * the hash_table_lock without problems on a shared processor.
  753. */
  754. DISABLE_INTS
  755. /*
  756. * r3 contains the faulting address
  757. * r4 contains the required access permissions
  758. * r5 contains the trap number
  759. *
  760. * at return r3 = 0 for success
  761. */
  762. bl .hash_page /* build HPTE if possible */
  763. cmpdi r3,0 /* see if hash_page succeeded */
  764. #ifdef DO_SOFT_DISABLE
  765. BEGIN_FW_FTR_SECTION
  766. /*
  767. * If we had interrupts soft-enabled at the point where the
  768. * DSI/ISI occurred, and an interrupt came in during hash_page,
  769. * handle it now.
  770. * We jump to ret_from_except_lite rather than fast_exception_return
  771. * because ret_from_except_lite will check for and handle pending
  772. * interrupts if necessary.
  773. */
  774. beq 13f
  775. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  776. #endif
  777. BEGIN_FW_FTR_SECTION
  778. /*
  779. * Here we have interrupts hard-disabled, so it is sufficient
  780. * to restore paca->{soft,hard}_enable and get out.
  781. */
  782. beq fast_exc_return_irq /* Return from exception on success */
  783. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  784. /* For a hash failure, we don't bother re-enabling interrupts */
  785. ble- 12f
  786. /*
  787. * hash_page couldn't handle it, set soft interrupt enable back
  788. * to what it was before the trap. Note that .local_irq_restore
  789. * handles any interrupts pending at this point.
  790. */
  791. ld r3,SOFTE(r1)
  792. bl .local_irq_restore
  793. b 11f
  794. /* Here we have a page fault that hash_page can't handle. */
  795. handle_page_fault:
  796. ENABLE_INTS
  797. 11: ld r4,_DAR(r1)
  798. ld r5,_DSISR(r1)
  799. addi r3,r1,STACK_FRAME_OVERHEAD
  800. bl .do_page_fault
  801. cmpdi r3,0
  802. beq+ 13f
  803. bl .save_nvgprs
  804. mr r5,r3
  805. addi r3,r1,STACK_FRAME_OVERHEAD
  806. lwz r4,_DAR(r1)
  807. bl .bad_page_fault
  808. b .ret_from_except
  809. 13: b .ret_from_except_lite
  810. /* We have a page fault that hash_page could handle but HV refused
  811. * the PTE insertion
  812. */
  813. 12: bl .save_nvgprs
  814. addi r3,r1,STACK_FRAME_OVERHEAD
  815. ld r4,_DAR(r1)
  816. bl .low_hash_fault
  817. b .ret_from_except
  818. /* here we have a segment miss */
  819. do_ste_alloc:
  820. bl .ste_allocate /* try to insert stab entry */
  821. cmpdi r3,0
  822. bne- handle_page_fault
  823. b fast_exception_return
  824. /*
  825. * r13 points to the PACA, r9 contains the saved CR,
  826. * r11 and r12 contain the saved SRR0 and SRR1.
  827. * r9 - r13 are saved in paca->exslb.
  828. * We assume we aren't going to take any exceptions during this procedure.
  829. * We assume (DAR >> 60) == 0xc.
  830. */
  831. .align 7
  832. _GLOBAL(do_stab_bolted)
  833. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  834. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  835. /* Hash to the primary group */
  836. ld r10,PACASTABVIRT(r13)
  837. mfspr r11,SPRN_DAR
  838. srdi r11,r11,28
  839. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  840. /* Calculate VSID */
  841. /* This is a kernel address, so protovsid = ESID */
  842. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  843. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  844. /* Search the primary group for a free entry */
  845. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  846. andi. r11,r11,0x80
  847. beq 2f
  848. addi r10,r10,16
  849. andi. r11,r10,0x70
  850. bne 1b
  851. /* Stick for only searching the primary group for now. */
  852. /* At least for now, we use a very simple random castout scheme */
  853. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  854. mftb r11
  855. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  856. ori r11,r11,0x10
  857. /* r10 currently points to an ste one past the group of interest */
  858. /* make it point to the randomly selected entry */
  859. subi r10,r10,128
  860. or r10,r10,r11 /* r10 is the entry to invalidate */
  861. isync /* mark the entry invalid */
  862. ld r11,0(r10)
  863. rldicl r11,r11,56,1 /* clear the valid bit */
  864. rotldi r11,r11,8
  865. std r11,0(r10)
  866. sync
  867. clrrdi r11,r11,28 /* Get the esid part of the ste */
  868. slbie r11
  869. 2: std r9,8(r10) /* Store the vsid part of the ste */
  870. eieio
  871. mfspr r11,SPRN_DAR /* Get the new esid */
  872. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  873. ori r11,r11,0x90 /* Turn on valid and kp */
  874. std r11,0(r10) /* Put new entry back into the stab */
  875. sync
  876. /* All done -- return from exception. */
  877. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  878. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  879. andi. r10,r12,MSR_RI
  880. beq- unrecov_slb
  881. mtcrf 0x80,r9 /* restore CR */
  882. mfmsr r10
  883. clrrdi r10,r10,2
  884. mtmsrd r10,1
  885. mtspr SPRN_SRR0,r11
  886. mtspr SPRN_SRR1,r12
  887. ld r9,PACA_EXSLB+EX_R9(r13)
  888. ld r10,PACA_EXSLB+EX_R10(r13)
  889. ld r11,PACA_EXSLB+EX_R11(r13)
  890. ld r12,PACA_EXSLB+EX_R12(r13)
  891. ld r13,PACA_EXSLB+EX_R13(r13)
  892. rfid
  893. b . /* prevent speculative execution */
  894. /*
  895. * Space for CPU0's segment table.
  896. *
  897. * On iSeries, the hypervisor must fill in at least one entry before
  898. * we get control (with relocate on). The address is given to the hv
  899. * as a page number (see xLparMap below), so this must be at a
  900. * fixed address (the linker can't compute (u64)&initial_stab >>
  901. * PAGE_SHIFT).
  902. */
  903. . = STAB0_OFFSET /* 0x6000 */
  904. .globl initial_stab
  905. initial_stab:
  906. .space 4096
  907. #ifdef CONFIG_PPC_PSERIES
  908. /*
  909. * Data area reserved for FWNMI option.
  910. * This address (0x7000) is fixed by the RPA.
  911. */
  912. .= 0x7000
  913. .globl fwnmi_data_area
  914. fwnmi_data_area:
  915. #endif /* CONFIG_PPC_PSERIES */
  916. /* iSeries does not use the FWNMI stuff, so it is safe to put
  917. * this here, even if we later allow kernels that will boot on
  918. * both pSeries and iSeries */
  919. #ifdef CONFIG_PPC_ISERIES
  920. . = LPARMAP_PHYS
  921. .globl xLparMap
  922. xLparMap:
  923. .quad HvEsidsToMap /* xNumberEsids */
  924. .quad HvRangesToMap /* xNumberRanges */
  925. .quad STAB0_PAGE /* xSegmentTableOffs */
  926. .zero 40 /* xRsvd */
  927. /* xEsids (HvEsidsToMap entries of 2 quads) */
  928. .quad PAGE_OFFSET_ESID /* xKernelEsid */
  929. .quad PAGE_OFFSET_VSID /* xKernelVsid */
  930. .quad VMALLOC_START_ESID /* xKernelEsid */
  931. .quad VMALLOC_START_VSID /* xKernelVsid */
  932. /* xRanges (HvRangesToMap entries of 3 quads) */
  933. .quad HvPagesToMap /* xPages */
  934. .quad 0 /* xOffset */
  935. .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
  936. #endif /* CONFIG_PPC_ISERIES */
  937. #ifdef CONFIG_PPC_PSERIES
  938. . = 0x8000
  939. #endif /* CONFIG_PPC_PSERIES */
  940. /*
  941. * On pSeries and most other platforms, secondary processors spin
  942. * in the following code.
  943. * At entry, r3 = this processor's number (physical cpu id)
  944. */
  945. _GLOBAL(generic_secondary_smp_init)
  946. mr r24,r3
  947. /* turn on 64-bit mode */
  948. bl .enable_64b_mode
  949. /* Set up a paca value for this processor. Since we have the
  950. * physical cpu id in r24, we need to search the pacas to find
  951. * which logical id maps to our physical one.
  952. */
  953. LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
  954. li r5,0 /* logical cpu id */
  955. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  956. cmpw r6,r24 /* Compare to our id */
  957. beq 2f
  958. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  959. addi r5,r5,1
  960. cmpwi r5,NR_CPUS
  961. blt 1b
  962. mr r3,r24 /* not found, copy phys to r3 */
  963. b .kexec_wait /* next kernel might do better */
  964. 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  965. /* From now on, r24 is expected to be logical cpuid */
  966. mr r24,r5
  967. 3: HMT_LOW
  968. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  969. /* start. */
  970. sync
  971. #ifndef CONFIG_SMP
  972. b 3b /* Never go on non-SMP */
  973. #else
  974. cmpwi 0,r23,0
  975. beq 3b /* Loop until told to go */
  976. /* See if we need to call a cpu state restore handler */
  977. LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
  978. ld r23,0(r23)
  979. ld r23,CPU_SPEC_RESTORE(r23)
  980. cmpdi 0,r23,0
  981. beq 4f
  982. ld r23,0(r23)
  983. mtctr r23
  984. bctrl
  985. 4: /* Create a temp kernel stack for use before relocation is on. */
  986. ld r1,PACAEMERGSP(r13)
  987. subi r1,r1,STACK_FRAME_OVERHEAD
  988. b __secondary_start
  989. #endif
  990. _STATIC(__mmu_off)
  991. mfmsr r3
  992. andi. r0,r3,MSR_IR|MSR_DR
  993. beqlr
  994. andc r3,r3,r0
  995. mtspr SPRN_SRR0,r4
  996. mtspr SPRN_SRR1,r3
  997. sync
  998. rfid
  999. b . /* prevent speculative execution */
  1000. /*
  1001. * Here is our main kernel entry point. We support currently 2 kind of entries
  1002. * depending on the value of r5.
  1003. *
  1004. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  1005. * in r3...r7
  1006. *
  1007. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  1008. * DT block, r4 is a physical pointer to the kernel itself
  1009. *
  1010. */
  1011. _GLOBAL(__start_initialization_multiplatform)
  1012. /*
  1013. * Are we booted from a PROM Of-type client-interface ?
  1014. */
  1015. cmpldi cr0,r5,0
  1016. beq 1f
  1017. b .__boot_from_prom /* yes -> prom */
  1018. 1:
  1019. /* Save parameters */
  1020. mr r31,r3
  1021. mr r30,r4
  1022. /* Make sure we are running in 64 bits mode */
  1023. bl .enable_64b_mode
  1024. /* Setup some critical 970 SPRs before switching MMU off */
  1025. mfspr r0,SPRN_PVR
  1026. srwi r0,r0,16
  1027. cmpwi r0,0x39 /* 970 */
  1028. beq 1f
  1029. cmpwi r0,0x3c /* 970FX */
  1030. beq 1f
  1031. cmpwi r0,0x44 /* 970MP */
  1032. beq 1f
  1033. cmpwi r0,0x45 /* 970GX */
  1034. bne 2f
  1035. 1: bl .__cpu_preinit_ppc970
  1036. 2:
  1037. /* Switch off MMU if not already */
  1038. LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
  1039. add r4,r4,r30
  1040. bl .__mmu_off
  1041. b .__after_prom_start
  1042. _INIT_STATIC(__boot_from_prom)
  1043. /* Save parameters */
  1044. mr r31,r3
  1045. mr r30,r4
  1046. mr r29,r5
  1047. mr r28,r6
  1048. mr r27,r7
  1049. /*
  1050. * Align the stack to 16-byte boundary
  1051. * Depending on the size and layout of the ELF sections in the initial
  1052. * boot binary, the stack pointer will be unalignet on PowerMac
  1053. */
  1054. rldicr r1,r1,0,59
  1055. /* Make sure we are running in 64 bits mode */
  1056. bl .enable_64b_mode
  1057. /* put a relocation offset into r3 */
  1058. bl .reloc_offset
  1059. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1060. addi r2,r2,0x4000
  1061. addi r2,r2,0x4000
  1062. /* Relocate the TOC from a virt addr to a real addr */
  1063. add r2,r2,r3
  1064. /* Restore parameters */
  1065. mr r3,r31
  1066. mr r4,r30
  1067. mr r5,r29
  1068. mr r6,r28
  1069. mr r7,r27
  1070. /* Do all of the interaction with OF client interface */
  1071. bl .prom_init
  1072. /* We never return */
  1073. trap
  1074. _STATIC(__after_prom_start)
  1075. /*
  1076. * We need to run with __start at physical address PHYSICAL_START.
  1077. * This will leave some code in the first 256B of
  1078. * real memory, which are reserved for software use.
  1079. * The remainder of the first page is loaded with the fixed
  1080. * interrupt vectors. The next two pages are filled with
  1081. * unknown exception placeholders.
  1082. *
  1083. * Note: This process overwrites the OF exception vectors.
  1084. * r26 == relocation offset
  1085. * r27 == KERNELBASE
  1086. */
  1087. bl .reloc_offset
  1088. mr r26,r3
  1089. LOAD_REG_IMMEDIATE(r27, KERNELBASE)
  1090. LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
  1091. // XXX FIXME: Use phys returned by OF (r30)
  1092. add r4,r27,r26 /* source addr */
  1093. /* current address of _start */
  1094. /* i.e. where we are running */
  1095. /* the source addr */
  1096. cmpdi r4,0 /* In some cases the loader may */
  1097. bne 1f
  1098. b .start_here_multiplatform /* have already put us at zero */
  1099. /* so we can skip the copy. */
  1100. 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
  1101. sub r5,r5,r27
  1102. li r6,0x100 /* Start offset, the first 0x100 */
  1103. /* bytes were copied earlier. */
  1104. bl .copy_and_flush /* copy the first n bytes */
  1105. /* this includes the code being */
  1106. /* executed here. */
  1107. LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
  1108. mtctr r0 /* that we just made/relocated */
  1109. bctr
  1110. 4: LOAD_REG_IMMEDIATE(r5,klimit)
  1111. add r5,r5,r26
  1112. ld r5,0(r5) /* get the value of klimit */
  1113. sub r5,r5,r27
  1114. bl .copy_and_flush /* copy the rest */
  1115. b .start_here_multiplatform
  1116. /*
  1117. * Copy routine used to copy the kernel to start at physical address 0
  1118. * and flush and invalidate the caches as needed.
  1119. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  1120. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  1121. *
  1122. * Note: this routine *only* clobbers r0, r6 and lr
  1123. */
  1124. _GLOBAL(copy_and_flush)
  1125. addi r5,r5,-8
  1126. addi r6,r6,-8
  1127. 4: li r0,8 /* Use the smallest common */
  1128. /* denominator cache line */
  1129. /* size. This results in */
  1130. /* extra cache line flushes */
  1131. /* but operation is correct. */
  1132. /* Can't get cache line size */
  1133. /* from NACA as it is being */
  1134. /* moved too. */
  1135. mtctr r0 /* put # words/line in ctr */
  1136. 3: addi r6,r6,8 /* copy a cache line */
  1137. ldx r0,r6,r4
  1138. stdx r0,r6,r3
  1139. bdnz 3b
  1140. dcbst r6,r3 /* write it to memory */
  1141. sync
  1142. icbi r6,r3 /* flush the icache line */
  1143. cmpld 0,r6,r5
  1144. blt 4b
  1145. sync
  1146. addi r5,r5,8
  1147. addi r6,r6,8
  1148. blr
  1149. .align 8
  1150. copy_to_here:
  1151. #ifdef CONFIG_SMP
  1152. #ifdef CONFIG_PPC_PMAC
  1153. /*
  1154. * On PowerMac, secondary processors starts from the reset vector, which
  1155. * is temporarily turned into a call to one of the functions below.
  1156. */
  1157. .section ".text";
  1158. .align 2 ;
  1159. .globl __secondary_start_pmac_0
  1160. __secondary_start_pmac_0:
  1161. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  1162. li r24,0
  1163. b 1f
  1164. li r24,1
  1165. b 1f
  1166. li r24,2
  1167. b 1f
  1168. li r24,3
  1169. 1:
  1170. _GLOBAL(pmac_secondary_start)
  1171. /* turn on 64-bit mode */
  1172. bl .enable_64b_mode
  1173. /* Copy some CPU settings from CPU 0 */
  1174. bl .__restore_cpu_ppc970
  1175. /* pSeries do that early though I don't think we really need it */
  1176. mfmsr r3
  1177. ori r3,r3,MSR_RI
  1178. mtmsrd r3 /* RI on */
  1179. /* Set up a paca value for this processor. */
  1180. LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
  1181. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  1182. add r13,r13,r4 /* for this processor. */
  1183. mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1184. /* Create a temp kernel stack for use before relocation is on. */
  1185. ld r1,PACAEMERGSP(r13)
  1186. subi r1,r1,STACK_FRAME_OVERHEAD
  1187. b __secondary_start
  1188. #endif /* CONFIG_PPC_PMAC */
  1189. /*
  1190. * This function is called after the master CPU has released the
  1191. * secondary processors. The execution environment is relocation off.
  1192. * The paca for this processor has the following fields initialized at
  1193. * this point:
  1194. * 1. Processor number
  1195. * 2. Segment table pointer (virtual address)
  1196. * On entry the following are set:
  1197. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  1198. * r24 = cpu# (in Linux terms)
  1199. * r13 = paca virtual address
  1200. * SPRG3 = paca virtual address
  1201. */
  1202. .globl __secondary_start
  1203. __secondary_start:
  1204. /* Set thread priority to MEDIUM */
  1205. HMT_MEDIUM
  1206. /* Load TOC */
  1207. ld r2,PACATOC(r13)
  1208. /* Do early setup for that CPU (stab, slb, hash table pointer) */
  1209. bl .early_setup_secondary
  1210. /* Initialize the kernel stack. Just a repeat for iSeries. */
  1211. LOAD_REG_ADDR(r3, current_set)
  1212. sldi r28,r24,3 /* get current_set[cpu#] */
  1213. ldx r1,r3,r28
  1214. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1215. std r1,PACAKSAVE(r13)
  1216. /* Clear backchain so we get nice backtraces */
  1217. li r7,0
  1218. mtlr r7
  1219. /* enable MMU and jump to start_secondary */
  1220. LOAD_REG_ADDR(r3, .start_secondary_prolog)
  1221. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1222. #ifdef CONFIG_PPC_ISERIES
  1223. BEGIN_FW_FTR_SECTION
  1224. ori r4,r4,MSR_EE
  1225. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1226. #endif
  1227. BEGIN_FW_FTR_SECTION
  1228. stb r7,PACASOFTIRQEN(r13)
  1229. stb r7,PACAHARDIRQEN(r13)
  1230. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  1231. mtspr SPRN_SRR0,r3
  1232. mtspr SPRN_SRR1,r4
  1233. rfid
  1234. b . /* prevent speculative execution */
  1235. /*
  1236. * Running with relocation on at this point. All we want to do is
  1237. * zero the stack back-chain pointer before going into C code.
  1238. */
  1239. _GLOBAL(start_secondary_prolog)
  1240. li r3,0
  1241. std r3,0(r1) /* Zero the stack frame pointer */
  1242. bl .start_secondary
  1243. b .
  1244. #endif
  1245. /*
  1246. * This subroutine clobbers r11 and r12
  1247. */
  1248. _GLOBAL(enable_64b_mode)
  1249. mfmsr r11 /* grab the current MSR */
  1250. li r12,1
  1251. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  1252. or r11,r11,r12
  1253. li r12,1
  1254. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  1255. or r11,r11,r12
  1256. mtmsrd r11
  1257. isync
  1258. blr
  1259. /*
  1260. * This is where the main kernel code starts.
  1261. */
  1262. _INIT_STATIC(start_here_multiplatform)
  1263. /* get a new offset, now that the kernel has moved. */
  1264. bl .reloc_offset
  1265. mr r26,r3
  1266. /* Clear out the BSS. It may have been done in prom_init,
  1267. * already but that's irrelevant since prom_init will soon
  1268. * be detached from the kernel completely. Besides, we need
  1269. * to clear it now for kexec-style entry.
  1270. */
  1271. LOAD_REG_IMMEDIATE(r11,__bss_stop)
  1272. LOAD_REG_IMMEDIATE(r8,__bss_start)
  1273. sub r11,r11,r8 /* bss size */
  1274. addi r11,r11,7 /* round up to an even double word */
  1275. rldicl. r11,r11,61,3 /* shift right by 3 */
  1276. beq 4f
  1277. addi r8,r8,-8
  1278. li r0,0
  1279. mtctr r11 /* zero this many doublewords */
  1280. 3: stdu r0,8(r8)
  1281. bdnz 3b
  1282. 4:
  1283. mfmsr r6
  1284. ori r6,r6,MSR_RI
  1285. mtmsrd r6 /* RI on */
  1286. /* The following gets the stack and TOC set up with the regs */
  1287. /* pointing to the real addr of the kernel stack. This is */
  1288. /* all done to support the C function call below which sets */
  1289. /* up the htab. This is done because we have relocated the */
  1290. /* kernel but are still running in real mode. */
  1291. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1292. add r3,r3,r26
  1293. /* set up a stack pointer (physical address) */
  1294. addi r1,r3,THREAD_SIZE
  1295. li r0,0
  1296. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1297. /* set up the TOC (physical address) */
  1298. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1299. addi r2,r2,0x4000
  1300. addi r2,r2,0x4000
  1301. add r2,r2,r26
  1302. /* Do very early kernel initializations, including initial hash table,
  1303. * stab and slb setup before we turn on relocation. */
  1304. /* Restore parameters passed from prom_init/kexec */
  1305. mr r3,r31
  1306. bl .early_setup
  1307. LOAD_REG_IMMEDIATE(r3, .start_here_common)
  1308. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1309. mtspr SPRN_SRR0,r3
  1310. mtspr SPRN_SRR1,r4
  1311. rfid
  1312. b . /* prevent speculative execution */
  1313. /* This is where all platforms converge execution */
  1314. _INIT_GLOBAL(start_here_common)
  1315. /* relocation is on at this point */
  1316. /* The following code sets up the SP and TOC now that we are */
  1317. /* running with translation enabled. */
  1318. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1319. /* set up the stack */
  1320. addi r1,r3,THREAD_SIZE
  1321. li r0,0
  1322. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1323. /* ptr to current */
  1324. LOAD_REG_IMMEDIATE(r4, init_task)
  1325. std r4,PACACURRENT(r13)
  1326. /* Load the TOC */
  1327. ld r2,PACATOC(r13)
  1328. std r1,PACAKSAVE(r13)
  1329. bl .setup_system
  1330. /* Load up the kernel context */
  1331. 5:
  1332. li r5,0
  1333. stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
  1334. #ifdef CONFIG_PPC_ISERIES
  1335. BEGIN_FW_FTR_SECTION
  1336. mfmsr r5
  1337. ori r5,r5,MSR_EE /* Hard Enabled */
  1338. mtmsrd r5
  1339. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1340. #endif
  1341. BEGIN_FW_FTR_SECTION
  1342. stb r5,PACAHARDIRQEN(r13)
  1343. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  1344. bl .start_kernel
  1345. /* Not reached */
  1346. BUG_OPCODE
  1347. /*
  1348. * We put a few things here that have to be page-aligned.
  1349. * This stuff goes at the beginning of the bss, which is page-aligned.
  1350. */
  1351. .section ".bss"
  1352. .align PAGE_SHIFT
  1353. .globl empty_zero_page
  1354. empty_zero_page:
  1355. .space PAGE_SIZE
  1356. .globl swapper_pg_dir
  1357. swapper_pg_dir:
  1358. .space PGD_TABLE_SIZE