head_64.S 55 KB

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