head_64.S 19 KB

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