head.S 52 KB

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