Home | History | Annotate | Line # | Download | only in libsa
SRT0.S revision 1.1
      1 |	$NetBSD: SRT0.S,v 1.1 1995/07/25 23:12:21 chuck Exp $
      2 
      3 | Copyright (c) 1995 Gordon W. Ross
      4 | All rights reserved.
      5 |
      6 | Redistribution and use in source and binary forms, with or without
      7 | modification, are permitted provided that the following conditions
      8 | are met:
      9 | 1. Redistributions of source code must retain the above copyright
     10 |    notice, this list of conditions and the following disclaimer.
     11 | 2. Redistributions in binary form must reproduce the above copyright
     12 |    notice, this list of conditions and the following disclaimer in the
     13 |    documentation and/or other materials provided with the distribution.
     14 | 3. The name of the author may not be used to endorse or promote products
     15 |    derived from this software without specific prior written permission.
     16 | 4. All advertising materials mentioning features or use of this software
     17 |    must display the following acknowledgement:
     18 |      This product includes software developed by Gordon Ross
     19 |
     20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 |	SRT0.S - Stand-alone Run-Time startup code, part 0
     32 	.file	"SRT0.S"
     33 	.text
     34 	.globl	__estack
     35 __estack:
     36 	.globl	start
     37 start:
     38 | Check to see if the code is located correctly.
     39 | This SHOULD do a PC-relative load into a0, but...
     40 |	lea	start, a0	| current location (0x4000)
     41 | XXX - GAS version 1.93 gets the above lea wrong!
     42 	.word	0x41fa
     43 	.word	0xfffe
     44 | Now force a long (not PC-relative) load to a1 and compare.
     45 	lea	start:l, a1	| desired location (LINKADDR)
     46 	cmpl	a0, a1
     47 	beqs	restart
     48 
     49 | Relocate the code and data to where they belong.
     50 	movl	#_edata,d0	| Desired end of program
     51 	subl	a1,d0		| Calculate length, round up.
     52 	lsrl	#2,d0
     53 Lcp:
     54 	movl	a0@+, a1@+
     55 	dbra	d0, Lcp
     56 
     57 | Force a long jump to the relocated code (not pc-relative)
     58 	lea	restart:l, a0
     59 	jmp	a0@
     60 
     61 restart:
     62 | now in the relocated code
     63 
     64 	movl	a6@(8), __cmd_buf	| get cmd_line from sboot
     65 
     66 | Set up stack (just before relocated text)
     67 	lea	__estack:l, a0
     68 	movl	a0, sp
     69 	subl	a6, a6
     70 
     71 | Call the run-time startup C code, which will:
     72 |   initialize, call main, call exit
     73 	jsr	__start:l
     74 
     75 | If _start returns, fall into abort.
     76 	.globl	_abort
     77 _abort:
     78 	jsr	0x4000
     79 
     80 | If abort returns, fall into reset.
     81 	.globl	_reset
     82 _reset:
     83 	reset
     84 	jmp	_reset
     85 
     86 | The end.
     87