head_64.S 52 KB

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