head.S 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. /*
  2. * arch/ppc64/kernel/head.S
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  8. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  9. * Adapted for Power Macintosh by Paul Mackerras.
  10. * Low-level exception handlers and MMU support
  11. * rewritten by Paul Mackerras.
  12. * Copyright (C) 1996 Paul Mackerras.
  13. *
  14. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  15. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  16. *
  17. * This file contains the low-level support and setup for the
  18. * PowerPC-64 platform, including trap and interrupt dispatch.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License
  22. * as published by the Free Software Foundation; either version
  23. * 2 of the License, or (at your option) any later version.
  24. */
  25. #include <linux/config.h>
  26. #include <linux/threads.h>
  27. #include <asm/processor.h>
  28. #include <asm/page.h>
  29. #include <asm/mmu.h>
  30. #include <asm/systemcfg.h>
  31. #include <asm/ppc_asm.h>
  32. #include <asm/asm-offsets.h>
  33. #include <asm/bug.h>
  34. #include <asm/cputable.h>
  35. #include <asm/setup.h>
  36. #include <asm/hvcall.h>
  37. #include <asm/iseries/lpar_map.h>
  38. #include <asm/thread_info.h>
  39. #ifdef CONFIG_PPC_ISERIES
  40. #define DO_SOFT_DISABLE
  41. #endif
  42. /*
  43. * We layout physical memory as follows:
  44. * 0x0000 - 0x00ff : Secondary processor spin code
  45. * 0x0100 - 0x2fff : pSeries Interrupt prologs
  46. * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
  47. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  48. * 0x7000 - 0x7fff : FWNMI data area
  49. * 0x8000 - : Early init and support code
  50. */
  51. /*
  52. * SPRG Usage
  53. *
  54. * Register Definition
  55. *
  56. * SPRG0 reserved for hypervisor
  57. * SPRG1 temp - used to save gpr
  58. * SPRG2 temp - used to save gpr
  59. * SPRG3 virt addr of paca
  60. */
  61. /*
  62. * Entering into this code we make the following assumptions:
  63. * For pSeries:
  64. * 1. The MMU is off & open firmware is running in real mode.
  65. * 2. The kernel is entered at __start
  66. *
  67. * For iSeries:
  68. * 1. The MMU is on (as it always is for iSeries)
  69. * 2. The kernel is entered at system_reset_iSeries
  70. */
  71. .text
  72. .globl _stext
  73. _stext:
  74. #ifdef CONFIG_PPC_MULTIPLATFORM
  75. _GLOBAL(__start)
  76. /* NOP this out unconditionally */
  77. BEGIN_FTR_SECTION
  78. b .__start_initialization_multiplatform
  79. END_FTR_SECTION(0, 1)
  80. #endif /* CONFIG_PPC_MULTIPLATFORM */
  81. /* Catch branch to 0 in real mode */
  82. trap
  83. #ifdef CONFIG_PPC_ISERIES
  84. /*
  85. * At offset 0x20, there is a pointer to iSeries LPAR data.
  86. * This is required by the hypervisor
  87. */
  88. . = 0x20
  89. .llong hvReleaseData-KERNELBASE
  90. /*
  91. * At offset 0x28 and 0x30 are offsets to the mschunks_map
  92. * array (used by the iSeries LPAR debugger to do translation
  93. * between physical addresses and absolute addresses) and
  94. * to the pidhash table (also used by the debugger)
  95. */
  96. .llong mschunks_map-KERNELBASE
  97. .llong 0 /* pidhash-KERNELBASE SFRXXX */
  98. /* Offset 0x38 - Pointer to start of embedded System.map */
  99. .globl embedded_sysmap_start
  100. embedded_sysmap_start:
  101. .llong 0
  102. /* Offset 0x40 - Pointer to end of embedded System.map */
  103. .globl embedded_sysmap_end
  104. embedded_sysmap_end:
  105. .llong 0
  106. #endif /* CONFIG_PPC_ISERIES */
  107. /* Secondary processors spin on this value until it goes to 1. */
  108. .globl __secondary_hold_spinloop
  109. __secondary_hold_spinloop:
  110. .llong 0x0
  111. /* Secondary processors write this value with their cpu # */
  112. /* after they enter the spin loop immediately below. */
  113. .globl __secondary_hold_acknowledge
  114. __secondary_hold_acknowledge:
  115. .llong 0x0
  116. . = 0x60
  117. /*
  118. * The following code is used on pSeries to hold secondary processors
  119. * in a spin loop after they have been freed from OpenFirmware, but
  120. * before the bulk of the kernel has been relocated. This code
  121. * is relocated to physical address 0x60 before prom_init is run.
  122. * All of it must fit below the first exception vector at 0x100.
  123. */
  124. _GLOBAL(__secondary_hold)
  125. mfmsr r24
  126. ori r24,r24,MSR_RI
  127. mtmsrd r24 /* RI on */
  128. /* Grab our linux cpu number */
  129. mr r24,r3
  130. /* Tell the master cpu we're here */
  131. /* Relocation is off & we are located at an address less */
  132. /* than 0x100, so only need to grab low order offset. */
  133. std r24,__secondary_hold_acknowledge@l(0)
  134. sync
  135. /* All secondary cpus wait here until told to start. */
  136. 100: ld r4,__secondary_hold_spinloop@l(0)
  137. cmpdi 0,r4,1
  138. bne 100b
  139. #ifdef CONFIG_HMT
  140. b .hmt_init
  141. #else
  142. #ifdef CONFIG_SMP
  143. mr r3,r24
  144. b .pSeries_secondary_smp_init
  145. #else
  146. BUG_OPCODE
  147. #endif
  148. #endif
  149. /* This value is used to mark exception frames on the stack. */
  150. .section ".toc","aw"
  151. exception_marker:
  152. .tc ID_72656773_68657265[TC],0x7265677368657265
  153. .text
  154. /*
  155. * The following macros define the code that appears as
  156. * the prologue to each of the exception handlers. They
  157. * are split into two parts to allow a single kernel binary
  158. * to be used for pSeries and iSeries.
  159. * LOL. One day... - paulus
  160. */
  161. /*
  162. * We make as much of the exception code common between native
  163. * exception handlers (including pSeries LPAR) and iSeries LPAR
  164. * implementations as possible.
  165. */
  166. /*
  167. * This is the start of the interrupt handlers for pSeries
  168. * This code runs with relocation off.
  169. */
  170. #define EX_R9 0
  171. #define EX_R10 8
  172. #define EX_R11 16
  173. #define EX_R12 24
  174. #define EX_R13 32
  175. #define EX_SRR0 40
  176. #define EX_R3 40 /* SLB miss saves R3, but not SRR0 */
  177. #define EX_DAR 48
  178. #define EX_LR 48 /* SLB miss saves LR, but not DAR */
  179. #define EX_DSISR 56
  180. #define EX_CCR 60
  181. #define EXCEPTION_PROLOG_PSERIES(area, label) \
  182. mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
  183. std r9,area+EX_R9(r13); /* save r9 - r12 */ \
  184. std r10,area+EX_R10(r13); \
  185. std r11,area+EX_R11(r13); \
  186. std r12,area+EX_R12(r13); \
  187. mfspr r9,SPRN_SPRG1; \
  188. std r9,area+EX_R13(r13); \
  189. mfcr r9; \
  190. clrrdi r12,r13,32; /* get high part of &label */ \
  191. mfmsr r10; \
  192. mfspr r11,SPRN_SRR0; /* save SRR0 */ \
  193. ori r12,r12,(label)@l; /* virt addr of handler */ \
  194. ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
  195. mtspr SPRN_SRR0,r12; \
  196. mfspr r12,SPRN_SRR1; /* and SRR1 */ \
  197. mtspr SPRN_SRR1,r10; \
  198. rfid; \
  199. b . /* prevent speculative execution */
  200. /*
  201. * This is the start of the interrupt handlers for iSeries
  202. * This code runs with relocation on.
  203. */
  204. #define EXCEPTION_PROLOG_ISERIES_1(area) \
  205. mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
  206. std r9,area+EX_R9(r13); /* save r9 - r12 */ \
  207. std r10,area+EX_R10(r13); \
  208. std r11,area+EX_R11(r13); \
  209. std r12,area+EX_R12(r13); \
  210. mfspr r9,SPRN_SPRG1; \
  211. std r9,area+EX_R13(r13); \
  212. mfcr r9
  213. #define EXCEPTION_PROLOG_ISERIES_2 \
  214. mfmsr r10; \
  215. ld r11,PACALPPACA+LPPACASRR0(r13); \
  216. ld r12,PACALPPACA+LPPACASRR1(r13); \
  217. ori r10,r10,MSR_RI; \
  218. mtmsrd r10,1
  219. /*
  220. * The common exception prolog is used for all except a few exceptions
  221. * such as a segment miss on a kernel address. We have to be prepared
  222. * to take another exception from the point where we first touch the
  223. * kernel stack onwards.
  224. *
  225. * On entry r13 points to the paca, r9-r13 are saved in the paca,
  226. * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
  227. * SRR1, and relocation is on.
  228. */
  229. #define EXCEPTION_PROLOG_COMMON(n, area) \
  230. andi. r10,r12,MSR_PR; /* See if coming from user */ \
  231. mr r10,r1; /* Save r1 */ \
  232. subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
  233. beq- 1f; \
  234. ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
  235. 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
  236. bge- cr1,bad_stack; /* abort if it is */ \
  237. std r9,_CCR(r1); /* save CR in stackframe */ \
  238. std r11,_NIP(r1); /* save SRR0 in stackframe */ \
  239. std r12,_MSR(r1); /* save SRR1 in stackframe */ \
  240. std r10,0(r1); /* make stack chain pointer */ \
  241. std r0,GPR0(r1); /* save r0 in stackframe */ \
  242. std r10,GPR1(r1); /* save r1 in stackframe */ \
  243. std r2,GPR2(r1); /* save r2 in stackframe */ \
  244. SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
  245. SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
  246. ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
  247. ld r10,area+EX_R10(r13); \
  248. std r9,GPR9(r1); \
  249. std r10,GPR10(r1); \
  250. ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
  251. ld r10,area+EX_R12(r13); \
  252. ld r11,area+EX_R13(r13); \
  253. std r9,GPR11(r1); \
  254. std r10,GPR12(r1); \
  255. std r11,GPR13(r1); \
  256. ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
  257. mflr r9; /* save LR in stackframe */ \
  258. std r9,_LINK(r1); \
  259. mfctr r10; /* save CTR in stackframe */ \
  260. std r10,_CTR(r1); \
  261. mfspr r11,SPRN_XER; /* save XER in stackframe */ \
  262. std r11,_XER(r1); \
  263. li r9,(n)+1; \
  264. std r9,_TRAP(r1); /* set trap number */ \
  265. li r10,0; \
  266. ld r11,exception_marker@toc(r2); \
  267. std r10,RESULT(r1); /* clear regs->result */ \
  268. std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
  269. /*
  270. * Exception vectors.
  271. */
  272. #define STD_EXCEPTION_PSERIES(n, label) \
  273. . = n; \
  274. .globl label##_pSeries; \
  275. label##_pSeries: \
  276. HMT_MEDIUM; \
  277. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  278. RUNLATCH_ON(r13); \
  279. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
  280. #define STD_EXCEPTION_ISERIES(n, label, area) \
  281. .globl label##_iSeries; \
  282. label##_iSeries: \
  283. HMT_MEDIUM; \
  284. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  285. RUNLATCH_ON(r13); \
  286. EXCEPTION_PROLOG_ISERIES_1(area); \
  287. EXCEPTION_PROLOG_ISERIES_2; \
  288. b label##_common
  289. #define MASKABLE_EXCEPTION_ISERIES(n, label) \
  290. .globl label##_iSeries; \
  291. label##_iSeries: \
  292. HMT_MEDIUM; \
  293. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  294. RUNLATCH_ON(r13); \
  295. EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \
  296. lbz r10,PACAPROCENABLED(r13); \
  297. cmpwi 0,r10,0; \
  298. beq- label##_iSeries_masked; \
  299. EXCEPTION_PROLOG_ISERIES_2; \
  300. b label##_common; \
  301. #ifdef DO_SOFT_DISABLE
  302. #define DISABLE_INTS \
  303. lbz r10,PACAPROCENABLED(r13); \
  304. li r11,0; \
  305. std r10,SOFTE(r1); \
  306. mfmsr r10; \
  307. stb r11,PACAPROCENABLED(r13); \
  308. ori r10,r10,MSR_EE; \
  309. mtmsrd r10,1
  310. #define ENABLE_INTS \
  311. lbz r10,PACAPROCENABLED(r13); \
  312. mfmsr r11; \
  313. std r10,SOFTE(r1); \
  314. ori r11,r11,MSR_EE; \
  315. mtmsrd r11,1
  316. #else /* hard enable/disable interrupts */
  317. #define DISABLE_INTS
  318. #define ENABLE_INTS \
  319. ld r12,_MSR(r1); \
  320. mfmsr r11; \
  321. rlwimi r11,r12,0,MSR_EE; \
  322. mtmsrd r11,1
  323. #endif
  324. #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
  325. .align 7; \
  326. .globl label##_common; \
  327. label##_common: \
  328. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  329. DISABLE_INTS; \
  330. bl .save_nvgprs; \
  331. addi r3,r1,STACK_FRAME_OVERHEAD; \
  332. bl hdlr; \
  333. b .ret_from_except
  334. #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
  335. .align 7; \
  336. .globl label##_common; \
  337. label##_common: \
  338. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  339. DISABLE_INTS; \
  340. addi r3,r1,STACK_FRAME_OVERHEAD; \
  341. bl hdlr; \
  342. b .ret_from_except_lite
  343. /*
  344. * Start of pSeries system interrupt routines
  345. */
  346. . = 0x100
  347. .globl __start_interrupts
  348. __start_interrupts:
  349. STD_EXCEPTION_PSERIES(0x100, system_reset)
  350. . = 0x200
  351. _machine_check_pSeries:
  352. HMT_MEDIUM
  353. mtspr SPRN_SPRG1,r13 /* save r13 */
  354. RUNLATCH_ON(r13)
  355. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  356. . = 0x300
  357. .globl data_access_pSeries
  358. data_access_pSeries:
  359. HMT_MEDIUM
  360. mtspr SPRN_SPRG1,r13
  361. BEGIN_FTR_SECTION
  362. mtspr SPRN_SPRG2,r12
  363. mfspr r13,SPRN_DAR
  364. mfspr r12,SPRN_DSISR
  365. srdi r13,r13,60
  366. rlwimi r13,r12,16,0x20
  367. mfcr r12
  368. cmpwi r13,0x2c
  369. beq .do_stab_bolted_pSeries
  370. mtcrf 0x80,r12
  371. mfspr r12,SPRN_SPRG2
  372. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  373. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
  374. . = 0x380
  375. .globl data_access_slb_pSeries
  376. data_access_slb_pSeries:
  377. HMT_MEDIUM
  378. mtspr SPRN_SPRG1,r13
  379. RUNLATCH_ON(r13)
  380. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  381. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  382. std r10,PACA_EXSLB+EX_R10(r13)
  383. std r11,PACA_EXSLB+EX_R11(r13)
  384. std r12,PACA_EXSLB+EX_R12(r13)
  385. std r3,PACA_EXSLB+EX_R3(r13)
  386. mfspr r9,SPRN_SPRG1
  387. std r9,PACA_EXSLB+EX_R13(r13)
  388. mfcr r9
  389. mfspr r12,SPRN_SRR1 /* and SRR1 */
  390. mfspr r3,SPRN_DAR
  391. b .do_slb_miss /* Rel. branch works in real mode */
  392. STD_EXCEPTION_PSERIES(0x400, instruction_access)
  393. . = 0x480
  394. .globl instruction_access_slb_pSeries
  395. instruction_access_slb_pSeries:
  396. HMT_MEDIUM
  397. mtspr SPRN_SPRG1,r13
  398. RUNLATCH_ON(r13)
  399. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  400. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  401. std r10,PACA_EXSLB+EX_R10(r13)
  402. std r11,PACA_EXSLB+EX_R11(r13)
  403. std r12,PACA_EXSLB+EX_R12(r13)
  404. std r3,PACA_EXSLB+EX_R3(r13)
  405. mfspr r9,SPRN_SPRG1
  406. std r9,PACA_EXSLB+EX_R13(r13)
  407. mfcr r9
  408. mfspr r12,SPRN_SRR1 /* and SRR1 */
  409. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  410. b .do_slb_miss /* Rel. branch works in real mode */
  411. STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
  412. STD_EXCEPTION_PSERIES(0x600, alignment)
  413. STD_EXCEPTION_PSERIES(0x700, program_check)
  414. STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
  415. STD_EXCEPTION_PSERIES(0x900, decrementer)
  416. STD_EXCEPTION_PSERIES(0xa00, trap_0a)
  417. STD_EXCEPTION_PSERIES(0xb00, trap_0b)
  418. . = 0xc00
  419. .globl system_call_pSeries
  420. system_call_pSeries:
  421. HMT_MEDIUM
  422. RUNLATCH_ON(r9)
  423. mr r9,r13
  424. mfmsr r10
  425. mfspr r13,SPRN_SPRG3
  426. mfspr r11,SPRN_SRR0
  427. clrrdi r12,r13,32
  428. oris r12,r12,system_call_common@h
  429. ori r12,r12,system_call_common@l
  430. mtspr SPRN_SRR0,r12
  431. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  432. mfspr r12,SPRN_SRR1
  433. mtspr SPRN_SRR1,r10
  434. rfid
  435. b . /* prevent speculative execution */
  436. STD_EXCEPTION_PSERIES(0xd00, single_step)
  437. STD_EXCEPTION_PSERIES(0xe00, trap_0e)
  438. /* We need to deal with the Altivec unavailable exception
  439. * here which is at 0xf20, thus in the middle of the
  440. * prolog code of the PerformanceMonitor one. A little
  441. * trickery is thus necessary
  442. */
  443. . = 0xf00
  444. b performance_monitor_pSeries
  445. STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
  446. STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
  447. STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
  448. . = 0x3000
  449. /*** pSeries interrupt support ***/
  450. /* moved from 0xf00 */
  451. STD_EXCEPTION_PSERIES(., performance_monitor)
  452. .align 7
  453. _GLOBAL(do_stab_bolted_pSeries)
  454. mtcrf 0x80,r12
  455. mfspr r12,SPRN_SPRG2
  456. EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
  457. /*
  458. * Vectors for the FWNMI option. Share common code.
  459. */
  460. .globl system_reset_fwnmi
  461. system_reset_fwnmi:
  462. HMT_MEDIUM
  463. mtspr SPRN_SPRG1,r13 /* save r13 */
  464. RUNLATCH_ON(r13)
  465. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
  466. .globl machine_check_fwnmi
  467. machine_check_fwnmi:
  468. HMT_MEDIUM
  469. mtspr SPRN_SPRG1,r13 /* save r13 */
  470. RUNLATCH_ON(r13)
  471. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  472. #ifdef CONFIG_PPC_ISERIES
  473. /*** ISeries-LPAR interrupt handlers ***/
  474. STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
  475. .globl data_access_iSeries
  476. data_access_iSeries:
  477. mtspr SPRN_SPRG1,r13
  478. BEGIN_FTR_SECTION
  479. mtspr SPRN_SPRG2,r12
  480. mfspr r13,SPRN_DAR
  481. mfspr r12,SPRN_DSISR
  482. srdi r13,r13,60
  483. rlwimi r13,r12,16,0x20
  484. mfcr r12
  485. cmpwi r13,0x2c
  486. beq .do_stab_bolted_iSeries
  487. mtcrf 0x80,r12
  488. mfspr r12,SPRN_SPRG2
  489. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  490. EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
  491. EXCEPTION_PROLOG_ISERIES_2
  492. b data_access_common
  493. .do_stab_bolted_iSeries:
  494. mtcrf 0x80,r12
  495. mfspr r12,SPRN_SPRG2
  496. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  497. EXCEPTION_PROLOG_ISERIES_2
  498. b .do_stab_bolted
  499. .globl data_access_slb_iSeries
  500. data_access_slb_iSeries:
  501. mtspr SPRN_SPRG1,r13 /* save r13 */
  502. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  503. std r3,PACA_EXSLB+EX_R3(r13)
  504. ld r12,PACALPPACA+LPPACASRR1(r13)
  505. mfspr r3,SPRN_DAR
  506. b .do_slb_miss
  507. STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
  508. .globl instruction_access_slb_iSeries
  509. instruction_access_slb_iSeries:
  510. mtspr SPRN_SPRG1,r13 /* save r13 */
  511. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  512. std r3,PACA_EXSLB+EX_R3(r13)
  513. ld r12,PACALPPACA+LPPACASRR1(r13)
  514. ld r3,PACALPPACA+LPPACASRR0(r13)
  515. b .do_slb_miss
  516. MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
  517. STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
  518. STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
  519. STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
  520. MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
  521. STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
  522. STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
  523. .globl system_call_iSeries
  524. system_call_iSeries:
  525. mr r9,r13
  526. mfspr r13,SPRN_SPRG3
  527. EXCEPTION_PROLOG_ISERIES_2
  528. b system_call_common
  529. STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
  530. STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
  531. STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
  532. .globl system_reset_iSeries
  533. system_reset_iSeries:
  534. mfspr r13,SPRN_SPRG3 /* Get paca address */
  535. mfmsr r24
  536. ori r24,r24,MSR_RI
  537. mtmsrd r24 /* RI on */
  538. lhz r24,PACAPACAINDEX(r13) /* Get processor # */
  539. cmpwi 0,r24,0 /* Are we processor 0? */
  540. beq .__start_initialization_iSeries /* Start up the first processor */
  541. mfspr r4,SPRN_CTRLF
  542. li r5,CTRL_RUNLATCH /* Turn off the run light */
  543. andc r4,r4,r5
  544. mtspr SPRN_CTRLT,r4
  545. 1:
  546. HMT_LOW
  547. #ifdef CONFIG_SMP
  548. lbz r23,PACAPROCSTART(r13) /* Test if this processor
  549. * should start */
  550. sync
  551. LOADADDR(r3,current_set)
  552. sldi r28,r24,3 /* get current_set[cpu#] */
  553. ldx r3,r3,r28
  554. addi r1,r3,THREAD_SIZE
  555. subi r1,r1,STACK_FRAME_OVERHEAD
  556. cmpwi 0,r23,0
  557. beq iSeries_secondary_smp_loop /* Loop until told to go */
  558. bne .__secondary_start /* Loop until told to go */
  559. iSeries_secondary_smp_loop:
  560. /* Let the Hypervisor know we are alive */
  561. /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
  562. lis r3,0x8002
  563. rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
  564. #else /* CONFIG_SMP */
  565. /* Yield the processor. This is required for non-SMP kernels
  566. which are running on multi-threaded machines. */
  567. lis r3,0x8000
  568. rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
  569. addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
  570. li r4,0 /* "yield timed" */
  571. li r5,-1 /* "yield forever" */
  572. #endif /* CONFIG_SMP */
  573. li r0,-1 /* r0=-1 indicates a Hypervisor call */
  574. sc /* Invoke the hypervisor via a system call */
  575. mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */
  576. b 1b /* If SMP not configured, secondaries
  577. * loop forever */
  578. .globl decrementer_iSeries_masked
  579. decrementer_iSeries_masked:
  580. li r11,1
  581. stb r11,PACALPPACA+LPPACADECRINT(r13)
  582. lwz r12,PACADEFAULTDECR(r13)
  583. mtspr SPRN_DEC,r12
  584. /* fall through */
  585. .globl hardware_interrupt_iSeries_masked
  586. hardware_interrupt_iSeries_masked:
  587. mtcrf 0x80,r9 /* Restore regs */
  588. ld r11,PACALPPACA+LPPACASRR0(r13)
  589. ld r12,PACALPPACA+LPPACASRR1(r13)
  590. mtspr SPRN_SRR0,r11
  591. mtspr SPRN_SRR1,r12
  592. ld r9,PACA_EXGEN+EX_R9(r13)
  593. ld r10,PACA_EXGEN+EX_R10(r13)
  594. ld r11,PACA_EXGEN+EX_R11(r13)
  595. ld r12,PACA_EXGEN+EX_R12(r13)
  596. ld r13,PACA_EXGEN+EX_R13(r13)
  597. rfid
  598. b . /* prevent speculative execution */
  599. #endif /* CONFIG_PPC_ISERIES */
  600. /*** Common interrupt handlers ***/
  601. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  602. /*
  603. * Machine check is different because we use a different
  604. * save area: PACA_EXMC instead of PACA_EXGEN.
  605. */
  606. .align 7
  607. .globl machine_check_common
  608. machine_check_common:
  609. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  610. DISABLE_INTS
  611. bl .save_nvgprs
  612. addi r3,r1,STACK_FRAME_OVERHEAD
  613. bl .machine_check_exception
  614. b .ret_from_except
  615. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  616. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  617. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  618. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  619. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  620. STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
  621. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  622. #ifdef CONFIG_ALTIVEC
  623. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  624. #else
  625. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  626. #endif
  627. /*
  628. * Here we have detected that the kernel stack pointer is bad.
  629. * R9 contains the saved CR, r13 points to the paca,
  630. * r10 contains the (bad) kernel stack pointer,
  631. * r11 and r12 contain the saved SRR0 and SRR1.
  632. * We switch to using an emergency stack, save the registers there,
  633. * and call kernel_bad_stack(), which panics.
  634. */
  635. bad_stack:
  636. ld r1,PACAEMERGSP(r13)
  637. subi r1,r1,64+INT_FRAME_SIZE
  638. std r9,_CCR(r1)
  639. std r10,GPR1(r1)
  640. std r11,_NIP(r1)
  641. std r12,_MSR(r1)
  642. mfspr r11,SPRN_DAR
  643. mfspr r12,SPRN_DSISR
  644. std r11,_DAR(r1)
  645. std r12,_DSISR(r1)
  646. mflr r10
  647. mfctr r11
  648. mfxer r12
  649. std r10,_LINK(r1)
  650. std r11,_CTR(r1)
  651. std r12,_XER(r1)
  652. SAVE_GPR(0,r1)
  653. SAVE_GPR(2,r1)
  654. SAVE_4GPRS(3,r1)
  655. SAVE_2GPRS(7,r1)
  656. SAVE_10GPRS(12,r1)
  657. SAVE_10GPRS(22,r1)
  658. addi r11,r1,INT_FRAME_SIZE
  659. std r11,0(r1)
  660. li r12,0
  661. std r12,0(r11)
  662. ld r2,PACATOC(r13)
  663. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  664. bl .kernel_bad_stack
  665. b 1b
  666. /*
  667. * Return from an exception with minimal checks.
  668. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  669. * If interrupts have been enabled, or anything has been
  670. * done that might have changed the scheduling status of
  671. * any task or sent any task a signal, you should use
  672. * ret_from_except or ret_from_except_lite instead of this.
  673. */
  674. .globl fast_exception_return
  675. fast_exception_return:
  676. ld r12,_MSR(r1)
  677. ld r11,_NIP(r1)
  678. andi. r3,r12,MSR_RI /* check if RI is set */
  679. beq- unrecov_fer
  680. ld r3,_CCR(r1)
  681. ld r4,_LINK(r1)
  682. ld r5,_CTR(r1)
  683. ld r6,_XER(r1)
  684. mtcr r3
  685. mtlr r4
  686. mtctr r5
  687. mtxer r6
  688. REST_GPR(0, r1)
  689. REST_8GPRS(2, r1)
  690. mfmsr r10
  691. clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
  692. mtmsrd r10,1
  693. mtspr SPRN_SRR1,r12
  694. mtspr SPRN_SRR0,r11
  695. REST_4GPRS(10, r1)
  696. ld r1,GPR1(r1)
  697. rfid
  698. b . /* prevent speculative execution */
  699. unrecov_fer:
  700. bl .save_nvgprs
  701. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  702. bl .unrecoverable_exception
  703. b 1b
  704. /*
  705. * Here r13 points to the paca, r9 contains the saved CR,
  706. * SRR0 and SRR1 are saved in r11 and r12,
  707. * r9 - r13 are saved in paca->exgen.
  708. */
  709. .align 7
  710. .globl data_access_common
  711. data_access_common:
  712. RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
  713. mfspr r10,SPRN_DAR
  714. std r10,PACA_EXGEN+EX_DAR(r13)
  715. mfspr r10,SPRN_DSISR
  716. stw r10,PACA_EXGEN+EX_DSISR(r13)
  717. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  718. ld r3,PACA_EXGEN+EX_DAR(r13)
  719. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  720. li r5,0x300
  721. b .do_hash_page /* Try to handle as hpte fault */
  722. .align 7
  723. .globl instruction_access_common
  724. instruction_access_common:
  725. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  726. ld r3,_NIP(r1)
  727. andis. r4,r12,0x5820
  728. li r5,0x400
  729. b .do_hash_page /* Try to handle as hpte fault */
  730. .align 7
  731. .globl hardware_interrupt_common
  732. .globl hardware_interrupt_entry
  733. hardware_interrupt_common:
  734. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  735. hardware_interrupt_entry:
  736. DISABLE_INTS
  737. addi r3,r1,STACK_FRAME_OVERHEAD
  738. bl .do_IRQ
  739. b .ret_from_except_lite
  740. .align 7
  741. .globl alignment_common
  742. alignment_common:
  743. mfspr r10,SPRN_DAR
  744. std r10,PACA_EXGEN+EX_DAR(r13)
  745. mfspr r10,SPRN_DSISR
  746. stw r10,PACA_EXGEN+EX_DSISR(r13)
  747. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  748. ld r3,PACA_EXGEN+EX_DAR(r13)
  749. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  750. std r3,_DAR(r1)
  751. std r4,_DSISR(r1)
  752. bl .save_nvgprs
  753. addi r3,r1,STACK_FRAME_OVERHEAD
  754. ENABLE_INTS
  755. bl .alignment_exception
  756. b .ret_from_except
  757. .align 7
  758. .globl program_check_common
  759. program_check_common:
  760. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  761. bl .save_nvgprs
  762. addi r3,r1,STACK_FRAME_OVERHEAD
  763. ENABLE_INTS
  764. bl .program_check_exception
  765. b .ret_from_except
  766. .align 7
  767. .globl fp_unavailable_common
  768. fp_unavailable_common:
  769. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  770. bne .load_up_fpu /* if from user, just load it up */
  771. bl .save_nvgprs
  772. addi r3,r1,STACK_FRAME_OVERHEAD
  773. ENABLE_INTS
  774. bl .kernel_fp_unavailable_exception
  775. BUG_OPCODE
  776. .align 7
  777. .globl altivec_unavailable_common
  778. altivec_unavailable_common:
  779. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  780. #ifdef CONFIG_ALTIVEC
  781. BEGIN_FTR_SECTION
  782. bne .load_up_altivec /* if from user, just load it up */
  783. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  784. #endif
  785. bl .save_nvgprs
  786. addi r3,r1,STACK_FRAME_OVERHEAD
  787. ENABLE_INTS
  788. bl .altivec_unavailable_exception
  789. b .ret_from_except
  790. #ifdef CONFIG_ALTIVEC
  791. /*
  792. * load_up_altivec(unused, unused, tsk)
  793. * Disable VMX for the task which had it previously,
  794. * and save its vector registers in its thread_struct.
  795. * Enables the VMX for use in the kernel on return.
  796. * On SMP we know the VMX is free, since we give it up every
  797. * switch (ie, no lazy save of the vector registers).
  798. * On entry: r13 == 'current' && last_task_used_altivec != 'current'
  799. */
  800. _STATIC(load_up_altivec)
  801. mfmsr r5 /* grab the current MSR */
  802. oris r5,r5,MSR_VEC@h
  803. mtmsrd r5 /* enable use of VMX now */
  804. isync
  805. /*
  806. * For SMP, we don't do lazy VMX switching because it just gets too
  807. * horrendously complex, especially when a task switches from one CPU
  808. * to another. Instead we call giveup_altvec in switch_to.
  809. * VRSAVE isn't dealt with here, that is done in the normal context
  810. * switch code. Note that we could rely on vrsave value to eventually
  811. * avoid saving all of the VREGs here...
  812. */
  813. #ifndef CONFIG_SMP
  814. ld r3,last_task_used_altivec@got(r2)
  815. ld r4,0(r3)
  816. cmpdi 0,r4,0
  817. beq 1f
  818. /* Save VMX state to last_task_used_altivec's THREAD struct */
  819. addi r4,r4,THREAD
  820. SAVE_32VRS(0,r5,r4)
  821. mfvscr vr0
  822. li r10,THREAD_VSCR
  823. stvx vr0,r10,r4
  824. /* Disable VMX for last_task_used_altivec */
  825. ld r5,PT_REGS(r4)
  826. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  827. lis r6,MSR_VEC@h
  828. andc r4,r4,r6
  829. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  830. 1:
  831. #endif /* CONFIG_SMP */
  832. /* Hack: if we get an altivec unavailable trap with VRSAVE
  833. * set to all zeros, we assume this is a broken application
  834. * that fails to set it properly, and thus we switch it to
  835. * all 1's
  836. */
  837. mfspr r4,SPRN_VRSAVE
  838. cmpdi 0,r4,0
  839. bne+ 1f
  840. li r4,-1
  841. mtspr SPRN_VRSAVE,r4
  842. 1:
  843. /* enable use of VMX after return */
  844. ld r4,PACACURRENT(r13)
  845. addi r5,r4,THREAD /* Get THREAD */
  846. oris r12,r12,MSR_VEC@h
  847. std r12,_MSR(r1)
  848. li r4,1
  849. li r10,THREAD_VSCR
  850. stw r4,THREAD_USED_VR(r5)
  851. lvx vr0,r10,r5
  852. mtvscr vr0
  853. REST_32VRS(0,r4,r5)
  854. #ifndef CONFIG_SMP
  855. /* Update last_task_used_math to 'current' */
  856. subi r4,r5,THREAD /* Back to 'current' */
  857. std r4,0(r3)
  858. #endif /* CONFIG_SMP */
  859. /* restore registers and return */
  860. b fast_exception_return
  861. #endif /* CONFIG_ALTIVEC */
  862. /*
  863. * Hash table stuff
  864. */
  865. .align 7
  866. _GLOBAL(do_hash_page)
  867. std r3,_DAR(r1)
  868. std r4,_DSISR(r1)
  869. andis. r0,r4,0xa450 /* weird error? */
  870. bne- .handle_page_fault /* if not, try to insert a HPTE */
  871. BEGIN_FTR_SECTION
  872. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  873. bne- .do_ste_alloc /* If so handle it */
  874. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  875. /*
  876. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  877. * accessing a userspace segment (even from the kernel). We assume
  878. * kernel addresses always have the high bit set.
  879. */
  880. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  881. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  882. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  883. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  884. ori r4,r4,1 /* add _PAGE_PRESENT */
  885. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  886. /*
  887. * On iSeries, we soft-disable interrupts here, then
  888. * hard-enable interrupts so that the hash_page code can spin on
  889. * the hash_table_lock without problems on a shared processor.
  890. */
  891. DISABLE_INTS
  892. /*
  893. * r3 contains the faulting address
  894. * r4 contains the required access permissions
  895. * r5 contains the trap number
  896. *
  897. * at return r3 = 0 for success
  898. */
  899. bl .hash_page /* build HPTE if possible */
  900. cmpdi r3,0 /* see if hash_page succeeded */
  901. #ifdef DO_SOFT_DISABLE
  902. /*
  903. * If we had interrupts soft-enabled at the point where the
  904. * DSI/ISI occurred, and an interrupt came in during hash_page,
  905. * handle it now.
  906. * We jump to ret_from_except_lite rather than fast_exception_return
  907. * because ret_from_except_lite will check for and handle pending
  908. * interrupts if necessary.
  909. */
  910. beq .ret_from_except_lite
  911. /* For a hash failure, we don't bother re-enabling interrupts */
  912. ble- 12f
  913. /*
  914. * hash_page couldn't handle it, set soft interrupt enable back
  915. * to what it was before the trap. Note that .local_irq_restore
  916. * handles any interrupts pending at this point.
  917. */
  918. ld r3,SOFTE(r1)
  919. bl .local_irq_restore
  920. b 11f
  921. #else
  922. beq fast_exception_return /* Return from exception on success */
  923. ble- 12f /* Failure return from hash_page */
  924. /* fall through */
  925. #endif
  926. /* Here we have a page fault that hash_page can't handle. */
  927. _GLOBAL(handle_page_fault)
  928. ENABLE_INTS
  929. 11: ld r4,_DAR(r1)
  930. ld r5,_DSISR(r1)
  931. addi r3,r1,STACK_FRAME_OVERHEAD
  932. bl .do_page_fault
  933. cmpdi r3,0
  934. beq+ .ret_from_except_lite
  935. bl .save_nvgprs
  936. mr r5,r3
  937. addi r3,r1,STACK_FRAME_OVERHEAD
  938. lwz r4,_DAR(r1)
  939. bl .bad_page_fault
  940. b .ret_from_except
  941. /* We have a page fault that hash_page could handle but HV refused
  942. * the PTE insertion
  943. */
  944. 12: bl .save_nvgprs
  945. addi r3,r1,STACK_FRAME_OVERHEAD
  946. lwz r4,_DAR(r1)
  947. bl .low_hash_fault
  948. b .ret_from_except
  949. /* here we have a segment miss */
  950. _GLOBAL(do_ste_alloc)
  951. bl .ste_allocate /* try to insert stab entry */
  952. cmpdi r3,0
  953. beq+ fast_exception_return
  954. b .handle_page_fault
  955. /*
  956. * r13 points to the PACA, r9 contains the saved CR,
  957. * r11 and r12 contain the saved SRR0 and SRR1.
  958. * r9 - r13 are saved in paca->exslb.
  959. * We assume we aren't going to take any exceptions during this procedure.
  960. * We assume (DAR >> 60) == 0xc.
  961. */
  962. .align 7
  963. _GLOBAL(do_stab_bolted)
  964. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  965. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  966. /* Hash to the primary group */
  967. ld r10,PACASTABVIRT(r13)
  968. mfspr r11,SPRN_DAR
  969. srdi r11,r11,28
  970. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  971. /* Calculate VSID */
  972. /* This is a kernel address, so protovsid = ESID */
  973. ASM_VSID_SCRAMBLE(r11, r9)
  974. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  975. /* Search the primary group for a free entry */
  976. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  977. andi. r11,r11,0x80
  978. beq 2f
  979. addi r10,r10,16
  980. andi. r11,r10,0x70
  981. bne 1b
  982. /* Stick for only searching the primary group for now. */
  983. /* At least for now, we use a very simple random castout scheme */
  984. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  985. mftb r11
  986. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  987. ori r11,r11,0x10
  988. /* r10 currently points to an ste one past the group of interest */
  989. /* make it point to the randomly selected entry */
  990. subi r10,r10,128
  991. or r10,r10,r11 /* r10 is the entry to invalidate */
  992. isync /* mark the entry invalid */
  993. ld r11,0(r10)
  994. rldicl r11,r11,56,1 /* clear the valid bit */
  995. rotldi r11,r11,8
  996. std r11,0(r10)
  997. sync
  998. clrrdi r11,r11,28 /* Get the esid part of the ste */
  999. slbie r11
  1000. 2: std r9,8(r10) /* Store the vsid part of the ste */
  1001. eieio
  1002. mfspr r11,SPRN_DAR /* Get the new esid */
  1003. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  1004. ori r11,r11,0x90 /* Turn on valid and kp */
  1005. std r11,0(r10) /* Put new entry back into the stab */
  1006. sync
  1007. /* All done -- return from exception. */
  1008. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1009. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  1010. andi. r10,r12,MSR_RI
  1011. beq- unrecov_slb
  1012. mtcrf 0x80,r9 /* restore CR */
  1013. mfmsr r10
  1014. clrrdi r10,r10,2
  1015. mtmsrd r10,1
  1016. mtspr SPRN_SRR0,r11
  1017. mtspr SPRN_SRR1,r12
  1018. ld r9,PACA_EXSLB+EX_R9(r13)
  1019. ld r10,PACA_EXSLB+EX_R10(r13)
  1020. ld r11,PACA_EXSLB+EX_R11(r13)
  1021. ld r12,PACA_EXSLB+EX_R12(r13)
  1022. ld r13,PACA_EXSLB+EX_R13(r13)
  1023. rfid
  1024. b . /* prevent speculative execution */
  1025. /*
  1026. * r13 points to the PACA, r9 contains the saved CR,
  1027. * r11 and r12 contain the saved SRR0 and SRR1.
  1028. * r3 has the faulting address
  1029. * r9 - r13 are saved in paca->exslb.
  1030. * r3 is saved in paca->slb_r3
  1031. * We assume we aren't going to take any exceptions during this procedure.
  1032. */
  1033. _GLOBAL(do_slb_miss)
  1034. mflr r10
  1035. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1036. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1037. bl .slb_allocate /* handle it */
  1038. /* All done -- return from exception. */
  1039. ld r10,PACA_EXSLB+EX_LR(r13)
  1040. ld r3,PACA_EXSLB+EX_R3(r13)
  1041. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1042. #ifdef CONFIG_PPC_ISERIES
  1043. ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
  1044. #endif /* CONFIG_PPC_ISERIES */
  1045. mtlr r10
  1046. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1047. beq- unrecov_slb
  1048. .machine push
  1049. .machine "power4"
  1050. mtcrf 0x80,r9
  1051. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1052. .machine pop
  1053. #ifdef CONFIG_PPC_ISERIES
  1054. mtspr SPRN_SRR0,r11
  1055. mtspr SPRN_SRR1,r12
  1056. #endif /* CONFIG_PPC_ISERIES */
  1057. ld r9,PACA_EXSLB+EX_R9(r13)
  1058. ld r10,PACA_EXSLB+EX_R10(r13)
  1059. ld r11,PACA_EXSLB+EX_R11(r13)
  1060. ld r12,PACA_EXSLB+EX_R12(r13)
  1061. ld r13,PACA_EXSLB+EX_R13(r13)
  1062. rfid
  1063. b . /* prevent speculative execution */
  1064. unrecov_slb:
  1065. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1066. DISABLE_INTS
  1067. bl .save_nvgprs
  1068. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1069. bl .unrecoverable_exception
  1070. b 1b
  1071. /*
  1072. * Space for CPU0's segment table.
  1073. *
  1074. * On iSeries, the hypervisor must fill in at least one entry before
  1075. * we get control (with relocate on). The address is give to the hv
  1076. * as a page number (see xLparMap in lpardata.c), so this must be at a
  1077. * fixed address (the linker can't compute (u64)&initial_stab >>
  1078. * PAGE_SHIFT).
  1079. */
  1080. . = STAB0_PHYS_ADDR /* 0x6000 */
  1081. .globl initial_stab
  1082. initial_stab:
  1083. .space 4096
  1084. /*
  1085. * Data area reserved for FWNMI option.
  1086. * This address (0x7000) is fixed by the RPA.
  1087. */
  1088. .= 0x7000
  1089. .globl fwnmi_data_area
  1090. fwnmi_data_area:
  1091. /* iSeries does not use the FWNMI stuff, so it is safe to put
  1092. * this here, even if we later allow kernels that will boot on
  1093. * both pSeries and iSeries */
  1094. #ifdef CONFIG_PPC_ISERIES
  1095. . = LPARMAP_PHYS
  1096. #include "lparmap.s"
  1097. /*
  1098. * This ".text" is here for old compilers that generate a trailing
  1099. * .note section when compiling .c files to .s
  1100. */
  1101. .text
  1102. #endif /* CONFIG_PPC_ISERIES */
  1103. . = 0x8000
  1104. /*
  1105. * On pSeries, secondary processors spin in the following code.
  1106. * At entry, r3 = this processor's number (physical cpu id)
  1107. */
  1108. _GLOBAL(pSeries_secondary_smp_init)
  1109. mr r24,r3
  1110. /* turn on 64-bit mode */
  1111. bl .enable_64b_mode
  1112. isync
  1113. /* Copy some CPU settings from CPU 0 */
  1114. bl .__restore_cpu_setup
  1115. /* Set up a paca value for this processor. Since we have the
  1116. * physical cpu id in r24, we need to search the pacas to find
  1117. * which logical id maps to our physical one.
  1118. */
  1119. LOADADDR(r13, paca) /* Get base vaddr of paca array */
  1120. li r5,0 /* logical cpu id */
  1121. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  1122. cmpw r6,r24 /* Compare to our id */
  1123. beq 2f
  1124. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  1125. addi r5,r5,1
  1126. cmpwi r5,NR_CPUS
  1127. blt 1b
  1128. mr r3,r24 /* not found, copy phys to r3 */
  1129. b .kexec_wait /* next kernel might do better */
  1130. 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1131. /* From now on, r24 is expected to be logical cpuid */
  1132. mr r24,r5
  1133. 3: HMT_LOW
  1134. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  1135. /* start. */
  1136. sync
  1137. /* Create a temp kernel stack for use before relocation is on. */
  1138. ld r1,PACAEMERGSP(r13)
  1139. subi r1,r1,STACK_FRAME_OVERHEAD
  1140. cmpwi 0,r23,0
  1141. #ifdef CONFIG_SMP
  1142. bne .__secondary_start
  1143. #endif
  1144. b 3b /* Loop until told to go */
  1145. #ifdef CONFIG_PPC_ISERIES
  1146. _STATIC(__start_initialization_iSeries)
  1147. /* Clear out the BSS */
  1148. LOADADDR(r11,__bss_stop)
  1149. LOADADDR(r8,__bss_start)
  1150. sub r11,r11,r8 /* bss size */
  1151. addi r11,r11,7 /* round up to an even double word */
  1152. rldicl. r11,r11,61,3 /* shift right by 3 */
  1153. beq 4f
  1154. addi r8,r8,-8
  1155. li r0,0
  1156. mtctr r11 /* zero this many doublewords */
  1157. 3: stdu r0,8(r8)
  1158. bdnz 3b
  1159. 4:
  1160. LOADADDR(r1,init_thread_union)
  1161. addi r1,r1,THREAD_SIZE
  1162. li r0,0
  1163. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1164. LOADADDR(r3,cpu_specs)
  1165. LOADADDR(r4,cur_cpu_spec)
  1166. li r5,0
  1167. bl .identify_cpu
  1168. LOADADDR(r2,__toc_start)
  1169. addi r2,r2,0x4000
  1170. addi r2,r2,0x4000
  1171. bl .iSeries_early_setup
  1172. bl .early_setup
  1173. /* relocation is on at this point */
  1174. b .start_here_common
  1175. #endif /* CONFIG_PPC_ISERIES */
  1176. #ifdef CONFIG_PPC_MULTIPLATFORM
  1177. _STATIC(__mmu_off)
  1178. mfmsr r3
  1179. andi. r0,r3,MSR_IR|MSR_DR
  1180. beqlr
  1181. andc r3,r3,r0
  1182. mtspr SPRN_SRR0,r4
  1183. mtspr SPRN_SRR1,r3
  1184. sync
  1185. rfid
  1186. b . /* prevent speculative execution */
  1187. /*
  1188. * Here is our main kernel entry point. We support currently 2 kind of entries
  1189. * depending on the value of r5.
  1190. *
  1191. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  1192. * in r3...r7
  1193. *
  1194. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  1195. * DT block, r4 is a physical pointer to the kernel itself
  1196. *
  1197. */
  1198. _GLOBAL(__start_initialization_multiplatform)
  1199. /*
  1200. * Are we booted from a PROM Of-type client-interface ?
  1201. */
  1202. cmpldi cr0,r5,0
  1203. bne .__boot_from_prom /* yes -> prom */
  1204. /* Save parameters */
  1205. mr r31,r3
  1206. mr r30,r4
  1207. /* Make sure we are running in 64 bits mode */
  1208. bl .enable_64b_mode
  1209. /* Setup some critical 970 SPRs before switching MMU off */
  1210. bl .__970_cpu_preinit
  1211. /* cpu # */
  1212. li r24,0
  1213. /* Switch off MMU if not already */
  1214. LOADADDR(r4, .__after_prom_start - KERNELBASE)
  1215. add r4,r4,r30
  1216. bl .__mmu_off
  1217. b .__after_prom_start
  1218. _STATIC(__boot_from_prom)
  1219. /* Save parameters */
  1220. mr r31,r3
  1221. mr r30,r4
  1222. mr r29,r5
  1223. mr r28,r6
  1224. mr r27,r7
  1225. /* Make sure we are running in 64 bits mode */
  1226. bl .enable_64b_mode
  1227. /* put a relocation offset into r3 */
  1228. bl .reloc_offset
  1229. LOADADDR(r2,__toc_start)
  1230. addi r2,r2,0x4000
  1231. addi r2,r2,0x4000
  1232. /* Relocate the TOC from a virt addr to a real addr */
  1233. sub r2,r2,r3
  1234. /* Restore parameters */
  1235. mr r3,r31
  1236. mr r4,r30
  1237. mr r5,r29
  1238. mr r6,r28
  1239. mr r7,r27
  1240. /* Do all of the interaction with OF client interface */
  1241. bl .prom_init
  1242. /* We never return */
  1243. trap
  1244. /*
  1245. * At this point, r3 contains the physical address we are running at,
  1246. * returned by prom_init()
  1247. */
  1248. _STATIC(__after_prom_start)
  1249. /*
  1250. * We need to run with __start at physical address 0.
  1251. * This will leave some code in the first 256B of
  1252. * real memory, which are reserved for software use.
  1253. * The remainder of the first page is loaded with the fixed
  1254. * interrupt vectors. The next two pages are filled with
  1255. * unknown exception placeholders.
  1256. *
  1257. * Note: This process overwrites the OF exception vectors.
  1258. * r26 == relocation offset
  1259. * r27 == KERNELBASE
  1260. */
  1261. bl .reloc_offset
  1262. mr r26,r3
  1263. SET_REG_TO_CONST(r27,KERNELBASE)
  1264. li r3,0 /* target addr */
  1265. // XXX FIXME: Use phys returned by OF (r30)
  1266. sub r4,r27,r26 /* source addr */
  1267. /* current address of _start */
  1268. /* i.e. where we are running */
  1269. /* the source addr */
  1270. LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
  1271. sub r5,r5,r27
  1272. li r6,0x100 /* Start offset, the first 0x100 */
  1273. /* bytes were copied earlier. */
  1274. bl .copy_and_flush /* copy the first n bytes */
  1275. /* this includes the code being */
  1276. /* executed here. */
  1277. LOADADDR(r0, 4f) /* Jump to the copy of this code */
  1278. mtctr r0 /* that we just made/relocated */
  1279. bctr
  1280. 4: LOADADDR(r5,klimit)
  1281. sub r5,r5,r26
  1282. ld r5,0(r5) /* get the value of klimit */
  1283. sub r5,r5,r27
  1284. bl .copy_and_flush /* copy the rest */
  1285. b .start_here_multiplatform
  1286. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1287. /*
  1288. * Copy routine used to copy the kernel to start at physical address 0
  1289. * and flush and invalidate the caches as needed.
  1290. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  1291. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  1292. *
  1293. * Note: this routine *only* clobbers r0, r6 and lr
  1294. */
  1295. _GLOBAL(copy_and_flush)
  1296. addi r5,r5,-8
  1297. addi r6,r6,-8
  1298. 4: li r0,16 /* Use the least common */
  1299. /* denominator cache line */
  1300. /* size. This results in */
  1301. /* extra cache line flushes */
  1302. /* but operation is correct. */
  1303. /* Can't get cache line size */
  1304. /* from NACA as it is being */
  1305. /* moved too. */
  1306. mtctr r0 /* put # words/line in ctr */
  1307. 3: addi r6,r6,8 /* copy a cache line */
  1308. ldx r0,r6,r4
  1309. stdx r0,r6,r3
  1310. bdnz 3b
  1311. dcbst r6,r3 /* write it to memory */
  1312. sync
  1313. icbi r6,r3 /* flush the icache line */
  1314. cmpld 0,r6,r5
  1315. blt 4b
  1316. sync
  1317. addi r5,r5,8
  1318. addi r6,r6,8
  1319. blr
  1320. .align 8
  1321. copy_to_here:
  1322. #ifdef CONFIG_SMP
  1323. #ifdef CONFIG_PPC_PMAC
  1324. /*
  1325. * On PowerMac, secondary processors starts from the reset vector, which
  1326. * is temporarily turned into a call to one of the functions below.
  1327. */
  1328. .section ".text";
  1329. .align 2 ;
  1330. .globl __secondary_start_pmac_0
  1331. __secondary_start_pmac_0:
  1332. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  1333. li r24,0
  1334. b 1f
  1335. li r24,1
  1336. b 1f
  1337. li r24,2
  1338. b 1f
  1339. li r24,3
  1340. 1:
  1341. _GLOBAL(pmac_secondary_start)
  1342. /* turn on 64-bit mode */
  1343. bl .enable_64b_mode
  1344. isync
  1345. /* Copy some CPU settings from CPU 0 */
  1346. bl .__restore_cpu_setup
  1347. /* pSeries do that early though I don't think we really need it */
  1348. mfmsr r3
  1349. ori r3,r3,MSR_RI
  1350. mtmsrd r3 /* RI on */
  1351. /* Set up a paca value for this processor. */
  1352. LOADADDR(r4, paca) /* Get base vaddr of paca array */
  1353. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  1354. add r13,r13,r4 /* for this processor. */
  1355. mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1356. /* Create a temp kernel stack for use before relocation is on. */
  1357. ld r1,PACAEMERGSP(r13)
  1358. subi r1,r1,STACK_FRAME_OVERHEAD
  1359. b .__secondary_start
  1360. #endif /* CONFIG_PPC_PMAC */
  1361. /*
  1362. * This function is called after the master CPU has released the
  1363. * secondary processors. The execution environment is relocation off.
  1364. * The paca for this processor has the following fields initialized at
  1365. * this point:
  1366. * 1. Processor number
  1367. * 2. Segment table pointer (virtual address)
  1368. * On entry the following are set:
  1369. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  1370. * r24 = cpu# (in Linux terms)
  1371. * r13 = paca virtual address
  1372. * SPRG3 = paca virtual address
  1373. */
  1374. _GLOBAL(__secondary_start)
  1375. HMT_MEDIUM /* Set thread priority to MEDIUM */
  1376. ld r2,PACATOC(r13)
  1377. li r6,0
  1378. stb r6,PACAPROCENABLED(r13)
  1379. #ifndef CONFIG_PPC_ISERIES
  1380. /* Initialize the page table pointer register. */
  1381. LOADADDR(r6,_SDR1)
  1382. ld r6,0(r6) /* get the value of _SDR1 */
  1383. mtspr SPRN_SDR1,r6 /* set the htab location */
  1384. #endif
  1385. /* Initialize the first segment table (or SLB) entry */
  1386. ld r3,PACASTABVIRT(r13) /* get addr of segment table */
  1387. bl .stab_initialize
  1388. /* Initialize the kernel stack. Just a repeat for iSeries. */
  1389. LOADADDR(r3,current_set)
  1390. sldi r28,r24,3 /* get current_set[cpu#] */
  1391. ldx r1,r3,r28
  1392. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1393. std r1,PACAKSAVE(r13)
  1394. ld r3,PACASTABREAL(r13) /* get raddr of segment table */
  1395. ori r4,r3,1 /* turn on valid bit */
  1396. #ifdef CONFIG_PPC_ISERIES
  1397. li r0,-1 /* hypervisor call */
  1398. li r3,1
  1399. sldi r3,r3,63 /* 0x8000000000000000 */
  1400. ori r3,r3,4 /* 0x8000000000000004 */
  1401. sc /* HvCall_setASR */
  1402. #else
  1403. /* set the ASR */
  1404. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1405. ld r3,0(r3)
  1406. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1407. andi. r3,r3,PLATFORM_LPAR /* Test if bit 0 is set (LPAR bit) */
  1408. beq 98f /* branch if result is 0 */
  1409. mfspr r3,SPRN_PVR
  1410. srwi r3,r3,16
  1411. cmpwi r3,0x37 /* SStar */
  1412. beq 97f
  1413. cmpwi r3,0x36 /* IStar */
  1414. beq 97f
  1415. cmpwi r3,0x34 /* Pulsar */
  1416. bne 98f
  1417. 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
  1418. HVSC /* Invoking hcall */
  1419. b 99f
  1420. 98: /* !(rpa hypervisor) || !(star) */
  1421. mtasr r4 /* set the stab location */
  1422. 99:
  1423. #endif
  1424. li r7,0
  1425. mtlr r7
  1426. /* enable MMU and jump to start_secondary */
  1427. LOADADDR(r3,.start_secondary_prolog)
  1428. SET_REG_TO_CONST(r4, MSR_KERNEL)
  1429. #ifdef DO_SOFT_DISABLE
  1430. ori r4,r4,MSR_EE
  1431. #endif
  1432. mtspr SPRN_SRR0,r3
  1433. mtspr SPRN_SRR1,r4
  1434. rfid
  1435. b . /* prevent speculative execution */
  1436. /*
  1437. * Running with relocation on at this point. All we want to do is
  1438. * zero the stack back-chain pointer before going into C code.
  1439. */
  1440. _GLOBAL(start_secondary_prolog)
  1441. li r3,0
  1442. std r3,0(r1) /* Zero the stack frame pointer */
  1443. bl .start_secondary
  1444. #endif
  1445. /*
  1446. * This subroutine clobbers r11 and r12
  1447. */
  1448. _GLOBAL(enable_64b_mode)
  1449. mfmsr r11 /* grab the current MSR */
  1450. li r12,1
  1451. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  1452. or r11,r11,r12
  1453. li r12,1
  1454. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  1455. or r11,r11,r12
  1456. mtmsrd r11
  1457. isync
  1458. blr
  1459. #ifdef CONFIG_PPC_MULTIPLATFORM
  1460. /*
  1461. * This is where the main kernel code starts.
  1462. */
  1463. _STATIC(start_here_multiplatform)
  1464. /* get a new offset, now that the kernel has moved. */
  1465. bl .reloc_offset
  1466. mr r26,r3
  1467. /* Clear out the BSS. It may have been done in prom_init,
  1468. * already but that's irrelevant since prom_init will soon
  1469. * be detached from the kernel completely. Besides, we need
  1470. * to clear it now for kexec-style entry.
  1471. */
  1472. LOADADDR(r11,__bss_stop)
  1473. LOADADDR(r8,__bss_start)
  1474. sub r11,r11,r8 /* bss size */
  1475. addi r11,r11,7 /* round up to an even double word */
  1476. rldicl. r11,r11,61,3 /* shift right by 3 */
  1477. beq 4f
  1478. addi r8,r8,-8
  1479. li r0,0
  1480. mtctr r11 /* zero this many doublewords */
  1481. 3: stdu r0,8(r8)
  1482. bdnz 3b
  1483. 4:
  1484. mfmsr r6
  1485. ori r6,r6,MSR_RI
  1486. mtmsrd r6 /* RI on */
  1487. #ifdef CONFIG_HMT
  1488. /* Start up the second thread on cpu 0 */
  1489. mfspr r3,SPRN_PVR
  1490. srwi r3,r3,16
  1491. cmpwi r3,0x34 /* Pulsar */
  1492. beq 90f
  1493. cmpwi r3,0x36 /* Icestar */
  1494. beq 90f
  1495. cmpwi r3,0x37 /* SStar */
  1496. beq 90f
  1497. b 91f /* HMT not supported */
  1498. 90: li r3,0
  1499. bl .hmt_start_secondary
  1500. 91:
  1501. #endif
  1502. /* The following gets the stack and TOC set up with the regs */
  1503. /* pointing to the real addr of the kernel stack. This is */
  1504. /* all done to support the C function call below which sets */
  1505. /* up the htab. This is done because we have relocated the */
  1506. /* kernel but are still running in real mode. */
  1507. LOADADDR(r3,init_thread_union)
  1508. sub r3,r3,r26
  1509. /* set up a stack pointer (physical address) */
  1510. addi r1,r3,THREAD_SIZE
  1511. li r0,0
  1512. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1513. /* set up the TOC (physical address) */
  1514. LOADADDR(r2,__toc_start)
  1515. addi r2,r2,0x4000
  1516. addi r2,r2,0x4000
  1517. sub r2,r2,r26
  1518. LOADADDR(r3,cpu_specs)
  1519. sub r3,r3,r26
  1520. LOADADDR(r4,cur_cpu_spec)
  1521. sub r4,r4,r26
  1522. mr r5,r26
  1523. bl .identify_cpu
  1524. /* Save some low level config HIDs of CPU0 to be copied to
  1525. * other CPUs later on, or used for suspend/resume
  1526. */
  1527. bl .__save_cpu_setup
  1528. sync
  1529. /* Setup a valid physical PACA pointer in SPRG3 for early_setup
  1530. * note that boot_cpuid can always be 0 nowadays since there is
  1531. * nowhere it can be initialized differently before we reach this
  1532. * code
  1533. */
  1534. LOADADDR(r27, boot_cpuid)
  1535. sub r27,r27,r26
  1536. lwz r27,0(r27)
  1537. LOADADDR(r24, paca) /* Get base vaddr of paca array */
  1538. mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
  1539. add r13,r13,r24 /* for this processor. */
  1540. sub r13,r13,r26 /* convert to physical addr */
  1541. mtspr SPRN_SPRG3,r13 /* PPPBBB: Temp... -Peter */
  1542. /* Do very early kernel initializations, including initial hash table,
  1543. * stab and slb setup before we turn on relocation. */
  1544. /* Restore parameters passed from prom_init/kexec */
  1545. mr r3,r31
  1546. bl .early_setup
  1547. /* set the ASR */
  1548. ld r3,PACASTABREAL(r13)
  1549. ori r4,r3,1 /* turn on valid bit */
  1550. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1551. ld r3,0(r3)
  1552. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1553. andi. r3,r3,PLATFORM_LPAR /* Test if bit 0 is set (LPAR bit) */
  1554. beq 98f /* branch if result is 0 */
  1555. mfspr r3,SPRN_PVR
  1556. srwi r3,r3,16
  1557. cmpwi r3,0x37 /* SStar */
  1558. beq 97f
  1559. cmpwi r3,0x36 /* IStar */
  1560. beq 97f
  1561. cmpwi r3,0x34 /* Pulsar */
  1562. bne 98f
  1563. 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
  1564. HVSC /* Invoking hcall */
  1565. b 99f
  1566. 98: /* !(rpa hypervisor) || !(star) */
  1567. mtasr r4 /* set the stab location */
  1568. 99:
  1569. /* Set SDR1 (hash table pointer) */
  1570. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1571. ld r3,0(r3)
  1572. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1573. /* Test if bit 0 is set (LPAR bit) */
  1574. andi. r3,r3,PLATFORM_LPAR
  1575. bne 98f /* branch if result is !0 */
  1576. LOADADDR(r6,_SDR1) /* Only if NOT LPAR */
  1577. sub r6,r6,r26
  1578. ld r6,0(r6) /* get the value of _SDR1 */
  1579. mtspr SPRN_SDR1,r6 /* set the htab location */
  1580. 98:
  1581. LOADADDR(r3,.start_here_common)
  1582. SET_REG_TO_CONST(r4, MSR_KERNEL)
  1583. mtspr SPRN_SRR0,r3
  1584. mtspr SPRN_SRR1,r4
  1585. rfid
  1586. b . /* prevent speculative execution */
  1587. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1588. /* This is where all platforms converge execution */
  1589. _STATIC(start_here_common)
  1590. /* relocation is on at this point */
  1591. /* The following code sets up the SP and TOC now that we are */
  1592. /* running with translation enabled. */
  1593. LOADADDR(r3,init_thread_union)
  1594. /* set up the stack */
  1595. addi r1,r3,THREAD_SIZE
  1596. li r0,0
  1597. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1598. /* Apply the CPUs-specific fixups (nop out sections not relevant
  1599. * to this CPU
  1600. */
  1601. li r3,0
  1602. bl .do_cpu_ftr_fixups
  1603. LOADADDR(r26, boot_cpuid)
  1604. lwz r26,0(r26)
  1605. LOADADDR(r24, paca) /* Get base vaddr of paca array */
  1606. mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
  1607. add r13,r13,r24 /* for this processor. */
  1608. mtspr SPRN_SPRG3,r13
  1609. /* ptr to current */
  1610. LOADADDR(r4,init_task)
  1611. std r4,PACACURRENT(r13)
  1612. /* Load the TOC */
  1613. ld r2,PACATOC(r13)
  1614. std r1,PACAKSAVE(r13)
  1615. bl .setup_system
  1616. /* Load up the kernel context */
  1617. 5:
  1618. #ifdef DO_SOFT_DISABLE
  1619. li r5,0
  1620. stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
  1621. mfmsr r5
  1622. ori r5,r5,MSR_EE /* Hard Enabled */
  1623. mtmsrd r5
  1624. #endif
  1625. bl .start_kernel
  1626. _GLOBAL(hmt_init)
  1627. #ifdef CONFIG_HMT
  1628. LOADADDR(r5, hmt_thread_data)
  1629. mfspr r7,SPRN_PVR
  1630. srwi r7,r7,16
  1631. cmpwi r7,0x34 /* Pulsar */
  1632. beq 90f
  1633. cmpwi r7,0x36 /* Icestar */
  1634. beq 91f
  1635. cmpwi r7,0x37 /* SStar */
  1636. beq 91f
  1637. b 101f
  1638. 90: mfspr r6,SPRN_PIR
  1639. andi. r6,r6,0x1f
  1640. b 92f
  1641. 91: mfspr r6,SPRN_PIR
  1642. andi. r6,r6,0x3ff
  1643. 92: sldi r4,r24,3
  1644. stwx r6,r5,r4
  1645. bl .hmt_start_secondary
  1646. b 101f
  1647. __hmt_secondary_hold:
  1648. LOADADDR(r5, hmt_thread_data)
  1649. clrldi r5,r5,4
  1650. li r7,0
  1651. mfspr r6,SPRN_PIR
  1652. mfspr r8,SPRN_PVR
  1653. srwi r8,r8,16
  1654. cmpwi r8,0x34
  1655. bne 93f
  1656. andi. r6,r6,0x1f
  1657. b 103f
  1658. 93: andi. r6,r6,0x3f
  1659. 103: lwzx r8,r5,r7
  1660. cmpw r8,r6
  1661. beq 104f
  1662. addi r7,r7,8
  1663. b 103b
  1664. 104: addi r7,r7,4
  1665. lwzx r9,r5,r7
  1666. mr r24,r9
  1667. 101:
  1668. #endif
  1669. mr r3,r24
  1670. b .pSeries_secondary_smp_init
  1671. #ifdef CONFIG_HMT
  1672. _GLOBAL(hmt_start_secondary)
  1673. LOADADDR(r4,__hmt_secondary_hold)
  1674. clrldi r4,r4,4
  1675. mtspr SPRN_NIADORM, r4
  1676. mfspr r4, SPRN_MSRDORM
  1677. li r5, -65
  1678. and r4, r4, r5
  1679. mtspr SPRN_MSRDORM, r4
  1680. lis r4,0xffef
  1681. ori r4,r4,0x7403
  1682. mtspr SPRN_TSC, r4
  1683. li r4,0x1f4
  1684. mtspr SPRN_TST, r4
  1685. mfspr r4, SPRN_HID0
  1686. ori r4, r4, 0x1
  1687. mtspr SPRN_HID0, r4
  1688. mfspr r4, SPRN_CTRLF
  1689. oris r4, r4, 0x40
  1690. mtspr SPRN_CTRLT, r4
  1691. blr
  1692. #endif
  1693. /*
  1694. * We put a few things here that have to be page-aligned.
  1695. * This stuff goes at the beginning of the bss, which is page-aligned.
  1696. */
  1697. .section ".bss"
  1698. .align PAGE_SHIFT
  1699. .globl empty_zero_page
  1700. empty_zero_page:
  1701. .space PAGE_SIZE
  1702. .globl swapper_pg_dir
  1703. swapper_pg_dir:
  1704. .space PAGE_SIZE
  1705. /*
  1706. * This space gets a copy of optional info passed to us by the bootstrap
  1707. * Used to pass parameters into the kernel like root=/dev/sda1, etc.
  1708. */
  1709. .globl cmd_line
  1710. cmd_line:
  1711. .space COMMAND_LINE_SIZE