srt0.S revision 1.3 1 /* $NetBSD: srt0.S,v 1.3 1999/02/15 19:01:38 pk 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/psl.h>
43
44 #define CCFSZ 96
45
46 .file "str0.s"
47
48 .comm _romp, 4
49 .comm _opf_romp, 4
50 .comm _cputyp, 4
51 .comm _nbpg, 4
52 .comm _pgofset, 4
53 .comm _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 * Relocate.
67 */
68 1: call 2f
69 nop
70 2: add %o7, (start-1b), %l0
71 set start, %l1
72 set _end, %o0
73 sub %o0, %l1, %l2 ! length
74 3: ld [%l0], %o0
75 add %l0, 4, %l0
76 st %o0, [%l1]
77 subcc %l2, 4, %l2
78 bg 3b
79 add %l1, 4, %l1
80
81 set 4f, %g1
82 jmp %g1
83 nop
84
85 4:
86 #ifdef notyet
87 /*
88 * Enable traps
89 */
90 wr %g0, 0, %wim ! make sure we can set psr
91 nop; nop; nop
92 wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
93 nop; nop; nop
94 wr %g0, 2, %wim ! set initial %wim (w1 invalid)
95
96 rd %psr, %l0
97 wr %l0, PSR_ET, %psr
98 nop; nop; nop
99 #endif
100
101 /*
102 * Clear BSS
103 */
104 set _edata, %o0 ! bzero(edata, end - edata)
105 set _end, %o1
106 /* note: bzero() expanded inline for compactness */
107 subcc %o1, %o0, %o1
108 bz 2f ! in case there is no BSS
109
110 srl %o1, 2, %o1 ! assume _edata & _end are aligned
111 1:
112 st %g0, [%o0] ! while (n--)
113 subcc %o1, 1, %o1 ! *p = 0; etc..
114 bnz 1b
115 add %o0, 4, %o0
116 2:
117
118 /*
119 * Enable interrupts, but only above level 11. This enables "L1-A",
120 * but avoids spurious interrupt bites from most other devices.
121 */
122 rd %psr, %o0
123 andn %o0, PSR_PIL, %o0
124 wr %o0, 0xb00, %psr ! (11 << 8)
125 nop; nop; nop
126
127 /*
128 * Set CPU type that we are running on.
129 */
130 sethi %hi(_cputyp), %o0
131 set 0x4000, %g7
132 cmp %i0, %g7
133 beq is_sun4
134 nop
135
136 mov CPU_SUN4C, %g4
137 mov SUN4CM_PGSHIFT, %g5
138
139 /*
140 * Save address of PROM vector (passed in %i0).
141 */
142 sethi %hi(_romp), %o1
143 st %i0, [%o1 + %lo(_romp)]
144
145 /* Also save %i3, which is the Openfirmware entry, if any */
146 sethi %hi(_opf_romp), %o1
147 st %i3, [%o1 + %lo(_opf_romp)]
148 b,a is_sun4cm
149
150 is_sun4:
151 mov CPU_SUN4, %g4
152 mov SUN4_PGSHIFT, %g5
153
154 is_sun4cm:
155 st %g4, [%o0 + %lo(_cputyp)]
156 sethi %hi(_pgshift), %o0 ! pgshift = log2(nbpg)
157 st %g5, [%o0 + %lo(_pgshift)]
158
159 mov 1, %o0 ! nbpg = 1 << pgshift
160 sll %o0, %g5, %g5
161 sethi %hi(_nbpg), %o0 ! nbpg = bytes in a page
162 st %g5, [%o0 + %lo(_nbpg)]
163
164 sub %g5, 1, %g5
165 sethi %hi(_pgofset), %o0 ! page offset = bytes in a page - 1
166 st %g5, [%o0 + %lo(_pgofset)]
167
168 call _main
169 mov %i0, %o0
170
171 ret
172 restore
173
174 /*
175 * NO-OP place holder function.
176 */
177 .globl _sparc_noop
178 _sparc_noop:
179 retl
180 nop
181
182
183 #ifdef TIGHT
184
185 /*
186 * XXX - Space saving .div & .rem routines (small & non-negative numbres only)
187 */
188 .align 4
189 .global .div, .udiv
190 ! int n = 0; while (a >= b) { a -= b; n++; }; return n;
191 .div:
192 .udiv:
193 cmp %o0, %o1
194 bl 2f
195 mov 0, %o5
196 1:
197 sub %o0, %o1, %o0
198 cmp %o0, %o1
199 bge 1b
200 add %o5, 1, %o5
201 2:
202 retl
203 mov %o5, %o0
204
205 .align 4
206 .global .rem, .urem
207 ! while (a>=b) a -= b; return a;
208 .rem:
209 .urem:
210 cmp %o0, %o1
211 bl 2f
212 nop
213 sub %o0, %o1, %o0
214 1:
215 cmp %o0, %o1
216 bge,a 1b
217 sub %o0, %o1, %o0
218 2:
219 retl
220 nop
221
222 #endif /* TIGHT */
223