head_64.S 42 KB

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