head_64.S 20 KB

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