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