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