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