Home | History | Annotate | Line # | Download | only in boot
bbstart.s revision 1.1.1.1
      1 /*
      2  * $NetBSD: bbstart.s,v 1.1.1.1 1996/11/29 23:36:29 is Exp $
      3  *
      4  * Copyright (c) 1996 Ignatios Souvatzis
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Ignatios Souvatzis
     18  *      for the NetBSD project.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  */
     34 
     35 #include "aout2bb/aout2bb.h"
     36 
     37 #define LVOAllocMem	-0x0c6
     38 #define LVODoIO		-0x1c8
     39 #define LVOCacheClearU	-0x27c
     40 
     41 #define IOcmd	28
     42 #define IOerr	31
     43 #define IOlen	36
     44 #define IObuf	40
     45 #define IOoff	44
     46 
     47 #define Cmd_Rd	2
     48 
     49 	.globl	_configure
     50 	.globl	_pain
     51 
     52 	.text
     53 Lzero:	.asciz "DOS"			| "DOS type"
     54 	/*
     55 	 * We put the relocator version here, for aout2bb, which replaces
     56 	 * it with the bootblock checksum.
     57 	 */
     58 Chksum:	.long RELVER_RELATIVE_BYTES_FORWARD
     59 Filesz:	.long 8192			| dummy
     60 
     61 /*
     62  * Entry point from Kickstart.
     63  * A1 points to an IOrequest, A6 points to ExecBase, we have a stack.
     64  * _must_ be at offset 12.
     65  */
     66 	.globl _start
     67 _start:
     68 #ifdef AUTOLOAD
     69 	jra	Lautoload
     70 #else
     71 	jra	Lrelocate
     72 #endif
     73 
     74 Lreltab:
     75 	.word 0			| aout2bb puts the reloc table address here
     76 
     77 #ifdef AUTOLOAD
     78 /*
     79  * autoload
     80  */
     81 Lautoload:
     82 	movl	a6,sp@-			|SysBase
     83 	movl	a1,sp@-			|IORequest
     84 
     85 	movl	#AUTOLOAD,d0		|Howmuch
     86 	movl	d0,a1@(IOlen)		| for the actual read...
     87 	movl	#0x10001,d1		|MEMF_CLEAR|MEMF_PUBLIC
     88 	jsr	a6@(LVOAllocMem)
     89 	movl	sp@+,a1			|IORequest
     90 	movl	sp@+,a6			|SysBase
     91 	orl	d0,d0
     92 	jne	Lgotmem
     93 	movql	#1,d0
     94 	rts
     95 
     96 Lgotmem:
     97 	movl	d0,sp@-			|Address
     98 	movl	a1@(IOoff),sp@-		|Old offset
     99 	movl	a1,sp@-
    100 	movl	a6,sp@-
    101 
    102 /* we've set IOlen above */
    103 	movl	d0,a1@(IObuf)
    104 	movw	#Cmd_Rd,a1@(IOcmd)
    105 	jsr	a6@(LVODoIO)
    106 
    107 	movl	sp@+,a6
    108 	movl	sp@+,a1
    109 	movl	sp@+,a1@(IOoff)
    110 
    111 	tstb	a1@(IOerr)
    112 	jne	Lioerr
    113 	addl	#Lrelocate-Lzero,sp@
    114 
    115 	movl	a6,sp@-
    116 	jsr	a6@(LVOCacheClearU)
    117 	movl	sp@+,a6
    118 	rts
    119 Lioerr:
    120 	movql	#1,d0
    121 	addql	#4,sp
    122 	rts
    123 #endif
    124 
    125 /*
    126  * Relocate ourselves, at the same time clearing the relocation table
    127  * (in case it overlaps with BSS).
    128  *
    129  * Register usage:
    130  * A2: points into the reloc table, located at our end.
    131  * A0: pointer to the longword to relocate.
    132  * D0: word offset of longword to relocate
    133  * D1: points to our start.
    134  *
    135  * Table has relative byte offsets, if a byte offset is zero, it is
    136  * followed by an absolute word offset. If this is zero, too, table
    137  * end is reached.
    138  */
    139 
    140 Lrelocate:
    141 	lea	pc@(Lzero),a0
    142 	movl	a0,d1
    143 	movw	pc@(Lreltab),a2
    144 	addl	d1,a2
    145 	jra	Loopend
    146 
    147 Loopw:
    148 	clrw	a2@+
    149 	movl	d1,a0	| for a variant with relative words, erase this line
    150 Loopb:
    151 	addl	d0,a0
    152 	addl	d1,a0@
    153 Loopend:
    154 	movq	#0,d0
    155 	movb	a2@,d0
    156 	clrb	a2@+	| bfclr a2@+{0:8} is still two shorts
    157 	tstb	d0	| we could save one short by using casb d0,d0,a2@+
    158 	jne	Loopb
    159 
    160 	movw	a2@,d0
    161 	jne	Loopw
    162 
    163 Lendtab:
    164 	movl	a6,sp@-
    165 	jsr	a6@(LVOCacheClearU)
    166 	movl	sp@+,a6
    167 
    168 /* We are relocated. Now it is safe to initialize _SysBase: */
    169 
    170 	movl	a6,_SysBase
    171 
    172 	movl	a1,sp@-
    173 	bsr	_configure
    174 	addql	#4,sp
    175 	tstl	d0
    176 	jne	Lerr
    177 
    178 	bsr	_pain
    179 
    180 Lerr:
    181 	movq	#1,d0
    182 	rts
    183 
    184 	.comm _SysBase,4
    185