head_64.S 19 KB

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