Home | History | Annotate | Line # | Download | only in libsa
      1  1.2    martin | $NetBSD: SRT0.S,v 1.2 2008/05/04 00:18:16 martin Exp $
      2  1.1  fredette 
      3  1.1  fredette | Copyright (c) 1998 The NetBSD Foundation, Inc.
      4  1.1  fredette | All rights reserved.
      5  1.1  fredette |
      6  1.1  fredette | This code is derived from software contributed to The NetBSD Foundation
      7  1.1  fredette | by Gordon W. Ross.
      8  1.1  fredette |
      9  1.1  fredette | Redistribution and use in source and binary forms, with or without
     10  1.1  fredette | modification, are permitted provided that the following conditions
     11  1.1  fredette | are met:
     12  1.1  fredette | 1. Redistributions of source code must retain the above copyright
     13  1.1  fredette |    notice, this list of conditions and the following disclaimer.
     14  1.1  fredette | 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  fredette |    notice, this list of conditions and the following disclaimer in the
     16  1.1  fredette |    documentation and/or other materials provided with the distribution.
     17  1.1  fredette |
     18  1.1  fredette | THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.1  fredette | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.1  fredette | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.1  fredette | PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.1  fredette | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.1  fredette | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.1  fredette | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1  fredette | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.1  fredette | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.1  fredette | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  fredette | POSSIBILITY OF SUCH DAMAGE.
     29  1.1  fredette 
     30  1.1  fredette #include <machine/asm.h>
     31  1.1  fredette 
     32  1.1  fredette |	SRT0.S - Stand-alone Run-Time startup code, part 0
     33  1.1  fredette 	.file	"SRT0.S"
     34  1.1  fredette 	.data
     35  1.1  fredette 
     36  1.1  fredette | Flush the CPU cache using MC68020 values just to be safe.
     37  1.1  fredette | This will cause the MC68030 to run with the data cache
     38  1.1  fredette | disabled, but that is OK for boot programs.
     39  1.1  fredette 	.set	IC_CLEAR,0x9
     40  1.1  fredette 	.set	PSL_HIGHIPL,0x2700
     41  1.1  fredette 
     42  1.1  fredette 	.text
     43  1.1  fredette 
     44  1.1  fredette ASENTRY_NOPROFILE(start)
     45  1.1  fredette | Disable interrupts (just in case...)
     46  1.1  fredette 	movw	#PSL_HIGHIPL,%sr
     47  1.1  fredette 
     48  1.1  fredette | Check to see if the code is located correctly.
     49  1.1  fredette | Get current location via PC-relative load, then...
     50  1.1  fredette 	lea	%pc@(start:w),%a0	| current location (0x4000)
     51  1.1  fredette | ...force a long (not PC-relative) load to a1 and compare.
     52  1.1  fredette 	lea	start:l,%a1		| desired location (LINKADDR)
     53  1.1  fredette 	cmpl	%a0,%a1
     54  1.1  fredette 	beqs	restart
     55  1.1  fredette 
     56  1.1  fredette | Relocate the code and data to where they belong.
     57  1.1  fredette 	movl	#_edata,%d0		| Desired end of program
     58  1.1  fredette 	subl	%a1,%d0			| Calculate length, round up.
     59  1.1  fredette 	lsrl	#2,%d0
     60  1.1  fredette Lcp:
     61  1.1  fredette 	movl	%a0@+,%a1@+
     62  1.1  fredette 	dbra	%d0,Lcp
     63  1.1  fredette 
     64  1.1  fredette | If we are on a sun2, we don't want to clear the I-cache
     65  1.1  fredette | because we don't have one.  We are on a sun2 if the PROM
     66  1.1  fredette | has pointed the vector base register to zero.  This is
     67  1.1  fredette | similar to the test that SRT1.c's _start does.
     68  1.1  fredette 	movc	%vbr, %d0
     69  1.1  fredette 	tstl	%d0
     70  1.1  fredette 	beqs	Ljmpreloc
     71  1.1  fredette | Clear the I-cache in case the copied code was cached.
     72  1.1  fredette 	movl	#IC_CLEAR,%d0
     73  1.1  fredette 	movc	%d0,%cacr
     74  1.1  fredette Ljmpreloc:
     75  1.1  fredette | Force a long jump to the relocated code (not pc-relative)
     76  1.1  fredette 	lea	restart:l,%a0
     77  1.1  fredette 	jmp	%a0@
     78  1.1  fredette 
     79  1.1  fredette | Define the location of our stack (just before relocated text).
     80  1.1  fredette | Leave room the exit jmpbuf at the end of our stack.
     81  1.1  fredette 	.set	estack,start-60
     82  1.1  fredette 
     83  1.1  fredette restart:
     84  1.1  fredette | Now in the relocated code, using the monitor stack.
     85  1.1  fredette | Save this context so we can return with it.
     86  1.1  fredette 	pea	estack
     87  1.1  fredette 	jsr	_C_LABEL(setjmp)
     88  1.1  fredette 	addqw	#4,%sp
     89  1.1  fredette 	tstl	%d0
     90  1.1  fredette 	bne	Ldone	| here via longjmp
     91  1.1  fredette 
     92  1.1  fredette | Switch to our own stack.
     93  1.1  fredette 	lea	estack,%a0
     94  1.1  fredette 	movl	%a0,%sp
     95  1.1  fredette 	subl	%a6,%a6
     96  1.1  fredette 
     97  1.1  fredette | Clear out BSS...
     98  1.1  fredette 	lea	_edata,%a0
     99  1.1  fredette 	lea	_end,%a1
    100  1.1  fredette Lclrbss:
    101  1.1  fredette 	clrl	%a0@+
    102  1.1  fredette 	cmpl	%a1,%a0
    103  1.1  fredette 	ble	Lclrbss
    104  1.1  fredette 
    105  1.1  fredette | Call the run-time startup C code, which will:
    106  1.1  fredette |   initialize, call main, call exit.
    107  1.1  fredette 	jsr	_C_LABEL(_start)
    108  1.1  fredette 
    109  1.1  fredette | Switch back to the monitor stack, then either
    110  1.1  fredette | "chain" to the next program or return.
    111  1.1  fredette ENTRY(exit)
    112  1.1  fredette 	pea	estack
    113  1.1  fredette 	jsr	_C_LABEL(longjmp)	| to next line
    114  1.1  fredette Ldone:
    115  1.1  fredette 	movl	_C_LABEL(chain_to_func),%a0
    116  1.1  fredette 	movl	%a0,%d0
    117  1.1  fredette 	beq	Lret
    118  1.1  fredette 	jmp	%a0@
    119  1.1  fredette Lret:
    120  1.1  fredette 	rts
    121  1.1  fredette 
    122  1.1  fredette | function to clear the I-cache
    123  1.1  fredette ENTRY(ICIA)
    124  1.1  fredette 	tstl	_C_LABEL(_is2)
    125  1.1  fredette 	bne	Lret
    126  1.1  fredette 	movl	#IC_CLEAR,%d0
    127  1.1  fredette 	movc	%d0,%cacr
    128  1.1  fredette 	rts
    129  1.1  fredette 
    130  1.1  fredette | function to get the vector base register
    131  1.1  fredette ENTRY(getvbr)
    132  1.1  fredette 	movc	%vbr,%a0
    133  1.1  fredette 	rts
    134  1.1  fredette 
    135  1.1  fredette | Kernel version of setjmp/longjmp (label_t is 16 words)
    136  1.1  fredette 
    137  1.1  fredette ENTRY(setjmp)
    138  1.1  fredette 	movl	%sp@(4),%a0	| savearea pointer
    139  1.1  fredette 	moveml	#0xFCFC,%a0@	| save d2-d7/a2-a7
    140  1.1  fredette 	movl	%sp@,%a0@(48)	| and return address
    141  1.1  fredette 	movl	#0,%d0		| return 0
    142  1.1  fredette 	rts
    143  1.1  fredette 
    144  1.1  fredette ENTRY(longjmp)
    145  1.1  fredette 	movl	%sp@(4),%a0	| savearea pointer
    146  1.1  fredette 	moveml	%a0@+,#0xFCFC	| restore d2-d7/a2-a7
    147  1.1  fredette 	| Note: just changed sp!
    148  1.1  fredette 	movl	%a0@,%sp@	| and return address
    149  1.1  fredette 	movl	#1,%d0		| return 1
    150  1.1  fredette 	rts
    151  1.1  fredette 
    152  1.1  fredette | The end.
    153