head.S 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006
  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/systemcfg.h>
  32. #include <asm/ppc_asm.h>
  33. #include <asm/offsets.h>
  34. #include <asm/bug.h>
  35. #include <asm/cputable.h>
  36. #include <asm/setup.h>
  37. #include <asm/hvcall.h>
  38. #include <asm/iSeries/LparMap.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 - 0x5fff : interrupt support, iSeries and common interrupt prologs
  51. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  52. * 0x7000 - 0x7fff : FWNMI data area
  53. * 0x8000 - : Early init and support code
  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. . = 0x3000
  454. /*** pSeries interrupt support ***/
  455. /* moved from 0xf00 */
  456. STD_EXCEPTION_PSERIES(., performance_monitor)
  457. .align 7
  458. _GLOBAL(do_stab_bolted_pSeries)
  459. mtcrf 0x80,r12
  460. mfspr r12,SPRG2
  461. EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
  462. /*
  463. * Vectors for the FWNMI option. Share common code.
  464. */
  465. .globl system_reset_fwnmi
  466. system_reset_fwnmi:
  467. HMT_MEDIUM
  468. mtspr SPRG1,r13 /* save r13 */
  469. RUNLATCH_ON(r13)
  470. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
  471. .globl machine_check_fwnmi
  472. machine_check_fwnmi:
  473. HMT_MEDIUM
  474. mtspr SPRG1,r13 /* save r13 */
  475. RUNLATCH_ON(r13)
  476. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  477. #ifdef CONFIG_PPC_ISERIES
  478. /*** ISeries-LPAR interrupt handlers ***/
  479. STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
  480. .globl data_access_iSeries
  481. data_access_iSeries:
  482. mtspr SPRG1,r13
  483. BEGIN_FTR_SECTION
  484. mtspr SPRG2,r12
  485. mfspr r13,DAR
  486. mfspr r12,DSISR
  487. srdi r13,r13,60
  488. rlwimi r13,r12,16,0x20
  489. mfcr r12
  490. cmpwi r13,0x2c
  491. beq .do_stab_bolted_iSeries
  492. mtcrf 0x80,r12
  493. mfspr r12,SPRG2
  494. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  495. EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
  496. EXCEPTION_PROLOG_ISERIES_2
  497. b data_access_common
  498. .do_stab_bolted_iSeries:
  499. mtcrf 0x80,r12
  500. mfspr r12,SPRG2
  501. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  502. EXCEPTION_PROLOG_ISERIES_2
  503. b .do_stab_bolted
  504. .globl data_access_slb_iSeries
  505. data_access_slb_iSeries:
  506. mtspr SPRG1,r13 /* save r13 */
  507. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  508. std r3,PACA_EXSLB+EX_R3(r13)
  509. ld r12,PACALPPACA+LPPACASRR1(r13)
  510. mfspr r3,DAR
  511. b .do_slb_miss
  512. STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
  513. .globl instruction_access_slb_iSeries
  514. instruction_access_slb_iSeries:
  515. mtspr SPRG1,r13 /* save r13 */
  516. EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
  517. std r3,PACA_EXSLB+EX_R3(r13)
  518. ld r12,PACALPPACA+LPPACASRR1(r13)
  519. ld r3,PACALPPACA+LPPACASRR0(r13)
  520. b .do_slb_miss
  521. MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
  522. STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
  523. STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
  524. STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
  525. MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
  526. STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
  527. STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
  528. .globl system_call_iSeries
  529. system_call_iSeries:
  530. mr r9,r13
  531. mfspr r13,SPRG3
  532. EXCEPTION_PROLOG_ISERIES_2
  533. b system_call_common
  534. STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
  535. STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
  536. STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
  537. .globl system_reset_iSeries
  538. system_reset_iSeries:
  539. mfspr r13,SPRG3 /* Get paca address */
  540. mfmsr r24
  541. ori r24,r24,MSR_RI
  542. mtmsrd r24 /* RI on */
  543. lhz r24,PACAPACAINDEX(r13) /* Get processor # */
  544. cmpwi 0,r24,0 /* Are we processor 0? */
  545. beq .__start_initialization_iSeries /* Start up the first processor */
  546. mfspr r4,SPRN_CTRLF
  547. li r5,CTRL_RUNLATCH /* Turn off the run light */
  548. andc r4,r4,r5
  549. mtspr SPRN_CTRLT,r4
  550. 1:
  551. HMT_LOW
  552. #ifdef CONFIG_SMP
  553. lbz r23,PACAPROCSTART(r13) /* Test if this processor
  554. * should start */
  555. sync
  556. LOADADDR(r3,current_set)
  557. sldi r28,r24,3 /* get current_set[cpu#] */
  558. ldx r3,r3,r28
  559. addi r1,r3,THREAD_SIZE
  560. subi r1,r1,STACK_FRAME_OVERHEAD
  561. cmpwi 0,r23,0
  562. beq iSeries_secondary_smp_loop /* Loop until told to go */
  563. #ifdef SECONDARY_PROCESSORS
  564. bne .__secondary_start /* Loop until told to go */
  565. #endif
  566. iSeries_secondary_smp_loop:
  567. /* Let the Hypervisor know we are alive */
  568. /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
  569. lis r3,0x8002
  570. rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */
  571. #else /* CONFIG_SMP */
  572. /* Yield the processor. This is required for non-SMP kernels
  573. which are running on multi-threaded machines. */
  574. lis r3,0x8000
  575. rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */
  576. addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */
  577. li r4,0 /* "yield timed" */
  578. li r5,-1 /* "yield forever" */
  579. #endif /* CONFIG_SMP */
  580. li r0,-1 /* r0=-1 indicates a Hypervisor call */
  581. sc /* Invoke the hypervisor via a system call */
  582. mfspr r13,SPRG3 /* Put r13 back ???? */
  583. b 1b /* If SMP not configured, secondaries
  584. * loop forever */
  585. .globl decrementer_iSeries_masked
  586. decrementer_iSeries_masked:
  587. li r11,1
  588. stb r11,PACALPPACA+LPPACADECRINT(r13)
  589. lwz r12,PACADEFAULTDECR(r13)
  590. mtspr SPRN_DEC,r12
  591. /* fall through */
  592. .globl hardware_interrupt_iSeries_masked
  593. hardware_interrupt_iSeries_masked:
  594. mtcrf 0x80,r9 /* Restore regs */
  595. ld r11,PACALPPACA+LPPACASRR0(r13)
  596. ld r12,PACALPPACA+LPPACASRR1(r13)
  597. mtspr SRR0,r11
  598. mtspr SRR1,r12
  599. ld r9,PACA_EXGEN+EX_R9(r13)
  600. ld r10,PACA_EXGEN+EX_R10(r13)
  601. ld r11,PACA_EXGEN+EX_R11(r13)
  602. ld r12,PACA_EXGEN+EX_R12(r13)
  603. ld r13,PACA_EXGEN+EX_R13(r13)
  604. rfid
  605. b . /* prevent speculative execution */
  606. #endif /* CONFIG_PPC_ISERIES */
  607. /*** Common interrupt handlers ***/
  608. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  609. /*
  610. * Machine check is different because we use a different
  611. * save area: PACA_EXMC instead of PACA_EXGEN.
  612. */
  613. .align 7
  614. .globl machine_check_common
  615. machine_check_common:
  616. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  617. DISABLE_INTS
  618. bl .save_nvgprs
  619. addi r3,r1,STACK_FRAME_OVERHEAD
  620. bl .machine_check_exception
  621. b .ret_from_except
  622. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  623. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  624. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  625. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  626. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  627. STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
  628. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  629. #ifdef CONFIG_ALTIVEC
  630. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  631. #else
  632. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  633. #endif
  634. /*
  635. * Here we have detected that the kernel stack pointer is bad.
  636. * R9 contains the saved CR, r13 points to the paca,
  637. * r10 contains the (bad) kernel stack pointer,
  638. * r11 and r12 contain the saved SRR0 and SRR1.
  639. * We switch to using the paca guard page as an emergency stack,
  640. * save the registers there, and call kernel_bad_stack(), which panics.
  641. */
  642. bad_stack:
  643. ld r1,PACAEMERGSP(r13)
  644. subi r1,r1,64+INT_FRAME_SIZE
  645. std r9,_CCR(r1)
  646. std r10,GPR1(r1)
  647. std r11,_NIP(r1)
  648. std r12,_MSR(r1)
  649. mfspr r11,DAR
  650. mfspr r12,DSISR
  651. std r11,_DAR(r1)
  652. std r12,_DSISR(r1)
  653. mflr r10
  654. mfctr r11
  655. mfxer r12
  656. std r10,_LINK(r1)
  657. std r11,_CTR(r1)
  658. std r12,_XER(r1)
  659. SAVE_GPR(0,r1)
  660. SAVE_GPR(2,r1)
  661. SAVE_4GPRS(3,r1)
  662. SAVE_2GPRS(7,r1)
  663. SAVE_10GPRS(12,r1)
  664. SAVE_10GPRS(22,r1)
  665. addi r11,r1,INT_FRAME_SIZE
  666. std r11,0(r1)
  667. li r12,0
  668. std r12,0(r11)
  669. ld r2,PACATOC(r13)
  670. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  671. bl .kernel_bad_stack
  672. b 1b
  673. /*
  674. * Return from an exception with minimal checks.
  675. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  676. * If interrupts have been enabled, or anything has been
  677. * done that might have changed the scheduling status of
  678. * any task or sent any task a signal, you should use
  679. * ret_from_except or ret_from_except_lite instead of this.
  680. */
  681. fast_exception_return:
  682. ld r12,_MSR(r1)
  683. ld r11,_NIP(r1)
  684. andi. r3,r12,MSR_RI /* check if RI is set */
  685. beq- unrecov_fer
  686. ld r3,_CCR(r1)
  687. ld r4,_LINK(r1)
  688. ld r5,_CTR(r1)
  689. ld r6,_XER(r1)
  690. mtcr r3
  691. mtlr r4
  692. mtctr r5
  693. mtxer r6
  694. REST_GPR(0, r1)
  695. REST_8GPRS(2, r1)
  696. mfmsr r10
  697. clrrdi r10,r10,2 /* clear RI (LE is 0 already) */
  698. mtmsrd r10,1
  699. mtspr SRR1,r12
  700. mtspr SRR0,r11
  701. REST_4GPRS(10, r1)
  702. ld r1,GPR1(r1)
  703. rfid
  704. b . /* prevent speculative execution */
  705. unrecov_fer:
  706. bl .save_nvgprs
  707. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  708. bl .unrecoverable_exception
  709. b 1b
  710. /*
  711. * Here r13 points to the paca, r9 contains the saved CR,
  712. * SRR0 and SRR1 are saved in r11 and r12,
  713. * r9 - r13 are saved in paca->exgen.
  714. */
  715. .align 7
  716. .globl data_access_common
  717. data_access_common:
  718. RUNLATCH_ON(r10) /* It wont fit in the 0x300 handler */
  719. mfspr r10,DAR
  720. std r10,PACA_EXGEN+EX_DAR(r13)
  721. mfspr r10,DSISR
  722. stw r10,PACA_EXGEN+EX_DSISR(r13)
  723. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  724. ld r3,PACA_EXGEN+EX_DAR(r13)
  725. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  726. li r5,0x300
  727. b .do_hash_page /* Try to handle as hpte fault */
  728. .align 7
  729. .globl instruction_access_common
  730. instruction_access_common:
  731. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  732. ld r3,_NIP(r1)
  733. andis. r4,r12,0x5820
  734. li r5,0x400
  735. b .do_hash_page /* Try to handle as hpte fault */
  736. .align 7
  737. .globl hardware_interrupt_common
  738. .globl hardware_interrupt_entry
  739. hardware_interrupt_common:
  740. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  741. hardware_interrupt_entry:
  742. DISABLE_INTS
  743. addi r3,r1,STACK_FRAME_OVERHEAD
  744. bl .do_IRQ
  745. b .ret_from_except_lite
  746. .align 7
  747. .globl alignment_common
  748. alignment_common:
  749. mfspr r10,DAR
  750. std r10,PACA_EXGEN+EX_DAR(r13)
  751. mfspr r10,DSISR
  752. stw r10,PACA_EXGEN+EX_DSISR(r13)
  753. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  754. ld r3,PACA_EXGEN+EX_DAR(r13)
  755. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  756. std r3,_DAR(r1)
  757. std r4,_DSISR(r1)
  758. bl .save_nvgprs
  759. addi r3,r1,STACK_FRAME_OVERHEAD
  760. ENABLE_INTS
  761. bl .alignment_exception
  762. b .ret_from_except
  763. .align 7
  764. .globl program_check_common
  765. program_check_common:
  766. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  767. bl .save_nvgprs
  768. addi r3,r1,STACK_FRAME_OVERHEAD
  769. ENABLE_INTS
  770. bl .program_check_exception
  771. b .ret_from_except
  772. .align 7
  773. .globl fp_unavailable_common
  774. fp_unavailable_common:
  775. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  776. bne .load_up_fpu /* if from user, just load it up */
  777. bl .save_nvgprs
  778. addi r3,r1,STACK_FRAME_OVERHEAD
  779. ENABLE_INTS
  780. bl .kernel_fp_unavailable_exception
  781. BUG_OPCODE
  782. /*
  783. * load_up_fpu(unused, unused, tsk)
  784. * Disable FP for the task which had the FPU previously,
  785. * and save its floating-point registers in its thread_struct.
  786. * Enables the FPU for use in the kernel on return.
  787. * On SMP we know the fpu is free, since we give it up every
  788. * switch (ie, no lazy save of the FP registers).
  789. * On entry: r13 == 'current' && last_task_used_math != 'current'
  790. */
  791. _STATIC(load_up_fpu)
  792. mfmsr r5 /* grab the current MSR */
  793. ori r5,r5,MSR_FP
  794. mtmsrd r5 /* enable use of fpu now */
  795. isync
  796. /*
  797. * For SMP, we don't do lazy FPU switching because it just gets too
  798. * horrendously complex, especially when a task switches from one CPU
  799. * to another. Instead we call giveup_fpu in switch_to.
  800. *
  801. */
  802. #ifndef CONFIG_SMP
  803. ld r3,last_task_used_math@got(r2)
  804. ld r4,0(r3)
  805. cmpdi 0,r4,0
  806. beq 1f
  807. /* Save FP state to last_task_used_math's THREAD struct */
  808. addi r4,r4,THREAD
  809. SAVE_32FPRS(0, r4)
  810. mffs fr0
  811. stfd fr0,THREAD_FPSCR(r4)
  812. /* Disable FP for last_task_used_math */
  813. ld r5,PT_REGS(r4)
  814. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  815. li r6,MSR_FP|MSR_FE0|MSR_FE1
  816. andc r4,r4,r6
  817. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  818. 1:
  819. #endif /* CONFIG_SMP */
  820. /* enable use of FP after return */
  821. ld r4,PACACURRENT(r13)
  822. addi r5,r4,THREAD /* Get THREAD */
  823. ld r4,THREAD_FPEXC_MODE(r5)
  824. ori r12,r12,MSR_FP
  825. or r12,r12,r4
  826. std r12,_MSR(r1)
  827. lfd fr0,THREAD_FPSCR(r5)
  828. mtfsf 0xff,fr0
  829. REST_32FPRS(0, r5)
  830. #ifndef CONFIG_SMP
  831. /* Update last_task_used_math to 'current' */
  832. subi r4,r5,THREAD /* Back to 'current' */
  833. std r4,0(r3)
  834. #endif /* CONFIG_SMP */
  835. /* restore registers and return */
  836. b fast_exception_return
  837. .align 7
  838. .globl altivec_unavailable_common
  839. altivec_unavailable_common:
  840. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  841. #ifdef CONFIG_ALTIVEC
  842. BEGIN_FTR_SECTION
  843. bne .load_up_altivec /* if from user, just load it up */
  844. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  845. #endif
  846. bl .save_nvgprs
  847. addi r3,r1,STACK_FRAME_OVERHEAD
  848. ENABLE_INTS
  849. bl .altivec_unavailable_exception
  850. b .ret_from_except
  851. #ifdef CONFIG_ALTIVEC
  852. /*
  853. * load_up_altivec(unused, unused, tsk)
  854. * Disable VMX for the task which had it previously,
  855. * and save its vector registers in its thread_struct.
  856. * Enables the VMX for use in the kernel on return.
  857. * On SMP we know the VMX is free, since we give it up every
  858. * switch (ie, no lazy save of the vector registers).
  859. * On entry: r13 == 'current' && last_task_used_altivec != 'current'
  860. */
  861. _STATIC(load_up_altivec)
  862. mfmsr r5 /* grab the current MSR */
  863. oris r5,r5,MSR_VEC@h
  864. mtmsrd r5 /* enable use of VMX now */
  865. isync
  866. /*
  867. * For SMP, we don't do lazy VMX switching because it just gets too
  868. * horrendously complex, especially when a task switches from one CPU
  869. * to another. Instead we call giveup_altvec in switch_to.
  870. * VRSAVE isn't dealt with here, that is done in the normal context
  871. * switch code. Note that we could rely on vrsave value to eventually
  872. * avoid saving all of the VREGs here...
  873. */
  874. #ifndef CONFIG_SMP
  875. ld r3,last_task_used_altivec@got(r2)
  876. ld r4,0(r3)
  877. cmpdi 0,r4,0
  878. beq 1f
  879. /* Save VMX state to last_task_used_altivec's THREAD struct */
  880. addi r4,r4,THREAD
  881. SAVE_32VRS(0,r5,r4)
  882. mfvscr vr0
  883. li r10,THREAD_VSCR
  884. stvx vr0,r10,r4
  885. /* Disable VMX for last_task_used_altivec */
  886. ld r5,PT_REGS(r4)
  887. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  888. lis r6,MSR_VEC@h
  889. andc r4,r4,r6
  890. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  891. 1:
  892. #endif /* CONFIG_SMP */
  893. /* Hack: if we get an altivec unavailable trap with VRSAVE
  894. * set to all zeros, we assume this is a broken application
  895. * that fails to set it properly, and thus we switch it to
  896. * all 1's
  897. */
  898. mfspr r4,SPRN_VRSAVE
  899. cmpdi 0,r4,0
  900. bne+ 1f
  901. li r4,-1
  902. mtspr SPRN_VRSAVE,r4
  903. 1:
  904. /* enable use of VMX after return */
  905. ld r4,PACACURRENT(r13)
  906. addi r5,r4,THREAD /* Get THREAD */
  907. oris r12,r12,MSR_VEC@h
  908. std r12,_MSR(r1)
  909. li r4,1
  910. li r10,THREAD_VSCR
  911. stw r4,THREAD_USED_VR(r5)
  912. lvx vr0,r10,r5
  913. mtvscr vr0
  914. REST_32VRS(0,r4,r5)
  915. #ifndef CONFIG_SMP
  916. /* Update last_task_used_math to 'current' */
  917. subi r4,r5,THREAD /* Back to 'current' */
  918. std r4,0(r3)
  919. #endif /* CONFIG_SMP */
  920. /* restore registers and return */
  921. b fast_exception_return
  922. #endif /* CONFIG_ALTIVEC */
  923. /*
  924. * Hash table stuff
  925. */
  926. .align 7
  927. _GLOBAL(do_hash_page)
  928. std r3,_DAR(r1)
  929. std r4,_DSISR(r1)
  930. andis. r0,r4,0xa450 /* weird error? */
  931. bne- .handle_page_fault /* if not, try to insert a HPTE */
  932. BEGIN_FTR_SECTION
  933. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  934. bne- .do_ste_alloc /* If so handle it */
  935. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  936. /*
  937. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  938. * accessing a userspace segment (even from the kernel). We assume
  939. * kernel addresses always have the high bit set.
  940. */
  941. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  942. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  943. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  944. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  945. ori r4,r4,1 /* add _PAGE_PRESENT */
  946. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  947. /*
  948. * On iSeries, we soft-disable interrupts here, then
  949. * hard-enable interrupts so that the hash_page code can spin on
  950. * the hash_table_lock without problems on a shared processor.
  951. */
  952. DISABLE_INTS
  953. /*
  954. * r3 contains the faulting address
  955. * r4 contains the required access permissions
  956. * r5 contains the trap number
  957. *
  958. * at return r3 = 0 for success
  959. */
  960. bl .hash_page /* build HPTE if possible */
  961. cmpdi r3,0 /* see if hash_page succeeded */
  962. #ifdef DO_SOFT_DISABLE
  963. /*
  964. * If we had interrupts soft-enabled at the point where the
  965. * DSI/ISI occurred, and an interrupt came in during hash_page,
  966. * handle it now.
  967. * We jump to ret_from_except_lite rather than fast_exception_return
  968. * because ret_from_except_lite will check for and handle pending
  969. * interrupts if necessary.
  970. */
  971. beq .ret_from_except_lite
  972. /* For a hash failure, we don't bother re-enabling interrupts */
  973. ble- 12f
  974. /*
  975. * hash_page couldn't handle it, set soft interrupt enable back
  976. * to what it was before the trap. Note that .local_irq_restore
  977. * handles any interrupts pending at this point.
  978. */
  979. ld r3,SOFTE(r1)
  980. bl .local_irq_restore
  981. b 11f
  982. #else
  983. beq fast_exception_return /* Return from exception on success */
  984. ble- 12f /* Failure return from hash_page */
  985. /* fall through */
  986. #endif
  987. /* Here we have a page fault that hash_page can't handle. */
  988. _GLOBAL(handle_page_fault)
  989. ENABLE_INTS
  990. 11: ld r4,_DAR(r1)
  991. ld r5,_DSISR(r1)
  992. addi r3,r1,STACK_FRAME_OVERHEAD
  993. bl .do_page_fault
  994. cmpdi r3,0
  995. beq+ .ret_from_except_lite
  996. bl .save_nvgprs
  997. mr r5,r3
  998. addi r3,r1,STACK_FRAME_OVERHEAD
  999. lwz r4,_DAR(r1)
  1000. bl .bad_page_fault
  1001. b .ret_from_except
  1002. /* We have a page fault that hash_page could handle but HV refused
  1003. * the PTE insertion
  1004. */
  1005. 12: bl .save_nvgprs
  1006. addi r3,r1,STACK_FRAME_OVERHEAD
  1007. lwz r4,_DAR(r1)
  1008. bl .low_hash_fault
  1009. b .ret_from_except
  1010. /* here we have a segment miss */
  1011. _GLOBAL(do_ste_alloc)
  1012. bl .ste_allocate /* try to insert stab entry */
  1013. cmpdi r3,0
  1014. beq+ fast_exception_return
  1015. b .handle_page_fault
  1016. /*
  1017. * r13 points to the PACA, r9 contains the saved CR,
  1018. * r11 and r12 contain the saved SRR0 and SRR1.
  1019. * r9 - r13 are saved in paca->exslb.
  1020. * We assume we aren't going to take any exceptions during this procedure.
  1021. * We assume (DAR >> 60) == 0xc.
  1022. */
  1023. .align 7
  1024. _GLOBAL(do_stab_bolted)
  1025. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1026. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  1027. /* Hash to the primary group */
  1028. ld r10,PACASTABVIRT(r13)
  1029. mfspr r11,DAR
  1030. srdi r11,r11,28
  1031. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  1032. /* Calculate VSID */
  1033. /* This is a kernel address, so protovsid = ESID */
  1034. ASM_VSID_SCRAMBLE(r11, r9)
  1035. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  1036. /* Search the primary group for a free entry */
  1037. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  1038. andi. r11,r11,0x80
  1039. beq 2f
  1040. addi r10,r10,16
  1041. andi. r11,r10,0x70
  1042. bne 1b
  1043. /* Stick for only searching the primary group for now. */
  1044. /* At least for now, we use a very simple random castout scheme */
  1045. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  1046. mftb r11
  1047. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  1048. ori r11,r11,0x10
  1049. /* r10 currently points to an ste one past the group of interest */
  1050. /* make it point to the randomly selected entry */
  1051. subi r10,r10,128
  1052. or r10,r10,r11 /* r10 is the entry to invalidate */
  1053. isync /* mark the entry invalid */
  1054. ld r11,0(r10)
  1055. rldicl r11,r11,56,1 /* clear the valid bit */
  1056. rotldi r11,r11,8
  1057. std r11,0(r10)
  1058. sync
  1059. clrrdi r11,r11,28 /* Get the esid part of the ste */
  1060. slbie r11
  1061. 2: std r9,8(r10) /* Store the vsid part of the ste */
  1062. eieio
  1063. mfspr r11,DAR /* Get the new esid */
  1064. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  1065. ori r11,r11,0x90 /* Turn on valid and kp */
  1066. std r11,0(r10) /* Put new entry back into the stab */
  1067. sync
  1068. /* All done -- return from exception. */
  1069. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1070. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  1071. andi. r10,r12,MSR_RI
  1072. beq- unrecov_slb
  1073. mtcrf 0x80,r9 /* restore CR */
  1074. mfmsr r10
  1075. clrrdi r10,r10,2
  1076. mtmsrd r10,1
  1077. mtspr SRR0,r11
  1078. mtspr SRR1,r12
  1079. ld r9,PACA_EXSLB+EX_R9(r13)
  1080. ld r10,PACA_EXSLB+EX_R10(r13)
  1081. ld r11,PACA_EXSLB+EX_R11(r13)
  1082. ld r12,PACA_EXSLB+EX_R12(r13)
  1083. ld r13,PACA_EXSLB+EX_R13(r13)
  1084. rfid
  1085. b . /* prevent speculative execution */
  1086. /*
  1087. * r13 points to the PACA, r9 contains the saved CR,
  1088. * r11 and r12 contain the saved SRR0 and SRR1.
  1089. * r3 has the faulting address
  1090. * r9 - r13 are saved in paca->exslb.
  1091. * r3 is saved in paca->slb_r3
  1092. * We assume we aren't going to take any exceptions during this procedure.
  1093. */
  1094. _GLOBAL(do_slb_miss)
  1095. mflr r10
  1096. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1097. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1098. bl .slb_allocate /* handle it */
  1099. /* All done -- return from exception. */
  1100. ld r10,PACA_EXSLB+EX_LR(r13)
  1101. ld r3,PACA_EXSLB+EX_R3(r13)
  1102. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1103. #ifdef CONFIG_PPC_ISERIES
  1104. ld r11,PACALPPACA+LPPACASRR0(r13) /* get SRR0 value */
  1105. #endif /* CONFIG_PPC_ISERIES */
  1106. mtlr r10
  1107. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1108. beq- unrecov_slb
  1109. .machine push
  1110. .machine "power4"
  1111. mtcrf 0x80,r9
  1112. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1113. .machine pop
  1114. #ifdef CONFIG_PPC_ISERIES
  1115. mtspr SRR0,r11
  1116. mtspr SRR1,r12
  1117. #endif /* CONFIG_PPC_ISERIES */
  1118. ld r9,PACA_EXSLB+EX_R9(r13)
  1119. ld r10,PACA_EXSLB+EX_R10(r13)
  1120. ld r11,PACA_EXSLB+EX_R11(r13)
  1121. ld r12,PACA_EXSLB+EX_R12(r13)
  1122. ld r13,PACA_EXSLB+EX_R13(r13)
  1123. rfid
  1124. b . /* prevent speculative execution */
  1125. unrecov_slb:
  1126. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1127. DISABLE_INTS
  1128. bl .save_nvgprs
  1129. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1130. bl .unrecoverable_exception
  1131. b 1b
  1132. /*
  1133. * Space for CPU0's segment table.
  1134. *
  1135. * On iSeries, the hypervisor must fill in at least one entry before
  1136. * we get control (with relocate on). The address is give to the hv
  1137. * as a page number (see xLparMap in LparData.c), so this must be at a
  1138. * fixed address (the linker can't compute (u64)&initial_stab >>
  1139. * PAGE_SHIFT).
  1140. */
  1141. . = STAB0_PHYS_ADDR /* 0x6000 */
  1142. .globl initial_stab
  1143. initial_stab:
  1144. .space 4096
  1145. /*
  1146. * Data area reserved for FWNMI option.
  1147. * This address (0x7000) is fixed by the RPA.
  1148. */
  1149. .= 0x7000
  1150. .globl fwnmi_data_area
  1151. fwnmi_data_area:
  1152. .space PAGE_SIZE
  1153. /*
  1154. * On pSeries, secondary processors spin in the following code.
  1155. * At entry, r3 = this processor's number (physical cpu id)
  1156. */
  1157. _GLOBAL(pSeries_secondary_smp_init)
  1158. mr r24,r3
  1159. /* turn on 64-bit mode */
  1160. bl .enable_64b_mode
  1161. isync
  1162. /* Copy some CPU settings from CPU 0 */
  1163. bl .__restore_cpu_setup
  1164. /* Set up a paca value for this processor. Since we have the
  1165. * physical cpu id in r24, we need to search the pacas to find
  1166. * which logical id maps to our physical one.
  1167. */
  1168. LOADADDR(r13, paca) /* Get base vaddr of paca array */
  1169. li r5,0 /* logical cpu id */
  1170. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  1171. cmpw r6,r24 /* Compare to our id */
  1172. beq 2f
  1173. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  1174. addi r5,r5,1
  1175. cmpwi r5,NR_CPUS
  1176. blt 1b
  1177. mr r3,r24 /* not found, copy phys to r3 */
  1178. b .kexec_wait /* next kernel might do better */
  1179. 2: mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1180. /* From now on, r24 is expected to be logica cpuid */
  1181. mr r24,r5
  1182. 3: HMT_LOW
  1183. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  1184. /* start. */
  1185. sync
  1186. /* Create a temp kernel stack for use before relocation is on. */
  1187. ld r1,PACAEMERGSP(r13)
  1188. subi r1,r1,STACK_FRAME_OVERHEAD
  1189. cmpwi 0,r23,0
  1190. #ifdef CONFIG_SMP
  1191. #ifdef SECONDARY_PROCESSORS
  1192. bne .__secondary_start
  1193. #endif
  1194. #endif
  1195. b 3b /* Loop until told to go */
  1196. #ifdef CONFIG_PPC_ISERIES
  1197. _STATIC(__start_initialization_iSeries)
  1198. /* Clear out the BSS */
  1199. LOADADDR(r11,__bss_stop)
  1200. LOADADDR(r8,__bss_start)
  1201. sub r11,r11,r8 /* bss size */
  1202. addi r11,r11,7 /* round up to an even double word */
  1203. rldicl. r11,r11,61,3 /* shift right by 3 */
  1204. beq 4f
  1205. addi r8,r8,-8
  1206. li r0,0
  1207. mtctr r11 /* zero this many doublewords */
  1208. 3: stdu r0,8(r8)
  1209. bdnz 3b
  1210. 4:
  1211. LOADADDR(r1,init_thread_union)
  1212. addi r1,r1,THREAD_SIZE
  1213. li r0,0
  1214. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1215. LOADADDR(r3,cpu_specs)
  1216. LOADADDR(r4,cur_cpu_spec)
  1217. li r5,0
  1218. bl .identify_cpu
  1219. LOADADDR(r2,__toc_start)
  1220. addi r2,r2,0x4000
  1221. addi r2,r2,0x4000
  1222. bl .iSeries_early_setup
  1223. /* relocation is on at this point */
  1224. b .start_here_common
  1225. #endif /* CONFIG_PPC_ISERIES */
  1226. #ifdef CONFIG_PPC_MULTIPLATFORM
  1227. _STATIC(__mmu_off)
  1228. mfmsr r3
  1229. andi. r0,r3,MSR_IR|MSR_DR
  1230. beqlr
  1231. andc r3,r3,r0
  1232. mtspr SPRN_SRR0,r4
  1233. mtspr SPRN_SRR1,r3
  1234. sync
  1235. rfid
  1236. b . /* prevent speculative execution */
  1237. /*
  1238. * Here is our main kernel entry point. We support currently 2 kind of entries
  1239. * depending on the value of r5.
  1240. *
  1241. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  1242. * in r3...r7
  1243. *
  1244. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  1245. * DT block, r4 is a physical pointer to the kernel itself
  1246. *
  1247. */
  1248. _GLOBAL(__start_initialization_multiplatform)
  1249. /*
  1250. * Are we booted from a PROM Of-type client-interface ?
  1251. */
  1252. cmpldi cr0,r5,0
  1253. bne .__boot_from_prom /* yes -> prom */
  1254. /* Save parameters */
  1255. mr r31,r3
  1256. mr r30,r4
  1257. /* Make sure we are running in 64 bits mode */
  1258. bl .enable_64b_mode
  1259. /* Setup some critical 970 SPRs before switching MMU off */
  1260. bl .__970_cpu_preinit
  1261. /* cpu # */
  1262. li r24,0
  1263. /* Switch off MMU if not already */
  1264. LOADADDR(r4, .__after_prom_start - KERNELBASE)
  1265. add r4,r4,r30
  1266. bl .__mmu_off
  1267. b .__after_prom_start
  1268. _STATIC(__boot_from_prom)
  1269. /* Save parameters */
  1270. mr r31,r3
  1271. mr r30,r4
  1272. mr r29,r5
  1273. mr r28,r6
  1274. mr r27,r7
  1275. /* Make sure we are running in 64 bits mode */
  1276. bl .enable_64b_mode
  1277. /* put a relocation offset into r3 */
  1278. bl .reloc_offset
  1279. LOADADDR(r2,__toc_start)
  1280. addi r2,r2,0x4000
  1281. addi r2,r2,0x4000
  1282. /* Relocate the TOC from a virt addr to a real addr */
  1283. sub r2,r2,r3
  1284. /* Restore parameters */
  1285. mr r3,r31
  1286. mr r4,r30
  1287. mr r5,r29
  1288. mr r6,r28
  1289. mr r7,r27
  1290. /* Do all of the interaction with OF client interface */
  1291. bl .prom_init
  1292. /* We never return */
  1293. trap
  1294. /*
  1295. * At this point, r3 contains the physical address we are running at,
  1296. * returned by prom_init()
  1297. */
  1298. _STATIC(__after_prom_start)
  1299. /*
  1300. * We need to run with __start at physical address 0.
  1301. * This will leave some code in the first 256B of
  1302. * real memory, which are reserved for software use.
  1303. * The remainder of the first page is loaded with the fixed
  1304. * interrupt vectors. The next two pages are filled with
  1305. * unknown exception placeholders.
  1306. *
  1307. * Note: This process overwrites the OF exception vectors.
  1308. * r26 == relocation offset
  1309. * r27 == KERNELBASE
  1310. */
  1311. bl .reloc_offset
  1312. mr r26,r3
  1313. SET_REG_TO_CONST(r27,KERNELBASE)
  1314. li r3,0 /* target addr */
  1315. // XXX FIXME: Use phys returned by OF (r30)
  1316. sub r4,r27,r26 /* source addr */
  1317. /* current address of _start */
  1318. /* i.e. where we are running */
  1319. /* the source addr */
  1320. LOADADDR(r5,copy_to_here) /* # bytes of memory to copy */
  1321. sub r5,r5,r27
  1322. li r6,0x100 /* Start offset, the first 0x100 */
  1323. /* bytes were copied earlier. */
  1324. bl .copy_and_flush /* copy the first n bytes */
  1325. /* this includes the code being */
  1326. /* executed here. */
  1327. LOADADDR(r0, 4f) /* Jump to the copy of this code */
  1328. mtctr r0 /* that we just made/relocated */
  1329. bctr
  1330. 4: LOADADDR(r5,klimit)
  1331. sub r5,r5,r26
  1332. ld r5,0(r5) /* get the value of klimit */
  1333. sub r5,r5,r27
  1334. bl .copy_and_flush /* copy the rest */
  1335. b .start_here_multiplatform
  1336. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1337. /*
  1338. * Copy routine used to copy the kernel to start at physical address 0
  1339. * and flush and invalidate the caches as needed.
  1340. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  1341. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  1342. *
  1343. * Note: this routine *only* clobbers r0, r6 and lr
  1344. */
  1345. _GLOBAL(copy_and_flush)
  1346. addi r5,r5,-8
  1347. addi r6,r6,-8
  1348. 4: li r0,16 /* Use the least common */
  1349. /* denominator cache line */
  1350. /* size. This results in */
  1351. /* extra cache line flushes */
  1352. /* but operation is correct. */
  1353. /* Can't get cache line size */
  1354. /* from NACA as it is being */
  1355. /* moved too. */
  1356. mtctr r0 /* put # words/line in ctr */
  1357. 3: addi r6,r6,8 /* copy a cache line */
  1358. ldx r0,r6,r4
  1359. stdx r0,r6,r3
  1360. bdnz 3b
  1361. dcbst r6,r3 /* write it to memory */
  1362. sync
  1363. icbi r6,r3 /* flush the icache line */
  1364. cmpld 0,r6,r5
  1365. blt 4b
  1366. sync
  1367. addi r5,r5,8
  1368. addi r6,r6,8
  1369. blr
  1370. .align 8
  1371. copy_to_here:
  1372. #ifdef CONFIG_SMP
  1373. #ifdef CONFIG_PPC_PMAC
  1374. /*
  1375. * On PowerMac, secondary processors starts from the reset vector, which
  1376. * is temporarily turned into a call to one of the functions below.
  1377. */
  1378. .section ".text";
  1379. .align 2 ;
  1380. .globl pmac_secondary_start_1
  1381. pmac_secondary_start_1:
  1382. li r24, 1
  1383. b .pmac_secondary_start
  1384. .globl pmac_secondary_start_2
  1385. pmac_secondary_start_2:
  1386. li r24, 2
  1387. b .pmac_secondary_start
  1388. .globl pmac_secondary_start_3
  1389. pmac_secondary_start_3:
  1390. li r24, 3
  1391. b .pmac_secondary_start
  1392. _GLOBAL(pmac_secondary_start)
  1393. /* turn on 64-bit mode */
  1394. bl .enable_64b_mode
  1395. isync
  1396. /* Copy some CPU settings from CPU 0 */
  1397. bl .__restore_cpu_setup
  1398. /* pSeries do that early though I don't think we really need it */
  1399. mfmsr r3
  1400. ori r3,r3,MSR_RI
  1401. mtmsrd r3 /* RI on */
  1402. /* Set up a paca value for this processor. */
  1403. LOADADDR(r4, paca) /* Get base vaddr of paca array */
  1404. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  1405. add r13,r13,r4 /* for this processor. */
  1406. mtspr SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1407. /* Create a temp kernel stack for use before relocation is on. */
  1408. ld r1,PACAEMERGSP(r13)
  1409. subi r1,r1,STACK_FRAME_OVERHEAD
  1410. b .__secondary_start
  1411. #endif /* CONFIG_PPC_PMAC */
  1412. /*
  1413. * This function is called after the master CPU has released the
  1414. * secondary processors. The execution environment is relocation off.
  1415. * The paca for this processor has the following fields initialized at
  1416. * this point:
  1417. * 1. Processor number
  1418. * 2. Segment table pointer (virtual address)
  1419. * On entry the following are set:
  1420. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  1421. * r24 = cpu# (in Linux terms)
  1422. * r13 = paca virtual address
  1423. * SPRG3 = paca virtual address
  1424. */
  1425. _GLOBAL(__secondary_start)
  1426. HMT_MEDIUM /* Set thread priority to MEDIUM */
  1427. ld r2,PACATOC(r13)
  1428. li r6,0
  1429. stb r6,PACAPROCENABLED(r13)
  1430. #ifndef CONFIG_PPC_ISERIES
  1431. /* Initialize the page table pointer register. */
  1432. LOADADDR(r6,_SDR1)
  1433. ld r6,0(r6) /* get the value of _SDR1 */
  1434. mtspr SDR1,r6 /* set the htab location */
  1435. #endif
  1436. /* Initialize the first segment table (or SLB) entry */
  1437. ld r3,PACASTABVIRT(r13) /* get addr of segment table */
  1438. bl .stab_initialize
  1439. /* Initialize the kernel stack. Just a repeat for iSeries. */
  1440. LOADADDR(r3,current_set)
  1441. sldi r28,r24,3 /* get current_set[cpu#] */
  1442. ldx r1,r3,r28
  1443. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1444. std r1,PACAKSAVE(r13)
  1445. ld r3,PACASTABREAL(r13) /* get raddr of segment table */
  1446. ori r4,r3,1 /* turn on valid bit */
  1447. #ifdef CONFIG_PPC_ISERIES
  1448. li r0,-1 /* hypervisor call */
  1449. li r3,1
  1450. sldi r3,r3,63 /* 0x8000000000000000 */
  1451. ori r3,r3,4 /* 0x8000000000000004 */
  1452. sc /* HvCall_setASR */
  1453. #else
  1454. /* set the ASR */
  1455. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1456. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1457. cmpldi r3,PLATFORM_PSERIES_LPAR
  1458. bne 98f
  1459. mfspr r3,PVR
  1460. srwi r3,r3,16
  1461. cmpwi r3,0x37 /* SStar */
  1462. beq 97f
  1463. cmpwi r3,0x36 /* IStar */
  1464. beq 97f
  1465. cmpwi r3,0x34 /* Pulsar */
  1466. bne 98f
  1467. 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
  1468. HVSC /* Invoking hcall */
  1469. b 99f
  1470. 98: /* !(rpa hypervisor) || !(star) */
  1471. mtasr r4 /* set the stab location */
  1472. 99:
  1473. #endif
  1474. li r7,0
  1475. mtlr r7
  1476. /* enable MMU and jump to start_secondary */
  1477. LOADADDR(r3,.start_secondary_prolog)
  1478. SET_REG_TO_CONST(r4, MSR_KERNEL)
  1479. #ifdef DO_SOFT_DISABLE
  1480. ori r4,r4,MSR_EE
  1481. #endif
  1482. mtspr SRR0,r3
  1483. mtspr SRR1,r4
  1484. rfid
  1485. b . /* prevent speculative execution */
  1486. /*
  1487. * Running with relocation on at this point. All we want to do is
  1488. * zero the stack back-chain pointer before going into C code.
  1489. */
  1490. _GLOBAL(start_secondary_prolog)
  1491. li r3,0
  1492. std r3,0(r1) /* Zero the stack frame pointer */
  1493. bl .start_secondary
  1494. #endif
  1495. /*
  1496. * This subroutine clobbers r11 and r12
  1497. */
  1498. _GLOBAL(enable_64b_mode)
  1499. mfmsr r11 /* grab the current MSR */
  1500. li r12,1
  1501. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  1502. or r11,r11,r12
  1503. li r12,1
  1504. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  1505. or r11,r11,r12
  1506. mtmsrd r11
  1507. isync
  1508. blr
  1509. #ifdef CONFIG_PPC_MULTIPLATFORM
  1510. /*
  1511. * This is where the main kernel code starts.
  1512. */
  1513. _STATIC(start_here_multiplatform)
  1514. /* get a new offset, now that the kernel has moved. */
  1515. bl .reloc_offset
  1516. mr r26,r3
  1517. /* Clear out the BSS. It may have been done in prom_init,
  1518. * already but that's irrelevant since prom_init will soon
  1519. * be detached from the kernel completely. Besides, we need
  1520. * to clear it now for kexec-style entry.
  1521. */
  1522. LOADADDR(r11,__bss_stop)
  1523. LOADADDR(r8,__bss_start)
  1524. sub r11,r11,r8 /* bss size */
  1525. addi r11,r11,7 /* round up to an even double word */
  1526. rldicl. r11,r11,61,3 /* shift right by 3 */
  1527. beq 4f
  1528. addi r8,r8,-8
  1529. li r0,0
  1530. mtctr r11 /* zero this many doublewords */
  1531. 3: stdu r0,8(r8)
  1532. bdnz 3b
  1533. 4:
  1534. mfmsr r6
  1535. ori r6,r6,MSR_RI
  1536. mtmsrd r6 /* RI on */
  1537. #ifdef CONFIG_HMT
  1538. /* Start up the second thread on cpu 0 */
  1539. mfspr r3,PVR
  1540. srwi r3,r3,16
  1541. cmpwi r3,0x34 /* Pulsar */
  1542. beq 90f
  1543. cmpwi r3,0x36 /* Icestar */
  1544. beq 90f
  1545. cmpwi r3,0x37 /* SStar */
  1546. beq 90f
  1547. b 91f /* HMT not supported */
  1548. 90: li r3,0
  1549. bl .hmt_start_secondary
  1550. 91:
  1551. #endif
  1552. /* The following gets the stack and TOC set up with the regs */
  1553. /* pointing to the real addr of the kernel stack. This is */
  1554. /* all done to support the C function call below which sets */
  1555. /* up the htab. This is done because we have relocated the */
  1556. /* kernel but are still running in real mode. */
  1557. LOADADDR(r3,init_thread_union)
  1558. sub r3,r3,r26
  1559. /* set up a stack pointer (physical address) */
  1560. addi r1,r3,THREAD_SIZE
  1561. li r0,0
  1562. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1563. /* set up the TOC (physical address) */
  1564. LOADADDR(r2,__toc_start)
  1565. addi r2,r2,0x4000
  1566. addi r2,r2,0x4000
  1567. sub r2,r2,r26
  1568. LOADADDR(r3,cpu_specs)
  1569. sub r3,r3,r26
  1570. LOADADDR(r4,cur_cpu_spec)
  1571. sub r4,r4,r26
  1572. mr r5,r26
  1573. bl .identify_cpu
  1574. /* Save some low level config HIDs of CPU0 to be copied to
  1575. * other CPUs later on, or used for suspend/resume
  1576. */
  1577. bl .__save_cpu_setup
  1578. sync
  1579. /* Setup a valid physical PACA pointer in SPRG3 for early_setup
  1580. * note that boot_cpuid can always be 0 nowadays since there is
  1581. * nowhere it can be initialized differently before we reach this
  1582. * code
  1583. */
  1584. LOADADDR(r27, boot_cpuid)
  1585. sub r27,r27,r26
  1586. lwz r27,0(r27)
  1587. LOADADDR(r24, paca) /* Get base vaddr of paca array */
  1588. mulli r13,r27,PACA_SIZE /* Calculate vaddr of right paca */
  1589. add r13,r13,r24 /* for this processor. */
  1590. sub r13,r13,r26 /* convert to physical addr */
  1591. mtspr SPRG3,r13 /* PPPBBB: Temp... -Peter */
  1592. /* Do very early kernel initializations, including initial hash table,
  1593. * stab and slb setup before we turn on relocation. */
  1594. /* Restore parameters passed from prom_init/kexec */
  1595. mr r3,r31
  1596. bl .early_setup
  1597. /* set the ASR */
  1598. ld r3,PACASTABREAL(r13)
  1599. ori r4,r3,1 /* turn on valid bit */
  1600. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1601. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1602. cmpldi r3,PLATFORM_PSERIES_LPAR
  1603. bne 98f
  1604. mfspr r3,PVR
  1605. srwi r3,r3,16
  1606. cmpwi r3,0x37 /* SStar */
  1607. beq 97f
  1608. cmpwi r3,0x36 /* IStar */
  1609. beq 97f
  1610. cmpwi r3,0x34 /* Pulsar */
  1611. bne 98f
  1612. 97: li r3,H_SET_ASR /* hcall = H_SET_ASR */
  1613. HVSC /* Invoking hcall */
  1614. b 99f
  1615. 98: /* !(rpa hypervisor) || !(star) */
  1616. mtasr r4 /* set the stab location */
  1617. 99:
  1618. /* Set SDR1 (hash table pointer) */
  1619. ld r3,systemcfg@got(r2) /* r3 = ptr to systemcfg */
  1620. lwz r3,PLATFORM(r3) /* r3 = platform flags */
  1621. /* Test if bit 0 is set (LPAR bit) */
  1622. andi. r3,r3,0x1
  1623. bne 98f
  1624. LOADADDR(r6,_SDR1) /* Only if NOT LPAR */
  1625. sub r6,r6,r26
  1626. ld r6,0(r6) /* get the value of _SDR1 */
  1627. mtspr SDR1,r6 /* set the htab location */
  1628. 98:
  1629. LOADADDR(r3,.start_here_common)
  1630. SET_REG_TO_CONST(r4, MSR_KERNEL)
  1631. mtspr SRR0,r3
  1632. mtspr SRR1,r4
  1633. rfid
  1634. b . /* prevent speculative execution */
  1635. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1636. /* This is where all platforms converge execution */
  1637. _STATIC(start_here_common)
  1638. /* relocation is on at this point */
  1639. /* The following code sets up the SP and TOC now that we are */
  1640. /* running with translation enabled. */
  1641. LOADADDR(r3,init_thread_union)
  1642. /* set up the stack */
  1643. addi r1,r3,THREAD_SIZE
  1644. li r0,0
  1645. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1646. /* Apply the CPUs-specific fixups (nop out sections not relevant
  1647. * to this CPU
  1648. */
  1649. li r3,0
  1650. bl .do_cpu_ftr_fixups
  1651. LOADADDR(r26, boot_cpuid)
  1652. lwz r26,0(r26)
  1653. LOADADDR(r24, paca) /* Get base vaddr of paca array */
  1654. mulli r13,r26,PACA_SIZE /* Calculate vaddr of right paca */
  1655. add r13,r13,r24 /* for this processor. */
  1656. mtspr SPRG3,r13
  1657. /* ptr to current */
  1658. LOADADDR(r4,init_task)
  1659. std r4,PACACURRENT(r13)
  1660. /* Load the TOC */
  1661. ld r2,PACATOC(r13)
  1662. std r1,PACAKSAVE(r13)
  1663. bl .setup_system
  1664. /* Load up the kernel context */
  1665. 5:
  1666. #ifdef DO_SOFT_DISABLE
  1667. li r5,0
  1668. stb r5,PACAPROCENABLED(r13) /* Soft Disabled */
  1669. mfmsr r5
  1670. ori r5,r5,MSR_EE /* Hard Enabled */
  1671. mtmsrd r5
  1672. #endif
  1673. bl .start_kernel
  1674. _GLOBAL(hmt_init)
  1675. #ifdef CONFIG_HMT
  1676. LOADADDR(r5, hmt_thread_data)
  1677. mfspr r7,PVR
  1678. srwi r7,r7,16
  1679. cmpwi r7,0x34 /* Pulsar */
  1680. beq 90f
  1681. cmpwi r7,0x36 /* Icestar */
  1682. beq 91f
  1683. cmpwi r7,0x37 /* SStar */
  1684. beq 91f
  1685. b 101f
  1686. 90: mfspr r6,PIR
  1687. andi. r6,r6,0x1f
  1688. b 92f
  1689. 91: mfspr r6,PIR
  1690. andi. r6,r6,0x3ff
  1691. 92: sldi r4,r24,3
  1692. stwx r6,r5,r4
  1693. bl .hmt_start_secondary
  1694. b 101f
  1695. __hmt_secondary_hold:
  1696. LOADADDR(r5, hmt_thread_data)
  1697. clrldi r5,r5,4
  1698. li r7,0
  1699. mfspr r6,PIR
  1700. mfspr r8,PVR
  1701. srwi r8,r8,16
  1702. cmpwi r8,0x34
  1703. bne 93f
  1704. andi. r6,r6,0x1f
  1705. b 103f
  1706. 93: andi. r6,r6,0x3f
  1707. 103: lwzx r8,r5,r7
  1708. cmpw r8,r6
  1709. beq 104f
  1710. addi r7,r7,8
  1711. b 103b
  1712. 104: addi r7,r7,4
  1713. lwzx r9,r5,r7
  1714. mr r24,r9
  1715. 101:
  1716. #endif
  1717. mr r3,r24
  1718. b .pSeries_secondary_smp_init
  1719. #ifdef CONFIG_HMT
  1720. _GLOBAL(hmt_start_secondary)
  1721. LOADADDR(r4,__hmt_secondary_hold)
  1722. clrldi r4,r4,4
  1723. mtspr NIADORM, r4
  1724. mfspr r4, MSRDORM
  1725. li r5, -65
  1726. and r4, r4, r5
  1727. mtspr MSRDORM, r4
  1728. lis r4,0xffef
  1729. ori r4,r4,0x7403
  1730. mtspr TSC, r4
  1731. li r4,0x1f4
  1732. mtspr TST, r4
  1733. mfspr r4, HID0
  1734. ori r4, r4, 0x1
  1735. mtspr HID0, r4
  1736. mfspr r4, SPRN_CTRLF
  1737. oris r4, r4, 0x40
  1738. mtspr SPRN_CTRLT, r4
  1739. blr
  1740. #endif
  1741. #if defined(CONFIG_KEXEC) || (defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES))
  1742. _GLOBAL(smp_release_cpus)
  1743. /* All secondary cpus are spinning on a common
  1744. * spinloop, release them all now so they can start
  1745. * to spin on their individual paca spinloops.
  1746. * For non SMP kernels, the secondary cpus never
  1747. * get out of the common spinloop.
  1748. */
  1749. li r3,1
  1750. LOADADDR(r5,__secondary_hold_spinloop)
  1751. std r3,0(r5)
  1752. sync
  1753. blr
  1754. #endif /* CONFIG_SMP && !CONFIG_PPC_ISERIES */
  1755. /*
  1756. * We put a few things here that have to be page-aligned.
  1757. * This stuff goes at the beginning of the data segment,
  1758. * which is page-aligned.
  1759. */
  1760. .data
  1761. .align 12
  1762. .globl sdata
  1763. sdata:
  1764. .globl empty_zero_page
  1765. empty_zero_page:
  1766. .space 4096
  1767. .globl swapper_pg_dir
  1768. swapper_pg_dir:
  1769. .space 4096
  1770. /*
  1771. * This space gets a copy of optional info passed to us by the bootstrap
  1772. * Used to pass parameters into the kernel like root=/dev/sda1, etc.
  1773. */
  1774. .globl cmd_line
  1775. cmd_line:
  1776. .space COMMAND_LINE_SIZE