head.S 54 KB

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