1 /* $NetBSD: srt0.S,v 1.10 2005/12/11 12:19:08 christos Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #define _LOCORE /* XXX - fix Makefile */
34 #include <machine/param.h>
35 #include <machine/asm.h>
36 #include <machine/psl.h>
42 .comm _C_LABEL(romp), 4
43 .comm _C_LABEL(cputyp), 4
44 .comm _C_LABEL(nbpg), 4
45 .comm _C_LABEL(pgofset), 4
46 .comm _C_LABEL(pgshift), 4
59 * Find which address we are at.
63 2: or %l0, %lo(1b), %l0
64 cmp %l0, %o7 ! %o7 contains actual address of 1b
65 beq 4f ! already there, no need to relocate
71 add %o7, (start-1b), %l0
74 sub %o0, %l1, %l2 ! length
83 * Jump to our relocated self.
94 wr %g0, 0, %wim ! make sure we can set psr
96 wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
98 wr %g0, 2, %wim ! set initial %wim (w1 invalid)
108 set _edata, %o0 ! bzero(edata, end - edata)
110 /* note: bzero() expanded inline for compactness */
112 bz 2f ! in case there is no BSS
114 srl %o1, 2, %o1 ! assume _edata & _end are aligned
116 st %g0, [%o0] ! while (n--)
117 subcc %o1, 1, %o1 ! *p = 0; etc..
123 * Enable interrupts, but only above level 11. This enables "L1-A",
124 * but avoids spurious interrupt bites from most other devices.
127 andn %o0, PSR_PIL, %o0
128 wr %o0, 0xb00, %psr ! (11 << 8)
132 * Set CPU type that we are running on.
134 sethi %hi(_C_LABEL(cputyp)), %o0
141 mov SUN4CM_PGSHIFT, %g5
144 * OpenProm machines pass PROM vector in %o0 (%i0 after save)
145 * OpenFirm machines pass OF entry in %o3 (%i3 after save)
151 ! save address of PROM vector
152 sethi %hi(_C_LABEL(romp)), %o1
153 st %i0, [%o1 + %lo(_C_LABEL(romp))]
157 ! only javastations have OFW, so we know it is a sun4m
159 ! save address of OpenFirmware client interface handler
160 sethi %hi(_C_LABEL(romp)), %o1
161 st %i3, [%o1 + %lo(_C_LABEL(romp))]
166 mov SUN4_PGSHIFT, %g5
169 st %g4, [%o0 + %lo(_C_LABEL(cputyp))]
170 sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg)
171 st %g5, [%o0 + %lo(_C_LABEL(pgshift))]
173 mov 1, %o0 ! nbpg = 1 << pgshift
175 sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page
176 st %g5, [%o0 + %lo(_C_LABEL(nbpg))]
179 sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1
180 st %g5, [%o0 + %lo(_C_LABEL(pgofset))]
189 * NO-OP place holder function.
196 * Openfirmware entry point: openfirmware(void *args)
199 sethi %hi(_C_LABEL(romp)), %o1
200 ld [%o1 + %lo(_C_LABEL(romp))], %o2
207 * XXX - Space saving .div & .rem routines (small & non-negative numbres only)
211 ! int n = 0; while (a >= b) { a -= b; n++; }; return n;
228 ! while (a>=b) a -= b; return a;