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