head_64.S 53 KB

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