1/* $NetBSD: srt0.S,v 1.11 2008/04/28 20:23:36 martin 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 * 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. 30 */ 31 32#define _LOCORE /* XXX - fix Makefile */ 33 34#include <machine/param.h> 35#include <machine/asm.h> 36#include <machine/psl.h> 37 38#define CCFSZ 96 39 40 .file "str0.s" 41 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 47 48 .text 49 .globl start 50 51start: 52 /* 53 * Set up a stack. 54 */ 55 set start, %o1 56 save %o1, -CCFSZ, %sp 57 58 /* 59 * Find which address we are at. 60 */ 611: call 2f 62 sethi %hi(1b), %l0 632: or %l0, %lo(1b), %l0 64 cmp %l0, %o7 ! %o7 contains actual address of 1b 65 beq 4f ! already there, no need to relocate 66 nop 67 68 /* 69 * Relocate. 70 */ 71 add %o7, (start-1b), %l0 72 set start, %l1 73 set _edata, %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 /* 83 * Jump to our relocated self. 84 */ 85 set 4f, %g1 86 jmp %g1 87 nop 88 894: 90#ifdef notyet 91 /* 92 * Enable traps 93 */ 94 wr %g0, 0, %wim ! make sure we can set psr 95 nop; nop; nop 96 wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr 97 nop; nop; nop 98 wr %g0, 2, %wim ! set initial %wim (w1 invalid) 99 100 rd %psr, %l0 101 wr %l0, PSR_ET, %psr 102 nop; nop; nop 103#endif 104 105 /* 106 * Clear BSS 107 */ 108 set _edata, %o0 ! bzero(edata, end - edata) 109 set _end, %o1 110 /* note: bzero() expanded inline for compactness */ 111 subcc %o1, %o0, %o1 112 bz 2f ! in case there is no BSS 113 114 srl %o1, 2, %o1 ! assume _edata & _end are aligned 1151: 116 st %g0, [%o0] ! while (n--) 117 subcc %o1, 1, %o1 ! *p = 0; etc.. 118 bnz 1b 119 add %o0, 4, %o0 1202: 121 122 /* 123 * Enable interrupts, but only above level 11. This enables "L1-A", 124 * but avoids spurious interrupt bites from most other devices. 125 */ 126 rd %psr, %o0 127 andn %o0, PSR_PIL, %o0 128 wr %o0, 0xb00, %psr ! (11 << 8) 129 nop; nop; nop 130 131 /* 132 * Set CPU type that we are running on. 133 */ 134 sethi %hi(_C_LABEL(cputyp)), %o0 135 set 0x4000, %g7 136 cmp %i0, %g7 137 beq is_sun4 138 nop 139 140 mov CPU_SUN4C, %g4 141 mov SUN4CM_PGSHIFT, %g5 142 143 /* 144 * OpenProm machines pass PROM vector in %o0 (%i0 after save) 145 * OpenFirm machines pass OF entry in %o3 (%i3 after save) 146 */ 147 cmp %i0, 0 148 be is_openfirm 149 nop 150 151 ! save address of PROM vector 152 sethi %hi(_C_LABEL(romp)), %o1 153 st %i0, [%o1 + %lo(_C_LABEL(romp))] 154 b,a is_sun4cm 155 156is_openfirm: 157 ! only javastations have OFW, so we know it is a sun4m 158 mov CPU_SUN4M, %g4 159 ! save address of OpenFirmware client interface handler 160 sethi %hi(_C_LABEL(romp)), %o1 161 st %i3, [%o1 + %lo(_C_LABEL(romp))] 162 b,a is_sun4cm 163 164is_sun4: 165 mov CPU_SUN4, %g4 166 mov SUN4_PGSHIFT, %g5 167 168is_sun4cm: 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))] 172 173 mov 1, %o0 ! nbpg = 1 << pgshift 174 sll %o0, %g5, %g5 175 sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page 176 st %g5, [%o0 + %lo(_C_LABEL(nbpg))] 177 178 sub %g5, 1, %g5 179 sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1 180 st %g5, [%o0 + %lo(_C_LABEL(pgofset))] 181 182 call _C_LABEL(main) 183 mov %i0, %o0 184 185 ret 186 restore 187 188/* 189 * NO-OP place holder function. 190 */ 191ENTRY(sparc_noop) 192 retl 193 nop 194 195/* 196 * Openfirmware entry point: openfirmware(void *args) 197 */ 198ENTRY(openfirmware) 199 sethi %hi(_C_LABEL(romp)), %o1 200 ld [%o1 + %lo(_C_LABEL(romp))], %o2 201 jmp %o2 202 nop 203 204#ifdef TIGHT 205 206/* 207 * XXX - Space saving .div & .rem routines (small & non-negative numbres only) 208 */ 209 .align 4 210 .global .div, .udiv 211! int n = 0; while (a >= b) { a -= b; n++; }; return n; 212.div: 213.udiv: 214 cmp %o0, %o1 215 bl 2f 216 mov 0, %o5 2171: 218 sub %o0, %o1, %o0 219 cmp %o0, %o1 220 bge 1b 221 add %o5, 1, %o5 2222: 223 retl 224 mov %o5, %o0 225 226 .align 4 227 .global .rem, .urem 228! while (a>=b) a -= b; return a; 229.rem: 230.urem: 231 cmp %o0, %o1 232 bl 2f 233 nop 234 sub %o0, %o1, %o0 2351: 236 cmp %o0, %o1 237 bge,a 1b 238 sub %o0, %o1, %o0 2392: 240 retl 241 nop 242 243#endif /* TIGHT */ 244