srt0.s revision 1.1 1 /* $NetBSD: srt0.s,v 1.1 2000/08/20 14:58:42 mrg Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <machine/psl.h>
35 #include <machine/param.h>
36 #include <machine/frame.h>
37 #include <machine/asm.h>
38
39 /*
40 * Globals
41 */
42 .globl _esym
43 .data
44 _esym: .word 0 /* end of symbol table */
45 .globl _C_LABEL(romp)
46 .align 8
47 _C_LABEL(romp): .xword 0 /* openfirmware entry point */
48
49 /*
50 * Startup entry
51 */
52 .text
53 .globl _start, _C_LABEL(kernel_text)
54 _C_LABEL(kernel_text) = _start
55 _start:
56 nop ! For some reason this is needed to fixup the text section
57
58 /*
59 * Step 1: Save rom entry pointer -- NOTE this probably needs to change
60 */
61
62 mov %o4, %g7 ! save prom vector pointer
63 set _C_LABEL(romp), %g1
64 stx %o4, [%g1] ! It's initialized data, I hope
65
66 /*
67 * Start by creating a stack for ourselves.
68 */
69 #ifdef _LP64
70 /* 64-bit stack */
71 btst 1, %sp
72 set CC64FSZ, %g1 ! Frame Size (negative)
73 bnz 1f
74 set BIAS, %g2 ! Bias (negative)
75 andn %sp, 0x0f, %sp ! 16 byte align, per ELF spec.
76 add %g1, %g2, %g1 ! Frame + Bias
77 1:
78 sub %sp, %g1, %g1
79 save %g1, %g0, %sp
80 #else
81 /* 32-bit stack */
82 btst 1, %sp
83 set CC64FSZ, %g1 ! Frame Size (negative)
84 bz 1f
85 set BIAS, %g2
86 sub %g1, %g2, %g1
87 1:
88 sub %sp, %g1, %g1 ! This is so we properly sign-extend things
89 andn %g1, 0x7, %g1
90 save %g1, %g0, %sp
91 #endif
92
93 ! mov %i0, %i4 ! Apparenty we get our CIF in i0
94
95 /*
96 * Set the psr into a known state:
97 * Set supervisor mode, interrupt level >= 13, traps enabled
98 */
99 wrpr %g0, 0, %pil ! So I lied
100 wrpr %g0, PSTATE_PRIV+PSTATE_IE, %pstate
101
102 clr %g4 ! Point %g4 to start of data segment
103 ! only problem is that apparently the
104 ! start of the data segment is 0
105
106 /*
107 * XXXXXXXX Need to determine what params are passed
108 */
109 call _C_LABEL(setup)
110 nop
111 mov %i1, %o1
112 call _C_LABEL(main)
113 mov %i2, %o0
114 call _C_LABEL(exit)
115 nop
116 call _C_LABEL(_rtt)
117 nop
118
119 /*
120 * void syncicache(void* start, int size)
121 *
122 * I$ flush. Really simple. Just flush over the whole range.
123 */
124 .align 8
125 .globl _C_LABEL(syncicache)
126 _C_LABEL(syncicache):
127 dec 4, %o1
128 flush %o0
129 brgz,a,pt %o1, _C_LABEL(syncicache)
130 inc 4, %o0
131 retl
132 nop
133
134 /*
135 * openfirmware(cell* param);
136 *
137 * OpenFirmware entry point
138 *
139 * If we're running in 32-bit mode we need to convert to a 64-bit stack
140 * and 64-bit cells. The cells we'll allocate off the stack for simplicity.
141 */
142 .align 8
143 .globl _C_LABEL(openfirmware)
144 .proc 1
145 FTYPE(openfirmware)
146 _C_LABEL(openfirmware):
147 andcc %sp, 1, %g0
148 bz,pt %icc, 1f
149 sethi %hi(_C_LABEL(romp)), %o1
150
151 ldx [%o1+%lo(_C_LABEL(romp))], %o4 ! v9 stack, just load the addr and callit
152 save %sp, -CC64FSZ, %sp
153 mov %i0, %o0 ! Copy over our parameter
154 mov %g1, %l1
155 mov %g2, %l2
156 mov %g3, %l3
157 mov %g4, %l4
158 mov %g5, %l5
159 mov %g6, %l6
160 mov %g7, %l7
161 rdpr %pstate, %l0
162 jmpl %i4, %o7
163 wrpr %g0, PSTATE_PROM|PSTATE_IE, %pstate
164 wrpr %l0, %g0, %pstate
165 mov %l1, %g1
166 mov %l2, %g2
167 mov %l3, %g3
168 mov %l4, %g4
169 mov %l5, %g5
170 mov %l6, %g6
171 mov %l7, %g7
172 ret
173 restore %o0, %g0, %o0
174
175 1: ! v8 -- need to screw with stack & params
176 save %sp, -CC64FSZ, %sp ! Get a new 64-bit stack frame
177 add %sp, -BIAS, %sp
178 sethi %hi(_C_LABEL(romp)), %o1
179 rdpr %pstate, %l0
180 ldx [%o1+%lo(_C_LABEL(romp))], %o1 ! Do the actual call
181 srl %sp, 0, %sp
182 mov %i0, %o0
183 mov %g1, %l1
184 mov %g2, %l2
185 mov %g3, %l3
186 mov %g4, %l4
187 mov %g5, %l5
188 mov %g6, %l6
189 mov %g7, %l7
190 jmpl %o1, %o7
191 wrpr %g0, PSTATE_PROM|PSTATE_IE, %pstate ! Enable 64-bit addresses for the prom
192 wrpr %l0, 0, %pstate
193 mov %l1, %g1
194 mov %l2, %g2
195 mov %l3, %g3
196 mov %l4, %g4
197 mov %l5, %g5
198 mov %l6, %g6
199 mov %l7, %g7
200 ret
201 restore %o0, %g0, %o0
202
203 #if 0
204 .data
205 .align 8
206 bootstack:
207 #define STACK_SIZE 0x14000
208 .skip STACK_SIZE
209 ebootstack: ! end (top) of boot stack
210 #endif
211