head.S 52 KB

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