head_64.S 52 KB

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