head_64.S 52 KB

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