head_64.S 53 KB

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