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