1/*	$NetBSD: sdboot.S,v 1.1.4.3 2004/09/21 13:14:19 skrll Exp $	*/
2
3/*
4 * Copyright (c) 1995 Waldi Ravens
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 Waldi Ravens.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "xxboot.h"
34
35#ifdef __ELF__
36	.globl	_start, main, fill
37
38	.text
39_start:
40#else
41	.globl	start, main, fill
42
43	.text
44start:
45#endif
46/*
47 * in: d3 ('DMAr' flag), d4 (SCSI target), d5 (boot pref), d7 (ACSI target)
48 */
49main:	lea	%pc@(regsav),%a0
50	movml	%d3-%d5/%d7,%sp@-
51	movl	%sp,%a0@
52
53	movw	#-1,%sp@-
54	movw	#Kbshift,%sp@-
55	trap	#BIOS
56	addql	#4,%sp
57
58	cmpl	#0x444d4172,%d3		| SCSI bootdev?
59	beqs	0f
60	movq	#-1,%d4			| no, ACSI
61	bras	1f
62
630:	tstb	%d5
64	beqs	1f			| no boot preference
65	cmpb	#0x20,%d5
66	bnes	exit			| bootpref != NetBSD
67
681:	btst	#3,%d0			| Alternate?
69	bnes	exit
70	subql	#1,%d0
71	movl	%d0,%a3			| autoboot flag
72
73	movl	_membot:w,%d0
74	lea	MAXBOT,%a4
75	cmpl	%a4,%d0
76	bhis	exit			| membot > MAXBOT
77
78	movl	_memtop:w,%d0
79	cmpl	#MINTOP,%d0
80	blts	exit			| memtop < MINTOP
81
82	andw	#-4,%d0
83	movl	%d0,%a0
84	movl	%sp,%a0@-
85	movl	%a0,%sp			| set new stack
86
87	movq	#NSEC,%d5		| sector count
88	movq	#1,%d6			| first sector
89	bsrs	rds0
90	tstl	%d0
91	bnes	0f
92/*
93 * loader (readsector, disklabel, autoboot)
94 */
95	pea	%a3@			| autoboot
96	pea	%a4@(LBLST-MAXBOT)	| disklabel
97	pea	%pc@(rds1)		| readsector
98	jsr	%a4@(BXXST-MAXBOT)
99	lea	%sp@(12),%sp		| NetBSD not booted
100
1010:	movl	%sp@,%sp			| restore BIOS stack
102	tstl	%d0
103	bmis	exit
104	movl	%d0,%sp@(8)		| new boot preference
105
106exit:	movml	%sp@+,%d3-%d5/%d7
107	rts
108
109/*
110 * int readsec (void *buffer, u_int offset, u_int count);
111 */
112rds1:	movml	%d2-%d7/%a2-%a6,%sp@-
113	movl	%pc@(regsav),%a0
114	movml	%a0@,%d3-%d5/%d7
115	movl	%sp@(48),%a4		| buffer
116	movl	%sp@(52),%d6		| offset
117	movl	%sp@(56),%d3		| count
1180:	movl	#255,%d5
119	cmpl	%d5,%d3
120	bccs	1f
121	movl	%d3,%d5
1221:	bsrs	rds0
123	tstl	%d0
124	bnes	2f
125	addl	#(255*512),%a4
126	addl	%d5,%d6
127	subl	%d5,%d3
128	bnes	0b
1292:	movml	%sp@+,%d2-%d7/%a2-%a6
130	rts
131/*
132 * in:  d4/d7 (target) d5 (count), d6 (offset), a4 (buffer)
133 * out: d0 (<= 0)
134 * mod: d0, d1, d2, a0, a5, a6
135 */
136rds0:	tstl	%d4
137	bmis	0f
138	movw	%d4,%sp@-			| device
139	pea	%a4@			| buffer
140	movw	%d5,%sp@-			| count
141	movl	%d6,%sp@-			| offset
142	movw	#DMAread,%sp@-
143	trap	#XBIOS
144	lea	%sp@(14),%sp
145	rts
146
1470:	st	flock:w
148	movl	_hz_200:w,%d0
149	addql	#2,%d0
1501:	cmpl	_hz_200:w,%d0
151	bccs	1b
152	movml	%d6/%a4,%sp@-
153	lea	dmahi:w,%a6
154	movb	%sp@(7),%a6@(4)
155	movb	%sp@(6),%a6@(2)
156	movb	%sp@(5),%a6@
157	lea	%pc@(r0com),%a6
158	movb	%sp@(1),%a6@(1)
159	movb	%sp@(2),%a6@(5)
160	movb	%sp@(3),%a6@(9)
161	movb	%d5,%a6@(13)
162	addql	#8,%sp
163	lea	dmodus:w,%a6
164	lea	daccess:w,%a5
165	movw	#0x198,%a6@
166	movw	#0x098,%a6@
167	movw	%d5,%a5@
168	movw	#0x88,%a6@
169	movq	#0,%d0
170	movb	%d7,%d0
171	orb	#0x08,%d0
172	swap	%d0
173	movw	#0x8a,%d0
174	bsrs	shake
175	lea	%pc@(r0com),%a0
176	movq	#3,%d2
1772:	movl	%a0@+,%d0
178	bsrs	shake
179	dbra	%d2,2b
180	movq	#0x0a,%d0
181	movl	%d0,%a5@
182	movl	#0x190,%d1
183	bsrs	wait
184	movw	#0x8a,%a6@
185	movw	%a5@,%d0
186	andw	#0xff,%d0
187	beqs	0f
188r0err:	movq	#-1,%d0
1890:	movw	#0x80,%a6@
190	clrb	flock:w
191r0ret:	rts
192
193shake:	movl	%d0,%a5@
194	movq	#0x0a,%d1
195wait:	addl	_hz_200:w,%d1
1960:	btst	#5,gpip:w
197	beqs	r0ret
198	cmpl	_hz_200:w,%d1
199	bccs	0b
200	addql	#4,%sp
201	bras	r0err
202
203r0com:	.long	0x0000008a
204	.long	0x0000008a
205	.long	0x0000008a
206	.long	0x0001008a
207
208regsav:	.long	0
209
210fill:	.space	24
211
212	.ascii	"NetBSD"
213hd_siz:	.long	0
214p0_dsc:	.long	0, 0, 0
215p1_dsc:	.long	0, 0, 0
216p2_dsc:	.long	0, 0, 0
217p3_dsc:	.long	0, 0, 0
218bsl_st:	.long	0
219bsl_sz:	.long	0
220	.word	0
221end:
222