head_64.S 22 KB

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