head_64.S 52 KB

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