head_64.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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 entry point for the 64-bit kernel along
  16. * with some early initialization code common to all 64-bit powerpc
  17. * variants.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version
  22. * 2 of the License, or (at your option) any later version.
  23. */
  24. #include <linux/threads.h>
  25. #include <asm/reg.h>
  26. #include <asm/page.h>
  27. #include <asm/mmu.h>
  28. #include <asm/ppc_asm.h>
  29. #include <asm/asm-offsets.h>
  30. #include <asm/bug.h>
  31. #include <asm/cputable.h>
  32. #include <asm/setup.h>
  33. #include <asm/hvcall.h>
  34. #include <asm/iseries/lpar_map.h>
  35. #include <asm/thread_info.h>
  36. #include <asm/firmware.h>
  37. #include <asm/page_64.h>
  38. #include <asm/irqflags.h>
  39. #include <asm/kvm_book3s_asm.h>
  40. #include <asm/ptrace.h>
  41. /* The physical memory is laid out such that the secondary processor
  42. * spin code sits at 0x0000...0x00ff. On server, the vectors follow
  43. * using the layout described in exceptions-64s.S
  44. */
  45. /*
  46. * Entering into this code we make the following assumptions:
  47. *
  48. * For pSeries or server processors:
  49. * 1. The MMU is off & open firmware is running in real mode.
  50. * 2. The kernel is entered at __start
  51. * -or- For OPAL entry:
  52. * 1. The MMU is off, processor in HV mode, primary CPU enters at 0
  53. * with device-tree in gpr3. We also get OPAL base in r8 and
  54. * entry in r9 for debugging purposes
  55. * 2. Secondary processors enter at 0x60 with PIR in gpr3
  56. *
  57. * For iSeries:
  58. * 1. The MMU is on (as it always is for iSeries)
  59. * 2. The kernel is entered at system_reset_iSeries
  60. *
  61. * For Book3E processors:
  62. * 1. The MMU is on running in AS0 in a state defined in ePAPR
  63. * 2. The kernel is entered at __start
  64. */
  65. .text
  66. .globl _stext
  67. _stext:
  68. _GLOBAL(__start)
  69. /* NOP this out unconditionally */
  70. BEGIN_FTR_SECTION
  71. b .__start_initialization_multiplatform
  72. END_FTR_SECTION(0, 1)
  73. /* Catch branch to 0 in real mode */
  74. trap
  75. /* Secondary processors spin on this value until it becomes nonzero.
  76. * When it does it contains the real address of the descriptor
  77. * of the function that the cpu should jump to to continue
  78. * initialization.
  79. */
  80. .globl __secondary_hold_spinloop
  81. __secondary_hold_spinloop:
  82. .llong 0x0
  83. /* Secondary processors write this value with their cpu # */
  84. /* after they enter the spin loop immediately below. */
  85. .globl __secondary_hold_acknowledge
  86. __secondary_hold_acknowledge:
  87. .llong 0x0
  88. #ifdef CONFIG_PPC_ISERIES
  89. /*
  90. * At offset 0x20, there is a pointer to iSeries LPAR data.
  91. * This is required by the hypervisor
  92. */
  93. . = 0x20
  94. .llong hvReleaseData-KERNELBASE
  95. #endif /* CONFIG_PPC_ISERIES */
  96. #ifdef CONFIG_RELOCATABLE
  97. /* This flag is set to 1 by a loader if the kernel should run
  98. * at the loaded address instead of the linked address. This
  99. * is used by kexec-tools to keep the the kdump kernel in the
  100. * crash_kernel region. The loader is responsible for
  101. * observing the alignment requirement.
  102. */
  103. /* Do not move this variable as kexec-tools knows about it. */
  104. . = 0x5c
  105. .globl __run_at_load
  106. __run_at_load:
  107. .long 0x72756e30 /* "run0" -- relocate to 0 by default */
  108. #endif
  109. . = 0x60
  110. /*
  111. * The following code is used to hold secondary processors
  112. * in a spin loop after they have entered the kernel, but
  113. * before the bulk of the kernel has been relocated. This code
  114. * is relocated to physical address 0x60 before prom_init is run.
  115. * All of it must fit below the first exception vector at 0x100.
  116. * Use .globl here not _GLOBAL because we want __secondary_hold
  117. * to be the actual text address, not a descriptor.
  118. */
  119. .globl __secondary_hold
  120. __secondary_hold:
  121. #ifndef CONFIG_PPC_BOOK3E
  122. mfmsr r24
  123. ori r24,r24,MSR_RI
  124. mtmsrd r24 /* RI on */
  125. #endif
  126. /* Grab our physical cpu number */
  127. mr r24,r3
  128. /* Tell the master cpu we're here */
  129. /* Relocation is off & we are located at an address less */
  130. /* than 0x100, so only need to grab low order offset. */
  131. std r24,__secondary_hold_acknowledge-_stext(0)
  132. sync
  133. /* All secondary cpus wait here until told to start. */
  134. 100: ld r4,__secondary_hold_spinloop-_stext(0)
  135. cmpdi 0,r4,0
  136. beq 100b
  137. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  138. ld r4,0(r4) /* deref function descriptor */
  139. mtctr r4
  140. mr r3,r24
  141. li r4,0
  142. /* Make sure that patched code is visible */
  143. isync
  144. bctr
  145. #else
  146. BUG_OPCODE
  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. * On server, we include the exception vectors code here as it
  155. * relies on absolute addressing which is only possible within
  156. * this compilation unit
  157. */
  158. #ifdef CONFIG_PPC_BOOK3S
  159. #include "exceptions-64s.S"
  160. #endif
  161. _GLOBAL(generic_secondary_thread_init)
  162. mr r24,r3
  163. /* turn on 64-bit mode */
  164. bl .enable_64b_mode
  165. /* get a valid TOC pointer, wherever we're mapped at */
  166. bl .relative_toc
  167. #ifdef CONFIG_PPC_BOOK3E
  168. /* Book3E initialization */
  169. mr r3,r24
  170. bl .book3e_secondary_thread_init
  171. #endif
  172. b generic_secondary_common_init
  173. /*
  174. * On pSeries and most other platforms, secondary processors spin
  175. * in the following code.
  176. * At entry, r3 = this processor's number (physical cpu id)
  177. *
  178. * On Book3E, r4 = 1 to indicate that the initial TLB entry for
  179. * this core already exists (setup via some other mechanism such
  180. * as SCOM before entry).
  181. */
  182. _GLOBAL(generic_secondary_smp_init)
  183. mr r24,r3
  184. mr r25,r4
  185. /* turn on 64-bit mode */
  186. bl .enable_64b_mode
  187. /* get a valid TOC pointer, wherever we're mapped at */
  188. bl .relative_toc
  189. #ifdef CONFIG_PPC_BOOK3E
  190. /* Book3E initialization */
  191. mr r3,r24
  192. mr r4,r25
  193. bl .book3e_secondary_core_init
  194. #endif
  195. generic_secondary_common_init:
  196. /* Set up a paca value for this processor. Since we have the
  197. * physical cpu id in r24, we need to search the pacas to find
  198. * which logical id maps to our physical one.
  199. */
  200. LOAD_REG_ADDR(r13, paca) /* Load paca pointer */
  201. ld r13,0(r13) /* Get base vaddr of paca array */
  202. #ifndef CONFIG_SMP
  203. addi r13,r13,PACA_SIZE /* know r13 if used accidentally */
  204. b .kexec_wait /* wait for next kernel if !SMP */
  205. #else
  206. LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */
  207. lwz r7,0(r7) /* also the max paca allocated */
  208. li r5,0 /* logical cpu id */
  209. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  210. cmpw r6,r24 /* Compare to our id */
  211. beq 2f
  212. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  213. addi r5,r5,1
  214. cmpw r5,r7 /* Check if more pacas exist */
  215. blt 1b
  216. mr r3,r24 /* not found, copy phys to r3 */
  217. b .kexec_wait /* next kernel might do better */
  218. 2: SET_PACA(r13)
  219. #ifdef CONFIG_PPC_BOOK3E
  220. addi r12,r13,PACA_EXTLB /* and TLB exc frame in another */
  221. mtspr SPRN_SPRG_TLB_EXFRAME,r12
  222. #endif
  223. /* From now on, r24 is expected to be logical cpuid */
  224. mr r24,r5
  225. /* See if we need to call a cpu state restore handler */
  226. LOAD_REG_ADDR(r23, cur_cpu_spec)
  227. ld r23,0(r23)
  228. ld r23,CPU_SPEC_RESTORE(r23)
  229. cmpdi 0,r23,0
  230. beq 3f
  231. ld r23,0(r23)
  232. mtctr r23
  233. bctrl
  234. 3: LOAD_REG_ADDR(r3, spinning_secondaries) /* Decrement spinning_secondaries */
  235. lwarx r4,0,r3
  236. subi r4,r4,1
  237. stwcx. r4,0,r3
  238. bne 3b
  239. isync
  240. 4: HMT_LOW
  241. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  242. /* start. */
  243. cmpwi 0,r23,0
  244. beq 4b /* Loop until told to go */
  245. sync /* order paca.run and cur_cpu_spec */
  246. isync /* In case code patching happened */
  247. /* Create a temp kernel stack for use before relocation is on. */
  248. ld r1,PACAEMERGSP(r13)
  249. subi r1,r1,STACK_FRAME_OVERHEAD
  250. b __secondary_start
  251. #endif /* SMP */
  252. /*
  253. * Turn the MMU off.
  254. * Assumes we're mapped EA == RA if the MMU is on.
  255. */
  256. #ifdef CONFIG_PPC_BOOK3S
  257. _STATIC(__mmu_off)
  258. mfmsr r3
  259. andi. r0,r3,MSR_IR|MSR_DR
  260. beqlr
  261. mflr r4
  262. andc r3,r3,r0
  263. mtspr SPRN_SRR0,r4
  264. mtspr SPRN_SRR1,r3
  265. sync
  266. rfid
  267. b . /* prevent speculative execution */
  268. #endif
  269. /*
  270. * Here is our main kernel entry point. We support currently 2 kind of entries
  271. * depending on the value of r5.
  272. *
  273. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  274. * in r3...r7
  275. *
  276. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  277. * DT block, r4 is a physical pointer to the kernel itself
  278. *
  279. */
  280. _GLOBAL(__start_initialization_multiplatform)
  281. /* Make sure we are running in 64 bits mode */
  282. bl .enable_64b_mode
  283. /* Get TOC pointer (current runtime address) */
  284. bl .relative_toc
  285. /* find out where we are now */
  286. bcl 20,31,$+4
  287. 0: mflr r26 /* r26 = runtime addr here */
  288. addis r26,r26,(_stext - 0b)@ha
  289. addi r26,r26,(_stext - 0b)@l /* current runtime base addr */
  290. /*
  291. * Are we booted from a PROM Of-type client-interface ?
  292. */
  293. cmpldi cr0,r5,0
  294. beq 1f
  295. b .__boot_from_prom /* yes -> prom */
  296. 1:
  297. /* Save parameters */
  298. mr r31,r3
  299. mr r30,r4
  300. #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
  301. /* Save OPAL entry */
  302. mr r28,r8
  303. mr r29,r9
  304. #endif
  305. #ifdef CONFIG_PPC_BOOK3E
  306. bl .start_initialization_book3e
  307. b .__after_prom_start
  308. #else
  309. /* Setup some critical 970 SPRs before switching MMU off */
  310. mfspr r0,SPRN_PVR
  311. srwi r0,r0,16
  312. cmpwi r0,0x39 /* 970 */
  313. beq 1f
  314. cmpwi r0,0x3c /* 970FX */
  315. beq 1f
  316. cmpwi r0,0x44 /* 970MP */
  317. beq 1f
  318. cmpwi r0,0x45 /* 970GX */
  319. bne 2f
  320. 1: bl .__cpu_preinit_ppc970
  321. 2:
  322. /* Switch off MMU if not already off */
  323. bl .__mmu_off
  324. b .__after_prom_start
  325. #endif /* CONFIG_PPC_BOOK3E */
  326. _INIT_STATIC(__boot_from_prom)
  327. #ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE
  328. /* Save parameters */
  329. mr r31,r3
  330. mr r30,r4
  331. mr r29,r5
  332. mr r28,r6
  333. mr r27,r7
  334. /*
  335. * Align the stack to 16-byte boundary
  336. * Depending on the size and layout of the ELF sections in the initial
  337. * boot binary, the stack pointer may be unaligned on PowerMac
  338. */
  339. rldicr r1,r1,0,59
  340. #ifdef CONFIG_RELOCATABLE
  341. /* Relocate code for where we are now */
  342. mr r3,r26
  343. bl .relocate
  344. #endif
  345. /* Restore parameters */
  346. mr r3,r31
  347. mr r4,r30
  348. mr r5,r29
  349. mr r6,r28
  350. mr r7,r27
  351. /* Do all of the interaction with OF client interface */
  352. mr r8,r26
  353. bl .prom_init
  354. #endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */
  355. /* We never return. We also hit that trap if trying to boot
  356. * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */
  357. trap
  358. _STATIC(__after_prom_start)
  359. #ifdef CONFIG_RELOCATABLE
  360. /* process relocations for the final address of the kernel */
  361. lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */
  362. sldi r25,r25,32
  363. lwz r7,__run_at_load-_stext(r26)
  364. cmplwi cr0,r7,1 /* flagged to stay where we are ? */
  365. bne 1f
  366. add r25,r25,r26
  367. 1: mr r3,r25
  368. bl .relocate
  369. #endif
  370. /*
  371. * We need to run with _stext at physical address PHYSICAL_START.
  372. * This will leave some code in the first 256B of
  373. * real memory, which are reserved for software use.
  374. *
  375. * Note: This process overwrites the OF exception vectors.
  376. */
  377. li r3,0 /* target addr */
  378. #ifdef CONFIG_PPC_BOOK3E
  379. tovirt(r3,r3) /* on booke, we already run at PAGE_OFFSET */
  380. #endif
  381. mr. r4,r26 /* In some cases the loader may */
  382. beq 9f /* have already put us at zero */
  383. li r6,0x100 /* Start offset, the first 0x100 */
  384. /* bytes were copied earlier. */
  385. #ifdef CONFIG_PPC_BOOK3E
  386. tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */
  387. #endif
  388. #ifdef CONFIG_CRASH_DUMP
  389. /*
  390. * Check if the kernel has to be running as relocatable kernel based on the
  391. * variable __run_at_load, if it is set the kernel is treated as relocatable
  392. * kernel, otherwise it will be moved to PHYSICAL_START
  393. */
  394. lwz r7,__run_at_load-_stext(r26)
  395. cmplwi cr0,r7,1
  396. bne 3f
  397. li r5,__end_interrupts - _stext /* just copy interrupts */
  398. b 5f
  399. 3:
  400. #endif
  401. lis r5,(copy_to_here - _stext)@ha
  402. addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */
  403. bl .copy_and_flush /* copy the first n bytes */
  404. /* this includes the code being */
  405. /* executed here. */
  406. addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */
  407. addi r8,r8,(4f - _stext)@l /* that we just made */
  408. mtctr r8
  409. bctr
  410. p_end: .llong _end - _stext
  411. 4: /* Now copy the rest of the kernel up to _end */
  412. addis r5,r26,(p_end - _stext)@ha
  413. ld r5,(p_end - _stext)@l(r5) /* get _end */
  414. 5: bl .copy_and_flush /* copy the rest */
  415. 9: b .start_here_multiplatform
  416. /*
  417. * Copy routine used to copy the kernel to start at physical address 0
  418. * and flush and invalidate the caches as needed.
  419. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  420. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  421. *
  422. * Note: this routine *only* clobbers r0, r6 and lr
  423. */
  424. _GLOBAL(copy_and_flush)
  425. addi r5,r5,-8
  426. addi r6,r6,-8
  427. 4: li r0,8 /* Use the smallest common */
  428. /* denominator cache line */
  429. /* size. This results in */
  430. /* extra cache line flushes */
  431. /* but operation is correct. */
  432. /* Can't get cache line size */
  433. /* from NACA as it is being */
  434. /* moved too. */
  435. mtctr r0 /* put # words/line in ctr */
  436. 3: addi r6,r6,8 /* copy a cache line */
  437. ldx r0,r6,r4
  438. stdx r0,r6,r3
  439. bdnz 3b
  440. dcbst r6,r3 /* write it to memory */
  441. sync
  442. icbi r6,r3 /* flush the icache line */
  443. cmpld 0,r6,r5
  444. blt 4b
  445. sync
  446. addi r5,r5,8
  447. addi r6,r6,8
  448. blr
  449. .align 8
  450. copy_to_here:
  451. #ifdef CONFIG_SMP
  452. #ifdef CONFIG_PPC_PMAC
  453. /*
  454. * On PowerMac, secondary processors starts from the reset vector, which
  455. * is temporarily turned into a call to one of the functions below.
  456. */
  457. .section ".text";
  458. .align 2 ;
  459. .globl __secondary_start_pmac_0
  460. __secondary_start_pmac_0:
  461. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  462. li r24,0
  463. b 1f
  464. li r24,1
  465. b 1f
  466. li r24,2
  467. b 1f
  468. li r24,3
  469. 1:
  470. _GLOBAL(pmac_secondary_start)
  471. /* turn on 64-bit mode */
  472. bl .enable_64b_mode
  473. li r0,0
  474. mfspr r3,SPRN_HID4
  475. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  476. sync
  477. mtspr SPRN_HID4,r3
  478. isync
  479. sync
  480. slbia
  481. /* get TOC pointer (real address) */
  482. bl .relative_toc
  483. /* Copy some CPU settings from CPU 0 */
  484. bl .__restore_cpu_ppc970
  485. /* pSeries do that early though I don't think we really need it */
  486. mfmsr r3
  487. ori r3,r3,MSR_RI
  488. mtmsrd r3 /* RI on */
  489. /* Set up a paca value for this processor. */
  490. LOAD_REG_ADDR(r4,paca) /* Load paca pointer */
  491. ld r4,0(r4) /* Get base vaddr of paca array */
  492. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  493. add r13,r13,r4 /* for this processor. */
  494. SET_PACA(r13) /* Save vaddr of paca in an SPRG*/
  495. /* Mark interrupts soft and hard disabled (they might be enabled
  496. * in the PACA when doing hotplug)
  497. */
  498. li r0,0
  499. stb r0,PACASOFTIRQEN(r13)
  500. stb r0,PACAHARDIRQEN(r13)
  501. /* Create a temp kernel stack for use before relocation is on. */
  502. ld r1,PACAEMERGSP(r13)
  503. subi r1,r1,STACK_FRAME_OVERHEAD
  504. b __secondary_start
  505. #endif /* CONFIG_PPC_PMAC */
  506. /*
  507. * This function is called after the master CPU has released the
  508. * secondary processors. The execution environment is relocation off.
  509. * The paca for this processor has the following fields initialized at
  510. * this point:
  511. * 1. Processor number
  512. * 2. Segment table pointer (virtual address)
  513. * On entry the following are set:
  514. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  515. * r24 = cpu# (in Linux terms)
  516. * r13 = paca virtual address
  517. * SPRG_PACA = paca virtual address
  518. */
  519. .section ".text";
  520. .align 2 ;
  521. .globl __secondary_start
  522. __secondary_start:
  523. /* Set thread priority to MEDIUM */
  524. HMT_MEDIUM
  525. /* Initialize the kernel stack. Just a repeat for iSeries. */
  526. LOAD_REG_ADDR(r3, current_set)
  527. sldi r28,r24,3 /* get current_set[cpu#] */
  528. ldx r14,r3,r28
  529. addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD
  530. std r14,PACAKSAVE(r13)
  531. /* Do early setup for that CPU (stab, slb, hash table pointer) */
  532. bl .early_setup_secondary
  533. /*
  534. * setup the new stack pointer, but *don't* use this until
  535. * translation is on.
  536. */
  537. mr r1, r14
  538. /* Clear backchain so we get nice backtraces */
  539. li r7,0
  540. mtlr r7
  541. /* enable MMU and jump to start_secondary */
  542. LOAD_REG_ADDR(r3, .start_secondary_prolog)
  543. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  544. #ifdef CONFIG_PPC_ISERIES
  545. BEGIN_FW_FTR_SECTION
  546. ori r4,r4,MSR_EE
  547. li r8,1
  548. stb r8,PACAHARDIRQEN(r13)
  549. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  550. #endif
  551. BEGIN_FW_FTR_SECTION
  552. stb r7,PACAHARDIRQEN(r13)
  553. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  554. stb r7,PACASOFTIRQEN(r13)
  555. mtspr SPRN_SRR0,r3
  556. mtspr SPRN_SRR1,r4
  557. RFI
  558. b . /* prevent speculative execution */
  559. /*
  560. * Running with relocation on at this point. All we want to do is
  561. * zero the stack back-chain pointer and get the TOC virtual address
  562. * before going into C code.
  563. */
  564. _GLOBAL(start_secondary_prolog)
  565. ld r2,PACATOC(r13)
  566. li r3,0
  567. std r3,0(r1) /* Zero the stack frame pointer */
  568. bl .start_secondary
  569. b .
  570. /*
  571. * Reset stack pointer and call start_secondary
  572. * to continue with online operation when woken up
  573. * from cede in cpu offline.
  574. */
  575. _GLOBAL(start_secondary_resume)
  576. ld r1,PACAKSAVE(r13) /* Reload kernel stack pointer */
  577. li r3,0
  578. std r3,0(r1) /* Zero the stack frame pointer */
  579. bl .start_secondary
  580. b .
  581. #endif
  582. /*
  583. * This subroutine clobbers r11 and r12
  584. */
  585. _GLOBAL(enable_64b_mode)
  586. mfmsr r11 /* grab the current MSR */
  587. #ifdef CONFIG_PPC_BOOK3E
  588. oris r11,r11,0x8000 /* CM bit set, we'll set ICM later */
  589. mtmsr r11
  590. #else /* CONFIG_PPC_BOOK3E */
  591. li r12,(MSR_64BIT | MSR_ISF)@highest
  592. sldi r12,r12,48
  593. or r11,r11,r12
  594. mtmsrd r11
  595. isync
  596. #endif
  597. blr
  598. /*
  599. * This puts the TOC pointer into r2, offset by 0x8000 (as expected
  600. * by the toolchain). It computes the correct value for wherever we
  601. * are running at the moment, using position-independent code.
  602. */
  603. _GLOBAL(relative_toc)
  604. mflr r0
  605. bcl 20,31,$+4
  606. 0: mflr r11
  607. ld r2,(p_toc - 0b)(r11)
  608. add r2,r2,r11
  609. mtlr r0
  610. blr
  611. p_toc: .llong __toc_start + 0x8000 - 0b
  612. /*
  613. * This is where the main kernel code starts.
  614. */
  615. _INIT_STATIC(start_here_multiplatform)
  616. /* set up the TOC (real address) */
  617. bl .relative_toc
  618. /* Clear out the BSS. It may have been done in prom_init,
  619. * already but that's irrelevant since prom_init will soon
  620. * be detached from the kernel completely. Besides, we need
  621. * to clear it now for kexec-style entry.
  622. */
  623. LOAD_REG_ADDR(r11,__bss_stop)
  624. LOAD_REG_ADDR(r8,__bss_start)
  625. sub r11,r11,r8 /* bss size */
  626. addi r11,r11,7 /* round up to an even double word */
  627. srdi. r11,r11,3 /* shift right by 3 */
  628. beq 4f
  629. addi r8,r8,-8
  630. li r0,0
  631. mtctr r11 /* zero this many doublewords */
  632. 3: stdu r0,8(r8)
  633. bdnz 3b
  634. 4:
  635. #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
  636. /* Setup OPAL entry */
  637. std r28,0(r11);
  638. std r29,8(r11);
  639. #endif
  640. #ifndef CONFIG_PPC_BOOK3E
  641. mfmsr r6
  642. ori r6,r6,MSR_RI
  643. mtmsrd r6 /* RI on */
  644. #endif
  645. #ifdef CONFIG_RELOCATABLE
  646. /* Save the physical address we're running at in kernstart_addr */
  647. LOAD_REG_ADDR(r4, kernstart_addr)
  648. clrldi r0,r25,2
  649. std r0,0(r4)
  650. #endif
  651. /* The following gets the stack set up with the regs */
  652. /* pointing to the real addr of the kernel stack. This is */
  653. /* all done to support the C function call below which sets */
  654. /* up the htab. This is done because we have relocated the */
  655. /* kernel but are still running in real mode. */
  656. LOAD_REG_ADDR(r3,init_thread_union)
  657. /* set up a stack pointer */
  658. addi r1,r3,THREAD_SIZE
  659. li r0,0
  660. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  661. /* Do very early kernel initializations, including initial hash table,
  662. * stab and slb setup before we turn on relocation. */
  663. /* Restore parameters passed from prom_init/kexec */
  664. mr r3,r31
  665. bl .early_setup /* also sets r13 and SPRG_PACA */
  666. LOAD_REG_ADDR(r3, .start_here_common)
  667. ld r4,PACAKMSR(r13)
  668. mtspr SPRN_SRR0,r3
  669. mtspr SPRN_SRR1,r4
  670. RFI
  671. b . /* prevent speculative execution */
  672. /* This is where all platforms converge execution */
  673. _INIT_GLOBAL(start_here_common)
  674. /* relocation is on at this point */
  675. std r1,PACAKSAVE(r13)
  676. /* Load the TOC (virtual address) */
  677. ld r2,PACATOC(r13)
  678. bl .setup_system
  679. /* Load up the kernel context */
  680. 5:
  681. li r5,0
  682. stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
  683. #ifdef CONFIG_PPC_ISERIES
  684. BEGIN_FW_FTR_SECTION
  685. mfmsr r5
  686. ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
  687. mtmsrd r5
  688. li r5,1
  689. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  690. #endif
  691. stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
  692. bl .start_kernel
  693. /* Not reached */
  694. BUG_OPCODE
  695. /*
  696. * We put a few things here that have to be page-aligned.
  697. * This stuff goes at the beginning of the bss, which is page-aligned.
  698. */
  699. .section ".bss"
  700. .align PAGE_SHIFT
  701. .globl empty_zero_page
  702. empty_zero_page:
  703. .space PAGE_SIZE
  704. .globl swapper_pg_dir
  705. swapper_pg_dir:
  706. .space PGD_TABLE_SIZE