bios_disk.S revision 1.8.6.2 1 1.8.6.2 perry /* $NetBSD: bios_disk.S,v 1.8.6.2 2000/05/21 16:59:29 perry Exp $ */
2 1.8.6.2 perry
3 1.8.6.2 perry /*
4 1.8.6.2 perry * Ported to boot 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
5 1.8.6.2 perry *
6 1.8.6.2 perry * Mach Operating System
7 1.8.6.2 perry * Copyright (c) 1992, 1991 Carnegie Mellon University
8 1.8.6.2 perry * All Rights Reserved.
9 1.8.6.2 perry *
10 1.8.6.2 perry * Permission to use, copy, modify and distribute this software and its
11 1.8.6.2 perry * documentation is hereby granted, provided that both the copyright
12 1.8.6.2 perry * notice and this permission notice appear in all copies of the
13 1.8.6.2 perry * software, derivative works or modified versions, and any portions
14 1.8.6.2 perry * thereof, and that both notices appear in supporting documentation.
15 1.8.6.2 perry *
16 1.8.6.2 perry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 1.8.6.2 perry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18 1.8.6.2 perry * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 1.8.6.2 perry *
20 1.8.6.2 perry * Carnegie Mellon requests users of this software to return to
21 1.8.6.2 perry *
22 1.8.6.2 perry * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
23 1.8.6.2 perry * School of Computer Science
24 1.8.6.2 perry * Carnegie Mellon University
25 1.8.6.2 perry * Pittsburgh PA 15213-3890
26 1.8.6.2 perry *
27 1.8.6.2 perry * any improvements or extensions that they make and grant Carnegie Mellon
28 1.8.6.2 perry * the rights to redistribute these changes.
29 1.8.6.2 perry */
30 1.8.6.2 perry
31 1.8.6.2 perry /*
32 1.8.6.2 perry Copyright 1988, 1989, 1990, 1991, 1992
33 1.8.6.2 perry by Intel Corporation, Santa Clara, California.
34 1.8.6.2 perry
35 1.8.6.2 perry All Rights Reserved
36 1.8.6.2 perry
37 1.8.6.2 perry Permission to use, copy, modify, and distribute this software and
38 1.8.6.2 perry its documentation for any purpose and without fee is hereby
39 1.8.6.2 perry granted, provided that the above copyright notice appears in all
40 1.8.6.2 perry copies and that both the copyright notice and this permission notice
41 1.8.6.2 perry appear in supporting documentation, and that the name of Intel
42 1.8.6.2 perry not be used in advertising or publicity pertaining to distribution
43 1.8.6.2 perry of the software without specific, written prior permission.
44 1.8.6.2 perry
45 1.8.6.2 perry INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 1.8.6.2 perry INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 1.8.6.2 perry IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 1.8.6.2 perry CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 1.8.6.2 perry LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 1.8.6.2 perry NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 1.8.6.2 perry WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 1.8.6.2 perry */
53 1.8.6.2 perry
54 1.8.6.2 perry /* extracted from netbsd:sys/arch/i386/boot/bios.S */
55 1.8.6.2 perry
56 1.8.6.2 perry #include <machine/asm.h>
57 1.8.6.2 perry
58 1.8.6.2 perry #define addr32 .byte 0x67
59 1.8.6.2 perry #define data32 .byte 0x66
60 1.8.6.2 perry
61 1.8.6.2 perry /*
62 1.8.6.2 perry # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
63 1.8.6.2 perry # Call with %ah = 0x2
64 1.8.6.2 perry # %al = number of sectors
65 1.8.6.2 perry # %ch = cylinder
66 1.8.6.2 perry # %cl = sector
67 1.8.6.2 perry # %dh = head
68 1.8.6.2 perry # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
69 1.8.6.2 perry # %es:%bx = segment:offset of buffer
70 1.8.6.2 perry # Return:
71 1.8.6.2 perry # %al = 0x0 on success; err code on failure
72 1.8.6.2 perry */
73 1.8.6.2 perry ENTRY(biosread)
74 1.8.6.2 perry pushl %ebp
75 1.8.6.2 perry movl %esp, %ebp
76 1.8.6.2 perry pushl %ebx
77 1.8.6.2 perry push %ecx
78 1.8.6.2 perry push %edx
79 1.8.6.2 perry push %esi
80 1.8.6.2 perry push %edi
81 1.8.6.2 perry
82 1.8.6.2 perry movb 16(%ebp), %dh
83 1.8.6.2 perry movw 12(%ebp), %cx
84 1.8.6.2 perry xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl
85 1.8.6.2 perry rorb $2, %cl
86 1.8.6.2 perry movb 20(%ebp), %al
87 1.8.6.2 perry orb %al, %cl
88 1.8.6.2 perry incb %cl # sector; sec starts from 1, not 0
89 1.8.6.2 perry movb 8(%ebp), %dl # device
90 1.8.6.2 perry movl 28(%ebp), %ebx # offset
91 1.8.6.2 perry # prot_to_real will set %es to BOOTSEG
92 1.8.6.2 perry
93 1.8.6.2 perry call _C_LABEL(prot_to_real) # enter real mode
94 1.8.6.2 perry
95 1.8.6.2 perry movb $0x2, %ah # subfunction
96 1.8.6.2 perry addr32
97 1.8.6.2 perry movb 24(%ebp), %al # number of sectors
98 1.8.6.2 perry int $0x13
99 1.8.6.2 perry setc %bl
100 1.8.6.2 perry movb %ah, %bh # save error code
101 1.8.6.2 perry
102 1.8.6.2 perry data32
103 1.8.6.2 perry call _C_LABEL(real_to_prot) # back to protected mode
104 1.8.6.2 perry
105 1.8.6.2 perry xorl %eax, %eax
106 1.8.6.2 perry movw %bx, %ax # return value in %ax
107 1.8.6.2 perry
108 1.8.6.2 perry pop %edi
109 1.8.6.2 perry pop %esi
110 1.8.6.2 perry pop %edx
111 1.8.6.2 perry pop %ecx
112 1.8.6.2 perry popl %ebx
113 1.8.6.2 perry popl %ebp
114 1.8.6.2 perry ret
115 1.8.6.2 perry
116 1.8.6.2 perry /*
117 1.8.6.2 perry #
118 1.8.6.2 perry # get_diskinfo(): return a word that represents the
119 1.8.6.2 perry # max number of sectors, heads and cylinders for this device
120 1.8.6.2 perry #
121 1.8.6.2 perry */
122 1.8.6.2 perry
123 1.8.6.2 perry ENTRY(get_diskinfo)
124 1.8.6.2 perry pushl %ebp
125 1.8.6.2 perry movl %esp, %ebp
126 1.8.6.2 perry push %es
127 1.8.6.2 perry pushl %ebx
128 1.8.6.2 perry push %ecx
129 1.8.6.2 perry push %edx
130 1.8.6.2 perry push %esi
131 1.8.6.2 perry push %edi
132 1.8.6.2 perry
133 1.8.6.2 perry movb 8(%ebp), %dl # diskinfo(drive #)
134 1.8.6.2 perry
135 1.8.6.2 perry call _C_LABEL(prot_to_real) # enter real mode
136 1.8.6.2 perry
137 1.8.6.2 perry movb $0x08, %ah # ask for disk info
138 1.8.6.2 perry int $0x13
139 1.8.6.2 perry jnc ok
140 1.8.6.2 perry
141 1.8.6.2 perry /*
142 1.8.6.2 perry * Urk. Call failed. It is not supported for floppies by old BIOS's.
143 1.8.6.2 perry * Guess it's a 15-sector floppy. Initialize all the registers for
144 1.8.6.2 perry * documentation, although we only need head and sector counts.
145 1.8.6.2 perry */
146 1.8.6.2 perry # subb %ah, %ah # %ax = 0
147 1.8.6.2 perry # movb %ah, %bh # %bh = 0
148 1.8.6.2 perry # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
149 1.8.6.2 perry movb $79, %ch # max track
150 1.8.6.2 perry movb $15, %cl # max sector
151 1.8.6.2 perry movb $1, %dh # max head
152 1.8.6.2 perry # movb $1, %dl # # floppy drives installed
153 1.8.6.2 perry # es:di = parameter table
154 1.8.6.2 perry # carry = 0
155 1.8.6.2 perry
156 1.8.6.2 perry ok:
157 1.8.6.2 perry data32
158 1.8.6.2 perry call _C_LABEL(real_to_prot) # back to protected mode
159 1.8.6.2 perry
160 1.8.6.2 perry /* form a longword representing all this gunk */
161 1.8.6.2 perry shll $8, %ecx
162 1.8.6.2 perry movb %dh, %cl
163 1.8.6.2 perry
164 1.8.6.2 perry movl %ecx, %eax
165 1.8.6.2 perry
166 1.8.6.2 perry pop %edi
167 1.8.6.2 perry pop %esi
168 1.8.6.2 perry pop %edx
169 1.8.6.2 perry pop %ecx
170 1.8.6.2 perry popl %ebx
171 1.8.6.2 perry pop %es
172 1.8.6.2 perry popl %ebp
173 1.8.6.2 perry ret
174 1.8.6.2 perry
175 1.8.6.2 perry /*
176 1.8.6.2 perry # int13_extension: check for availibility of int13 extensions.
177 1.8.6.2 perry */
178 1.8.6.2 perry
179 1.8.6.2 perry ENTRY(int13_extension)
180 1.8.6.2 perry pushl %ebp
181 1.8.6.2 perry movl %esp, %ebp
182 1.8.6.2 perry pushl %ebx
183 1.8.6.2 perry pushl %ecx
184 1.8.6.2 perry pushl %edx
185 1.8.6.2 perry pushl %esi
186 1.8.6.2 perry pushl %edi
187 1.8.6.2 perry
188 1.8.6.2 perry movb 8(%ebp), %dl # drive #
189 1.8.6.2 perry movw $0x55aa, %bx
190 1.8.6.2 perry
191 1.8.6.2 perry call _C_LABEL(prot_to_real) # enter real mode
192 1.8.6.2 perry
193 1.8.6.2 perry movb $0x41, %ah # ask for disk info
194 1.8.6.2 perry int $0x13
195 1.8.6.2 perry setnc %dl
196 1.8.6.2 perry
197 1.8.6.2 perry data32
198 1.8.6.2 perry CALL _C_LABEL(real_to_prot) # switch back
199 1.8.6.2 perry
200 1.8.6.2 perry xorl %eax, %eax
201 1.8.6.2 perry movb %dl, %al # return value in %ax
202 1.8.6.2 perry
203 1.8.6.2 perry cmpw $0xaa55, %bx
204 1.8.6.2 perry sete %dl
205 1.8.6.2 perry andb %dl, %al
206 1.8.6.2 perry
207 1.8.6.2 perry andb %cl, %al
208 1.8.6.2 perry
209 1.8.6.2 perry popl %edi
210 1.8.6.2 perry popl %esi
211 1.8.6.2 perry popl %edx
212 1.8.6.2 perry popl %ecx
213 1.8.6.2 perry popl %ebx
214 1.8.6.2 perry popl %ebp
215 1.8.6.2 perry ret
216 1.8.6.2 perry
217 1.8.6.2 perry /*
218 1.8.6.2 perry # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
219 1.8.6.2 perry # Call with %ah = 0x42
220 1.8.6.2 perry # %ds:%si = parameter block
221 1.8.6.2 perry # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
222 1.8.6.2 perry # Return:
223 1.8.6.2 perry # %al = 0x0 on success; err code on failure
224 1.8.6.2 perry */
225 1.8.6.2 perry ENTRY(biosextread)
226 1.8.6.2 perry pushl %ebp
227 1.8.6.2 perry movl %esp, %ebp
228 1.8.6.2 perry pushl %ebx
229 1.8.6.2 perry push %ecx
230 1.8.6.2 perry push %edx
231 1.8.6.2 perry push %esi
232 1.8.6.2 perry push %edi
233 1.8.6.2 perry
234 1.8.6.2 perry movb 8(%ebp), %dl # device
235 1.8.6.2 perry movl 12(%ebp), %esi # parameter block
236 1.8.6.2 perry
237 1.8.6.2 perry call _C_LABEL(prot_to_real) # enter real mode
238 1.8.6.2 perry
239 1.8.6.2 perry movb $0x42, %ah # subfunction
240 1.8.6.2 perry int $0x13
241 1.8.6.2 perry setc %bl
242 1.8.6.2 perry movb %ah, %bh # save error code
243 1.8.6.2 perry
244 1.8.6.2 perry data32
245 1.8.6.2 perry call _C_LABEL(real_to_prot) # back to protected mode
246 1.8.6.2 perry
247 1.8.6.2 perry xorl %eax, %eax
248 1.8.6.2 perry movw %bx, %ax # return value in %ax
249 1.8.6.2 perry
250 1.8.6.2 perry pop %edi
251 1.8.6.2 perry pop %esi
252 1.8.6.2 perry pop %edx
253 1.8.6.2 perry pop %ecx
254 1.8.6.2 perry popl %ebx
255 1.8.6.2 perry popl %ebp
256 1.8.6.2 perry ret
257 1.8.6.2 perry
258 1.8.6.2 perry ENTRY(int13_getextinfo)
259 1.8.6.2 perry pushl %ebp
260 1.8.6.2 perry movl %esp, %ebp
261 1.8.6.2 perry pushl %ebx
262 1.8.6.2 perry push %ecx
263 1.8.6.2 perry push %edx
264 1.8.6.2 perry push %esi
265 1.8.6.2 perry push %edi
266 1.8.6.2 perry
267 1.8.6.2 perry movb 8(%ebp), %dl # device
268 1.8.6.2 perry movl 12(%ebp), %esi # parameter block
269 1.8.6.2 perry movl $0x01a, (%esi) # length (v 1.x)
270 1.8.6.2 perry
271 1.8.6.2 perry call _C_LABEL(prot_to_real) # enter real mode
272 1.8.6.2 perry
273 1.8.6.2 perry movb $0x48, %ah # subfunction
274 1.8.6.2 perry int $0x13
275 1.8.6.2 perry setc %bl
276 1.8.6.2 perry
277 1.8.6.2 perry data32
278 1.8.6.2 perry call _C_LABEL(real_to_prot) # back to protected mode
279 1.8.6.2 perry
280 1.8.6.2 perry xorl %eax, %eax
281 1.8.6.2 perry movb %bl, %al # return value in %ax
282 1.8.6.2 perry
283 1.8.6.2 perry pop %edi
284 1.8.6.2 perry pop %esi
285 1.8.6.2 perry pop %edx
286 1.8.6.2 perry pop %ecx
287 1.8.6.2 perry popl %ebx
288 1.8.6.2 perry popl %ebp
289 1.8.6.2 perry ret
290