head_64.S 21 KB

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