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/i386/boot/biosboot/bios.S,v 1.15 1999/08/28 00:43:11 peter Exp $
31 Copyright 1988, 1989, 1990, 1991, 1992
32 by Intel Corporation, Santa Clara, California.
36 Permission to use, copy, modify, and distribute this software and
37 its documentation for any purpose and without fee is hereby
38 granted, provided that the above copyright notice appears in all
39 copies and that both the copyright notice and this permission notice
40 appear in supporting documentation, and that the name of Intel
41 not be used in advertising or publicity pertaining to distribution
42 of the software without specific, written prior permission.
44 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
45 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
46 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
47 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
49 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54 * Extensions for El Torito CD-ROM booting:
56 * Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
57 * Copyright © 1997 interface business GmbH, Dresden.
58 * All rights reserved.
60 * This code has been written by Jörg Wunsch, Dresden.
61 * Direct comments to <joerg_wunsch@interface-business.de>.
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
66 * 1. Redistributions of source code must retain the above copyright
67 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in the
70 * documentation and/or other materials provided with the distribution.
72 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
73 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
74 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
75 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
76 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
77 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
78 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
81 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
82 * POSSIBILITY OF SUCH DAMAGE.
94 * biosread(dev, cyl, head, sec, nsec, offset)
95 * Read "nsec" sectors from disk to offset "offset" in boot segment
96 * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
98 * %al = number of sectors
102 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
103 * %es:%bx = segment:offset of buffer
105 * %al = 0x0 on success; err code on failure
118 /* cylinder; the highest 2 bits of cyl is in %cl */
123 incb %cl /* sector; sec starts from 1, not 0 */
124 movb 0x8(%ebp), %dl /* device */
125 movl 0x1c(%ebp), %ebx /* offset */
127 /* prot_to_real will set %es to BOOTSEG */
128 call EXT(prot_to_real) /* enter real mode */
129 movb $0x2, %ah /* subfunction */
131 movb 0x18(%ebp), %al /* number of sectors */
137 /* save return value (actually movw %ax, %bx) */
141 call EXT(real_to_prot) /* back to protected mode */
144 movb %bh, %al /* return value in %ax */
158 * getbootspec(struct specpacket *offset)
160 * Read CD-ROM boot specification packet to "offset".
172 /* prot_to_real will set %es to BOOTSEG */
173 call EXT(prot_to_real) /* enter real mode */
174 movw $0x4b01, %ax /* (do not) terminate disk emulation */
175 movb $0x7f, %dl /* any drive */
181 /* save return value (actually movw %ax, %bx) */
185 call EXT(real_to_prot) /* back to protected mode */
188 movb %bh, %al /* return value in %ax */
199 * biosreadlba(struct daddrpacket *daddr)
200 * Read sectors using the BIOS "read extended" function
201 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
202 * Call with %ah = 0x42
203 * %dl = drive (0x0 for floppy disk, or emulated CD)
204 * %ds:%si = ptr to disk address packet
206 * %ah = 0x0 on success; err code on failure
217 movl $0, %edx /* emulated CD is always drive 0 */
219 /* prot_to_real will set %es to BOOTSEG */
220 call EXT(prot_to_real) /* enter real mode */
221 movw $0x4200, %ax /* subfunction */
228 /* save return value (actually movw %ax, %bx) */
232 call EXT(real_to_prot) /* back to protected mode */
235 movb %bh, %al /* return value in %ax */
247 * BIOS call "INT 10H Function 0Eh" to write character to console
248 * Call with %ah = 0x0e
251 * %bl = foreground color ( graphics modes)
264 call EXT(prot_to_real)
267 mov $0x1, %ebx /* %bh=0, %bl=1 (blue) */
271 int $0x10 /* display a byte */
275 call EXT(real_to_prot)
286 * BIOS call "INT 16H Function 00H" to read character from keyboard
287 * Call with %ah = 0x0
288 * Return: %ah = keyboard scan code
289 * %al = ASCII character
295 push %ebx /* save %ebx */
299 call EXT(prot_to_real)
306 movb %al, %bl /* real_to_prot uses %eax */
309 call EXT(real_to_prot)
321 * if there is a character pending, return it; otherwise return 0
322 * BIOS call "INT 16H Function 01H" to check whether a character is pending
323 * Call with %ah = 0x1
325 * If key waiting to be input:
326 * %ah = keyboard scan code
327 * %al = ASCII character
339 call EXT(prot_to_real) /* enter real mode */
352 call EXT(real_to_prot)
365 * get_diskinfo(): return a word that represents the
366 * max number of sectors and heads and drives for this device
377 movb 0x8(%ebp), %dl /* diskinfo(drive #) */
378 call EXT(prot_to_real) /* enter real mode */
380 movb $0x8, %ah /* ask for disk info */
388 * Urk. Call failed. It is not supported for floppies by old BIOS's.
389 * Guess it's a 15-sector floppy.
391 subb %ah, %ah /* %ax = 0 */
393 movb %ah, %bh /* %bh = 0 */
394 movb $2, %bl /* %bl bits 0-3 = drive type,
396 movb $79, %ch /* max track */
397 movb $15, %cl /* max sector */
398 movb $1, %dh /* max head */
399 movb $1, %dl /* # floppy drives installed */
400 /* es:di = parameter table */
405 call EXT(real_to_prot) /* back to protected mode */
408 * form a longword representing all this gunk:
410 * 10 bit max cylinder (0 based)
411 * 8 bit max head (0 based)
413 * 6 bit max sector (1 based) = # sectors
415 movb %cl, %al /* Upper two bits of cylinder count */
417 leal 0(,%eax,4),%eax /* << 2 */
418 movb %ch, %al /* Lower 8 bits */
419 sall $16,%eax /* << 16 */
420 movb %dh, %ah /* max head */
421 andb $0x3f, %cl /* mask of cylinder gunk */
422 movb %cl, %al /* max sector (and # sectors) */
432 * memsize(i) : return the memory size in KB. i == 0 for conventional memory,
433 * i == 1 for extended memory
434 * BIOS call "INT 12H" to get conventional memory size
435 * BIOS call "INT 15H, AH=88H" to get extended memory size
436 * Both have the return value in AX.
449 call EXT(prot_to_real) /* enter real mode */
461 xext: movb $0x88, %ah
467 pushl $0 /* actually pushw $0 */
468 pushl %eax /* actually pushw %ax */
471 call EXT(real_to_prot)