head_64.S 53 KB

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