Home | History | Annotate | Line # | Download | only in common
srt0.S revision 1.8
      1  1.8  uwe /*	$NetBSD: srt0.S,v 1.8 2003/06/28 00:59:09 uwe 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.4   pk #include <machine/asm.h>
     43  1.1  mrg #include <machine/psl.h>
     44  1.1  mrg 
     45  1.1  mrg #define	CCFSZ	96
     46  1.1  mrg 
     47  1.1  mrg 	.file	"str0.s"
     48  1.1  mrg 
     49  1.4   pk 	.comm	_C_LABEL(romp), 4
     50  1.4   pk 	.comm	_C_LABEL(cputyp), 4
     51  1.4   pk 	.comm	_C_LABEL(nbpg), 4
     52  1.4   pk 	.comm	_C_LABEL(pgofset), 4
     53  1.4   pk 	.comm	_C_LABEL(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.7  uwe 	 * Find which address we are at.
     67  1.1  mrg 	 */
     68  1.1  mrg 1:	call	2f
     69  1.7  uwe 	 sethi	%hi(1b), %l0
     70  1.7  uwe 2:	or	%l0, %lo(1b), %l0
     71  1.7  uwe 	cmp	%l0, %o7	! %o7 contains actual address of 1b
     72  1.7  uwe 	beq	4f		! already there, no need to relocate
     73  1.1  mrg 	 nop
     74  1.7  uwe 
     75  1.7  uwe 	/*
     76  1.7  uwe 	 * Relocate.
     77  1.7  uwe 	 */
     78  1.7  uwe 	add	%o7, (start-1b), %l0
     79  1.1  mrg 	set	start, %l1
     80  1.5   pk 	set	_edata, %o0
     81  1.1  mrg 	sub	%o0, %l1, %l2		! length
     82  1.1  mrg 3:	ld	[%l0], %o0
     83  1.1  mrg 	add	%l0, 4, %l0
     84  1.1  mrg 	st	%o0, [%l1]
     85  1.1  mrg 	subcc	%l2, 4, %l2
     86  1.1  mrg 	bg	3b
     87  1.1  mrg 	 add	%l1, 4, %l1
     88  1.1  mrg 
     89  1.7  uwe 	/*
     90  1.7  uwe 	 * Jump to our relocated self.
     91  1.7  uwe 	 */
     92  1.1  mrg 	set	4f, %g1
     93  1.1  mrg 	jmp	%g1
     94  1.1  mrg 	 nop
     95  1.1  mrg 
     96  1.1  mrg 4:
     97  1.1  mrg #ifdef notyet
     98  1.1  mrg 	/*
     99  1.1  mrg 	 * Enable traps
    100  1.1  mrg 	 */
    101  1.1  mrg 	wr	%g0, 0, %wim		! make sure we can set psr
    102  1.1  mrg 	nop; nop; nop
    103  1.1  mrg 	wr	%g0, PSR_S|PSR_PS|PSR_PIL, %psr	! set initial psr
    104  1.1  mrg 	nop; nop; nop
    105  1.1  mrg 	wr	%g0, 2, %wim		! set initial %wim (w1 invalid)
    106  1.1  mrg 
    107  1.1  mrg 	rd	%psr, %l0
    108  1.1  mrg 	wr	%l0, PSR_ET, %psr
    109  1.1  mrg 	nop; nop; nop
    110  1.1  mrg #endif
    111  1.1  mrg 
    112  1.1  mrg 	/*
    113  1.1  mrg 	 * Clear BSS
    114  1.1  mrg 	 */
    115  1.1  mrg 	set     _edata, %o0             ! bzero(edata, end - edata)
    116  1.1  mrg 	set     _end, %o1
    117  1.2   pk 	/* note: bzero() expanded inline for compactness */
    118  1.2   pk 	subcc	%o1, %o0, %o1
    119  1.2   pk 	bz	2f			! in case there is no BSS
    120  1.2   pk 
    121  1.2   pk 	srl	%o1, 2, %o1		! assume _edata & _end are aligned
    122  1.2   pk 1:
    123  1.2   pk 	st	%g0, [%o0]		! while (n--)
    124  1.2   pk 	subcc	%o1, 1, %o1		!	*p = 0; etc..
    125  1.2   pk 	bnz	1b
    126  1.2   pk 	 add	%o0, 4, %o0
    127  1.2   pk 2:
    128  1.1  mrg 
    129  1.1  mrg 	/*
    130  1.1  mrg 	 * Enable interrupts, but only above level 11. This enables "L1-A",
    131  1.1  mrg 	 * but avoids spurious interrupt bites from most other devices.
    132  1.1  mrg 	 */
    133  1.1  mrg 	rd	%psr, %o0
    134  1.1  mrg 	andn	%o0, PSR_PIL, %o0
    135  1.1  mrg 	wr	%o0, 0xb00, %psr	! (11 << 8)
    136  1.1  mrg 	nop; nop; nop
    137  1.1  mrg 
    138  1.1  mrg 	/*
    139  1.1  mrg 	 * Set CPU type that we are running on.
    140  1.1  mrg 	 */
    141  1.4   pk 	sethi	%hi(_C_LABEL(cputyp)), %o0
    142  1.1  mrg 	set	0x4000, %g7
    143  1.1  mrg 	cmp	%i0, %g7
    144  1.2   pk 	beq	is_sun4
    145  1.1  mrg 	 nop
    146  1.1  mrg 
    147  1.2   pk 	mov	CPU_SUN4C, %g4
    148  1.2   pk 	mov	SUN4CM_PGSHIFT, %g5
    149  1.2   pk 
    150  1.1  mrg 	/*
    151  1.6  uwe 	 * OpenProm machines pass PROM vector in %o0 (%i0 after save)
    152  1.6  uwe 	 * OpenFirm machines pass OF entry in %o3 (%i3 after save)
    153  1.1  mrg 	 */
    154  1.6  uwe 	cmp	%i0, 0
    155  1.6  uwe 	be	is_openfirm
    156  1.6  uwe 	 nop
    157  1.6  uwe 
    158  1.6  uwe 	! save address of PROM vector
    159  1.4   pk 	sethi	%hi(_C_LABEL(romp)), %o1
    160  1.4   pk 	st	%i0, [%o1 + %lo(_C_LABEL(romp))]
    161  1.6  uwe 	b,a	is_sun4cm
    162  1.1  mrg 
    163  1.6  uwe is_openfirm:
    164  1.8  uwe 	! only javastations have OFW, so we know it is a sun4m
    165  1.8  uwe 	mov	CPU_SUN4M, %g4
    166  1.6  uwe 	! save address of OpenFirmware client interface handler
    167  1.6  uwe 	sethi	%hi(_C_LABEL(romp)), %o1
    168  1.6  uwe 	st	%i3, [%o1 + %lo(_C_LABEL(romp))]
    169  1.2   pk 	b,a	is_sun4cm
    170  1.1  mrg 
    171  1.2   pk is_sun4:
    172  1.1  mrg 	mov	CPU_SUN4, %g4
    173  1.1  mrg 	mov	SUN4_PGSHIFT, %g5
    174  1.1  mrg 
    175  1.2   pk is_sun4cm:
    176  1.4   pk 	st	%g4, [%o0 + %lo(_C_LABEL(cputyp))]
    177  1.4   pk 	sethi	%hi(_C_LABEL(pgshift)), %o0	! pgshift = log2(nbpg)
    178  1.4   pk 	st	%g5, [%o0 + %lo(_C_LABEL(pgshift))]
    179  1.1  mrg 
    180  1.4   pk 	mov	1, %o0				! nbpg = 1 << pgshift
    181  1.1  mrg 	sll	%o0, %g5, %g5
    182  1.4   pk 	sethi	%hi(_C_LABEL(nbpg)), %o0	! nbpg = bytes in a page
    183  1.4   pk 	st	%g5, [%o0 + %lo(_C_LABEL(nbpg))]
    184  1.1  mrg 
    185  1.1  mrg 	sub	%g5, 1, %g5
    186  1.4   pk 	sethi	%hi(_C_LABEL(pgofset)), %o0	! page offset = nbpg - 1
    187  1.4   pk 	st	%g5, [%o0 + %lo(_C_LABEL(pgofset))]
    188  1.1  mrg 
    189  1.4   pk 	call	_C_LABEL(main)
    190  1.1  mrg 	 mov	%i0, %o0
    191  1.1  mrg 
    192  1.1  mrg 	ret
    193  1.1  mrg 	 restore
    194  1.2   pk 
    195  1.2   pk /*
    196  1.2   pk  * NO-OP place holder function.
    197  1.2   pk  */
    198  1.4   pk ENTRY(sparc_noop)
    199  1.2   pk 	retl
    200  1.2   pk 	 nop
    201  1.1  mrg 
    202  1.1  mrg 
    203  1.1  mrg #ifdef TIGHT
    204  1.1  mrg 
    205  1.1  mrg /*
    206  1.1  mrg  * XXX - Space saving .div & .rem routines (small & non-negative numbres only)
    207  1.1  mrg  */
    208  1.1  mrg 	.align	4
    209  1.1  mrg 	.global .div, .udiv
    210  1.1  mrg ! int n = 0; while (a >= b) { a -= b; n++; }; return n;
    211  1.1  mrg .div:
    212  1.1  mrg .udiv:
    213  1.1  mrg 	cmp	%o0, %o1
    214  1.1  mrg 	bl	2f
    215  1.1  mrg 	 mov	0, %o5
    216  1.1  mrg 1:
    217  1.1  mrg 	sub	%o0, %o1, %o0
    218  1.1  mrg 	cmp	%o0, %o1
    219  1.1  mrg 	bge	1b
    220  1.1  mrg 	 add	%o5, 1, %o5
    221  1.1  mrg 2:
    222  1.1  mrg 	retl
    223  1.1  mrg 	 mov	%o5, %o0
    224  1.1  mrg 
    225  1.1  mrg 	.align	4
    226  1.1  mrg 	.global .rem, .urem
    227  1.1  mrg ! while (a>=b) a -= b; return a;
    228  1.1  mrg .rem:
    229  1.1  mrg .urem:
    230  1.1  mrg 	cmp	%o0, %o1
    231  1.1  mrg 	bl	2f
    232  1.1  mrg 	 nop
    233  1.1  mrg 	sub	%o0, %o1, %o0
    234  1.1  mrg 1:
    235  1.1  mrg 	cmp	%o0, %o1
    236  1.1  mrg 	bge,a	1b
    237  1.1  mrg 	 sub	%o0, %o1, %o0
    238  1.1  mrg 2:
    239  1.1  mrg 	retl
    240  1.1  mrg 	 nop
    241  1.1  mrg 
    242  1.1  mrg #endif /* TIGHT */
    243