head_64.S 19 KB

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