xref: /netbsd-src/sys/arch/atari/stand/xxboot/ahdi-xxboot/xxboot.ahdi.S (revision 9fd8799cb5ceb66c69f2eb1a6d26a1d587ba1f1e)
1/*	$NetBSD: xxboot.ahdi.S,v 1.2 2005/12/11 12:17:02 christos 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
40_start:	bras	main
41#else
42	.globl	start, main, fill
43
44	.text
45
46start:	bras	main
47#endif
48/*
49 * Fake gemdos-fs bootsector, to keep TOS away.
50 */
51	.ascii	"NetBSD"	| oem
52	.byte	0,0,0		| serial
53	.word	0		| bps
54	.byte	0		| spc
55	.word	0		| res
56	.byte	0		| fat
57	.word	0		| ndirs
58	.word	0		| sec
59	.byte	0		| media
60	.word	0		| spf
61	.word	0		| spt
62	.word	0		| side
63	.word	0		| hid
64	.even
65/*
66 * AHDI rootsector code passes:
67 * d3: SCSI/IDE <-> ACSI flag	d4: SCSI/IDE target (or -1)
68 * d5: boot preference		d6: offset of boot block
69 * d7: ACSI target		a3: pointer to readsector()
70 * a4: pointer to `start'	a5: pointer to back-to-ROM
71 */
72main:	movml	%d3-%d7/%a3-%a5,%sp@-
73	lea	%pc@(regsav),%a0
74	movl	%sp,%a0@
75
76	movw	#-1,%sp@-
77	movw	#Kbshift,%sp@-
78	trap	#BIOS
79	addql	#4,%sp
80	subql	#1,%d0
81	movl	%d0,%a5			| autoboot flag
82
83	lea	%pc@(m_bot),%a6
84	movl	_membot:w,%d3
85	lea	MAXBOT,%a4
86	cmpl	%a4,%d3
87	bhis	exit			| membot > MAXBOT
88
89	lea	%pc@(m_top),%a6
90	movl	_memtop:w,%d3
91	cmpl	#MINTOP,%d3
92	blts	exit			| memtop < MINTOP
93
94	andw	#-4,%d3
95	movl	%d3,%a0
96	movl	%sp,%a0@-
97	movl	%a0,%sp			| set new stack
98/*
99 * Load secondary boot loader and disklabel.
100 */
101	movml	%a4/%a5,%sp@-
102	movq	#NSEC,%d3		| # of sectors
103	addql	#1,%d6			| first sector
104	bsr	rds1
105	lea	%pc@(m_rds),%a6
106	movml	%sp@+,%a4/%a5
107	bnes	0f			| I/O error
108/*
109 * int bootxx(readsector, disklabel, autoboot)
110 */
111	pea	%a5@			| autoboot
112	pea	%a4@(LBLST-MAXBOT)	| disklabel
113	pea	%pc@(rds2)		| readsector
114	jsr	%a4@(BXXST-MAXBOT)
115	lea	%pc@(m_sbl),%a6		| NetBSD not booted
116	lea	%sp@(12),%sp
117
1180:	movl	%sp@,%sp			| restore BIOS stack
119	movl	%d0,%d3
120	bmis	exit
121	movml	%sp@+,%d3-%d7/%a3-%a5
122	movl	%d0,%d5			| new boot preference
123	jmp	%a4@(-0x200)
124
125exit:	bsrs	puts			| display error
126	lea	%pc@(m_key),%a6
127	bsrs	puts			| wait for key
128	movml	%sp@+,%d3-%d7/%a3-%a5
129	jmp	%a5@
130
131/*
132 * puts (in: a6, d3)
133 */
1340:	cmpw	#35,%d0		| '#'
135	bnes	1f
136	bsrs	puti
137	bras	puts
1381:	cmpw	#64,%d0		| '@'
139	bnes	2f
140	movw	#2,%sp@-
141	movw	#Bconin,%sp@-
142	trap	#BIOS
143	addql	#4,%sp
144	bras	puts
1452:	bsrs	putc
146puts:	movq	#0,%d0
147	movb	%a6@+,%d0
148	bnes	0b
149	rts
150
151puti:	swap	%d3
152	bsrs	0f
153	swap	%d3
1540:	rorw	#8,%d3
155	bsrs	1f
156	rorw	#8,%d3
1571:	rorb	#4,%d3
158	bsrs	2f
159	rorb	#4,%d3
1602:	movw	%d3,%d0
161	andw	#15,%d0
162	addw	#48,%d0
163	cmpw	#58,%d0
164	bcss	putc
165	addw	#39,%d0
166putc:	movw	%d0,%sp@-
167	movw	#2,%sp@-
168	movw	#Bconout,%sp@-
169	trap	#BIOS
170	addql	#6,%sp
171	rts
172/*
173 * int readsec (void *buffer, u_int offset, u_int count);
174 */
175rds2:	movml	%d2-%d7/%a2-%a6,%sp@-
176	movl	%pc@(regsav),%a0
177	movml	%a0@,%d3-%d7/%a3-%a5
178	movl	%sp@(48),%a4		| buffer
179	movl	%sp@(52),%d6		| offset
180	movl	%sp@(56),%d3		| count
181	bsrs	rds1
182	movml	%sp@+,%d2-%d7/%a2-%a6
183	rts
184
185rds1:	movl	#255,%d5
186	cmpl	%d5,%d3
187	bccs	0f
188	movl	%d3,%d5
1890:	jsr	%a3@
190	tstl	%d0
191	bnes	1f
192	addl	#(255*512),%a4
193	addl	%d5,%d6
194	subl	%d5,%d3
195	bnes	rds1
1961:	rts
197
198m_bot:	.asciz	"xxboot: membot == 0x#\r\n"
199m_top:	.asciz	"xxboot: memtop == 0x#\r\n"
200m_sbl:	.asciz	"xxboot: bootxx => 0x#\r\n"
201m_rds:	.asciz	"xxboot: Floprd => 0x#\r\n"
202m_key:	.asciz	"\007\r\npress any key... @\r\n"
203
204regsav:	.long	0
205
206fill:	.space	54		| 510-(fill-start)
207	.word	0		| checksum
208end:
209