head_64.S 51 KB

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