summaryrefslogtreecommitdiffstats
path: root/stand/pc98/boot0.5/boot0.5.s
blob: f878006567679b43e7c9c81d44aac8adc6eaa62e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Copyright (c) KATO Takenori, 1999, 2000, 2007.
#
# All rights reserved.  Unpublished rights reserved under the copyright
# laws of Japan.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer as
#    the first lines of this file unmodified.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $FreeBSD$
#
	.global	main
	.code16

	.text
main:
	# Check hireso mode
	movw	$0x501, %bx		# BIOS_FLAG
	call	read_biosparam
	testb	$0x08, %dl
	jz	normalmode
	movb	$1, ishireso
normalmode:
	call	sc_init

	# Display title and copyright.
	movw	$title, %di
	call	sc_puts
	xorw	%cx, %cx
	movw	$1, %dx
	call	sc_goto
	movw	$copyright, %di
	call	sc_puts

	# Scan hard drives
	xorw	%si, %si		# number of partition
	call	scan_sasi		# SASI/IDE
	call	scan_scsi		# SCSI
	movw	%si, ndevice
	orw	%si, %si
	jnz	drives_found
	jmp	exit			# No hard drives

drives_found:
	# Setup sector size dependent parameters
	movw	%si, %cx		# %cx = number of devices
setup_loop:
	movw	%cx, %di
	decw	%di
	shlw	%di
	movw	secsize(%di), %ax
	cmpw	$1024, %ax
	je	setup_1024
	cmpw	$512, %ax
	je	setup_512
	# 256 bytes/sector
	movw	$0x100, partoff(%di)
	movw	$0x0fa, defflagoff(%di)
	movw	$0x0fb, defpartoff(%di)
	movw	$8, maxpart(%di)
	jmp	setup_secsize_end
	# 1024 bytes/sector
setup_1024:
	# XXX Fix me!
	movw	$0x400, partoff(%di)
	movw	$0x3fa, defflagoff(%di)
	movw	$0x3fb, defpartoff(%di)
	movb	$32, maxpart(%di)
	jmp	setup_secsize_end
	# 512 bytes/sector
setup_512:
	movw	$0x200, partoff(%di)
	movw	$0x1fa, defflagoff(%di)
	movw	$0x1fb, defpartoff(%di)
	movb	$16, maxpart(%di)
setup_secsize_end:
	loop	setup_loop

	# For debug with floppy, fake the parameter.
	movw	$0x584, %bx		# DISK_BOOT
	call	read_biosparam
	andb	$0xf0, %dl
	cmpb	$0x90, %ah
	jne	boot_from_hdd
	movb	daua, %dl
	call	write_biosparam

boot_from_hdd:
	movw	$500, %cx
wait_0_5:
	call	wait1ms
	loop	wait_0_5

	# If the TAB is pressed, don't try to boot from default partition
	xorw	%di, %di		# flag
wait_key_release:
	call	sc_iskeypress
	orw	%ax, %ax
	jz	key_release		# KBD buffer empty.
	call	sc_getc
	cmpb	$0x0f, %ah		# TAB
	jne	wait_key_release
	# TAB pressed
	movw	$1, %di
	jmp	wait_key_release
key_release:
	orw	%di, %di
	jnz	dont_try_default	# TAB pressed.
	call	trydefault
	# Default partition not found.
dont_try_default:
	call	show_usage
	call	showdevices
	call	selector
exit:
	ret
#
# Display usage
#
show_usage:
	movw	$44, %cx
	movw	$3, %dx
	call	sc_goto
	movw	$msg_usage1, %di
	call	sc_puts
	movw	$44, %cx
	movw	$4, %dx
	call	sc_goto
	movw	$msg_usage2, %di
	call	sc_puts
	movw	$44, %cx
	movw	$5, %dx
	call	sc_goto
	movw	$msg_usage3, %di
	call	sc_puts
	movw	$44, %cx
	movw	$7, %dx
	call	sc_goto
	movw	$msg_usage4, %di
	call	sc_puts
	movw	$44, %cx
	movw	$8, %dx
	call	sc_goto
	movw	$msg_usage5, %di
	call	sc_puts
	movw	$44, %cx
	movw	$9, %dx
	call	sc_goto
	movw	$msg_usage6, %di
	call	sc_puts
	movw	$44, %cx
	movw	$10, %dx
	call	sc_goto
	movw	$msg_usage7, %di
	call	sc_puts
	movw	$44, %cx
	movw	$11, %dx
	call	sc_goto
	movw	$msg_usage8, %di
	call	sc_puts
	movw	$44, %cx
	movw	$16, %dx
	call	sc_goto
	movw	$msg_usage9, %di
	call	sc_puts
	movw	$44, %cx
	movw	$17, %dx
	call	sc_goto
	movw	$msg_usage10, %di
	call	sc_puts
	movw	$44, %cx
	movw	$18, %dx
	call	sc_goto
	movw	$msg_usage11, %di
	call	sc_puts
	movw	$44, %cx
	movw	$19, %dx
	call	sc_goto
	movw	$msg_usage12, %di
	call	sc_puts
	ret

#
# Display device list
#
showdevices:
	movw	$2, %cx
	movw	$4, %dx
	call	sc_goto
	movw	$msg_device, %di
	call	sc_puts
	xorw	%si, %si		# %si = device number
	movw	ndevice, %cx		# %cx = number of devices
showdev_loop:
	push	%cx
	movw	$2, %cx
	movw	$5, %dx
	addw	%si, %dx
	call	sc_goto
	# Check DA
	movb	daua(%si), %al
	push	%ax
	andb	$0xf0, %al
	cmpb	$0x80, %al
	je	show_sasi
	cmpb	$0xa0, %al
	je	show_scsi
	# unknown device
	movw	$msg_unknown, %di
	call	sc_puts
	jmp	showunit
	# SASI
show_sasi:
	movw	$msg_sasi, %di
	call	sc_puts
	jmp	showunit
	# SCSI
show_scsi:
	movw	$msg_scsi, %di
	call	sc_puts
	# Display unit number.
showunit:
	pop	%ax
	andb	$0x0f, %al
	addb	$'0', %al
	call	sc_putc
	incw	%si
	pop	%cx
	loop	showdev_loop
	movw	ndevice, %dx
	addw	$5, %dx
	movw	$2, %cx
	call	sc_goto
	movw	$msg_exitmenu, %di
	call	sc_puts
	ret

	.data
	.global	curdevice, ndevice
ndevice:	.word	0		# number of device
curdevice:	.word	0		# current device

	.global	ishireso
ishireso:	.byte	0

title:		.asciz	"PC98 Boot Selector Version 1.2"
copyright:	.ascii	"(C)Copyright 1999-2007 KATO Takenori. "
		.asciz	"All rights reserved."
msg_device:	.asciz	"Device"
msg_sasi:	.asciz	"SASI/IDE unit "
msg_scsi:	.asciz	"SCSI ID "
msg_unknown:	.asciz	"unknown unit "
msg_exitmenu:	.asciz	"Exit this menu"
msg_usage1:	.asciz	"Device list"
msg_usage2:	.asciz	"UP, DOWN: select boot device"
msg_usage3:	.asciz	"RETURN: move to slice list"
msg_usage4:	.asciz	"Slice list"
msg_usage5:	.asciz	"UP, DOWN: select boot slice"
msg_usage6:	.asciz	"RETURN: boot"
msg_usage7:	.asciz	"SPACE: toggle default"
msg_usage8:	.asciz	"ESC: move to device list"
msg_usage9:	.asciz	"LEGEND"
msg_usage10:	.asciz	">>: selected device/slice"
msg_usage11:	.asciz	"*: default slice to boot"
msg_usage12:	.asciz	"!: unbootable slice"

	.bss
	.global	daua, secsize, defflagoff, defpartoff
	.global	maxpart, partoff
daua:		.space	12		# DA/DU list
secsize:	.space	12 * 2		# Sector soize
defflagoff:	.space	12 * 2
defpartoff:	.space	12 * 2
maxpart:	.space	12 * 2
partoff:	.space	12 * 2
OpenPOWER on IntegriCloud