4 * Copyright (C) 2010-2016 Nathan Whitehorn
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/syscall.h>
34 #include <machine/trap.h>
35 #include <machine/param.h>
36 #include <machine/spr.h>
37 #include <machine/asm.h>
43 /* Glue for linker script */
45 .set kernbase, KERNBASE
60 #define TMPSTKSZ 16384 /* 16K temporary stack */
68 * Entry point for bootloaders that do not fully implement ELF and start
69 * at the beginning of the image (kexec, notably). In its own section so
70 * that it ends up before any linker-generated call stubs and actually at
71 * the beginning of the image. kexec on some systems also enters at
72 * (start of image) + 0x60, so put a spin loop there.
74 .section ".text.kboot", "x", @progbits
77 . = kbootentry + 0x40 /* Magic address used in platform layer */
81 . = kbootentry + 0x60 /* Entry point for kexec APs */
82 ap_kexec_start: /* At 0x60 past start, copied to 0x60 by kexec */
83 /* r3 set to CPU ID by kexec */
85 /* Invalidate icache for low-memory copy and jump there */
91 ba 0x80 /* Absolute branch to next inst */
93 . = kbootentry + 0x80 /* Aligned to cache line */
94 1: or 31,31,31 /* yield */
96 lwz %r1,0x40(0) /* Spin on ap_kexec_spin_sem */
97 cmpw %r1,%r3 /* Until it equals our CPU ID */
101 or 2,2,2 /* unyield */
103 /* Make sure that it will be software reset. Clear SRR1 */
110 * Now start the real text section
118 * Main kernel entry point.
120 * Calling convention:
121 * r3: Flattened Device Tree pointer (or zero)
123 * r5: OF client interface pointer (or zero)
124 * r6: Loader metadata pointer (or zero)
125 * r7: Magic cookie (0xfb5d104d) to indicate that r6 has loader metadata
128 ASENTRY_NOPROF(__start)
129 /* Set 64-bit mode if not yet set before branching to C */
135 nop /* Make this block a multiple of 8 bytes */
137 /* Set up the TOC pointer */
142 .llong __tocbase + 0x8000 - .
147 /* Get load offset */
148 ld %r31,-0x8000(%r2) /* First TOC entry is TOC base */
149 subf %r31,%r31,%r2 /* Subtract from real TOC base to get base */
151 /* Set up the stack pointer */
152 ld %r1,TOC_REF(tmpstk)(%r2)
153 addi %r1,%r1,TMPSTKSZ-96
156 /* Relocate kernel */
178 mr %r4,%r2 /* Replace ignored r4 with tocbase for trap handlers */
182 /* Set stack pointer to new value and branch to mi_startup */
192 #include <powerpc/aim/trap_subr64.S>