head_64.S 20 KB

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