head_64.S 20 KB

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