srt0.s revision 1.2 1 /* $NetBSD: srt0.s,v 1.2 2002/10/30 01:46:09 petrov 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 .register %g2,#ignore
40 .register %g3,#ignore
41
42 /*
43 * Globals
44 */
45 .globl _esym
46 .data
47 _esym: .word 0 /* end of symbol table */
48 .globl _C_LABEL(romp)
49 .align 8
50 _C_LABEL(romp): .xword 0 /* openfirmware entry point */
51
52 /*
53 * Startup entry
54 */
55 .text
56 .globl _start, _C_LABEL(kernel_text)
57 _C_LABEL(kernel_text) = _start
58 _start:
59 nop ! For some reason this is needed to fixup the text section
60
61 /*
62 * Step 1: Save rom entry pointer -- NOTE this probably needs to change
63 */
64
65 mov %o4, %g7 ! save prom vector pointer
66 set _C_LABEL(romp), %g1
67 stx %o4, [%g1] ! It's initialized data, I hope
68
69 /*
70 * Start by creating a stack for ourselves.
71 */
72 #ifdef _LP64
73 /* 64-bit stack */
74 btst 1, %sp
75 set CC64FSZ, %g1 ! Frame Size (negative)
76 bnz 1f
77 set BIAS, %g2 ! Bias (negative)
78 andn %sp, 0x0f, %sp ! 16 byte align, per ELF spec.
79 add %g1, %g2, %g1 ! Frame + Bias
80 1:
81 sub %sp, %g1, %g1
82 save %g1, %g0, %sp
83 #else
84 /* 32-bit stack */
85 btst 1, %sp
86 set CC64FSZ, %g1 ! Frame Size (negative)
87 bz 1f
88 set BIAS, %g2
89 sub %g1, %g2, %g1
90 1:
91 sub %sp, %g1, %g1 ! This is so we properly sign-extend things
92 andn %g1, 0x7, %g1
93 save %g1, %g0, %sp
94 #endif
95
96 ! mov %i0, %i4 ! Apparenty we get our CIF in i0
97
98 /*
99 * Set the psr into a known state:
100 * Set supervisor mode, interrupt level >= 13, traps enabled
101 */
102 wrpr %g0, 0, %pil ! So I lied
103 wrpr %g0, PSTATE_PRIV+PSTATE_IE, %pstate
104
105 clr %g4 ! Point %g4 to start of data segment
106 ! only problem is that apparently the
107 ! start of the data segment is 0
108
109 /*
110 * XXXXXXXX Need to determine what params are passed
111 */
112 call _C_LABEL(setup)
113 nop
114 mov %i1, %o1
115 call _C_LABEL(main)
116 mov %i2, %o0
117 call _C_LABEL(exit)
118 nop
119 call _C_LABEL(_rtt)
120 nop
121
122 /*
123 * void syncicache(void* start, int size)
124 *
125 * I$ flush. Really simple. Just flush over the whole range.
126 */
127 .align 8
128 .globl _C_LABEL(syncicache)
129 _C_LABEL(syncicache):
130 dec 4, %o1
131 flush %o0
132 brgz,a,pt %o1, _C_LABEL(syncicache)
133 inc 4, %o0
134 retl
135 nop
136
137 /*
138 * openfirmware(cell* param);
139 *
140 * OpenFirmware entry point
141 *
142 * If we're running in 32-bit mode we need to convert to a 64-bit stack
143 * and 64-bit cells. The cells we'll allocate off the stack for simplicity.
144 */
145 .align 8
146 .globl _C_LABEL(openfirmware)
147 .proc 1
148 FTYPE(openfirmware)
149 _C_LABEL(openfirmware):
150 andcc %sp, 1, %g0
151 bz,pt %icc, 1f
152 sethi %hi(_C_LABEL(romp)), %o1
153
154 ldx [%o1+%lo(_C_LABEL(romp))], %o4 ! v9 stack, just load the addr and callit
155 save %sp, -CC64FSZ, %sp
156 mov %i0, %o0 ! Copy over our parameter
157 mov %g1, %l1
158 mov %g2, %l2
159 mov %g3, %l3
160 mov %g4, %l4
161 mov %g5, %l5
162 mov %g6, %l6
163 mov %g7, %l7
164 rdpr %pstate, %l0
165 jmpl %i4, %o7
166 wrpr %g0, PSTATE_PROM|PSTATE_IE, %pstate
167 wrpr %l0, %g0, %pstate
168 mov %l1, %g1
169 mov %l2, %g2
170 mov %l3, %g3
171 mov %l4, %g4
172 mov %l5, %g5
173 mov %l6, %g6
174 mov %l7, %g7
175 ret
176 restore %o0, %g0, %o0
177
178 1: ! v8 -- need to screw with stack & params
179 save %sp, -CC64FSZ, %sp ! Get a new 64-bit stack frame
180 add %sp, -BIAS, %sp
181 sethi %hi(_C_LABEL(romp)), %o1
182 rdpr %pstate, %l0
183 ldx [%o1+%lo(_C_LABEL(romp))], %o1 ! Do the actual call
184 srl %sp, 0, %sp
185 mov %i0, %o0
186 mov %g1, %l1
187 mov %g2, %l2
188 mov %g3, %l3
189 mov %g4, %l4
190 mov %g5, %l5
191 mov %g6, %l6
192 mov %g7, %l7
193 jmpl %o1, %o7
194 wrpr %g0, PSTATE_PROM|PSTATE_IE, %pstate ! Enable 64-bit addresses for the prom
195 wrpr %l0, 0, %pstate
196 mov %l1, %g1
197 mov %l2, %g2
198 mov %l3, %g3
199 mov %l4, %g4
200 mov %l5, %g5
201 mov %l6, %g6
202 mov %l7, %g7
203 ret
204 restore %o0, %g0, %o0
205
206 #if 0
207 .data
208 .align 8
209 bootstack:
210 #define STACK_SIZE 0x14000
211 .skip STACK_SIZE
212 ebootstack: ! end (top) of boot stack
213 #endif
214