head_64.S 19 KB

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