2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, Revision 2.2 92/04/04 11:34:26 rpd
27 * $FreeBSD: src/sys/boot/pc98/boot2/bios.S,v 1.4 2003/01/06 13:43:13 nyan Exp $
28 * $DragonFly: src/sys/boot/pc98/boot2/Attic/bios.S,v 1.3 2003/11/10 06:08:38 dillon Exp $
32 Copyright 1988, 1989, 1990, 1991, 1992
33 by Intel Corporation, Santa Clara, California.
37 Permission to use, copy, modify, and distribute this software and
38 its documentation for any purpose and without fee is hereby
39 granted, provided that the above copyright notice appears in all
40 copies and that both the copyright notice and this permission notice
41 appear in supporting documentation, and that the name of Intel
42 not be used in advertising or publicity pertaining to distribution
43 of the software without specific, written prior permission.
45 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54 * Ported to PC-9801 by Yoshio Kimura
58 * Extensions for El Torito CD-ROM booting:
60 * Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
61 * Copyright © 1997 interface business GmbH, Dresden.
62 * All rights reserved.
64 * This code has been written by Jörg Wunsch, Dresden.
65 * Direct comments to <joerg_wunsch@interface-business.de>.
67 * Redistribution and use in source and binary forms, with or without
68 * modification, are permitted provided that the following conditions
70 * 1. Redistributions of source code must retain the above copyright
71 * notice, this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright
73 * notice, this list of conditions and the following disclaimer in the
74 * documentation and/or other materials provided with the distribution.
76 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
77 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
78 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
79 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
80 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
81 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
82 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
84 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
85 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
86 * POSSIBILITY OF SUCH DAMAGE.
98 * PC-9801/PC-9821 SCSI MO booting
99 * 2002/06/05-07/03 Kawanobe Koh <kawanobe@st.rim.or.jp>
106 mov %bl, %cl /* UA */
110 mov (0x0482), %al /* SCSI HD equipment bits */
118 * biosread(dev, cyl, head, sec, nsec, offset)
119 * Read "nsec" sectors from disk to offset "offset" in boot segment
120 * BIOS call "INT 0x1B Function 0xn6" to read sectors from disk into memory
121 * Call with %ah = 0xd6(for floppy disk) or 0x06(for hard disk)
124 * %ch = sector size(for floppy) or cylinder(for hard)
128 * %es:%bp = segment:offset of buffer
130 * %al = 0x0 on success; err code on failure
142 mov 0x08(%ebp), %bl /* (byte) DA/UA */
143 mov 0x0C(%ebp), %ecx /* (word) cylinder */
144 mov 0x10(%ebp), %dh /* (byte) head */
145 mov 0x14(%ebp), %dl /* (byte) sector */
146 mov 0x18(%ebp), %esi /* (byte) number of sectors */
147 mov 0x1C(%ebp), %edi /* (word) destination offset */
149 /* prot_to_real will set %es to BOOTSEG */
150 call EXT(prot_to_real) /* enter real mode */
152 mov $0x06, %bh /* read data function */
153 mov %bl, %al /* DA */
155 cmp $0x30, %al /* 1440KB FD */
157 cmp $0x90, %al /* 1200KB FD */
159 cmp $0xA0, %al /* SCSI HD or MO */
164 mov %dh, %al /* change to linear sector */
165 shl $5, %al /* multiply by 32 sector per track */
167 xor %dh, %dh /* higher 16 bits into %dx */
169 mov %cl, %ch /* lower 16 bits into %cx */
171 and $0x7F, %bl /* linear access DA/UA */
174 inc %dx /* sector address begins from one */
175 mov $0x02, %ch /* 512 bytes sector */
176 mov $0xD6, %bh /* MT MFM retry seek */
178 mov %si, %ax /* number of sectors */
179 shl $9, %ax /* multiply by 512 bytes */
181 mov %di, %bp /* destination offset */
182 int $0x1B /* disk bios call */
186 mov %ax, %bx /* save return value */
190 call EXT(real_to_prot) /* back to protected mode */
193 mov %bh, %al /* return value in %eax */
207 * getbootspec(struct specpacket *offset)
209 * Read CD-ROM boot specification packet to "offset".
221 /* prot_to_real will set %es to BOOTSEG */
222 call EXT(prot_to_real) /* enter real mode */
223 movw $0x4b01, %ax /* (do not) terminate disk emulation */
224 movb $0x7f, %dl /* any drive */
230 /* save return value (actually movw %ax, %bx) */
234 call EXT(real_to_prot) /* back to protected mode */
237 movb %bh, %al /* return value in %ax */
248 * biosreadlba(struct daddrpacket *daddr)
249 * Read sectors using the BIOS "read extended" function
250 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
251 * Call with %ah = 0x42
252 * %dl = drive (0x0 for floppy disk, or emulated CD)
253 * %ds:%si = ptr to disk address packet
255 * %ah = 0x0 on success; err code on failure
266 movl $0, %edx /* emulated CD is always drive 0 */
268 /* prot_to_real will set %es to BOOTSEG */
269 call EXT(prot_to_real) /* enter real mode */
270 movw $0x4200, %ax /* subfunction */
277 /* save return value (actually movw %ax, %bx) */
281 call EXT(real_to_prot) /* back to protected mode */
284 movb %bh, %al /* return value in %ax */
296 * BIOS call "INT 18H Function 00H" to read character from keyboard
297 * Call with %ah = 0x0
298 * Return: %ah = keyboard scan code
299 * %al = ASCII character
306 push %ebx /* save %ebx */
310 call EXT(prot_to_real)
316 movb %al, %bl /* real_to_prot uses %eax */
320 call EXT(real_to_prot)
332 * if there is a character pending, return it; otherwise return 0
333 * BIOS call "INT 18H Function 01H" to check whether a character is pending
334 * Call with %ah = 0x1
336 * If key waiting to be input:
337 * %ah = keyboard scan code
338 * %al = ASCII character
351 call EXT(prot_to_real) /* enter real mode */
365 call EXT(real_to_prot)
378 * get_diskinfo(): return a word that represents the
379 * max number of sectors and heads and drives for this device
389 mov 0x08(%ebp), %bl /* (byte) DA/UA */
391 call EXT(prot_to_real) /* enter real mode */
393 mov %bl, %al /* DA */
395 mov $18, %dl /* 1440KB FD sectors per track */
398 mov $15, %dl /* 1200KB FD sectors per track */
401 cmp $0xA0, %al /* SCSI HD or MO */
406 push %ds /* SCSI MO or CD ? */
409 and $0x0F, %bx /* UA */
410 shl $2, %bx /* parameter offset */
412 mov (%bx), %al /* SCSI equipment parameter[0] */
413 and $0x1F, %al /* peripheral device type */
414 cmp $7, %al /* SCSI MO */
417 mov (%bx), %al /* SCSI equipment parameter[3] */
418 test $0x30, %al /* sector length from 256 to 2048 */
420 or $0x10, %al /* forced set 512 bytes sector */
422 mov $0xA100, %dx /* refered by C language */
428 mov $0xFFFE, %cx /* virtual 65535 cylinders setting */
429 mov $0x0820, %dx /* standard 8 heads and 32 sectors */
432 mov $0x84, %ah /* ask for disk info */
435 jnc ok /* use %cx and %dx after */
437 * Urk. Call failed. It is not supported for floppies by old BIOS's.
438 * Guess it's a 15-sector floppy.
441 mov $79, %cx /* 80 cylinders 1200K and 1440K FD */
442 mov $2, %dh /* 2 heads as double side */
446 call EXT(real_to_prot) /* back to protected mode */
449 * form a longword representing all this gunk:
455 sal $16, %eax /* max cylinder number from zero */
456 mov %dx, %ax /* number of heads and sectors */
464 * memsize(i) : return the memory size in KB. i == 0 for conventional memory,
465 * i == 1 for extended memory
466 * Both have the return value in AX.
484 movb 0xA1401 - BOOTSEG * 0x10, %al
487 movw 0xA1594 - BOOTSEG * 0x10, %bx
493 movb 0xA1501 - BOOTSEG * 0x10, %al