head_64.S 21 KB

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