head.S 53 KB

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