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