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