Deleted Added
sdiff udiff text old ( 64660 ) new ( 65271 )
full compact
1# Copyright (c) KATO Takenori, 1999, 2000.
2#
3# All rights reserved. Unpublished rights reserved under the copyright
4# laws of Japan.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer as
12# the first lines of this file unmodified.
13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28# $FreeBSD: head/sys/boot/pc98/boot0.5/disk.s 64660 2000-08-15 08:17:03Z kato $
29#
30
31 .code16
32 .text
33#
34# Check magic number at the end of the sector 0
35#
36check_magic:
37 movw curdevice, %si
38 shlw %si
39 movw secsize(%si), %bx
40 decw %bx
41 decw %bx
42 movw iplbuf(%bx), %ax
43 cmpw $0xaa55, %ax
44 je magic_ok
45 movw $1, %ax
46 ret
47magic_ok:
48 xorw %ax, %ax
49 ret
50
51#
52# Copy partition table from buffer to parttable.
53#
54setup_partition:
55 push %cs
56 pop %es
57 movw curdevice, %bx
58 shlw %bx
59 movw maxpart(%bx), %cx # %cx = max num of partitions
60 movw partoff(%bx), %di
61 movw %di, %bx # %bx = offset to partition table
62 xorw %dx, %dx # %dx = partition number
63setup_partition_loop:
64 push %cx
65 movw %dx, %si
66 movb $5, %cl
67 shlw %cl, %si
68 addw %bx, %si
69 movb iplbuf(%si), %al
70 orb %al, %al
71 jz unused_partition
72 addw $iplbuf, %si
73 movw npartition, %ax
74 movw %ax, %di
75 movb $5, %cl
76 shlw %cl, %di
77 addw $parttable, %di
78 movw $32, %cx
79 rep
80 movsb
81 movw %ax, %di
82 addw $partnum, %di
83 movb %dl, (%di)
84 incw npartition
85unused_partition:
86 incw %dx
87 pop %cx
88 loop setup_partition_loop
89 ret
90
91#
92# Read IPL and partition table in the current device.
93#
94 .global read_ipl
95read_ipl:
96 movw curdevice, %ax
97 movw %ax, %si # %si = device number
98 movw %ax, %di
99 shlw %di
100
101 movw %cs, %ax
102 movw %ax, %es
103 movb $6, %ah
104 movb daua(%si), %al
105 movw $0x400, %bx
106 xorw %cx, %cx
107 xorw %dx, %dx
108 movw $iplbuf, %bp
109 int $0x1b
110 jc read_ipl_error
111 movw defflagoff(%di), %bx
112 movb iplbuf(%bx), %al
113 movb %al, defpartflag
114 incw %bx
115 movb iplbuf(%bx), %al
116 movb %al, defpartnum
117 movw $0, npartition
118 call check_magic
119 orw %ax, %ax
120 jnz no_magic
121 call setup_partition
122no_magic:
123 xorw %ax, %ax
124read_ipl_error:
125 xorw %bx, %bx
126 movw %bx, %es
127 ret
128
129#
130# Restore IPL from the buffer
131#
132 .global write_ipl
133write_ipl:
134 movw curdevice, %ax
135 movw %ax, %si
136 movw %ax, %di
137 shlw %di
138
139 # Restore default boot partition info.
140 movw defflagoff(%di), %bx
141 movb defpartflag, %al
142 movb %al, iplbuf(%bx)
143 incw %bx
144 movb defpartnum, %al
145 movb %al, iplbuf(%bx)
146
147 movw %cs, %ax
148 movw %ax, %es
149 movb $5, %ah
150 movb daua(%si), %al
151 movw secsize(%di), %bx
152 xorw %cx, %cx
153 xorw %dx, %dx
154 movw $iplbuf, %bp
155 int $0x1b
156 jc write_ipl_error
157 xorw %ax, %ax
158write_ipl_error:
159 xorw %bx, %bx
160 movw %bx, %es
161 ret
162
163#
164# Scan HDD devices
165#
166 .global scan_sasi, scan_scsi
167 # Scan SASI disk
168scan_sasi:
169 # SASI Disk
170 movw $4, %cx
171 movw $0x0001, %ax # %ah = unit number, %al = for bit operation
172
173sasi_loop:
174 movw %si, %di
175 shlw %di
176 movw $0x55d, %bx # DISK_EQUIP
177 call read_biosparam
178 testb %al, %dl
179 jz no_sasi_unit
180 movb $0x80, %dh
181 addb %ah, %dh
182 movb %dh, daua(%si)
183 movw $0x457, %bx # capacity & sector size of IDE HDD
184 call read_biosparam
185 orb %ah, %ah
186 jz sasi_1
187 cmpb $1, %ah
188 jz sasi_2
189
190 # SASI #3/#4
191 movw $512, %dx # XXX
192 jmp found_sasi_unit
193
194sasi_1:
195 # SASI #1
196 testb $0x80, %dl
197 jz sasi_256
198 jmp sasi_512
199sasi_2:
200 # SASI #2
201 testb $0x40, %dl
202 jz sasi_256
203 jmp sasi_512
204
205sasi_256:
206 movw $256, %dx
207 jmp found_sasi_unit
208sasi_512:
209 movw $512, %dx
210found_sasi_unit:
211 movw %dx, secsize(%di)
212 incw %si
213no_sasi_unit:
214 incb %ah
215 shlb %al
216 loop sasi_loop
217 ret
218
219#
220# Scan SCSI disk
221# SI number of disks
222# destroyed: %ax, %bx, %cx, %dx
223scan_scsi:
224 movw $8, %cx
225 movw $0x0001, %ax # %ah = ID number, %al = for bit operation
226scsi_loop:
227 # Check whether drive exist.
228 movw %si, %di
229 shlw %di
230 movw $0x482, %bx # DISK_EQUIPS
231 call read_biosparam
232 testb %al, %dl
233 jz no_scsi_unit
234 xorw %bx, %bx
235 movb %ah, %bl
236 shlw %bx
237 shlw %bx
238 addw $0x460, %bx # SCSI paramter block
239 call read_biosparam
240 orb %dl, %dl
241 jz no_scsi_unit
242
243 # SCSI harddrive found.
244 movb $0xa0, %dh
245 addb %ah, %dh
246 movb %dh, daua(%si)
247
248 # Check sector size.
249 addw $3, %bx
250 call read_biosparam
251 andb $0x30, %dl
252 cmpb $0x20, %dl
253 je scsi_1024
254 cmpb $0x10, %dl
255 je scsi_512
256 movw $256, %dx
257 jmp found_scsi
258scsi_1024:
259 movw $1024, %dx
260 jmp found_scsi
261scsi_512:
262 movw $512, %dx
263found_scsi:
264 movw %dx, secsize(%di)
265 incw %si
266no_scsi_unit:
267 incb %ah
268 shlb %al
269 loop scsi_loop
270 ret
271
272 .data
273 .global partnum, parttable, defpartflag, defpartnum, npartition
274partnum: .space 32 # Index of parttable
275parttable: .space 1024 # Copy of valid partition table
276defpartflag: .byte 0
277defpartnum: .byte 0
278npartition: .word 0 # number of partitions
279 .bss
280iplbuf: .space 0x400