head_64.S 50 KB

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