Home | History | Annotate | Line # | Download | only in boot
bbstart.s revision 1.10
      1  1.10  mhitch /* $NetBSD: bbstart.s,v 1.10 2001/12/17 05:41:12 mhitch 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.6      is #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.10  mhitch #if defined(_PRIMARY_BOOT) || defined(AUTOLOAD)
     56   1.1      is Lzero:	.asciz "DOS"			| "DOS type"
     57  1.10  mhitch #else
     58  1.10  mhitch Lzero:	.ascii	"BOOT"			| Secondary Boot
     59  1.10  mhitch #endif
     60   1.1      is 	/*
     61   1.1      is 	 * We put the relocator version here, for aout2bb, which replaces
     62   1.1      is 	 * it with the bootblock checksum.
     63   1.1      is 	 */
     64   1.1      is Chksum:	.long RELVER_RELATIVE_BYTES_FORWARD
     65   1.1      is Filesz:	.long 8192			| dummy
     66   1.1      is 
     67   1.1      is /*
     68   1.1      is  * Entry point from Kickstart.
     69   1.1      is  * A1 points to an IOrequest, A6 points to ExecBase, we have a stack.
     70   1.1      is  * _must_ be at offset 12.
     71   1.1      is  */
     72   1.6      is ENTRY_NOPROFILE(start)
     73   1.1      is #ifdef AUTOLOAD
     74   1.1      is 	jra	Lautoload
     75   1.1      is #else
     76   1.1      is 	jra	Lrelocate
     77   1.1      is #endif
     78   1.1      is 
     79   1.1      is Lreltab:
     80   1.1      is 	.word 0			| aout2bb puts the reloc table address here
     81   1.9      is 
     82   1.9      is 	.globl _C_LABEL(default_command)
     83   1.9      is _C_LABEL(default_command):
     84   1.9      is 	.asciz	"netbsd -ASn2"
     85   1.9      is 	.org	(_C_LABEL(default_command)+32)
     86   1.1      is 
     87   1.1      is #ifdef AUTOLOAD
     88   1.1      is /*
     89   1.1      is  * autoload
     90   1.1      is  */
     91   1.1      is Lautoload:
     92   1.8  mhitch 	movl	%a6,%sp@-			|SysBase
     93   1.8  mhitch 	movl	%a1,%sp@-			|IORequest
     94   1.1      is 
     95   1.7      is 	movl	#AUTOLOAD,%d0		|Howmuch
     96   1.8  mhitch 	movl	%d0,%a1@(IOlen)		| for the actual read...
     97   1.7      is 	movl	#0x10001,%d1		|MEMF_CLEAR|MEMF_PUBLIC
     98   1.7      is 	jsr	%a6@(LVOAllocMem)
     99   1.7      is 	movl	%sp@+,%a1			|IORequest
    100   1.7      is 	movl	%sp@+,%a6			|SysBase
    101   1.8  mhitch 	orl	%d0,%d0
    102   1.1      is 	jne	Lgotmem
    103   1.7      is 	movql	#1,%d0
    104   1.1      is 	rts
    105   1.1      is 
    106   1.1      is Lgotmem:
    107   1.8  mhitch 	movl	%d0,%sp@-			|Address
    108   1.7      is 	movl	%a1@(IOoff),%sp@-		|Old offset
    109   1.8  mhitch 	movl	%a1,%sp@-
    110   1.8  mhitch 	movl	%a6,%sp@-
    111   1.1      is 
    112   1.1      is /* we've set IOlen above */
    113   1.8  mhitch 	movl	%d0,%a1@(IObuf)
    114   1.7      is 	movw	#Cmd_Rd,%a1@(IOcmd)
    115   1.7      is 	jsr	%a6@(LVODoIO)
    116   1.7      is 
    117   1.7      is 	movl	%sp@+,%a6
    118   1.7      is 	movl	%sp@+,%a1
    119   1.7      is 	movl	%sp@+,%a1@(IOoff)
    120   1.1      is 
    121   1.7      is 	tstb	%a1@(IOerr)
    122   1.1      is 	jne	Lioerr
    123   1.7      is 	addl	#Lrelocate-Lzero,%sp@
    124   1.1      is 
    125   1.8  mhitch 	movl	%a6,%sp@-
    126   1.7      is 	jsr	%a6@(LVOCacheClearU)
    127   1.7      is 	movl	%sp@+,%a6
    128   1.1      is 	rts
    129   1.1      is Lioerr:
    130   1.7      is 	movql	#1,%d0
    131   1.7      is 	addql	#4,%sp
    132   1.1      is 	rts
    133   1.1      is #endif
    134   1.1      is 
    135   1.1      is /*
    136   1.1      is  * Relocate ourselves, at the same time clearing the relocation table
    137   1.1      is  * (in case it overlaps with BSS).
    138   1.1      is  *
    139   1.1      is  * Register usage:
    140   1.1      is  * A2: points into the reloc table, located at our end.
    141   1.1      is  * A0: pointer to the longword to relocate.
    142   1.1      is  * D0: word offset of longword to relocate
    143   1.1      is  * D1: points to our start.
    144   1.1      is  *
    145   1.1      is  * Table has relative byte offsets, if a byte offset is zero, it is
    146   1.1      is  * followed by an absolute word offset. If this is zero, too, table
    147   1.1      is  * end is reached.
    148   1.1      is  */
    149   1.1      is 
    150   1.1      is Lrelocate:
    151   1.7      is 	lea	%pc@(Lzero),%a0
    152   1.8  mhitch 	movl	%a0,%d1
    153   1.7      is 	movw	%pc@(Lreltab),%a2
    154   1.8  mhitch 	addl	%d1,%a2
    155   1.1      is 	jra	Loopend
    156   1.1      is 
    157   1.1      is Loopw:
    158   1.7      is 	clrw	%a2@+
    159   1.8  mhitch 	movl	%d1,%a0	| for a variant with relative words, erase this line
    160   1.1      is Loopb:
    161   1.8  mhitch 	addl	%d0,%a0
    162   1.8  mhitch 	addl	%d1,%a0@
    163   1.1      is Loopend:
    164   1.7      is 	movq	#0,%d0
    165   1.7      is 	movb	%a2@,%d0
    166   1.7      is 	clrb	%a2@+	| bfclr %a2@+{0:8} is still two shorts
    167   1.7      is 	tstb	%d0	| we could save one short by using casb %d0,d0,%a2@+
    168   1.1      is 	jne	Loopb
    169   1.1      is 
    170   1.7      is 	movw	%a2@,%d0
    171   1.1      is 	jne	Loopw
    172   1.1      is 
    173   1.1      is Lendtab:
    174   1.8  mhitch 	movl	%a6,%sp@-
    175   1.7      is 	jsr	%a6@(LVOCacheClearU)
    176   1.7      is 	movl	%sp@+,%a6
    177   1.1      is 
    178   1.1      is /* We are relocated. Now it is safe to initialize _SysBase: */
    179   1.1      is 
    180   1.8  mhitch 	movl	%a6,_C_LABEL(SysBase)
    181   1.1      is 
    182  1.10  mhitch #ifndef _PRIMARY_BOOT
    183  1.10  mhitch 	movl	%a5,%sp@-		| Console info
    184  1.10  mhitch #endif
    185   1.8  mhitch 	movl	%a1,%sp@-
    186   1.6      is 	bsr	_C_LABEL(pain)
    187  1.10  mhitch #ifdef _PRIMARY_BOOT
    188  1.10  mhitch 	addql	#4,%sp
    189  1.10  mhitch #else
    190  1.10  mhitch 	addql	#8,%sp
    191  1.10  mhitch #endif
    192   1.1      is 
    193   1.1      is Lerr:
    194   1.7      is 	movq	#1,%d0
    195   1.1      is 	rts
    196   1.1      is 
    197   1.6      is 	.comm _C_LABEL(SysBase),4
    198