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