head_64.S 43 KB

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