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 $
28 * $DragonFly: src/sys/platform/pc32/boot/biosboot/Attic/bios.S,v 1.2 2003/06/17 04:28:34 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.
55 * Extensions for El Torito CD-ROM booting:
57 * Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
58 * Copyright © 1997 interface business GmbH, Dresden.
59 * All rights reserved.
61 * This code has been written by Jörg Wunsch, Dresden.
62 * Direct comments to <joerg_wunsch@interface-business.de>.
64 * Redistribution and use in source and binary forms, with or without
65 * modification, are permitted provided that the following conditions
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright
70 * notice, this list of conditions and the following disclaimer in the
71 * documentation and/or other materials provided with the distribution.
73 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
74 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
75 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
77 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
79 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
80 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
81 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
82 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
83 * POSSIBILITY OF SUCH DAMAGE.
95 * biosread(dev, cyl, head, sec, nsec, offset)
96 * Read "nsec" sectors from disk to offset "offset" in boot segment
97 * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
99 * %al = number of sectors
103 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
104 * %es:%bx = segment:offset of buffer
106 * %al = 0x0 on success; err code on failure
119 /* cylinder; the highest 2 bits of cyl is in %cl */
124 incb %cl /* sector; sec starts from 1, not 0 */
125 movb 0x8(%ebp), %dl /* device */
126 movl 0x1c(%ebp), %ebx /* offset */
128 /* prot_to_real will set %es to BOOTSEG */
129 call EXT(prot_to_real) /* enter real mode */
130 movb $0x2, %ah /* subfunction */
132 movb 0x18(%ebp), %al /* number of sectors */
138 /* save return value (actually movw %ax, %bx) */
142 call EXT(real_to_prot) /* back to protected mode */
145 movb %bh, %al /* return value in %ax */
159 * getbootspec(struct specpacket *offset)
161 * Read CD-ROM boot specification packet to "offset".
173 /* prot_to_real will set %es to BOOTSEG */
174 call EXT(prot_to_real) /* enter real mode */
175 movw $0x4b01, %ax /* (do not) terminate disk emulation */
176 movb $0x7f, %dl /* any drive */
182 /* save return value (actually movw %ax, %bx) */
186 call EXT(real_to_prot) /* back to protected mode */
189 movb %bh, %al /* return value in %ax */
200 * biosreadlba(struct daddrpacket *daddr)
201 * Read sectors using the BIOS "read extended" function
202 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
203 * Call with %ah = 0x42
204 * %dl = drive (0x0 for floppy disk, or emulated CD)
205 * %ds:%si = ptr to disk address packet
207 * %ah = 0x0 on success; err code on failure
218 movl $0, %edx /* emulated CD is always drive 0 */
220 /* prot_to_real will set %es to BOOTSEG */
221 call EXT(prot_to_real) /* enter real mode */
222 movw $0x4200, %ax /* subfunction */
229 /* save return value (actually movw %ax, %bx) */
233 call EXT(real_to_prot) /* back to protected mode */
236 movb %bh, %al /* return value in %ax */
248 * BIOS call "INT 10H Function 0Eh" to write character to console
249 * Call with %ah = 0x0e
252 * %bl = foreground color ( graphics modes)
265 call EXT(prot_to_real)
268 mov $0x1, %ebx /* %bh=0, %bl=1 (blue) */
272 int $0x10 /* display a byte */
276 call EXT(real_to_prot)
287 * BIOS call "INT 16H Function 00H" to read character from keyboard
288 * Call with %ah = 0x0
289 * Return: %ah = keyboard scan code
290 * %al = ASCII character
296 push %ebx /* save %ebx */
300 call EXT(prot_to_real)
307 movb %al, %bl /* real_to_prot uses %eax */
310 call EXT(real_to_prot)
322 * if there is a character pending, return it; otherwise return 0
323 * BIOS call "INT 16H Function 01H" to check whether a character is pending
324 * Call with %ah = 0x1
326 * If key waiting to be input:
327 * %ah = keyboard scan code
328 * %al = ASCII character
340 call EXT(prot_to_real) /* enter real mode */
353 call EXT(real_to_prot)
366 * get_diskinfo(): return a word that represents the
367 * max number of sectors and heads and drives for this device
378 movb 0x8(%ebp), %dl /* diskinfo(drive #) */
379 call EXT(prot_to_real) /* enter real mode */
381 movb $0x8, %ah /* ask for disk info */
389 * Urk. Call failed. It is not supported for floppies by old BIOS's.
390 * Guess it's a 15-sector floppy.
392 subb %ah, %ah /* %ax = 0 */
394 movb %ah, %bh /* %bh = 0 */
395 movb $2, %bl /* %bl bits 0-3 = drive type,
397 movb $79, %ch /* max track */
398 movb $15, %cl /* max sector */
399 movb $1, %dh /* max head */
400 movb $1, %dl /* # floppy drives installed */
401 /* es:di = parameter table */
406 call EXT(real_to_prot) /* back to protected mode */
409 * form a longword representing all this gunk:
411 * 10 bit max cylinder (0 based)
412 * 8 bit max head (0 based)
414 * 6 bit max sector (1 based) = # sectors
416 movb %cl, %al /* Upper two bits of cylinder count */
418 leal 0(,%eax,4),%eax /* << 2 */
419 movb %ch, %al /* Lower 8 bits */
420 sall $16,%eax /* << 16 */
421 movb %dh, %ah /* max head */
422 andb $0x3f, %cl /* mask of cylinder gunk */
423 movb %cl, %al /* max sector (and # sectors) */
433 * memsize(i) : return the memory size in KB. i == 0 for conventional memory,
434 * i == 1 for extended memory
435 * BIOS call "INT 12H" to get conventional memory size
436 * BIOS call "INT 15H, AH=88H" to get extended memory size
437 * Both have the return value in AX.
450 call EXT(prot_to_real) /* enter real mode */
462 xext: movb $0x88, %ah
468 pushl $0 /* actually pushw $0 */
469 pushl %eax /* actually pushw %ax */
472 call EXT(real_to_prot)