Home | History | Annotate | Line # | Download | only in common
srt0.S revision 1.3
      1  1.3   pk /*	$NetBSD: srt0.S,v 1.3 1999/02/15 19:01:38 pk Exp $	*/
      2  1.1  mrg 
      3  1.3   pk /*-
      4  1.3   pk  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1  mrg  * All rights reserved.
      6  1.1  mrg  *
      7  1.3   pk  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3   pk  * by Paul Kranenburg.
      9  1.3   pk  *
     10  1.1  mrg  * Redistribution and use in source and binary forms, with or without
     11  1.1  mrg  * modification, are permitted provided that the following conditions
     12  1.1  mrg  * are met:
     13  1.1  mrg  * 1. Redistributions of source code must retain the above copyright
     14  1.1  mrg  *    notice, this list of conditions and the following disclaimer.
     15  1.1  mrg  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  mrg  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  mrg  *    documentation and/or other materials provided with the distribution.
     18  1.1  mrg  * 3. All advertising materials mentioning features or use of this software
     19  1.1  mrg  *    must display the following acknowledgement:
     20  1.3   pk  *        This product includes software developed by the NetBSD
     21  1.3   pk  *        Foundation, Inc. and its contributors.
     22  1.3   pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3   pk  *    contributors may be used to endorse or promote products derived
     24  1.3   pk  *    from this software without specific prior written permission.
     25  1.1  mrg  *
     26  1.3   pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3   pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3   pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3   pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3   pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3   pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3   pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3   pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3   pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3   pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3   pk  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  mrg  */
     38  1.1  mrg 
     39  1.2   pk #define _LOCORE		/* XXX - fix Makefile */
     40  1.2   pk 
     41  1.1  mrg #include <machine/param.h>
     42  1.1  mrg #include <machine/psl.h>
     43  1.1  mrg 
     44  1.1  mrg #define	CCFSZ	96
     45  1.1  mrg 
     46  1.1  mrg 	.file	"str0.s"
     47  1.1  mrg 
     48  1.2   pk 	.comm	_romp, 4
     49  1.2   pk 	.comm	_opf_romp, 4
     50  1.2   pk 	.comm	_cputyp, 4
     51  1.2   pk 	.comm	_nbpg, 4
     52  1.2   pk 	.comm	_pgofset, 4
     53  1.2   pk 	.comm	_pgshift, 4
     54  1.1  mrg 
     55  1.1  mrg 	.text
     56  1.1  mrg 	.globl	start
     57  1.1  mrg 
     58  1.1  mrg start:
     59  1.1  mrg 	/*
     60  1.1  mrg 	 * Set up a stack.
     61  1.1  mrg 	 */
     62  1.1  mrg 	set	start, %o1
     63  1.1  mrg 	save	%o1, -CCFSZ, %sp
     64  1.1  mrg 
     65  1.1  mrg 	/*
     66  1.1  mrg 	 * Relocate.
     67  1.1  mrg 	 */
     68  1.1  mrg 1:	call	2f
     69  1.1  mrg 	 nop
     70  1.1  mrg 2:	add	%o7, (start-1b), %l0
     71  1.1  mrg 	set	start, %l1
     72  1.1  mrg 	set	_end, %o0
     73  1.1  mrg 	sub	%o0, %l1, %l2		! length
     74  1.1  mrg 3:	ld	[%l0], %o0
     75  1.1  mrg 	add	%l0, 4, %l0
     76  1.1  mrg 	st	%o0, [%l1]
     77  1.1  mrg 	subcc	%l2, 4, %l2
     78  1.1  mrg 	bg	3b
     79  1.1  mrg 	 add	%l1, 4, %l1
     80  1.1  mrg 
     81  1.1  mrg 	set	4f, %g1
     82  1.1  mrg 	jmp	%g1
     83  1.1  mrg 	 nop
     84  1.1  mrg 
     85  1.1  mrg 4:
     86  1.1  mrg #ifdef notyet
     87  1.1  mrg 	/*
     88  1.1  mrg 	 * Enable traps
     89  1.1  mrg 	 */
     90  1.1  mrg 	wr	%g0, 0, %wim		! make sure we can set psr
     91  1.1  mrg 	nop; nop; nop
     92  1.1  mrg 	wr	%g0, PSR_S|PSR_PS|PSR_PIL, %psr	! set initial psr
     93  1.1  mrg 	nop; nop; nop
     94  1.1  mrg 	wr	%g0, 2, %wim		! set initial %wim (w1 invalid)
     95  1.1  mrg 
     96  1.1  mrg 	rd	%psr, %l0
     97  1.1  mrg 	wr	%l0, PSR_ET, %psr
     98  1.1  mrg 	nop; nop; nop
     99  1.1  mrg #endif
    100  1.1  mrg 
    101  1.1  mrg 	/*
    102  1.1  mrg 	 * Clear BSS
    103  1.1  mrg 	 */
    104  1.1  mrg 	set     _edata, %o0             ! bzero(edata, end - edata)
    105  1.1  mrg 	set     _end, %o1
    106  1.2   pk 	/* note: bzero() expanded inline for compactness */
    107  1.2   pk 	subcc	%o1, %o0, %o1
    108  1.2   pk 	bz	2f			! in case there is no BSS
    109  1.2   pk 
    110  1.2   pk 	srl	%o1, 2, %o1		! assume _edata & _end are aligned
    111  1.2   pk 1:
    112  1.2   pk 	st	%g0, [%o0]		! while (n--)
    113  1.2   pk 	subcc	%o1, 1, %o1		!	*p = 0; etc..
    114  1.2   pk 	bnz	1b
    115  1.2   pk 	 add	%o0, 4, %o0
    116  1.2   pk 2:
    117  1.1  mrg 
    118  1.1  mrg 	/*
    119  1.1  mrg 	 * Enable interrupts, but only above level 11. This enables "L1-A",
    120  1.1  mrg 	 * but avoids spurious interrupt bites from most other devices.
    121  1.1  mrg 	 */
    122  1.1  mrg 	rd	%psr, %o0
    123  1.1  mrg 	andn	%o0, PSR_PIL, %o0
    124  1.1  mrg 	wr	%o0, 0xb00, %psr	! (11 << 8)
    125  1.1  mrg 	nop; nop; nop
    126  1.1  mrg 
    127  1.1  mrg 	/*
    128  1.1  mrg 	 * Set CPU type that we are running on.
    129  1.1  mrg 	 */
    130  1.1  mrg 	sethi	%hi(_cputyp), %o0
    131  1.1  mrg 	set	0x4000, %g7
    132  1.1  mrg 	cmp	%i0, %g7
    133  1.2   pk 	beq	is_sun4
    134  1.1  mrg 	 nop
    135  1.1  mrg 
    136  1.2   pk 	mov	CPU_SUN4C, %g4
    137  1.2   pk 	mov	SUN4CM_PGSHIFT, %g5
    138  1.2   pk 
    139  1.1  mrg 	/*
    140  1.1  mrg 	 * Save address of PROM vector (passed in %i0).
    141  1.1  mrg 	 */
    142  1.2   pk 	sethi	%hi(_romp), %o1
    143  1.2   pk 	st	%i0, [%o1 + %lo(_romp)]
    144  1.1  mrg 
    145  1.2   pk 	/* Also save %i3, which is the Openfirmware entry, if any */
    146  1.2   pk 	sethi	%hi(_opf_romp), %o1
    147  1.2   pk 	st	%i3, [%o1 + %lo(_opf_romp)]
    148  1.2   pk 	b,a	is_sun4cm
    149  1.1  mrg 
    150  1.2   pk is_sun4:
    151  1.1  mrg 	mov	CPU_SUN4, %g4
    152  1.1  mrg 	mov	SUN4_PGSHIFT, %g5
    153  1.1  mrg 
    154  1.2   pk is_sun4cm:
    155  1.1  mrg 	st	%g4, [%o0 + %lo(_cputyp)]
    156  1.1  mrg 	sethi	%hi(_pgshift), %o0	! pgshift = log2(nbpg)
    157  1.1  mrg 	st	%g5, [%o0 + %lo(_pgshift)]
    158  1.1  mrg 
    159  1.1  mrg 	mov	1, %o0			! nbpg = 1 << pgshift
    160  1.1  mrg 	sll	%o0, %g5, %g5
    161  1.1  mrg 	sethi	%hi(_nbpg), %o0		! nbpg = bytes in a page
    162  1.1  mrg 	st	%g5, [%o0 + %lo(_nbpg)]
    163  1.1  mrg 
    164  1.1  mrg 	sub	%g5, 1, %g5
    165  1.1  mrg 	sethi	%hi(_pgofset), %o0	! page offset = bytes in a page - 1
    166  1.1  mrg 	st	%g5, [%o0 + %lo(_pgofset)]
    167  1.1  mrg 
    168  1.1  mrg 	call	_main
    169  1.1  mrg 	 mov	%i0, %o0
    170  1.1  mrg 
    171  1.1  mrg 	ret
    172  1.1  mrg 	 restore
    173  1.2   pk 
    174  1.2   pk /*
    175  1.2   pk  * NO-OP place holder function.
    176  1.2   pk  */
    177  1.2   pk 	.globl	_sparc_noop
    178  1.2   pk _sparc_noop:
    179  1.2   pk 	retl
    180  1.2   pk 	 nop
    181  1.1  mrg 
    182  1.1  mrg 
    183  1.1  mrg #ifdef TIGHT
    184  1.1  mrg 
    185  1.1  mrg /*
    186  1.1  mrg  * XXX - Space saving .div & .rem routines (small & non-negative numbres only)
    187  1.1  mrg  */
    188  1.1  mrg 	.align	4
    189  1.1  mrg 	.global .div, .udiv
    190  1.1  mrg ! int n = 0; while (a >= b) { a -= b; n++; }; return n;
    191  1.1  mrg .div:
    192  1.1  mrg .udiv:
    193  1.1  mrg 	cmp	%o0, %o1
    194  1.1  mrg 	bl	2f
    195  1.1  mrg 	 mov	0, %o5
    196  1.1  mrg 1:
    197  1.1  mrg 	sub	%o0, %o1, %o0
    198  1.1  mrg 	cmp	%o0, %o1
    199  1.1  mrg 	bge	1b
    200  1.1  mrg 	 add	%o5, 1, %o5
    201  1.1  mrg 2:
    202  1.1  mrg 	retl
    203  1.1  mrg 	 mov	%o5, %o0
    204  1.1  mrg 
    205  1.1  mrg 	.align	4
    206  1.1  mrg 	.global .rem, .urem
    207  1.1  mrg ! while (a>=b) a -= b; return a;
    208  1.1  mrg .rem:
    209  1.1  mrg .urem:
    210  1.1  mrg 	cmp	%o0, %o1
    211  1.1  mrg 	bl	2f
    212  1.1  mrg 	 nop
    213  1.1  mrg 	sub	%o0, %o1, %o0
    214  1.1  mrg 1:
    215  1.1  mrg 	cmp	%o0, %o1
    216  1.1  mrg 	bge,a	1b
    217  1.1  mrg 	 sub	%o0, %o1, %o0
    218  1.1  mrg 2:
    219  1.1  mrg 	retl
    220  1.1  mrg 	 nop
    221  1.1  mrg 
    222  1.1  mrg #endif /* TIGHT */
    223