srt0.S revision 1.12
1/* $NetBSD: srt0.S,v 1.12 2016/03/10 20:22:52 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) 1091: ! check if %o0 is well aligned 110 andcc %o0, 3, %o2 111 bz 2f 112 nop 113 stb %g0, [%o0] 114 b 1b 115 add %o0, 1, %o0 116 1172: ! now we have %o0 4 byte aligned 118 set _end, %o1 119 subcc %o1, %o0, %o1 120 bz 2f ! in case there is no BSS 121 122 srl %o1, 2, %o1 ! we do 4 byte writes now 1231: 124 st %g0, [%o0] ! while (n--) 125 subcc %o1, 1, %o1 ! *p = 0; etc.. 126 bnz 1b 127 add %o0, 4, %o0 1282: 129 130 /* 131 * Enable interrupts, but only above level 11. This enables "L1-A", 132 * but avoids spurious interrupt bites from most other devices. 133 */ 134 rd %psr, %o0 135 andn %o0, PSR_PIL, %o0 136 wr %o0, 0xb00, %psr ! (11 << 8) 137 nop; nop; nop 138 139 /* 140 * Set CPU type that we are running on. 141 */ 142 sethi %hi(_C_LABEL(cputyp)), %o0 143 set 0x4000, %g7 144 cmp %i0, %g7 145 beq is_sun4 146 nop 147 148 mov CPU_SUN4C, %g4 149 mov SUN4CM_PGSHIFT, %g5 150 151 /* 152 * OpenProm machines pass PROM vector in %o0 (%i0 after save) 153 * OpenFirm machines pass OF entry in %o3 (%i3 after save) 154 */ 155 cmp %i0, 0 156 be is_openfirm 157 nop 158 159 ! save address of PROM vector 160 sethi %hi(_C_LABEL(romp)), %o1 161 st %i0, [%o1 + %lo(_C_LABEL(romp))] 162 b,a is_sun4cm 163 164is_openfirm: 165 ! only javastations have OFW, so we know it is a sun4m 166 mov CPU_SUN4M, %g4 167 ! save address of OpenFirmware client interface handler 168 sethi %hi(_C_LABEL(romp)), %o1 169 st %i3, [%o1 + %lo(_C_LABEL(romp))] 170 b,a is_sun4cm 171 172is_sun4: 173 mov CPU_SUN4, %g4 174 mov SUN4_PGSHIFT, %g5 175 176is_sun4cm: 177 st %g4, [%o0 + %lo(_C_LABEL(cputyp))] 178 sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg) 179 st %g5, [%o0 + %lo(_C_LABEL(pgshift))] 180 181 mov 1, %o0 ! nbpg = 1 << pgshift 182 sll %o0, %g5, %g5 183 sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page 184 st %g5, [%o0 + %lo(_C_LABEL(nbpg))] 185 186 sub %g5, 1, %g5 187 sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1 188 st %g5, [%o0 + %lo(_C_LABEL(pgofset))] 189 190 call _C_LABEL(main) 191 mov %i0, %o0 192 193 ret 194 restore 195 196/* 197 * NO-OP place holder function. 198 */ 199ENTRY(sparc_noop) 200 retl 201 nop 202 203/* 204 * Openfirmware entry point: openfirmware(void *args) 205 */ 206ENTRY(openfirmware) 207 sethi %hi(_C_LABEL(romp)), %o1 208 ld [%o1 + %lo(_C_LABEL(romp))], %o2 209 jmp %o2 210 nop 211 212#ifdef TIGHT 213 214/* 215 * XXX - Space saving .div & .rem routines (small & non-negative numbres only) 216 */ 217 .align 4 218 .global .div, .udiv 219! int n = 0; while (a >= b) { a -= b; n++; }; return n; 220.div: 221.udiv: 222 cmp %o0, %o1 223 bl 2f 224 mov 0, %o5 2251: 226 sub %o0, %o1, %o0 227 cmp %o0, %o1 228 bge 1b 229 add %o5, 1, %o5 2302: 231 retl 232 mov %o5, %o0 233 234 .align 4 235 .global .rem, .urem 236! while (a>=b) a -= b; return a; 237.rem: 238.urem: 239 cmp %o0, %o1 240 bl 2f 241 nop 242 sub %o0, %o1, %o0 2431: 244 cmp %o0, %o1 245 bge,a 1b 246 sub %o0, %o1, %o0 2472: 248 retl 249 nop 250 251#endif /* TIGHT */ 252