head.S 54 KB

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