head_64.S 52 KB

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