head_64.S 20 KB

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