head_64.S 52 KB

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