head_64.S 52 KB

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