head_64.S 55 KB

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