head_64.S 21 KB

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