head_64.S 55 KB

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