1;;  antares.asm : Extended-IPL/scorpius
2;;
3;;	multi OS boot utility for IBM PC/AT and compatibles, Since 1993
4;;
5;;					Auther : takamiti@tsden.org
6;;					last update : 1999/04/05
7;;
8;;	This program requires NASM - "The Netwide Assembler"
9;;		(http://www.web-sites.co.uk/nasm/)
10;;
11;;  $Id: antares.asm,v 1.1.1.1 2000/11/29 11:58:06 takamiti Exp $
12;;
13
14%include	"biosdef.inc"
15%include	"ipldef.inc"
16
17		bits	16
18		org	0x0600		;; BOOT_LOC
19
20		section .text
21
22		cli
23		xor	ax,ax
24		mov	ss,ax
25		mov	es,ax
26		mov	ds,ax
27		xchg	ax,dx
28		mov	sp,BIOS_LOC
29		mov	si,sp
30		sti
31		cld
32		mov	di,BOOT_LOC
33		mov	cx,256
34		repnz	movsw
35%ifdef FDTEST
36		jmp	launcher - BIOS_LOC + BOOT_LOC
37%else
38		jmp	start - BIOS_LOC + BOOT_LOC
39%endif
40
41start:		test	byte [kbd_stat],SHIFT_BIT
42		jnz	doselect
43		test	byte [fd_stat],0x0F
44		jnz	start
45		jmp	short chkTable
46
47doselect:	inc	dx
48chkTable:	call	initCRT
49		push	word chkTable
50		mov	cx,4
51		mov	di,BOOT_LOC + PART_TBL_OFS
52		mov	bx,0x3130
53		mov	si,guid_msg
54		call	putstr
55chtabloop:	inc	bx
56		test	byte [di],0x80
57		jz	prntab
58		or	dx,dx
59		jz	bootProc
60		mov	bh,bl
61		and	byte [di],0x7F
62prntab:		mov	ah,1
63		mov	al,bl
64		call	putSPC
65		mov	al,[di+4]
66		or	al,al
67		jz	nosys
68		push	ax
69		mov	ax,0x0473
70		call	putSPC
71		pop	ax
72		call	hex2
73nosys:		add	di,byte 16
74		call	putCRLF
75		loop	chtabloop
76		inc	dx
77
78retry0:		mov	bl,bh
79retry1:		push	bx
80retry:		mov	si,selmsg
81		call	putstr
82keyin:		pop	ax
83		call	putch
84keyin1:		xor	ah,ah
85		int	KEYBIOS
86		cmp	al,0x30
87		jc	selOK
88		cmp	al,0x34
89		ja	keyin1
90		xchg	ax,bx
91		jmp	short retry1
92
93selOK:		cmp	ah,EXEC_KEY		; check key-scan code
94		jz	bootProc
95		cmp	ah,ENTER_KEY
96		jnz	keyin1
97
98bootProc:	push	dx
99		mov	bh,bl
100		sub	bl,0x30
101		jz	switch_HD
102
103		xchg	ax,bp			; boot condition flag save to bp
104		dec	bx
105		mov	al,16
106		mul	bl
107		add	ax,BOOT_LOC + PART_TBL_OFS
108		xchg	ax,si			; partition table address in si
109		push	si
110		lodsw
111		xchg	ax,dx
112		lodsw
113		xchg	ax,cx
114		lodsw
115		pop	si
116		or	al,al			; check system-identity
117		jnz	bootcontinue
118		pop	dx
119		push	word retry0
120bell:		mov	al,BELL
121		jmp	putch
122
123bootcontinue:	mov	dl,byte [drive]
124		add	dl,0x50
125		push	ax			; save system identity
126		call	HDread
127		pop	ax
128		cmp	word [BIOS_LOC + 0x1FE],IPL_MAGIC
129		jz	checksysid
130		pop	dx
131		jmp	short bell
132
133checksysid:	mov	ah,byte [prompt]
134		inc	ah
135		cmp	al,EXTDOS_PART
136		jz	moveTable
137		cmp	al,EXTLINUX_PART
138		jz	moveTable
139		cmp	al,EXTDOSLBA_PART
140		jz	moveTable
141
142		mov	byte [si],dl
143		cmp	dl,0x80			; first drive unit ?
144		jnz	kickOS
145		cmp	byte [prompt],PS0	; master boot sector ?
146		jnz	kickOS
147		xchg	ax,bp			; load boot condition flag
148		cmp	ah,EXEC_KEY		; spcified write table ?
149		jnz	kickOS
150		xor	dh,dh
151		mov	cx,1
152		mov	ax,0x301
153		mov	bx,BOOT_LOC
154		call	HDio
155
156kickOS:		call	initCRT
157		jmp	BIOS_LOC		;; jmp	far BIOS_LOC
158
159;  try next drive unit
160switch_HD:	mov	al,byte [drive]
161		sub	al,0x30
162		inc	ax
163		cmp	al,byte [nr_hdds]
164		jc	swhd1
165		xor	ax,ax
166swhd1:		push	ax
167		add	al,0x30
168		mov	byte [drive],al
169		pop	dx
170		xor	dh,dh
171rdsector00:	or	dl,0x80
172		mov	cx,1
173		call	HDread
174		mov	ah,PS0
175moveTable:	mov	byte [prompt],ah
176		mov	si,(BIOS_LOC + 0x01BE)
177		mov	di,BOOT_LOC + PART_TBL_OFS
178		mov	cx,33
179		repnz	movsw
180		pop	dx
181return:		ret
182
183HDread:		mov	bx,BIOS_LOC		; load address 0x7C00L
184		mov	ax,0x0201
185HDio:		int	DISKBIOS
186		jnc	return
187
188		push	ax			; disk BIOS error code
189		call	bell
190		mov	ax,0x043F
191		call	putSPC
192		pop	ax
193		mov	al,ah
194		call	hex2
195		hlt
196		jmp	short $
197
198initCRT:	mov	ax,2
199		jmp	short putch1
200putspace:	mov	al,0x20
201putch:		mov	ah,14
202putch1:		int	VIDEOBIOS
203		ret
204
205putCRLF:	mov	si,crlf_msg
206putstr:		lodsb
207		or	al,al
208		jz	return
209		call	putch
210		jmp	short putstr
211
212hex2:		push	ax
213		push	cx
214		mov	cl,4
215		shr	al,cl
216		pop	cx
217		call	hex1
218		pop	ax
219hex1:		and	al,0x0F
220		add	al,0x30
221		cmp	al,0x3A
222		jc	putch
223		add	al,7
224		jmp	short putch
225
226putSPC:		push	ax
227		call	putspace
228		pop	ax
229		dec	ah
230		jnz	putSPC
231		jmp	short putch
232
233guid_msg:	db	"Part  Sys"
234crlf_msg:	db	CR, LF, NULL
235selmsg:		db	CR, "Boot#"
236drive:		db	"0:"
237prompt:		db	PS0, ".", NULL
238
239%ifdef FDTEST
240launcher:	push	word start
241		xor	dx,dx
242		push	dx
243		jmp	rdsector00
244%endif
245
246; end of antares.asm
247