head_64.S 51 KB

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