srt0.S revision 1.7 1 /* $NetBSD: srt0.S,v 1.7 2001/11/21 21:38:00 uwe Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #define _LOCORE /* XXX - fix Makefile */
40
41 #include <machine/param.h>
42 #include <machine/asm.h>
43 #include <machine/psl.h>
44
45 #define CCFSZ 96
46
47 .file "str0.s"
48
49 .comm _C_LABEL(romp), 4
50 .comm _C_LABEL(cputyp), 4
51 .comm _C_LABEL(nbpg), 4
52 .comm _C_LABEL(pgofset), 4
53 .comm _C_LABEL(pgshift), 4
54
55 .text
56 .globl start
57
58 start:
59 /*
60 * Set up a stack.
61 */
62 set start, %o1
63 save %o1, -CCFSZ, %sp
64
65 /*
66 * Find which address we are at.
67 */
68 1: call 2f
69 sethi %hi(1b), %l0
70 2: or %l0, %lo(1b), %l0
71 cmp %l0, %o7 ! %o7 contains actual address of 1b
72 beq 4f ! already there, no need to relocate
73 nop
74
75 /*
76 * Relocate.
77 */
78 add %o7, (start-1b), %l0
79 set start, %l1
80 set _edata, %o0
81 sub %o0, %l1, %l2 ! length
82 3: ld [%l0], %o0
83 add %l0, 4, %l0
84 st %o0, [%l1]
85 subcc %l2, 4, %l2
86 bg 3b
87 add %l1, 4, %l1
88
89 /*
90 * Jump to our relocated self.
91 */
92 set 4f, %g1
93 jmp %g1
94 nop
95
96 4:
97 #ifdef notyet
98 /*
99 * Enable traps
100 */
101 wr %g0, 0, %wim ! make sure we can set psr
102 nop; nop; nop
103 wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
104 nop; nop; nop
105 wr %g0, 2, %wim ! set initial %wim (w1 invalid)
106
107 rd %psr, %l0
108 wr %l0, PSR_ET, %psr
109 nop; nop; nop
110 #endif
111
112 /*
113 * Clear BSS
114 */
115 set _edata, %o0 ! bzero(edata, end - edata)
116 set _end, %o1
117 /* note: bzero() expanded inline for compactness */
118 subcc %o1, %o0, %o1
119 bz 2f ! in case there is no BSS
120
121 srl %o1, 2, %o1 ! assume _edata & _end are aligned
122 1:
123 st %g0, [%o0] ! while (n--)
124 subcc %o1, 1, %o1 ! *p = 0; etc..
125 bnz 1b
126 add %o0, 4, %o0
127 2:
128
129 /*
130 * Enable interrupts, but only above level 11. This enables "L1-A",
131 * but avoids spurious interrupt bites from most other devices.
132 */
133 rd %psr, %o0
134 andn %o0, PSR_PIL, %o0
135 wr %o0, 0xb00, %psr ! (11 << 8)
136 nop; nop; nop
137
138 /*
139 * Set CPU type that we are running on.
140 */
141 sethi %hi(_C_LABEL(cputyp)), %o0
142 set 0x4000, %g7
143 cmp %i0, %g7
144 beq is_sun4
145 nop
146
147 mov CPU_SUN4C, %g4
148 mov SUN4CM_PGSHIFT, %g5
149
150 /*
151 * OpenProm machines pass PROM vector in %o0 (%i0 after save)
152 * OpenFirm machines pass OF entry in %o3 (%i3 after save)
153 */
154 cmp %i0, 0
155 be is_openfirm
156 nop
157
158 ! save address of PROM vector
159 sethi %hi(_C_LABEL(romp)), %o1
160 st %i0, [%o1 + %lo(_C_LABEL(romp))]
161 b,a is_sun4cm
162
163 is_openfirm:
164 ! save address of OpenFirmware client interface handler
165 sethi %hi(_C_LABEL(romp)), %o1
166 st %i3, [%o1 + %lo(_C_LABEL(romp))]
167 b,a is_sun4cm
168
169 is_sun4:
170 mov CPU_SUN4, %g4
171 mov SUN4_PGSHIFT, %g5
172
173 is_sun4cm:
174 st %g4, [%o0 + %lo(_C_LABEL(cputyp))]
175 sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg)
176 st %g5, [%o0 + %lo(_C_LABEL(pgshift))]
177
178 mov 1, %o0 ! nbpg = 1 << pgshift
179 sll %o0, %g5, %g5
180 sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page
181 st %g5, [%o0 + %lo(_C_LABEL(nbpg))]
182
183 sub %g5, 1, %g5
184 sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1
185 st %g5, [%o0 + %lo(_C_LABEL(pgofset))]
186
187 call _C_LABEL(main)
188 mov %i0, %o0
189
190 ret
191 restore
192
193 /*
194 * NO-OP place holder function.
195 */
196 ENTRY(sparc_noop)
197 retl
198 nop
199
200
201 #ifdef TIGHT
202
203 /*
204 * XXX - Space saving .div & .rem routines (small & non-negative numbres only)
205 */
206 .align 4
207 .global .div, .udiv
208 ! int n = 0; while (a >= b) { a -= b; n++; }; return n;
209 .div:
210 .udiv:
211 cmp %o0, %o1
212 bl 2f
213 mov 0, %o5
214 1:
215 sub %o0, %o1, %o0
216 cmp %o0, %o1
217 bge 1b
218 add %o5, 1, %o5
219 2:
220 retl
221 mov %o5, %o0
222
223 .align 4
224 .global .rem, .urem
225 ! while (a>=b) a -= b; return a;
226 .rem:
227 .urem:
228 cmp %o0, %o1
229 bl 2f
230 nop
231 sub %o0, %o1, %o0
232 1:
233 cmp %o0, %o1
234 bge,a 1b
235 sub %o0, %o1, %o0
236 2:
237 retl
238 nop
239
240 #endif /* TIGHT */
241