Home | History | Annotate | Line # | Download | only in wdboot
      1  1.3  tsutsui /*	$NetBSD: wdboot.S,v 1.3 2022/06/26 14:14:46 tsutsui Exp $	*/
      2  1.1       he 
      3  1.1       he /*
      4  1.1       he  * Copyright (c) 1995 Waldi Ravens
      5  1.1       he  * All rights reserved.
      6  1.1       he  *
      7  1.1       he  * Redistribution and use in source and binary forms, with or without
      8  1.1       he  * modification, are permitted provided that the following conditions
      9  1.1       he  * are met:
     10  1.1       he  * 1. Redistributions of source code must retain the above copyright
     11  1.1       he  *    notice, this list of conditions and the following disclaimer.
     12  1.1       he  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1       he  *    notice, this list of conditions and the following disclaimer in the
     14  1.1       he  *    documentation and/or other materials provided with the distribution.
     15  1.1       he  * 3. All advertising materials mentioning features or use of this software
     16  1.1       he  *    must display the following acknowledgement:
     17  1.1       he  *        This product includes software developed by Waldi Ravens.
     18  1.1       he  * 4. The name of the author may not be used to endorse or promote products
     19  1.1       he  *    derived from this software without specific prior written permission
     20  1.1       he  *
     21  1.1       he  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1       he  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1       he  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1       he  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1       he  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1       he  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1       he  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1       he  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1       he  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1       he  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1       he  */
     32  1.1       he 
     33  1.1       he #include "xxboot.h"
     34  1.1       he 
     35  1.1       he 	.globl	_start, main, fill
     36  1.1       he 
     37  1.1       he 	.text
     38  1.1       he _start:
     39  1.1       he /*
     40  1.1       he  * in: d3 ('DMAr' flag), d4 (SCSI target), d5 (boot pref), d7 (ACSI target)
     41  1.1       he  */
     42  1.1       he main:	lea	%pc@(regsav),%a0
     43  1.1       he 	movml	%d3-%d5/%d7,%sp@-
     44  1.1       he 	movl	%sp,%a0@
     45  1.1       he 
     46  1.1       he 	movw	#-1,%sp@-
     47  1.1       he 	movw	#Kbshift,%sp@-
     48  1.1       he 	trap	#BIOS
     49  1.1       he 	addql	#4,%sp
     50  1.1       he 
     51  1.1       he 	tstb	%d5
     52  1.1       he 	beqs	0f			| no boot preference
     53  1.1       he 	cmpb	#0x20,%d5
     54  1.1       he 	bnes	exit			| bootpref != NetBSD
     55  1.1       he 
     56  1.1       he 0:	btst	#3,%d0			| Alternate?
     57  1.1       he 	bnes	exit
     58  1.1       he 	subql	#1,%d0
     59  1.1       he 	movl	%d0,%a3			| autoboot flag
     60  1.1       he 
     61  1.1       he 	movl	_membot:w,%d3
     62  1.1       he 	lea	MAXBOT,%a4
     63  1.1       he 	cmpl	%a4,%d3
     64  1.1       he 	bhis	exit			| membot > MAXBOT
     65  1.1       he 
     66  1.1       he 	movl	_memtop:w,%d3
     67  1.1       he 	cmpl	#MINTOP,%d3
     68  1.1       he 	blts	exit			| memtop < MINTOP
     69  1.1       he 
     70  1.1       he 	andw	#-4,%d3
     71  1.1       he 	movl	%d3,%a0
     72  1.1       he 	movl	%sp,%a0@-
     73  1.1       he 	movl	%a0,%sp			| set new stack
     74  1.1       he 
     75  1.1       he 	movq	#NSEC,%d5		| sector count
     76  1.1       he 	movq	#1,%d6			| first sector
     77  1.1       he 	bsrs	rds0
     78  1.1       he 	tstl	%d0
     79  1.1       he 	bnes	0f
     80  1.1       he /*
     81  1.1       he  * loader (readsector, disklabel, autoboot)
     82  1.1       he  */
     83  1.1       he 	pea	%a3@			| autoboot
     84  1.1       he 	pea	%a4@(LBLST-MAXBOT)	| disklabel
     85  1.1       he 	pea	%pc@(rds1)		| readsector
     86  1.1       he 	jsr	%a4@(BXXST-MAXBOT)
     87  1.1       he 	lea	%sp@(12),%sp		| NetBSD not booted
     88  1.1       he 
     89  1.1       he 0:	movl	%sp@,%sp			| restore BIOS stack
     90  1.1       he 	tstl	%d0
     91  1.1       he 	bmis	exit
     92  1.1       he 	movl	%d0,%sp@(8)		| new boot preference
     93  1.1       he 
     94  1.1       he exit:	movml	%sp@+,%d3-%d5/%d7
     95  1.1       he 	rts
     96  1.1       he 
     97  1.1       he /*
     98  1.1       he  * int readsec (void *buffer, u_int offset, u_int count);
     99  1.1       he  */
    100  1.1       he rds1:	movml	%d2-%d7/%a2-%a6,%sp@-
    101  1.1       he 	movl	%pc@(regsav),%a0
    102  1.1       he 	movml	%a0@,%d3-%d5/%d7
    103  1.1       he 	movl	%sp@(48),%a4		| buffer
    104  1.1       he 	movl	%sp@(52),%d6		| offset
    105  1.1       he 	movl	%sp@(56),%d3		| count
    106  1.1       he 0:	movl	#255,%d5
    107  1.1       he 	cmpl	%d5,%d3
    108  1.1       he 	bccs	1f
    109  1.1       he 	movl	%d3,%d5
    110  1.1       he 1:	bsrs	rds0
    111  1.1       he 	tstl	%d0
    112  1.1       he 	bnes	2f
    113  1.1       he 	addl	#(255*512),%a4
    114  1.1       he 	addl	%d5,%d6
    115  1.1       he 	subl	%d5,%d3
    116  1.1       he 	bnes	0b
    117  1.1       he 2:	movml	%sp@+,%d2-%d7/%a2-%a6
    118  1.1       he 	rts
    119  1.1       he /*
    120  1.1       he  * in:  d4 (target) d5 (count), d6 (offset), a4 (buffer)
    121  1.1       he  * out: d0 (<= 0)
    122  1.1       he  * mod: d0, d1, d2, a0, a1, a5, a6
    123  1.1       he  */
    124  1.1       he rds0:	lea	%pc@(dpar),%a6
    125  1.1       he 	tstb	%a6@
    126  1.1       he 	bnes	0f
    127  1.1       he 	movb	%d4,%d0
    128  1.1       he 	andb	#1,%d0
    129  1.1       he 	aslb	#4,%d0
    130  1.1       he 	orb	#0xa0,%d0
    131  1.1       he 	movb	%d0,idesdh:l
    132  1.1       he 	movl	%a4,%a0
    133  1.1       he 	movq	#0,%d1
    134  1.1       he 	movb	#0,idedor:l
    135  1.1       he 	movb	#0xec,idecr:l		| IDENTIFY DRIVE
    136  1.1       he 	bsrs	wait
    137  1.1       he 	bnes	err
    138  1.1       he 	movb	%a4@(7),%a6@		| tracks/cylinder
    139  1.1       he 	movb	%a4@(13),%a6@(1)		| sectors/track
    140  1.1       he 0:	movl	%d6,%d1
    141  1.1       he 	movq	#0,%d0
    142  1.1       he 	movb	%a6@(1),%d0
    143  1.1       he 	movq	#0,%d2
    144  1.1       he 	movb	%a6@,%d2
    145  1.1       he 	mulu	%d0,%d2
    146  1.1       he 	divu	%d2,%d1
    147  1.1       he 	movb	%d1,idecl:l
    148  1.1       he 	lsrl	#8,%d1
    149  1.1       he 	movb	%d1,idech:l
    150  1.1       he 	lsrl	#8,%d1
    151  1.1       he 	divu	%d0,%d1
    152  1.1       he 	movb	%d4,%d0
    153  1.1       he 	andb	#1,%d0
    154  1.1       he 	aslb	#4,%d0
    155  1.1       he 	orb	%d0,%d1
    156  1.1       he 	orb	#0xa0,%d1
    157  1.1       he 	movb	%d1,idesdh:l
    158  1.1       he 	swap	%d1
    159  1.1       he 	addqw	#1,%d1
    160  1.1       he 	movb	%d1,idesn:l
    161  1.1       he 	movl	%a4,%a0
    162  1.1       he 	movb	%d5,idesc:l
    163  1.1       he 	movw	%d5,%d1
    164  1.1       he 	subqw	#1,%d1
    165  1.1       he 	movb	#0,idedor:l
    166  1.1       he 	movb	#0x20,idecr:l
    167  1.1       he wait:	movl	#0x7d0,%d0
    168  1.1       he 	addl	_hz_200:w,%d0
    169  1.1       he 2:	btst	#5,gpip:w
    170  1.1       he 	beqs	3f
    171  1.1       he 	cmpl	_hz_200:w,%d0
    172  1.1       he 	bhis	2b
    173  1.1       he err:	movq	#-1,%d0
    174  1.1       he 	rts
    175  1.1       he 3:	movb	idesr:l,%d0
    176  1.1       he 	btst	#0,%d0
    177  1.1       he 	bnes	err
    178  1.1       he 	btst	#3,%d0
    179  1.1       he 	beqs	err
    180  1.1       he 	movq	#63,%d0
    181  1.1       he 	lea	idedr:l,%a1
    182  1.1       he 4:	movw	%a1@,%a0@+
    183  1.1       he 	movw	%a1@,%a0@+
    184  1.1       he 	movw	%a1@,%a0@+
    185  1.1       he 	movw	%a1@,%a0@+
    186  1.1       he 	dbra	%d0,4b
    187  1.1       he 	dbra	%d1,wait
    188  1.1       he 	movq	#0,%d0
    189  1.1       he 	rts
    190  1.1       he 
    191  1.1       he regsav:	.long	0
    192  1.1       he 
    193  1.1       he fill:	.space	30
    194  1.1       he 
    195  1.1       he dpar:	.byte	0			| tracks/cylinder
    196  1.1       he 	.byte	0			| sectors/track
    197  1.1       he 
    198  1.1       he 	.ascii	"NetBSD"
    199  1.1       he hd_siz:	.long	0
    200  1.1       he p0_dsc:	.long	0, 0, 0
    201  1.1       he p1_dsc:	.long	0, 0, 0
    202  1.1       he p2_dsc:	.long	0, 0, 0
    203  1.1       he p3_dsc:	.long	0, 0, 0
    204  1.1       he bsl_st:	.long	0
    205  1.1       he bsl_sz:	.long	0
    206  1.1       he 	.word	0
    207  1.1       he end:
    208