head_64.S 52 KB

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