head_64.S 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  6. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Adapted for Power Macintosh by Paul Mackerras.
  8. * Low-level exception handlers and MMU support
  9. * rewritten by Paul Mackerras.
  10. * Copyright (C) 1996 Paul Mackerras.
  11. *
  12. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  13. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  14. *
  15. * This file contains the low-level support and setup for the
  16. * PowerPC-64 platform, including trap and interrupt dispatch.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #include <linux/threads.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/mmu.h>
  27. #include <asm/ppc_asm.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/bug.h>
  30. #include <asm/cputable.h>
  31. #include <asm/setup.h>
  32. #include <asm/hvcall.h>
  33. #include <asm/iseries/lpar_map.h>
  34. #include <asm/thread_info.h>
  35. #include <asm/firmware.h>
  36. #include <asm/page_64.h>
  37. #include <asm/exception.h>
  38. #include <asm/irqflags.h>
  39. /*
  40. * We layout physical memory as follows:
  41. * 0x0000 - 0x00ff : Secondary processor spin code
  42. * 0x0100 - 0x2fff : pSeries Interrupt prologs
  43. * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
  44. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  45. * 0x7000 - 0x7fff : FWNMI data area
  46. * 0x8000 - : Early init and support code
  47. */
  48. /*
  49. * SPRG Usage
  50. *
  51. * Register Definition
  52. *
  53. * SPRG0 reserved for hypervisor
  54. * SPRG1 temp - used to save gpr
  55. * SPRG2 temp - used to save gpr
  56. * SPRG3 virt addr of paca
  57. */
  58. /*
  59. * Entering into this code we make the following assumptions:
  60. * For pSeries:
  61. * 1. The MMU is off & open firmware is running in real mode.
  62. * 2. The kernel is entered at __start
  63. *
  64. * For iSeries:
  65. * 1. The MMU is on (as it always is for iSeries)
  66. * 2. The kernel is entered at system_reset_iSeries
  67. */
  68. .text
  69. .globl _stext
  70. _stext:
  71. _GLOBAL(__start)
  72. /* NOP this out unconditionally */
  73. BEGIN_FTR_SECTION
  74. b .__start_initialization_multiplatform
  75. END_FTR_SECTION(0, 1)
  76. /* Catch branch to 0 in real mode */
  77. trap
  78. /* Secondary processors spin on this value until it goes to 1. */
  79. .globl __secondary_hold_spinloop
  80. __secondary_hold_spinloop:
  81. .llong 0x0
  82. /* Secondary processors write this value with their cpu # */
  83. /* after they enter the spin loop immediately below. */
  84. .globl __secondary_hold_acknowledge
  85. __secondary_hold_acknowledge:
  86. .llong 0x0
  87. #ifdef CONFIG_PPC_ISERIES
  88. /*
  89. * At offset 0x20, there is a pointer to iSeries LPAR data.
  90. * This is required by the hypervisor
  91. */
  92. . = 0x20
  93. .llong hvReleaseData-KERNELBASE
  94. #endif /* CONFIG_PPC_ISERIES */
  95. . = 0x60
  96. /*
  97. * The following code is used to hold secondary processors
  98. * in a spin loop after they have entered the kernel, but
  99. * before the bulk of the kernel has been relocated. This code
  100. * is relocated to physical address 0x60 before prom_init is run.
  101. * All of it must fit below the first exception vector at 0x100.
  102. */
  103. _GLOBAL(__secondary_hold)
  104. mfmsr r24
  105. ori r24,r24,MSR_RI
  106. mtmsrd r24 /* RI on */
  107. /* Grab our physical cpu number */
  108. mr r24,r3
  109. /* Tell the master cpu we're here */
  110. /* Relocation is off & we are located at an address less */
  111. /* than 0x100, so only need to grab low order offset. */
  112. std r24,__secondary_hold_acknowledge@l(0)
  113. sync
  114. /* All secondary cpus wait here until told to start. */
  115. 100: ld r4,__secondary_hold_spinloop@l(0)
  116. cmpdi 0,r4,1
  117. bne 100b
  118. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  119. LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
  120. mtctr r4
  121. mr r3,r24
  122. bctr
  123. #else
  124. BUG_OPCODE
  125. #endif
  126. /* This value is used to mark exception frames on the stack. */
  127. .section ".toc","aw"
  128. exception_marker:
  129. .tc ID_72656773_68657265[TC],0x7265677368657265
  130. .text
  131. /*
  132. * This is the start of the interrupt handlers for pSeries
  133. * This code runs with relocation off.
  134. */
  135. . = 0x100
  136. .globl __start_interrupts
  137. __start_interrupts:
  138. STD_EXCEPTION_PSERIES(0x100, system_reset)
  139. . = 0x200
  140. _machine_check_pSeries:
  141. HMT_MEDIUM
  142. mtspr SPRN_SPRG1,r13 /* save r13 */
  143. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  144. . = 0x300
  145. .globl data_access_pSeries
  146. data_access_pSeries:
  147. HMT_MEDIUM
  148. mtspr SPRN_SPRG1,r13
  149. BEGIN_FTR_SECTION
  150. mtspr SPRN_SPRG2,r12
  151. mfspr r13,SPRN_DAR
  152. mfspr r12,SPRN_DSISR
  153. srdi r13,r13,60
  154. rlwimi r13,r12,16,0x20
  155. mfcr r12
  156. cmpwi r13,0x2c
  157. beq do_stab_bolted_pSeries
  158. mtcrf 0x80,r12
  159. mfspr r12,SPRN_SPRG2
  160. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  161. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
  162. . = 0x380
  163. .globl data_access_slb_pSeries
  164. data_access_slb_pSeries:
  165. HMT_MEDIUM
  166. mtspr SPRN_SPRG1,r13
  167. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  168. std r3,PACA_EXSLB+EX_R3(r13)
  169. mfspr r3,SPRN_DAR
  170. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  171. mfcr r9
  172. #ifdef __DISABLED__
  173. /* Keep that around for when we re-implement dynamic VSIDs */
  174. cmpdi r3,0
  175. bge slb_miss_user_pseries
  176. #endif /* __DISABLED__ */
  177. std r10,PACA_EXSLB+EX_R10(r13)
  178. std r11,PACA_EXSLB+EX_R11(r13)
  179. std r12,PACA_EXSLB+EX_R12(r13)
  180. mfspr r10,SPRN_SPRG1
  181. std r10,PACA_EXSLB+EX_R13(r13)
  182. mfspr r12,SPRN_SRR1 /* and SRR1 */
  183. b .slb_miss_realmode /* Rel. branch works in real mode */
  184. STD_EXCEPTION_PSERIES(0x400, instruction_access)
  185. . = 0x480
  186. .globl instruction_access_slb_pSeries
  187. instruction_access_slb_pSeries:
  188. HMT_MEDIUM
  189. mtspr SPRN_SPRG1,r13
  190. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  191. std r3,PACA_EXSLB+EX_R3(r13)
  192. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  193. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  194. mfcr r9
  195. #ifdef __DISABLED__
  196. /* Keep that around for when we re-implement dynamic VSIDs */
  197. cmpdi r3,0
  198. bge slb_miss_user_pseries
  199. #endif /* __DISABLED__ */
  200. std r10,PACA_EXSLB+EX_R10(r13)
  201. std r11,PACA_EXSLB+EX_R11(r13)
  202. std r12,PACA_EXSLB+EX_R12(r13)
  203. mfspr r10,SPRN_SPRG1
  204. std r10,PACA_EXSLB+EX_R13(r13)
  205. mfspr r12,SPRN_SRR1 /* and SRR1 */
  206. b .slb_miss_realmode /* Rel. branch works in real mode */
  207. MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
  208. STD_EXCEPTION_PSERIES(0x600, alignment)
  209. STD_EXCEPTION_PSERIES(0x700, program_check)
  210. STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
  211. MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
  212. STD_EXCEPTION_PSERIES(0xa00, trap_0a)
  213. STD_EXCEPTION_PSERIES(0xb00, trap_0b)
  214. . = 0xc00
  215. .globl system_call_pSeries
  216. system_call_pSeries:
  217. HMT_MEDIUM
  218. BEGIN_FTR_SECTION
  219. cmpdi r0,0x1ebe
  220. beq- 1f
  221. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
  222. mr r9,r13
  223. mfmsr r10
  224. mfspr r13,SPRN_SPRG3
  225. mfspr r11,SPRN_SRR0
  226. clrrdi r12,r13,32
  227. oris r12,r12,system_call_common@h
  228. ori r12,r12,system_call_common@l
  229. mtspr SPRN_SRR0,r12
  230. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  231. mfspr r12,SPRN_SRR1
  232. mtspr SPRN_SRR1,r10
  233. rfid
  234. b . /* prevent speculative execution */
  235. /* Fast LE/BE switch system call */
  236. 1: mfspr r12,SPRN_SRR1
  237. xori r12,r12,MSR_LE
  238. mtspr SPRN_SRR1,r12
  239. rfid /* return to userspace */
  240. b .
  241. STD_EXCEPTION_PSERIES(0xd00, single_step)
  242. STD_EXCEPTION_PSERIES(0xe00, trap_0e)
  243. /* We need to deal with the Altivec unavailable exception
  244. * here which is at 0xf20, thus in the middle of the
  245. * prolog code of the PerformanceMonitor one. A little
  246. * trickery is thus necessary
  247. */
  248. . = 0xf00
  249. b performance_monitor_pSeries
  250. . = 0xf20
  251. b altivec_unavailable_pSeries
  252. #ifdef CONFIG_CBE_RAS
  253. HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
  254. #endif /* CONFIG_CBE_RAS */
  255. STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
  256. #ifdef CONFIG_CBE_RAS
  257. HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
  258. #endif /* CONFIG_CBE_RAS */
  259. STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
  260. #ifdef CONFIG_CBE_RAS
  261. HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
  262. #endif /* CONFIG_CBE_RAS */
  263. . = 0x3000
  264. /*** pSeries interrupt support ***/
  265. /* moved from 0xf00 */
  266. STD_EXCEPTION_PSERIES(., performance_monitor)
  267. STD_EXCEPTION_PSERIES(., altivec_unavailable)
  268. /*
  269. * An interrupt came in while soft-disabled; clear EE in SRR1,
  270. * clear paca->hard_enabled and return.
  271. */
  272. masked_interrupt:
  273. stb r10,PACAHARDIRQEN(r13)
  274. mtcrf 0x80,r9
  275. ld r9,PACA_EXGEN+EX_R9(r13)
  276. mfspr r10,SPRN_SRR1
  277. rldicl r10,r10,48,1 /* clear MSR_EE */
  278. rotldi r10,r10,16
  279. mtspr SPRN_SRR1,r10
  280. ld r10,PACA_EXGEN+EX_R10(r13)
  281. mfspr r13,SPRN_SPRG1
  282. rfid
  283. b .
  284. .align 7
  285. do_stab_bolted_pSeries:
  286. mtcrf 0x80,r12
  287. mfspr r12,SPRN_SPRG2
  288. EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
  289. /*
  290. * We have some room here we use that to put
  291. * the peries slb miss user trampoline code so it's reasonably
  292. * away from slb_miss_user_common to avoid problems with rfid
  293. *
  294. * This is used for when the SLB miss handler has to go virtual,
  295. * which doesn't happen for now anymore but will once we re-implement
  296. * dynamic VSIDs for shared page tables
  297. */
  298. #ifdef __DISABLED__
  299. slb_miss_user_pseries:
  300. std r10,PACA_EXGEN+EX_R10(r13)
  301. std r11,PACA_EXGEN+EX_R11(r13)
  302. std r12,PACA_EXGEN+EX_R12(r13)
  303. mfspr r10,SPRG1
  304. ld r11,PACA_EXSLB+EX_R9(r13)
  305. ld r12,PACA_EXSLB+EX_R3(r13)
  306. std r10,PACA_EXGEN+EX_R13(r13)
  307. std r11,PACA_EXGEN+EX_R9(r13)
  308. std r12,PACA_EXGEN+EX_R3(r13)
  309. clrrdi r12,r13,32
  310. mfmsr r10
  311. mfspr r11,SRR0 /* save SRR0 */
  312. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  313. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  314. mtspr SRR0,r12
  315. mfspr r12,SRR1 /* and SRR1 */
  316. mtspr SRR1,r10
  317. rfid
  318. b . /* prevent spec. execution */
  319. #endif /* __DISABLED__ */
  320. #ifdef CONFIG_PPC_PSERIES
  321. /*
  322. * Vectors for the FWNMI option. Share common code.
  323. */
  324. .globl system_reset_fwnmi
  325. .align 7
  326. system_reset_fwnmi:
  327. HMT_MEDIUM
  328. mtspr SPRN_SPRG1,r13 /* save r13 */
  329. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
  330. .globl machine_check_fwnmi
  331. .align 7
  332. machine_check_fwnmi:
  333. HMT_MEDIUM
  334. mtspr SPRN_SPRG1,r13 /* save r13 */
  335. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
  336. #endif /* CONFIG_PPC_PSERIES */
  337. /*** Common interrupt handlers ***/
  338. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  339. /*
  340. * Machine check is different because we use a different
  341. * save area: PACA_EXMC instead of PACA_EXGEN.
  342. */
  343. .align 7
  344. .globl machine_check_common
  345. machine_check_common:
  346. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  347. FINISH_NAP
  348. DISABLE_INTS
  349. bl .save_nvgprs
  350. addi r3,r1,STACK_FRAME_OVERHEAD
  351. bl .machine_check_exception
  352. b .ret_from_except
  353. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  354. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  355. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  356. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  357. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  358. STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
  359. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  360. #ifdef CONFIG_ALTIVEC
  361. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  362. #else
  363. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  364. #endif
  365. #ifdef CONFIG_CBE_RAS
  366. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  367. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  368. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  369. #endif /* CONFIG_CBE_RAS */
  370. /*
  371. * Here we have detected that the kernel stack pointer is bad.
  372. * R9 contains the saved CR, r13 points to the paca,
  373. * r10 contains the (bad) kernel stack pointer,
  374. * r11 and r12 contain the saved SRR0 and SRR1.
  375. * We switch to using an emergency stack, save the registers there,
  376. * and call kernel_bad_stack(), which panics.
  377. */
  378. bad_stack:
  379. ld r1,PACAEMERGSP(r13)
  380. subi r1,r1,64+INT_FRAME_SIZE
  381. std r9,_CCR(r1)
  382. std r10,GPR1(r1)
  383. std r11,_NIP(r1)
  384. std r12,_MSR(r1)
  385. mfspr r11,SPRN_DAR
  386. mfspr r12,SPRN_DSISR
  387. std r11,_DAR(r1)
  388. std r12,_DSISR(r1)
  389. mflr r10
  390. mfctr r11
  391. mfxer r12
  392. std r10,_LINK(r1)
  393. std r11,_CTR(r1)
  394. std r12,_XER(r1)
  395. SAVE_GPR(0,r1)
  396. SAVE_GPR(2,r1)
  397. SAVE_4GPRS(3,r1)
  398. SAVE_2GPRS(7,r1)
  399. SAVE_10GPRS(12,r1)
  400. SAVE_10GPRS(22,r1)
  401. lhz r12,PACA_TRAP_SAVE(r13)
  402. std r12,_TRAP(r1)
  403. addi r11,r1,INT_FRAME_SIZE
  404. std r11,0(r1)
  405. li r12,0
  406. std r12,0(r11)
  407. ld r2,PACATOC(r13)
  408. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  409. bl .kernel_bad_stack
  410. b 1b
  411. /*
  412. * Return from an exception with minimal checks.
  413. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  414. * If interrupts have been enabled, or anything has been
  415. * done that might have changed the scheduling status of
  416. * any task or sent any task a signal, you should use
  417. * ret_from_except or ret_from_except_lite instead of this.
  418. */
  419. fast_exc_return_irq: /* restores irq state too */
  420. ld r3,SOFTE(r1)
  421. TRACE_AND_RESTORE_IRQ(r3);
  422. ld r12,_MSR(r1)
  423. rldicl r4,r12,49,63 /* get MSR_EE to LSB */
  424. stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
  425. b 1f
  426. .globl fast_exception_return
  427. fast_exception_return:
  428. ld r12,_MSR(r1)
  429. 1: ld r11,_NIP(r1)
  430. andi. r3,r12,MSR_RI /* check if RI is set */
  431. beq- unrecov_fer
  432. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  433. andi. r3,r12,MSR_PR
  434. beq 2f
  435. ACCOUNT_CPU_USER_EXIT(r3, r4)
  436. 2:
  437. #endif
  438. ld r3,_CCR(r1)
  439. ld r4,_LINK(r1)
  440. ld r5,_CTR(r1)
  441. ld r6,_XER(r1)
  442. mtcr r3
  443. mtlr r4
  444. mtctr r5
  445. mtxer r6
  446. REST_GPR(0, r1)
  447. REST_8GPRS(2, r1)
  448. mfmsr r10
  449. rldicl r10,r10,48,1 /* clear EE */
  450. rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
  451. mtmsrd r10,1
  452. mtspr SPRN_SRR1,r12
  453. mtspr SPRN_SRR0,r11
  454. REST_4GPRS(10, r1)
  455. ld r1,GPR1(r1)
  456. rfid
  457. b . /* prevent speculative execution */
  458. unrecov_fer:
  459. bl .save_nvgprs
  460. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  461. bl .unrecoverable_exception
  462. b 1b
  463. /*
  464. * Here r13 points to the paca, r9 contains the saved CR,
  465. * SRR0 and SRR1 are saved in r11 and r12,
  466. * r9 - r13 are saved in paca->exgen.
  467. */
  468. .align 7
  469. .globl data_access_common
  470. data_access_common:
  471. mfspr r10,SPRN_DAR
  472. std r10,PACA_EXGEN+EX_DAR(r13)
  473. mfspr r10,SPRN_DSISR
  474. stw r10,PACA_EXGEN+EX_DSISR(r13)
  475. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  476. ld r3,PACA_EXGEN+EX_DAR(r13)
  477. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  478. li r5,0x300
  479. b .do_hash_page /* Try to handle as hpte fault */
  480. .align 7
  481. .globl instruction_access_common
  482. instruction_access_common:
  483. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  484. ld r3,_NIP(r1)
  485. andis. r4,r12,0x5820
  486. li r5,0x400
  487. b .do_hash_page /* Try to handle as hpte fault */
  488. /*
  489. * Here is the common SLB miss user that is used when going to virtual
  490. * mode for SLB misses, that is currently not used
  491. */
  492. #ifdef __DISABLED__
  493. .align 7
  494. .globl slb_miss_user_common
  495. slb_miss_user_common:
  496. mflr r10
  497. std r3,PACA_EXGEN+EX_DAR(r13)
  498. stw r9,PACA_EXGEN+EX_CCR(r13)
  499. std r10,PACA_EXGEN+EX_LR(r13)
  500. std r11,PACA_EXGEN+EX_SRR0(r13)
  501. bl .slb_allocate_user
  502. ld r10,PACA_EXGEN+EX_LR(r13)
  503. ld r3,PACA_EXGEN+EX_R3(r13)
  504. lwz r9,PACA_EXGEN+EX_CCR(r13)
  505. ld r11,PACA_EXGEN+EX_SRR0(r13)
  506. mtlr r10
  507. beq- slb_miss_fault
  508. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  509. beq- unrecov_user_slb
  510. mfmsr r10
  511. .machine push
  512. .machine "power4"
  513. mtcrf 0x80,r9
  514. .machine pop
  515. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  516. mtmsrd r10,1
  517. mtspr SRR0,r11
  518. mtspr SRR1,r12
  519. ld r9,PACA_EXGEN+EX_R9(r13)
  520. ld r10,PACA_EXGEN+EX_R10(r13)
  521. ld r11,PACA_EXGEN+EX_R11(r13)
  522. ld r12,PACA_EXGEN+EX_R12(r13)
  523. ld r13,PACA_EXGEN+EX_R13(r13)
  524. rfid
  525. b .
  526. slb_miss_fault:
  527. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  528. ld r4,PACA_EXGEN+EX_DAR(r13)
  529. li r5,0
  530. std r4,_DAR(r1)
  531. std r5,_DSISR(r1)
  532. b handle_page_fault
  533. unrecov_user_slb:
  534. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  535. DISABLE_INTS
  536. bl .save_nvgprs
  537. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  538. bl .unrecoverable_exception
  539. b 1b
  540. #endif /* __DISABLED__ */
  541. /*
  542. * r13 points to the PACA, r9 contains the saved CR,
  543. * r12 contain the saved SRR1, SRR0 is still ready for return
  544. * r3 has the faulting address
  545. * r9 - r13 are saved in paca->exslb.
  546. * r3 is saved in paca->slb_r3
  547. * We assume we aren't going to take any exceptions during this procedure.
  548. */
  549. _GLOBAL(slb_miss_realmode)
  550. mflr r10
  551. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  552. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  553. bl .slb_allocate_realmode
  554. /* All done -- return from exception. */
  555. ld r10,PACA_EXSLB+EX_LR(r13)
  556. ld r3,PACA_EXSLB+EX_R3(r13)
  557. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  558. #ifdef CONFIG_PPC_ISERIES
  559. BEGIN_FW_FTR_SECTION
  560. ld r11,PACALPPACAPTR(r13)
  561. ld r11,LPPACASRR0(r11) /* get SRR0 value */
  562. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  563. #endif /* CONFIG_PPC_ISERIES */
  564. mtlr r10
  565. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  566. beq- 2f
  567. .machine push
  568. .machine "power4"
  569. mtcrf 0x80,r9
  570. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  571. .machine pop
  572. #ifdef CONFIG_PPC_ISERIES
  573. BEGIN_FW_FTR_SECTION
  574. mtspr SPRN_SRR0,r11
  575. mtspr SPRN_SRR1,r12
  576. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  577. #endif /* CONFIG_PPC_ISERIES */
  578. ld r9,PACA_EXSLB+EX_R9(r13)
  579. ld r10,PACA_EXSLB+EX_R10(r13)
  580. ld r11,PACA_EXSLB+EX_R11(r13)
  581. ld r12,PACA_EXSLB+EX_R12(r13)
  582. ld r13,PACA_EXSLB+EX_R13(r13)
  583. rfid
  584. b . /* prevent speculative execution */
  585. 2:
  586. #ifdef CONFIG_PPC_ISERIES
  587. BEGIN_FW_FTR_SECTION
  588. b unrecov_slb
  589. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  590. #endif /* CONFIG_PPC_ISERIES */
  591. mfspr r11,SPRN_SRR0
  592. clrrdi r10,r13,32
  593. LOAD_HANDLER(r10,unrecov_slb)
  594. mtspr SPRN_SRR0,r10
  595. mfmsr r10
  596. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  597. mtspr SPRN_SRR1,r10
  598. rfid
  599. b .
  600. unrecov_slb:
  601. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  602. DISABLE_INTS
  603. bl .save_nvgprs
  604. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  605. bl .unrecoverable_exception
  606. b 1b
  607. .align 7
  608. .globl hardware_interrupt_common
  609. .globl hardware_interrupt_entry
  610. hardware_interrupt_common:
  611. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  612. FINISH_NAP
  613. hardware_interrupt_entry:
  614. DISABLE_INTS
  615. BEGIN_FTR_SECTION
  616. bl .ppc64_runlatch_on
  617. END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
  618. addi r3,r1,STACK_FRAME_OVERHEAD
  619. bl .do_IRQ
  620. b .ret_from_except_lite
  621. #ifdef CONFIG_PPC_970_NAP
  622. power4_fixup_nap:
  623. andc r9,r9,r10
  624. std r9,TI_LOCAL_FLAGS(r11)
  625. ld r10,_LINK(r1) /* make idle task do the */
  626. std r10,_NIP(r1) /* equivalent of a blr */
  627. blr
  628. #endif
  629. .align 7
  630. .globl alignment_common
  631. alignment_common:
  632. mfspr r10,SPRN_DAR
  633. std r10,PACA_EXGEN+EX_DAR(r13)
  634. mfspr r10,SPRN_DSISR
  635. stw r10,PACA_EXGEN+EX_DSISR(r13)
  636. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  637. ld r3,PACA_EXGEN+EX_DAR(r13)
  638. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  639. std r3,_DAR(r1)
  640. std r4,_DSISR(r1)
  641. bl .save_nvgprs
  642. addi r3,r1,STACK_FRAME_OVERHEAD
  643. ENABLE_INTS
  644. bl .alignment_exception
  645. b .ret_from_except
  646. .align 7
  647. .globl program_check_common
  648. program_check_common:
  649. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  650. bl .save_nvgprs
  651. addi r3,r1,STACK_FRAME_OVERHEAD
  652. ENABLE_INTS
  653. bl .program_check_exception
  654. b .ret_from_except
  655. .align 7
  656. .globl fp_unavailable_common
  657. fp_unavailable_common:
  658. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  659. bne 1f /* if from user, just load it up */
  660. bl .save_nvgprs
  661. addi r3,r1,STACK_FRAME_OVERHEAD
  662. ENABLE_INTS
  663. bl .kernel_fp_unavailable_exception
  664. BUG_OPCODE
  665. 1: bl .load_up_fpu
  666. b fast_exception_return
  667. .align 7
  668. .globl altivec_unavailable_common
  669. altivec_unavailable_common:
  670. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  671. #ifdef CONFIG_ALTIVEC
  672. BEGIN_FTR_SECTION
  673. beq 1f
  674. bl .load_up_altivec
  675. b fast_exception_return
  676. 1:
  677. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  678. #endif
  679. bl .save_nvgprs
  680. addi r3,r1,STACK_FRAME_OVERHEAD
  681. ENABLE_INTS
  682. bl .altivec_unavailable_exception
  683. b .ret_from_except
  684. #ifdef CONFIG_ALTIVEC
  685. /*
  686. * load_up_altivec(unused, unused, tsk)
  687. * Disable VMX for the task which had it previously,
  688. * and save its vector registers in its thread_struct.
  689. * Enables the VMX for use in the kernel on return.
  690. * On SMP we know the VMX is free, since we give it up every
  691. * switch (ie, no lazy save of the vector registers).
  692. * On entry: r13 == 'current' && last_task_used_altivec != 'current'
  693. */
  694. _STATIC(load_up_altivec)
  695. mfmsr r5 /* grab the current MSR */
  696. oris r5,r5,MSR_VEC@h
  697. mtmsrd r5 /* enable use of VMX now */
  698. isync
  699. /*
  700. * For SMP, we don't do lazy VMX switching because it just gets too
  701. * horrendously complex, especially when a task switches from one CPU
  702. * to another. Instead we call giveup_altvec in switch_to.
  703. * VRSAVE isn't dealt with here, that is done in the normal context
  704. * switch code. Note that we could rely on vrsave value to eventually
  705. * avoid saving all of the VREGs here...
  706. */
  707. #ifndef CONFIG_SMP
  708. ld r3,last_task_used_altivec@got(r2)
  709. ld r4,0(r3)
  710. cmpdi 0,r4,0
  711. beq 1f
  712. /* Save VMX state to last_task_used_altivec's THREAD struct */
  713. addi r4,r4,THREAD
  714. SAVE_32VRS(0,r5,r4)
  715. mfvscr vr0
  716. li r10,THREAD_VSCR
  717. stvx vr0,r10,r4
  718. /* Disable VMX for last_task_used_altivec */
  719. ld r5,PT_REGS(r4)
  720. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  721. lis r6,MSR_VEC@h
  722. andc r4,r4,r6
  723. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  724. 1:
  725. #endif /* CONFIG_SMP */
  726. /* Hack: if we get an altivec unavailable trap with VRSAVE
  727. * set to all zeros, we assume this is a broken application
  728. * that fails to set it properly, and thus we switch it to
  729. * all 1's
  730. */
  731. mfspr r4,SPRN_VRSAVE
  732. cmpdi 0,r4,0
  733. bne+ 1f
  734. li r4,-1
  735. mtspr SPRN_VRSAVE,r4
  736. 1:
  737. /* enable use of VMX after return */
  738. ld r4,PACACURRENT(r13)
  739. addi r5,r4,THREAD /* Get THREAD */
  740. oris r12,r12,MSR_VEC@h
  741. std r12,_MSR(r1)
  742. li r4,1
  743. li r10,THREAD_VSCR
  744. stw r4,THREAD_USED_VR(r5)
  745. lvx vr0,r10,r5
  746. mtvscr vr0
  747. REST_32VRS(0,r4,r5)
  748. #ifndef CONFIG_SMP
  749. /* Update last_task_used_math to 'current' */
  750. subi r4,r5,THREAD /* Back to 'current' */
  751. std r4,0(r3)
  752. #endif /* CONFIG_SMP */
  753. /* restore registers and return */
  754. blr
  755. #endif /* CONFIG_ALTIVEC */
  756. /*
  757. * Hash table stuff
  758. */
  759. .align 7
  760. _STATIC(do_hash_page)
  761. std r3,_DAR(r1)
  762. std r4,_DSISR(r1)
  763. andis. r0,r4,0xa450 /* weird error? */
  764. bne- handle_page_fault /* if not, try to insert a HPTE */
  765. BEGIN_FTR_SECTION
  766. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  767. bne- do_ste_alloc /* If so handle it */
  768. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  769. /*
  770. * On iSeries, we soft-disable interrupts here, then
  771. * hard-enable interrupts so that the hash_page code can spin on
  772. * the hash_table_lock without problems on a shared processor.
  773. */
  774. DISABLE_INTS
  775. /*
  776. * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
  777. * and will clobber volatile registers when irq tracing is enabled
  778. * so we need to reload them. It may be possible to be smarter here
  779. * and move the irq tracing elsewhere but let's keep it simple for
  780. * now
  781. */
  782. #ifdef CONFIG_TRACE_IRQFLAGS
  783. ld r3,_DAR(r1)
  784. ld r4,_DSISR(r1)
  785. ld r5,_TRAP(r1)
  786. ld r12,_MSR(r1)
  787. clrrdi r5,r5,4
  788. #endif /* CONFIG_TRACE_IRQFLAGS */
  789. /*
  790. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  791. * accessing a userspace segment (even from the kernel). We assume
  792. * kernel addresses always have the high bit set.
  793. */
  794. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  795. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  796. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  797. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  798. ori r4,r4,1 /* add _PAGE_PRESENT */
  799. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  800. /*
  801. * r3 contains the faulting address
  802. * r4 contains the required access permissions
  803. * r5 contains the trap number
  804. *
  805. * at return r3 = 0 for success
  806. */
  807. bl .hash_page /* build HPTE if possible */
  808. cmpdi r3,0 /* see if hash_page succeeded */
  809. BEGIN_FW_FTR_SECTION
  810. /*
  811. * If we had interrupts soft-enabled at the point where the
  812. * DSI/ISI occurred, and an interrupt came in during hash_page,
  813. * handle it now.
  814. * We jump to ret_from_except_lite rather than fast_exception_return
  815. * because ret_from_except_lite will check for and handle pending
  816. * interrupts if necessary.
  817. */
  818. beq 13f
  819. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  820. BEGIN_FW_FTR_SECTION
  821. /*
  822. * Here we have interrupts hard-disabled, so it is sufficient
  823. * to restore paca->{soft,hard}_enable and get out.
  824. */
  825. beq fast_exc_return_irq /* Return from exception on success */
  826. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  827. /* For a hash failure, we don't bother re-enabling interrupts */
  828. ble- 12f
  829. /*
  830. * hash_page couldn't handle it, set soft interrupt enable back
  831. * to what it was before the trap. Note that .raw_local_irq_restore
  832. * handles any interrupts pending at this point.
  833. */
  834. ld r3,SOFTE(r1)
  835. TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
  836. bl .raw_local_irq_restore
  837. b 11f
  838. /* Here we have a page fault that hash_page can't handle. */
  839. handle_page_fault:
  840. ENABLE_INTS
  841. 11: ld r4,_DAR(r1)
  842. ld r5,_DSISR(r1)
  843. addi r3,r1,STACK_FRAME_OVERHEAD
  844. bl .do_page_fault
  845. cmpdi r3,0
  846. beq+ 13f
  847. bl .save_nvgprs
  848. mr r5,r3
  849. addi r3,r1,STACK_FRAME_OVERHEAD
  850. lwz r4,_DAR(r1)
  851. bl .bad_page_fault
  852. b .ret_from_except
  853. 13: b .ret_from_except_lite
  854. /* We have a page fault that hash_page could handle but HV refused
  855. * the PTE insertion
  856. */
  857. 12: bl .save_nvgprs
  858. mr r5,r3
  859. addi r3,r1,STACK_FRAME_OVERHEAD
  860. ld r4,_DAR(r1)
  861. bl .low_hash_fault
  862. b .ret_from_except
  863. /* here we have a segment miss */
  864. do_ste_alloc:
  865. bl .ste_allocate /* try to insert stab entry */
  866. cmpdi r3,0
  867. bne- handle_page_fault
  868. b fast_exception_return
  869. /*
  870. * r13 points to the PACA, r9 contains the saved CR,
  871. * r11 and r12 contain the saved SRR0 and SRR1.
  872. * r9 - r13 are saved in paca->exslb.
  873. * We assume we aren't going to take any exceptions during this procedure.
  874. * We assume (DAR >> 60) == 0xc.
  875. */
  876. .align 7
  877. _GLOBAL(do_stab_bolted)
  878. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  879. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  880. /* Hash to the primary group */
  881. ld r10,PACASTABVIRT(r13)
  882. mfspr r11,SPRN_DAR
  883. srdi r11,r11,28
  884. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  885. /* Calculate VSID */
  886. /* This is a kernel address, so protovsid = ESID */
  887. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  888. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  889. /* Search the primary group for a free entry */
  890. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  891. andi. r11,r11,0x80
  892. beq 2f
  893. addi r10,r10,16
  894. andi. r11,r10,0x70
  895. bne 1b
  896. /* Stick for only searching the primary group for now. */
  897. /* At least for now, we use a very simple random castout scheme */
  898. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  899. mftb r11
  900. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  901. ori r11,r11,0x10
  902. /* r10 currently points to an ste one past the group of interest */
  903. /* make it point to the randomly selected entry */
  904. subi r10,r10,128
  905. or r10,r10,r11 /* r10 is the entry to invalidate */
  906. isync /* mark the entry invalid */
  907. ld r11,0(r10)
  908. rldicl r11,r11,56,1 /* clear the valid bit */
  909. rotldi r11,r11,8
  910. std r11,0(r10)
  911. sync
  912. clrrdi r11,r11,28 /* Get the esid part of the ste */
  913. slbie r11
  914. 2: std r9,8(r10) /* Store the vsid part of the ste */
  915. eieio
  916. mfspr r11,SPRN_DAR /* Get the new esid */
  917. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  918. ori r11,r11,0x90 /* Turn on valid and kp */
  919. std r11,0(r10) /* Put new entry back into the stab */
  920. sync
  921. /* All done -- return from exception. */
  922. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  923. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  924. andi. r10,r12,MSR_RI
  925. beq- unrecov_slb
  926. mtcrf 0x80,r9 /* restore CR */
  927. mfmsr r10
  928. clrrdi r10,r10,2
  929. mtmsrd r10,1
  930. mtspr SPRN_SRR0,r11
  931. mtspr SPRN_SRR1,r12
  932. ld r9,PACA_EXSLB+EX_R9(r13)
  933. ld r10,PACA_EXSLB+EX_R10(r13)
  934. ld r11,PACA_EXSLB+EX_R11(r13)
  935. ld r12,PACA_EXSLB+EX_R12(r13)
  936. ld r13,PACA_EXSLB+EX_R13(r13)
  937. rfid
  938. b . /* prevent speculative execution */
  939. /*
  940. * Space for CPU0's segment table.
  941. *
  942. * On iSeries, the hypervisor must fill in at least one entry before
  943. * we get control (with relocate on). The address is given to the hv
  944. * as a page number (see xLparMap below), so this must be at a
  945. * fixed address (the linker can't compute (u64)&initial_stab >>
  946. * PAGE_SHIFT).
  947. */
  948. . = STAB0_OFFSET /* 0x6000 */
  949. .globl initial_stab
  950. initial_stab:
  951. .space 4096
  952. #ifdef CONFIG_PPC_PSERIES
  953. /*
  954. * Data area reserved for FWNMI option.
  955. * This address (0x7000) is fixed by the RPA.
  956. */
  957. .= 0x7000
  958. .globl fwnmi_data_area
  959. fwnmi_data_area:
  960. #endif /* CONFIG_PPC_PSERIES */
  961. /* iSeries does not use the FWNMI stuff, so it is safe to put
  962. * this here, even if we later allow kernels that will boot on
  963. * both pSeries and iSeries */
  964. #ifdef CONFIG_PPC_ISERIES
  965. . = LPARMAP_PHYS
  966. .globl xLparMap
  967. xLparMap:
  968. .quad HvEsidsToMap /* xNumberEsids */
  969. .quad HvRangesToMap /* xNumberRanges */
  970. .quad STAB0_PAGE /* xSegmentTableOffs */
  971. .zero 40 /* xRsvd */
  972. /* xEsids (HvEsidsToMap entries of 2 quads) */
  973. .quad PAGE_OFFSET_ESID /* xKernelEsid */
  974. .quad PAGE_OFFSET_VSID /* xKernelVsid */
  975. .quad VMALLOC_START_ESID /* xKernelEsid */
  976. .quad VMALLOC_START_VSID /* xKernelVsid */
  977. /* xRanges (HvRangesToMap entries of 3 quads) */
  978. .quad HvPagesToMap /* xPages */
  979. .quad 0 /* xOffset */
  980. .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
  981. #endif /* CONFIG_PPC_ISERIES */
  982. #ifdef CONFIG_PPC_PSERIES
  983. . = 0x8000
  984. #endif /* CONFIG_PPC_PSERIES */
  985. /*
  986. * On pSeries and most other platforms, secondary processors spin
  987. * in the following code.
  988. * At entry, r3 = this processor's number (physical cpu id)
  989. */
  990. _GLOBAL(generic_secondary_smp_init)
  991. mr r24,r3
  992. /* turn on 64-bit mode */
  993. bl .enable_64b_mode
  994. /* Set up a paca value for this processor. Since we have the
  995. * physical cpu id in r24, we need to search the pacas to find
  996. * which logical id maps to our physical one.
  997. */
  998. LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
  999. li r5,0 /* logical cpu id */
  1000. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  1001. cmpw r6,r24 /* Compare to our id */
  1002. beq 2f
  1003. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  1004. addi r5,r5,1
  1005. cmpwi r5,NR_CPUS
  1006. blt 1b
  1007. mr r3,r24 /* not found, copy phys to r3 */
  1008. b .kexec_wait /* next kernel might do better */
  1009. 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1010. /* From now on, r24 is expected to be logical cpuid */
  1011. mr r24,r5
  1012. 3: HMT_LOW
  1013. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  1014. /* start. */
  1015. sync
  1016. #ifndef CONFIG_SMP
  1017. b 3b /* Never go on non-SMP */
  1018. #else
  1019. cmpwi 0,r23,0
  1020. beq 3b /* Loop until told to go */
  1021. /* See if we need to call a cpu state restore handler */
  1022. LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
  1023. ld r23,0(r23)
  1024. ld r23,CPU_SPEC_RESTORE(r23)
  1025. cmpdi 0,r23,0
  1026. beq 4f
  1027. ld r23,0(r23)
  1028. mtctr r23
  1029. bctrl
  1030. 4: /* Create a temp kernel stack for use before relocation is on. */
  1031. ld r1,PACAEMERGSP(r13)
  1032. subi r1,r1,STACK_FRAME_OVERHEAD
  1033. b __secondary_start
  1034. #endif
  1035. _STATIC(__mmu_off)
  1036. mfmsr r3
  1037. andi. r0,r3,MSR_IR|MSR_DR
  1038. beqlr
  1039. andc r3,r3,r0
  1040. mtspr SPRN_SRR0,r4
  1041. mtspr SPRN_SRR1,r3
  1042. sync
  1043. rfid
  1044. b . /* prevent speculative execution */
  1045. /*
  1046. * Here is our main kernel entry point. We support currently 2 kind of entries
  1047. * depending on the value of r5.
  1048. *
  1049. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  1050. * in r3...r7
  1051. *
  1052. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  1053. * DT block, r4 is a physical pointer to the kernel itself
  1054. *
  1055. */
  1056. _GLOBAL(__start_initialization_multiplatform)
  1057. /*
  1058. * Are we booted from a PROM Of-type client-interface ?
  1059. */
  1060. cmpldi cr0,r5,0
  1061. beq 1f
  1062. b .__boot_from_prom /* yes -> prom */
  1063. 1:
  1064. /* Save parameters */
  1065. mr r31,r3
  1066. mr r30,r4
  1067. /* Make sure we are running in 64 bits mode */
  1068. bl .enable_64b_mode
  1069. /* Setup some critical 970 SPRs before switching MMU off */
  1070. mfspr r0,SPRN_PVR
  1071. srwi r0,r0,16
  1072. cmpwi r0,0x39 /* 970 */
  1073. beq 1f
  1074. cmpwi r0,0x3c /* 970FX */
  1075. beq 1f
  1076. cmpwi r0,0x44 /* 970MP */
  1077. beq 1f
  1078. cmpwi r0,0x45 /* 970GX */
  1079. bne 2f
  1080. 1: bl .__cpu_preinit_ppc970
  1081. 2:
  1082. /* Switch off MMU if not already */
  1083. LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
  1084. add r4,r4,r30
  1085. bl .__mmu_off
  1086. b .__after_prom_start
  1087. _INIT_STATIC(__boot_from_prom)
  1088. /* Save parameters */
  1089. mr r31,r3
  1090. mr r30,r4
  1091. mr r29,r5
  1092. mr r28,r6
  1093. mr r27,r7
  1094. /*
  1095. * Align the stack to 16-byte boundary
  1096. * Depending on the size and layout of the ELF sections in the initial
  1097. * boot binary, the stack pointer will be unalignet on PowerMac
  1098. */
  1099. rldicr r1,r1,0,59
  1100. /* Make sure we are running in 64 bits mode */
  1101. bl .enable_64b_mode
  1102. /* put a relocation offset into r3 */
  1103. bl .reloc_offset
  1104. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1105. addi r2,r2,0x4000
  1106. addi r2,r2,0x4000
  1107. /* Relocate the TOC from a virt addr to a real addr */
  1108. add r2,r2,r3
  1109. /* Restore parameters */
  1110. mr r3,r31
  1111. mr r4,r30
  1112. mr r5,r29
  1113. mr r6,r28
  1114. mr r7,r27
  1115. /* Do all of the interaction with OF client interface */
  1116. bl .prom_init
  1117. /* We never return */
  1118. trap
  1119. _STATIC(__after_prom_start)
  1120. /*
  1121. * We need to run with __start at physical address PHYSICAL_START.
  1122. * This will leave some code in the first 256B of
  1123. * real memory, which are reserved for software use.
  1124. * The remainder of the first page is loaded with the fixed
  1125. * interrupt vectors. The next two pages are filled with
  1126. * unknown exception placeholders.
  1127. *
  1128. * Note: This process overwrites the OF exception vectors.
  1129. * r26 == relocation offset
  1130. * r27 == KERNELBASE
  1131. */
  1132. bl .reloc_offset
  1133. mr r26,r3
  1134. LOAD_REG_IMMEDIATE(r27, KERNELBASE)
  1135. LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
  1136. // XXX FIXME: Use phys returned by OF (r30)
  1137. add r4,r27,r26 /* source addr */
  1138. /* current address of _start */
  1139. /* i.e. where we are running */
  1140. /* the source addr */
  1141. cmpdi r4,0 /* In some cases the loader may */
  1142. bne 1f
  1143. b .start_here_multiplatform /* have already put us at zero */
  1144. /* so we can skip the copy. */
  1145. 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
  1146. sub r5,r5,r27
  1147. li r6,0x100 /* Start offset, the first 0x100 */
  1148. /* bytes were copied earlier. */
  1149. bl .copy_and_flush /* copy the first n bytes */
  1150. /* this includes the code being */
  1151. /* executed here. */
  1152. LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
  1153. mtctr r0 /* that we just made/relocated */
  1154. bctr
  1155. 4: LOAD_REG_IMMEDIATE(r5,klimit)
  1156. add r5,r5,r26
  1157. ld r5,0(r5) /* get the value of klimit */
  1158. sub r5,r5,r27
  1159. bl .copy_and_flush /* copy the rest */
  1160. b .start_here_multiplatform
  1161. /*
  1162. * Copy routine used to copy the kernel to start at physical address 0
  1163. * and flush and invalidate the caches as needed.
  1164. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  1165. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  1166. *
  1167. * Note: this routine *only* clobbers r0, r6 and lr
  1168. */
  1169. _GLOBAL(copy_and_flush)
  1170. addi r5,r5,-8
  1171. addi r6,r6,-8
  1172. 4: li r0,8 /* Use the smallest common */
  1173. /* denominator cache line */
  1174. /* size. This results in */
  1175. /* extra cache line flushes */
  1176. /* but operation is correct. */
  1177. /* Can't get cache line size */
  1178. /* from NACA as it is being */
  1179. /* moved too. */
  1180. mtctr r0 /* put # words/line in ctr */
  1181. 3: addi r6,r6,8 /* copy a cache line */
  1182. ldx r0,r6,r4
  1183. stdx r0,r6,r3
  1184. bdnz 3b
  1185. dcbst r6,r3 /* write it to memory */
  1186. sync
  1187. icbi r6,r3 /* flush the icache line */
  1188. cmpld 0,r6,r5
  1189. blt 4b
  1190. sync
  1191. addi r5,r5,8
  1192. addi r6,r6,8
  1193. blr
  1194. .align 8
  1195. copy_to_here:
  1196. #ifdef CONFIG_SMP
  1197. #ifdef CONFIG_PPC_PMAC
  1198. /*
  1199. * On PowerMac, secondary processors starts from the reset vector, which
  1200. * is temporarily turned into a call to one of the functions below.
  1201. */
  1202. .section ".text";
  1203. .align 2 ;
  1204. .globl __secondary_start_pmac_0
  1205. __secondary_start_pmac_0:
  1206. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  1207. li r24,0
  1208. b 1f
  1209. li r24,1
  1210. b 1f
  1211. li r24,2
  1212. b 1f
  1213. li r24,3
  1214. 1:
  1215. _GLOBAL(pmac_secondary_start)
  1216. /* turn on 64-bit mode */
  1217. bl .enable_64b_mode
  1218. /* Copy some CPU settings from CPU 0 */
  1219. bl .__restore_cpu_ppc970
  1220. /* pSeries do that early though I don't think we really need it */
  1221. mfmsr r3
  1222. ori r3,r3,MSR_RI
  1223. mtmsrd r3 /* RI on */
  1224. /* Set up a paca value for this processor. */
  1225. LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
  1226. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  1227. add r13,r13,r4 /* for this processor. */
  1228. mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1229. /* Create a temp kernel stack for use before relocation is on. */
  1230. ld r1,PACAEMERGSP(r13)
  1231. subi r1,r1,STACK_FRAME_OVERHEAD
  1232. b __secondary_start
  1233. #endif /* CONFIG_PPC_PMAC */
  1234. /*
  1235. * This function is called after the master CPU has released the
  1236. * secondary processors. The execution environment is relocation off.
  1237. * The paca for this processor has the following fields initialized at
  1238. * this point:
  1239. * 1. Processor number
  1240. * 2. Segment table pointer (virtual address)
  1241. * On entry the following are set:
  1242. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  1243. * r24 = cpu# (in Linux terms)
  1244. * r13 = paca virtual address
  1245. * SPRG3 = paca virtual address
  1246. */
  1247. .globl __secondary_start
  1248. __secondary_start:
  1249. /* Set thread priority to MEDIUM */
  1250. HMT_MEDIUM
  1251. /* Load TOC */
  1252. ld r2,PACATOC(r13)
  1253. /* Do early setup for that CPU (stab, slb, hash table pointer) */
  1254. bl .early_setup_secondary
  1255. /* Initialize the kernel stack. Just a repeat for iSeries. */
  1256. LOAD_REG_ADDR(r3, current_set)
  1257. sldi r28,r24,3 /* get current_set[cpu#] */
  1258. ldx r1,r3,r28
  1259. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1260. std r1,PACAKSAVE(r13)
  1261. /* Clear backchain so we get nice backtraces */
  1262. li r7,0
  1263. mtlr r7
  1264. /* enable MMU and jump to start_secondary */
  1265. LOAD_REG_ADDR(r3, .start_secondary_prolog)
  1266. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1267. #ifdef CONFIG_PPC_ISERIES
  1268. BEGIN_FW_FTR_SECTION
  1269. ori r4,r4,MSR_EE
  1270. li r8,1
  1271. stb r8,PACAHARDIRQEN(r13)
  1272. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1273. #endif
  1274. BEGIN_FW_FTR_SECTION
  1275. stb r7,PACAHARDIRQEN(r13)
  1276. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  1277. stb r7,PACASOFTIRQEN(r13)
  1278. mtspr SPRN_SRR0,r3
  1279. mtspr SPRN_SRR1,r4
  1280. rfid
  1281. b . /* prevent speculative execution */
  1282. /*
  1283. * Running with relocation on at this point. All we want to do is
  1284. * zero the stack back-chain pointer before going into C code.
  1285. */
  1286. _GLOBAL(start_secondary_prolog)
  1287. li r3,0
  1288. std r3,0(r1) /* Zero the stack frame pointer */
  1289. bl .start_secondary
  1290. b .
  1291. #endif
  1292. /*
  1293. * This subroutine clobbers r11 and r12
  1294. */
  1295. _GLOBAL(enable_64b_mode)
  1296. mfmsr r11 /* grab the current MSR */
  1297. li r12,1
  1298. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  1299. or r11,r11,r12
  1300. li r12,1
  1301. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  1302. or r11,r11,r12
  1303. mtmsrd r11
  1304. isync
  1305. blr
  1306. /*
  1307. * This is where the main kernel code starts.
  1308. */
  1309. _INIT_STATIC(start_here_multiplatform)
  1310. /* get a new offset, now that the kernel has moved. */
  1311. bl .reloc_offset
  1312. mr r26,r3
  1313. /* Clear out the BSS. It may have been done in prom_init,
  1314. * already but that's irrelevant since prom_init will soon
  1315. * be detached from the kernel completely. Besides, we need
  1316. * to clear it now for kexec-style entry.
  1317. */
  1318. LOAD_REG_IMMEDIATE(r11,__bss_stop)
  1319. LOAD_REG_IMMEDIATE(r8,__bss_start)
  1320. sub r11,r11,r8 /* bss size */
  1321. addi r11,r11,7 /* round up to an even double word */
  1322. rldicl. r11,r11,61,3 /* shift right by 3 */
  1323. beq 4f
  1324. addi r8,r8,-8
  1325. li r0,0
  1326. mtctr r11 /* zero this many doublewords */
  1327. 3: stdu r0,8(r8)
  1328. bdnz 3b
  1329. 4:
  1330. mfmsr r6
  1331. ori r6,r6,MSR_RI
  1332. mtmsrd r6 /* RI on */
  1333. /* The following gets the stack and TOC set up with the regs */
  1334. /* pointing to the real addr of the kernel stack. This is */
  1335. /* all done to support the C function call below which sets */
  1336. /* up the htab. This is done because we have relocated the */
  1337. /* kernel but are still running in real mode. */
  1338. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1339. add r3,r3,r26
  1340. /* set up a stack pointer (physical address) */
  1341. addi r1,r3,THREAD_SIZE
  1342. li r0,0
  1343. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1344. /* set up the TOC (physical address) */
  1345. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1346. addi r2,r2,0x4000
  1347. addi r2,r2,0x4000
  1348. add r2,r2,r26
  1349. /* Do very early kernel initializations, including initial hash table,
  1350. * stab and slb setup before we turn on relocation. */
  1351. /* Restore parameters passed from prom_init/kexec */
  1352. mr r3,r31
  1353. bl .early_setup
  1354. LOAD_REG_IMMEDIATE(r3, .start_here_common)
  1355. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1356. mtspr SPRN_SRR0,r3
  1357. mtspr SPRN_SRR1,r4
  1358. rfid
  1359. b . /* prevent speculative execution */
  1360. /* This is where all platforms converge execution */
  1361. _INIT_GLOBAL(start_here_common)
  1362. /* relocation is on at this point */
  1363. /* The following code sets up the SP and TOC now that we are */
  1364. /* running with translation enabled. */
  1365. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1366. /* set up the stack */
  1367. addi r1,r3,THREAD_SIZE
  1368. li r0,0
  1369. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1370. /* Load the TOC */
  1371. ld r2,PACATOC(r13)
  1372. std r1,PACAKSAVE(r13)
  1373. bl .setup_system
  1374. /* Load up the kernel context */
  1375. 5:
  1376. li r5,0
  1377. stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
  1378. #ifdef CONFIG_PPC_ISERIES
  1379. BEGIN_FW_FTR_SECTION
  1380. mfmsr r5
  1381. ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
  1382. mtmsrd r5
  1383. li r5,1
  1384. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1385. #endif
  1386. stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
  1387. bl .start_kernel
  1388. /* Not reached */
  1389. BUG_OPCODE
  1390. /*
  1391. * We put a few things here that have to be page-aligned.
  1392. * This stuff goes at the beginning of the bss, which is page-aligned.
  1393. */
  1394. .section ".bss"
  1395. .align PAGE_SHIFT
  1396. .globl empty_zero_page
  1397. empty_zero_page:
  1398. .space PAGE_SIZE
  1399. .globl swapper_pg_dir
  1400. swapper_pg_dir:
  1401. .space PGD_TABLE_SIZE