srt0.S revision 1.4
1/* $NetBSD: srt0.S,v 1.4 1999/03/05 11:12:16 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/asm.h> 43#include <machine/psl.h> 44 45#define CCFSZ 96 46 47 .file "str0.s" 48 49 .comm _C_LABEL(romp), 4 50 .comm _C_LABEL(opf_romp), 4 51 .comm _C_LABEL(cputyp), 4 52 .comm _C_LABEL(nbpg), 4 53 .comm _C_LABEL(pgofset), 4 54 .comm _C_LABEL(pgshift), 4 55 56 .text 57 .globl start 58 59start: 60 /* 61 * Set up a stack. 62 */ 63 set start, %o1 64 save %o1, -CCFSZ, %sp 65 66 /* 67 * Relocate. 68 */ 691: call 2f 70 nop 712: add %o7, (start-1b), %l0 72 set start, %l1 73 set _end, %o0 74 sub %o0, %l1, %l2 ! length 753: ld [%l0], %o0 76 add %l0, 4, %l0 77 st %o0, [%l1] 78 subcc %l2, 4, %l2 79 bg 3b 80 add %l1, 4, %l1 81 82 set 4f, %g1 83 jmp %g1 84 nop 85 864: 87#ifdef notyet 88 /* 89 * Enable traps 90 */ 91 wr %g0, 0, %wim ! make sure we can set psr 92 nop; nop; nop 93 wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr 94 nop; nop; nop 95 wr %g0, 2, %wim ! set initial %wim (w1 invalid) 96 97 rd %psr, %l0 98 wr %l0, PSR_ET, %psr 99 nop; nop; nop 100#endif 101 102 /* 103 * Clear BSS 104 */ 105 set _edata, %o0 ! bzero(edata, end - edata) 106 set _end, %o1 107 /* note: bzero() expanded inline for compactness */ 108 subcc %o1, %o0, %o1 109 bz 2f ! in case there is no BSS 110 111 srl %o1, 2, %o1 ! assume _edata & _end are aligned 1121: 113 st %g0, [%o0] ! while (n--) 114 subcc %o1, 1, %o1 ! *p = 0; etc.. 115 bnz 1b 116 add %o0, 4, %o0 1172: 118 119 /* 120 * Enable interrupts, but only above level 11. This enables "L1-A", 121 * but avoids spurious interrupt bites from most other devices. 122 */ 123 rd %psr, %o0 124 andn %o0, PSR_PIL, %o0 125 wr %o0, 0xb00, %psr ! (11 << 8) 126 nop; nop; nop 127 128 /* 129 * Set CPU type that we are running on. 130 */ 131 sethi %hi(_C_LABEL(cputyp)), %o0 132 set 0x4000, %g7 133 cmp %i0, %g7 134 beq is_sun4 135 nop 136 137 mov CPU_SUN4C, %g4 138 mov SUN4CM_PGSHIFT, %g5 139 140 /* 141 * Save address of PROM vector (passed in %i0). 142 */ 143 sethi %hi(_C_LABEL(romp)), %o1 144 st %i0, [%o1 + %lo(_C_LABEL(romp))] 145 146 /* Also save %i3, which is the Openfirmware entry, if any */ 147 sethi %hi(_C_LABEL(opf_romp)), %o1 148 st %i3, [%o1 + %lo(_C_LABEL(opf_romp))] 149 b,a is_sun4cm 150 151is_sun4: 152 mov CPU_SUN4, %g4 153 mov SUN4_PGSHIFT, %g5 154 155is_sun4cm: 156 st %g4, [%o0 + %lo(_C_LABEL(cputyp))] 157 sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg) 158 st %g5, [%o0 + %lo(_C_LABEL(pgshift))] 159 160 mov 1, %o0 ! nbpg = 1 << pgshift 161 sll %o0, %g5, %g5 162 sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page 163 st %g5, [%o0 + %lo(_C_LABEL(nbpg))] 164 165 sub %g5, 1, %g5 166 sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1 167 st %g5, [%o0 + %lo(_C_LABEL(pgofset))] 168 169 call _C_LABEL(main) 170 mov %i0, %o0 171 172 ret 173 restore 174 175/* 176 * NO-OP place holder function. 177 */ 178ENTRY(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 1961: 197 sub %o0, %o1, %o0 198 cmp %o0, %o1 199 bge 1b 200 add %o5, 1, %o5 2012: 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 2141: 215 cmp %o0, %o1 216 bge,a 1b 217 sub %o0, %o1, %o0 2182: 219 retl 220 nop 221 222#endif /* TIGHT */ 223