head_64.S 20 KB

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