head_64.S 40 KB

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