]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/aim/locore64.S
dts: Import files from Linux 5.1
[FreeBSD/FreeBSD.git] / sys / powerpc / aim / locore64.S
1 /* $FreeBSD$ */
2
3 /*-
4  * Copyright (C) 2010-2016 Nathan Whitehorn
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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.
26  *
27  * $FreeBSD$
28  */
29
30 #include "assym.inc"
31
32 #include <sys/syscall.h>
33
34 #include <machine/trap.h>
35 #include <machine/param.h>
36 #include <machine/spr.h>
37 #include <machine/asm.h>
38 #include <machine/vmparam.h>
39
40 #ifdef _CALL_ELF
41 .abiversion _CALL_ELF
42 #endif
43
44 /* Glue for linker script */
45 .globl  kernbase
46 .set    kernbase, KERNBASE
47
48 /*
49  * Globals
50  */
51         .data
52         .align 3
53 GLOBAL(__startkernel)
54         .llong  begin
55 GLOBAL(__endkernel)
56         .llong  end
57 GLOBAL(can_wakeup)
58         .llong  0x0
59
60         .align  4
61 #define TMPSTKSZ        16384           /* 16K temporary stack */
62 GLOBAL(tmpstk)
63         .space  TMPSTKSZ
64
65 TOC_ENTRY(tmpstk)
66 TOC_ENTRY(can_wakeup)
67
68 #ifdef KDB
69 #define TRAPSTKSZ       4096            /* 4k trap stack */
70 GLOBAL(trapstk)
71         .space        TRAPSTKSZ
72 TOC_ENTRY(trapstk)
73 #endif
74
75
76 /*
77  * Entry point for bootloaders that do not fully implement ELF and start
78  * at the beginning of the image (kexec, notably). In its own section so
79  * that it ends up before any linker-generated call stubs and actually at
80  * the beginning of the image. kexec on some systems also enters at
81  * (start of image) + 0x60, so put a spin loop there.
82  */
83         .section ".text.kboot", "x", @progbits
84 kbootentry:
85         b __start
86 . = kbootentry + 0x40   /* Magic address used in platform layer */
87         .global smp_spin_sem
88 ap_kexec_spin_sem:
89         .long   -1
90 . = kbootentry + 0x60   /* Entry point for kexec APs */
91 ap_kexec_start:         /* At 0x60 past start, copied to 0x60 by kexec */
92         /* r3 set to CPU ID by kexec */
93
94         /* Invalidate icache for low-memory copy and jump there */
95         li      %r0,0x80
96         dcbst   0,%r0
97         sync
98         icbi    0,%r0
99         isync
100         ba      0x80                    /* Absolute branch to next inst */
101
102 . = kbootentry + 0x80                   /* Aligned to cache line */
103 1:      or      31,31,31                /* yield */
104         sync
105         lwz     %r1,0x40(0)             /* Spin on ap_kexec_spin_sem */
106         cmpw    %r1,%r3                 /* Until it equals our CPU ID */
107         bne     1b
108         
109         /* Released */
110         or      2,2,2                   /* unyield */
111
112         /* Make sure that it will be software reset. Clear SRR1 */
113         li      %r1,0
114         mtsrr1  %r1
115         ba      EXC_RST
116
117 /*
118  * Now start the real text section
119  */
120
121         .text
122         .globl  btext
123 btext:
124
125 /*
126  * Main kernel entry point.
127  *
128  * Calling convention:
129  * r3: Flattened Device Tree pointer (or zero)
130  * r4: ignored
131  * r5: OF client interface pointer (or zero)
132  * r6: Loader metadata pointer (or zero)
133  * r7: Magic cookie (0xfb5d104d) to indicate that r6 has loader metadata
134  */
135         .text
136 ASENTRY_NOPROF(__start)
137         /* Set 64-bit mode if not yet set before branching to C */
138         mfmsr   %r20
139         li      %r21,1
140         insrdi  %r20,%r21,1,0
141         mtmsrd  %r20
142         isync
143         nop     /* Make this block a multiple of 8 bytes */
144
145         /* Set up the TOC pointer */
146         b       0f
147         .align 3
148 0:      nop
149         bl      1f
150         .llong  __tocbase + 0x8000 - .
151 1:      mflr    %r2
152         ld      %r1,0(%r2)
153         add     %r2,%r1,%r2
154
155         /* Get load offset */
156         ld      %r31,-0x8000(%r2) /* First TOC entry is TOC base */
157         subf    %r31,%r31,%r2   /* Subtract from real TOC base to get base */
158
159         /* Set up the stack pointer */
160         bl      1f
161         .llong  tmpstk + TMPSTKSZ - 96 - .
162 1:      mflr    %r30
163         ld      %r1,0(%r30)
164         add     %r1,%r1,%r30
165         nop
166
167         /* Relocate kernel */
168         std     %r3,48(%r1)
169         std     %r4,56(%r1)
170         std     %r5,64(%r1)
171         std     %r6,72(%r1)
172         std     %r7,80(%r1)
173
174         bl      1f
175         .llong _DYNAMIC-.
176 1:      mflr    %r3
177         ld      %r4,0(%r3)
178         add     %r3,%r4,%r3
179         mr      %r4,%r31
180         bl      elf_reloc_self
181         nop
182         ld      %r3,48(%r1)
183         ld      %r4,56(%r1)
184         ld      %r5,64(%r1)
185         ld      %r6,72(%r1)
186         ld      %r7,80(%r1)
187
188         /* Begin CPU init */
189         mr      %r4,%r2 /* Replace ignored r4 with tocbase for trap handlers */
190         bl      powerpc_init
191         nop
192
193         /* Set stack pointer to new value and branch to mi_startup */
194         mr      %r1, %r3
195         li      %r3, 0
196         std     %r3, 0(%r1)
197         bl      mi_startup
198         nop
199
200         /* Unreachable */
201         b       .
202
203 ASENTRY_NOPROF(__restartkernel)
204         /*
205          * r3-r7: arguments to go to __start
206          * r8: offset from current kernel address to apply
207          * r9: MSR to set when (atomically) jumping to __start + r8
208          */
209         mtsrr1  %r9
210         bl      1f
211 1:      mflr    %r25
212         add     %r25,%r8,%r25
213         addi    %r25,%r25,2f-1b
214         mtsrr0  %r25
215         rfid
216 2:      bl      __start
217         nop
218
219 #include <powerpc/aim/trap_subr64.S>