head_64.S 53 KB

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