head_64.S 54 KB

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