head_64.S 55 KB

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