head_64.S 40 KB

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