head_64.S 51 KB

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