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