head_64.S 53 KB

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