Index: head/sys/i386/boot/Makefile =================================================================== --- head/sys/i386/boot/Makefile (revision 3292) +++ head/sys/i386/boot/Makefile (revision 3293) @@ -1,107 +1,50 @@ +# $Id$ # -# Permission to use, copy, modify and distribute this software and its -# documentation is hereby granted, provided that both the copyright -# notice and this permission notice appear in all copies of the -# software, derivative works or modified versions, and any portions -# thereof, and that both notices appear in supporting documentation. -# -# CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" -# CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR -# ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. -# -# Carnegie Mellon requests users of this software to return to -# -# Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU -# School of Computer Science -# Carnegie Mellon University -# Pittsburgh PA 15213-3890 -# -# any improvements or extensions that they make and grant Carnegie Mellon -# the rights to redistribute these changes. -# -# from: Mach, Revision 2.2 92/04/04 11:33:46 rpd -# $Id: Makefile,v 1.15 1994/09/19 19:54:49 adam Exp $ -# -wd0: - dd if=boot of=biosboot count=1 - dd if=boot of=bootbios skip=1 - disklabel -B -b biosboot -s bootbios wd0 - rm biosboot bootbios +PROG= boot +# Order is very important on the SRCS line for this prog +SRCS= start.S table.c boot2.S boot.c asm.S bios.S io.c disk.c sys.c -NOPROG= noprog -NOMAN= noman +BINDIR= /usr/mdec +BINMODE= 444 +CFLAGS+= -O2 -DDO_BAD144 -DBOOTWAIT=${BOOTWAIT} +CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../.. +CLEANFILES+= boot.nohdr boot.strip boot1 boot2 +DPADD= ${LIBC} +LDFLAGS+= -N -T 0 -nostdlib +LDADD= -lc +LINKS= ${BINDIR}/sdboot ${BINDIR}/wdboot\ + ${BINDIR}/sdboot ${BINDIR}/fdboot\ + ${BINDIR}/bootsd ${BINDIR}/bootwd\ + ${BINDIR}/bootsd ${BINDIR}/bootfd +NOSHARED= YES +NOMAN= +STRIP= # tunable timeout parameter, waiting for keypress, calibrated in mS BOOTWAIT?= 5000 - -CFLAGS = -O2 -DDO_BAD144 -DBOOTWAIT=${BOOTWAIT} -I${.CURDIR} -LIBS= -lc -INC= -I${.CURDIR}/../.. -# start.o should be first -OBJS = start.o table.o boot2.o boot.o asm.o bios.o io.o disk.o sys.o +boot.strip: boot + cp -p boot boot.strip + strip boot.strip + size boot.strip -.SUFFIXES: .S .c .o +boot.nohdr: boot.strip + dd if=boot.strip of=boot.nohdr ibs=32 skip=1 obs=1024b + ls -l boot.nohdr -.c.o: - $(CC) $(CFLAGS) $(INC) -c $< +boot1: boot.nohdr + dd if=boot.nohdr of=boot1 bs=512 count=1 -.S.o: - $(CC) $(CFLAGS) -c $< +boot2: boot.nohdr + dd if=boot.nohdr of=boot2 bs=512 skip=1 -boot: $(OBJS) - $(LD) -Bstatic -N -T 0 -o boot $(OBJS) ${LDDESTDIR} $(LIBS) - cp boot boot.sym - @strip boot - @size boot - @sh ${.CURDIR}/rmaouthdr boot boot.tmp - @mv -f boot.tmp boot - @ls -l boot +all: boot1 boot2 -biosboot: boot - dd if=boot of=biosboot count=1 - -bootbios: boot - dd if=boot of=bootbios skip=1 - -${DESTDIR}/usr/mdec/bootsd: bootbios - cp bootbios ${DESTDIR}/usr/mdec/bootsd - -${DESTDIR}/usr/mdec/sdboot: biosboot - cp biosboot ${DESTDIR}/usr/mdec/sdboot - -${DESTDIR}/usr/mdec/bootwd: ${DESTDIR}/usr/mdec/bootsd - rm -f ${DESTDIR}/usr/mdec/bootwd - ln ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/bootwd - -${DESTDIR}/usr/mdec/wdboot: ${DESTDIR}/usr/mdec/sdboot - rm -f ${DESTDIR}/usr/mdec/wdboot - ln ${DESTDIR}/usr/mdec/sdboot ${DESTDIR}/usr/mdec/wdboot - -${DESTDIR}/usr/mdec/bootfd: ${DESTDIR}/usr/mdec/bootsd - rm -f ${DESTDIR}/usr/mdec/bootfd - ln ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/bootfd - -${DESTDIR}/usr/mdec/fdboot: ${DESTDIR}/usr/mdec/sdboot - rm -f ${DESTDIR}/usr/mdec/fdboot - ln ${DESTDIR}/usr/mdec/sdboot ${DESTDIR}/usr/mdec/fdboot - -sd: ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/sdboot -wd: ${DESTDIR}/usr/mdec/bootwd ${DESTDIR}/usr/mdec/wdboot -fd: ${DESTDIR}/usr/mdec/bootfd ${DESTDIR}/usr/mdec/fdboot - -all: biosboot bootbios - -fd0: - dd if=boot of=biosboot count=1 - dd if=boot of=bootbios skip=1 - disklabel -B -b biosboot -s bootbios fd0 - rm biosboot bootbios - -install: wd sd fd - -clean: - /bin/rm -f *.o *.d boot bootbios biosboot boot.sym - +beforeinstall: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}\ + boot1 ${BINDIR}/sdboot + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}\ + boot2 ${BINDIR}/bootsd + .include Index: head/sys/i386/boot/asm.S =================================================================== --- head/sys/i386/boot/asm.S (revision 3292) +++ head/sys/i386/boot/asm.S (revision 3293) @@ -1,264 +1,268 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:34:13 rpd - * $Id: asm.S,v 1.2 1993/10/16 19:11:27 rgrimes Exp $ + * $Id: asm.S,v 1.3 1994/08/30 01:38:02 bde Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ .file "asm.s" #include "asm.h" CR0_PE_ON = 0x1 CR0_PE_OFF = 0xfffffffe .globl _ouraddr .text /* -# -# real_to_prot() -# transfer from real mode to protected mode. -*/ + * + * real_to_prot() + * transfer from real mode to protected mode. + */ ENTRY(real_to_prot) - # guarantee that interrupt is disabled when in prot mode + /* guarantee that interrupt is disabled when in prot mode */ cli - # load the gdtr + /* load the gdtr */ addr32 data32 lgdt EXT(Gdtr) - # set the PE bit of CR0 + /* set the PE bit of CR0 */ mov %cr0, %eax data32 or $CR0_PE_ON, %eax mov %eax, %cr0 - # make intrasegment jump to flush the processor pipeline and - # reload CS register + /* + * make intrasegment jump to flush the processor pipeline and + * reload CS register + */ data32 ljmp $0x18, $xprot xprot: - # we are in USE32 mode now - # set up the protected mode segment registers : DS, SS, ES + /* + * we are in USE32 mode now + * set up the protected mode segment registers : DS, SS, ES + */ mov $0x20, %eax movw %ax, %ds movw %ax, %ss movw %ax, %es #ifdef BDE_DEBUGGER - # load idtr so we can debug + /* load idtr so we can debug */ lidt EXT(Idtr_prot) #endif ret /* -# -# prot_to_real() -# transfer from protected mode to real mode -# -*/ + * + * prot_to_real() + * transfer from protected mode to real mode + * + */ ENTRY(prot_to_real) - # set up a dummy stack frame for the second seg change. + /* set up a dummy stack frame for the second seg change. */ movl _ouraddr, %eax sarl $4, %eax pushw %ax - movw $xreal, %ax # gas botches pushw $xreal - extra bytes 0, 0 - pushw %ax # decode to add %al, (%eax) (%al usually 0) + movw $xreal, %ax /* gas botches pushw $xreal, extra bytes 0, 0 */ + pushw %ax /* decode to add %al, (%eax) (%al usually 0) */ - # Change to use16 mode. + /* Change to use16 mode. */ ljmp $0x28, $x16 x16: - # clear the PE bit of CR0 + /* clear the PE bit of CR0 */ mov %cr0, %eax data32 and $CR0_PE_OFF, %eax mov %eax, %cr0 - # make intersegment jmp to flush the processor pipeline - # using the fake stack frame set up earlier - # and reload CS register + /* + * make intersegment jmp to flush the processor pipeline + * using the fake stack frame set up earlier + * and reload CS register + */ lret xreal: - # we are in real mode now - # set up the real mode segment registers : DS, SS, ES + /* + * we are in real mode now + * set up the real mode segment registers : DS, SS, ES + */ movw %cs, %ax movw %ax, %ds movw %ax, %ss movw %ax, %es #ifdef BDE_DEBUGGER - # load idtr so we can debug + /* load idtr so we can debug */ addr32 data32 lidt EXT(Idtr_real) #endif data32 ret /* -# -# startprog(phyaddr) -# start the program on protected mode where phyaddr is the entry point -# -*/ + * startprog(phyaddr) + * start the program on protected mode where phyaddr is the entry point + */ ENTRY(startprog) push %ebp mov %esp, %ebp - # get things we need into registers - movl 0x8(%ebp), %ecx # entry offset - movl 0x0c(%ebp), %eax # &argv + /* get things we need into registers */ + movl 0x8(%ebp), %ecx /* entry offset */ + movl 0x0c(%ebp), %eax /* &argv */ - # make a new stack at 0:0xa0000 (big segs) + /* make a new stack at 0:0xa0000 (big segs) */ mov $0x10, %ebx movw %bx, %ss movl $0xa0000, %ebx movl %ebx, %esp - # push some number of args onto the stack - pushl $0 # nominally a cyl offset in the boot. - pushl 0x8(%eax) # argv[2] = bootdev - pushl 0x4(%eax) # argv[1] = howto - pushl $0 # dummy 'return' address + /* push some number of args onto the stack */ + pushl $0 /* was a cyl offset in the boot. */ + pushl 0x8(%eax) /* argv[2] = bootdev */ + pushl 0x4(%eax) /* argv[1] = howto */ + pushl $0 /* dummy 'return' address */ - # push on our entry address - mov $0x08, %ebx # segment + /* push on our entry address */ + mov $0x08, %ebx /* segment */ pushl %ebx pushl %ecx - # convert over the other data segs + /* convert over the other data segs */ mov $0x10, %ebx movw %bx, %ds movw %bx, %es - # convert the PC (and code seg) + /* convert the PC (and code seg) */ lret /* -# -# pbzero( dst, cnt) -# where src is a virtual address and dst is a physical address -*/ + * + * pbzero( dst, cnt) + * where src is a virtual address and dst is a physical address + */ ENTRY(pbzero) push %ebp mov %esp, %ebp push %es push %esi push %edi push %ecx cld - # set %es to point at the flat segment + /* set %es to point at the flat segment */ mov $0x10, %eax movw %ax, %es - mov 0x8(%ebp), %edi # destination - mov 0xc(%ebp), %ecx # count - mov $0x0, %eax # value + mov 0x8(%ebp), %edi /* destination */ + mov 0xc(%ebp), %ecx /* count */ + mov $0x0, %eax /* value */ rep stosb pop %ecx pop %edi pop %esi pop %es pop %ebp ret /* -# -# pcpy(src, dst, cnt) -# where src is a virtual address and dst is a physical address -# -*/ + * pcpy(src, dst, cnt) + * where src is a virtual address and dst is a physical address + */ ENTRY(pcpy) push %ebp mov %esp, %ebp push %es push %esi push %edi push %ecx cld - # set %es to point at the flat segment + /* set %es to point at the flat segment */ mov $0x10, %eax movw %ax, %es - mov 0x8(%ebp), %esi # source - mov 0xc(%ebp), %edi # destination - mov 0x10(%ebp), %ecx # count + mov 0x8(%ebp), %esi /* source */ + mov 0xc(%ebp), %edi /* destination */ + mov 0x10(%ebp), %ecx /* count */ rep movsb pop %ecx pop %edi pop %esi pop %es pop %ebp ret Index: head/sys/i386/boot/bios.S =================================================================== --- head/sys/i386/boot/bios.S (revision 3292) +++ head/sys/i386/boot/bios.S (revision 3293) @@ -1,329 +1,332 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:34:26 rpd - * $Id$ + * $Id: bios.S,v 1.2 1993/10/16 19:11:30 rgrimes Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ .file "bios.s" #include "asm.h" .text /* -# biosread(dev, cyl, head, sec, nsec, offset) -# Read "nsec" sectors from disk to offset "offset" in boot segment -# BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory -# Call with %ah = 0x2 -# %al = number of sectors -# %ch = cylinder -# %cl = sector -# %dh = head -# %dl = drive (0x80 for hard disk, 0x0 for floppy disk) -# %es:%bx = segment:offset of buffer -# Return: -# %al = 0x0 on success; err code on failure -*/ + * biosread(dev, cyl, head, sec, nsec, offset) + * Read "nsec" sectors from disk to offset "offset" in boot segment + * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory + * Call with %ah = 0x2 + * %al = number of sectors + * %ch = cylinder + * %cl = sector + * %dh = head + * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) + * %es:%bx = segment:offset of buffer + * Return: + * %al = 0x0 on success; err code on failure + */ ENTRY(biosread) push %ebp mov %esp, %ebp push %ebx push %ecx push %edx push %es movb 0x10(%ebp), %dh movw 0x0c(%ebp), %cx - xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl + /* cylinder; the highest 2 bits of cyl is in %cl */ + xchgb %ch, %cl rorb $2, %cl movb 0x14(%ebp), %al orb %al, %cl - incb %cl # sector; sec starts from 1, not 0 - movb 0x8(%ebp), %dl # device - movl 0x1c(%ebp), %ebx # offset - # prot_to_real will set %es to BOOTSEG + incb %cl /* sector; sec starts from 1, not 0 */ + movb 0x8(%ebp), %dl /* device */ + movl 0x1c(%ebp), %ebx /* offset */ - call EXT(prot_to_real) # enter real mode - movb $0x2, %ah # subfunction + /* prot_to_real will set %es to BOOTSEG */ + call EXT(prot_to_real) /* enter real mode */ + movb $0x2, %ah /* subfunction */ addr32 - movb 0x18(%ebp), %al # number of sectors + movb 0x18(%ebp), %al /* number of sectors */ sti int $0x13 cli - mov %eax, %ebx # save return value (actually movw %ax, %bx) + /* save return value (actually movw %ax, %bx) */ + mov %eax, %ebx data32 - call EXT(real_to_prot) # back to protected mode + call EXT(real_to_prot) /* back to protected mode */ xor %eax, %eax - movb %bh, %al # return value in %ax + movb %bh, %al /* return value in %ax */ pop %es pop %edx pop %ecx pop %ebx pop %ebp ret /* -# putc(ch) -# BIOS call "INT 10H Function 0Eh" to write character to console -# Call with %ah = 0x0e -# %al = character -# %bh = page -# %bl = foreground color ( graphics modes) -*/ + * putc(ch) + * BIOS call "INT 10H Function 0Eh" to write character to console + * Call with %ah = 0x0e + * %al = character + * %bh = page + * %bl = foreground color ( graphics modes) + */ ENTRY(putc) push %ebp mov %esp, %ebp push %ebx push %ecx movb 0x8(%ebp), %cl call EXT(prot_to_real) data32 - mov $0x1, %ebx # %bh=0, %bl=1 (blue) + mov $0x1, %ebx /* %bh=0, %bl=1 (blue) */ movb $0xe, %ah movb %cl, %al sti - int $0x10 # display a byte + int $0x10 /* display a byte */ cli data32 call EXT(real_to_prot) pop %ecx pop %ebx pop %ebp ret /* -# getc() -# BIOS call "INT 16H Function 00H" to read character from keyboard -# Call with %ah = 0x0 -# Return: %ah = keyboard scan code -# %al = ASCII character -*/ + * getc() + * BIOS call "INT 16H Function 00H" to read character from keyboard + * Call with %ah = 0x0 + * Return: %ah = keyboard scan code + * %al = ASCII character + */ ENTRY(getc) push %ebp mov %esp, %ebp - push %ebx # save %ebx + push %ebx /* save %ebx */ call EXT(prot_to_real) movb $0x0, %ah sti int $0x16 cli - movb %al, %bl # real_to_prot uses %eax + movb %al, %bl /* real_to_prot uses %eax */ data32 call EXT(real_to_prot) xor %eax, %eax movb %bl, %al pop %ebx pop %ebp ret /* -# ischar() -# if there is a character pending, return it; otherwise return 0 -# BIOS call "INT 16H Function 01H" to check whether a character is pending -# Call with %ah = 0x1 -# Return: -# If key waiting to be input: -# %ah = keyboard scan code -# %al = ASCII character -# Zero flag = clear -# else -# Zero flag = set -*/ + * ischar() + * if there is a character pending, return it; otherwise return 0 + * BIOS call "INT 16H Function 01H" to check whether a character is pending + * Call with %ah = 0x1 + * Return: + * If key waiting to be input: + * %ah = keyboard scan code + * %al = ASCII character + * Zero flag = clear + * else + * Zero flag = set + */ ENTRY(ischar) push %ebp mov %esp, %ebp push %ebx - call EXT(prot_to_real) # enter real mode + call EXT(prot_to_real) /* enter real mode */ xor %ebx, %ebx movb $0x1, %ah sti int $0x16 cli data32 jz nochar movb %al, %bl nochar: data32 call EXT(real_to_prot) xor %eax, %eax movb %bl, %al pop %ebx pop %ebp ret /* -# -# get_diskinfo(): return a word that represents the -# max number of sectors and heads and drives for this device -# -*/ + * + * get_diskinfo(): return a word that represents the + * max number of sectors and heads and drives for this device + * + */ ENTRY(get_diskinfo) push %ebp mov %esp, %ebp push %es push %ebx push %ecx push %edx - movb 0x8(%ebp), %dl # diskinfo(drive #) - call EXT(prot_to_real) # enter real mode + movb 0x8(%ebp), %dl /* diskinfo(drive #) */ + call EXT(prot_to_real) /* enter real mode */ - movb $0x8, %ah # ask for disk info + movb $0x8, %ah /* ask for disk info */ sti int $0x13 cli jnc ok /* * Urk. Call failed. It is not supported for floppies by old BIOS's. * Guess it's a 15-sector floppy. Initialize all the registers for * documentation, although we only need head and sector counts. */ - subb %ah, %ah # %ax = 0 + subb %ah, %ah /* %ax = 0 */ movb %al, %al - movb %ah, %bh # %bh = 0 - movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M - movb $79, %ch # max track - movb $15, %cl # max sector - movb $1, %dh # max head - movb $1, %dl # # floppy drives installed - # es:di = parameter table - # carry = 0 + movb %ah, %bh /* %bh = 0 */ + movb $2, %bl /* %bl bits 0-3 = drive type, + bit 2 = 1.2M */ + movb $79, %ch /* max track */ + movb $15, %cl /* max sector */ + movb $1, %dh /* max head */ + movb $1, %dl /* # floppy drives installed */ + /* es:di = parameter table */ + /* carry = 0 */ ok: data32 - call EXT(real_to_prot) # back to protected mode + call EXT(real_to_prot) /* back to protected mode */ xor %eax, %eax - /*form a longword representing all this gunk*/ - movb %dh, %ah # max head - andb $0x3f, %cl # mask of cylinder gunk - movb %cl, %al # max sector (and # sectors) + /* form a longword representing all this gunk */ + movb %dh, %ah /* max head */ + andb $0x3f, %cl /* mask of cylinder gunk */ + movb %cl, %al /* max sector (and # sectors) */ pop %edx pop %ecx pop %ebx pop %es pop %ebp ret /* -# -# memsize(i) : return the memory size in KB. i == 0 for conventional memory, -# i == 1 for extended memory -# BIOS call "INT 12H" to get conventional memory size -# BIOS call "INT 15H, AH=88H" to get extended memory size -# Both have the return value in AX. -# -*/ + * + * memsize(i) : return the memory size in KB. i == 0 for conventional memory, + * i == 1 for extended memory + * BIOS call "INT 12H" to get conventional memory size + * BIOS call "INT 15H, AH=88H" to get extended memory size + * Both have the return value in AX. + * + */ ENTRY(memsize) push %ebp mov %esp, %ebp push %ebx mov 8(%ebp), %ebx - call EXT(prot_to_real) # enter real mode + call EXT(prot_to_real) /* enter real mode */ cmpb $0x1, %bl data32 je xext sti int $0x12 cli data32 jmp xdone xext: movb $0x88, %ah sti int $0x15 cli xdone: mov %eax, %ebx data32 call EXT(real_to_prot) mov %ebx, %eax pop %ebx pop %ebp ret Index: head/sys/i386/boot/biosboot/Makefile =================================================================== --- head/sys/i386/boot/biosboot/Makefile (revision 3292) +++ head/sys/i386/boot/biosboot/Makefile (revision 3293) @@ -1,107 +1,50 @@ +# $Id$ # -# Permission to use, copy, modify and distribute this software and its -# documentation is hereby granted, provided that both the copyright -# notice and this permission notice appear in all copies of the -# software, derivative works or modified versions, and any portions -# thereof, and that both notices appear in supporting documentation. -# -# CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" -# CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR -# ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. -# -# Carnegie Mellon requests users of this software to return to -# -# Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU -# School of Computer Science -# Carnegie Mellon University -# Pittsburgh PA 15213-3890 -# -# any improvements or extensions that they make and grant Carnegie Mellon -# the rights to redistribute these changes. -# -# from: Mach, Revision 2.2 92/04/04 11:33:46 rpd -# $Id: Makefile,v 1.15 1994/09/19 19:54:49 adam Exp $ -# -wd0: - dd if=boot of=biosboot count=1 - dd if=boot of=bootbios skip=1 - disklabel -B -b biosboot -s bootbios wd0 - rm biosboot bootbios +PROG= boot +# Order is very important on the SRCS line for this prog +SRCS= start.S table.c boot2.S boot.c asm.S bios.S io.c disk.c sys.c -NOPROG= noprog -NOMAN= noman +BINDIR= /usr/mdec +BINMODE= 444 +CFLAGS+= -O2 -DDO_BAD144 -DBOOTWAIT=${BOOTWAIT} +CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../.. +CLEANFILES+= boot.nohdr boot.strip boot1 boot2 +DPADD= ${LIBC} +LDFLAGS+= -N -T 0 -nostdlib +LDADD= -lc +LINKS= ${BINDIR}/sdboot ${BINDIR}/wdboot\ + ${BINDIR}/sdboot ${BINDIR}/fdboot\ + ${BINDIR}/bootsd ${BINDIR}/bootwd\ + ${BINDIR}/bootsd ${BINDIR}/bootfd +NOSHARED= YES +NOMAN= +STRIP= # tunable timeout parameter, waiting for keypress, calibrated in mS BOOTWAIT?= 5000 - -CFLAGS = -O2 -DDO_BAD144 -DBOOTWAIT=${BOOTWAIT} -I${.CURDIR} -LIBS= -lc -INC= -I${.CURDIR}/../.. -# start.o should be first -OBJS = start.o table.o boot2.o boot.o asm.o bios.o io.o disk.o sys.o +boot.strip: boot + cp -p boot boot.strip + strip boot.strip + size boot.strip -.SUFFIXES: .S .c .o +boot.nohdr: boot.strip + dd if=boot.strip of=boot.nohdr ibs=32 skip=1 obs=1024b + ls -l boot.nohdr -.c.o: - $(CC) $(CFLAGS) $(INC) -c $< +boot1: boot.nohdr + dd if=boot.nohdr of=boot1 bs=512 count=1 -.S.o: - $(CC) $(CFLAGS) -c $< +boot2: boot.nohdr + dd if=boot.nohdr of=boot2 bs=512 skip=1 -boot: $(OBJS) - $(LD) -Bstatic -N -T 0 -o boot $(OBJS) ${LDDESTDIR} $(LIBS) - cp boot boot.sym - @strip boot - @size boot - @sh ${.CURDIR}/rmaouthdr boot boot.tmp - @mv -f boot.tmp boot - @ls -l boot +all: boot1 boot2 -biosboot: boot - dd if=boot of=biosboot count=1 - -bootbios: boot - dd if=boot of=bootbios skip=1 - -${DESTDIR}/usr/mdec/bootsd: bootbios - cp bootbios ${DESTDIR}/usr/mdec/bootsd - -${DESTDIR}/usr/mdec/sdboot: biosboot - cp biosboot ${DESTDIR}/usr/mdec/sdboot - -${DESTDIR}/usr/mdec/bootwd: ${DESTDIR}/usr/mdec/bootsd - rm -f ${DESTDIR}/usr/mdec/bootwd - ln ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/bootwd - -${DESTDIR}/usr/mdec/wdboot: ${DESTDIR}/usr/mdec/sdboot - rm -f ${DESTDIR}/usr/mdec/wdboot - ln ${DESTDIR}/usr/mdec/sdboot ${DESTDIR}/usr/mdec/wdboot - -${DESTDIR}/usr/mdec/bootfd: ${DESTDIR}/usr/mdec/bootsd - rm -f ${DESTDIR}/usr/mdec/bootfd - ln ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/bootfd - -${DESTDIR}/usr/mdec/fdboot: ${DESTDIR}/usr/mdec/sdboot - rm -f ${DESTDIR}/usr/mdec/fdboot - ln ${DESTDIR}/usr/mdec/sdboot ${DESTDIR}/usr/mdec/fdboot - -sd: ${DESTDIR}/usr/mdec/bootsd ${DESTDIR}/usr/mdec/sdboot -wd: ${DESTDIR}/usr/mdec/bootwd ${DESTDIR}/usr/mdec/wdboot -fd: ${DESTDIR}/usr/mdec/bootfd ${DESTDIR}/usr/mdec/fdboot - -all: biosboot bootbios - -fd0: - dd if=boot of=biosboot count=1 - dd if=boot of=bootbios skip=1 - disklabel -B -b biosboot -s bootbios fd0 - rm biosboot bootbios - -install: wd sd fd - -clean: - /bin/rm -f *.o *.d boot bootbios biosboot boot.sym - +beforeinstall: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}\ + boot1 ${BINDIR}/sdboot + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}\ + boot2 ${BINDIR}/bootsd + .include Index: head/sys/i386/boot/biosboot/asm.S =================================================================== --- head/sys/i386/boot/biosboot/asm.S (revision 3292) +++ head/sys/i386/boot/biosboot/asm.S (revision 3293) @@ -1,264 +1,268 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:34:13 rpd - * $Id: asm.S,v 1.2 1993/10/16 19:11:27 rgrimes Exp $ + * $Id: asm.S,v 1.3 1994/08/30 01:38:02 bde Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ .file "asm.s" #include "asm.h" CR0_PE_ON = 0x1 CR0_PE_OFF = 0xfffffffe .globl _ouraddr .text /* -# -# real_to_prot() -# transfer from real mode to protected mode. -*/ + * + * real_to_prot() + * transfer from real mode to protected mode. + */ ENTRY(real_to_prot) - # guarantee that interrupt is disabled when in prot mode + /* guarantee that interrupt is disabled when in prot mode */ cli - # load the gdtr + /* load the gdtr */ addr32 data32 lgdt EXT(Gdtr) - # set the PE bit of CR0 + /* set the PE bit of CR0 */ mov %cr0, %eax data32 or $CR0_PE_ON, %eax mov %eax, %cr0 - # make intrasegment jump to flush the processor pipeline and - # reload CS register + /* + * make intrasegment jump to flush the processor pipeline and + * reload CS register + */ data32 ljmp $0x18, $xprot xprot: - # we are in USE32 mode now - # set up the protected mode segment registers : DS, SS, ES + /* + * we are in USE32 mode now + * set up the protected mode segment registers : DS, SS, ES + */ mov $0x20, %eax movw %ax, %ds movw %ax, %ss movw %ax, %es #ifdef BDE_DEBUGGER - # load idtr so we can debug + /* load idtr so we can debug */ lidt EXT(Idtr_prot) #endif ret /* -# -# prot_to_real() -# transfer from protected mode to real mode -# -*/ + * + * prot_to_real() + * transfer from protected mode to real mode + * + */ ENTRY(prot_to_real) - # set up a dummy stack frame for the second seg change. + /* set up a dummy stack frame for the second seg change. */ movl _ouraddr, %eax sarl $4, %eax pushw %ax - movw $xreal, %ax # gas botches pushw $xreal - extra bytes 0, 0 - pushw %ax # decode to add %al, (%eax) (%al usually 0) + movw $xreal, %ax /* gas botches pushw $xreal, extra bytes 0, 0 */ + pushw %ax /* decode to add %al, (%eax) (%al usually 0) */ - # Change to use16 mode. + /* Change to use16 mode. */ ljmp $0x28, $x16 x16: - # clear the PE bit of CR0 + /* clear the PE bit of CR0 */ mov %cr0, %eax data32 and $CR0_PE_OFF, %eax mov %eax, %cr0 - # make intersegment jmp to flush the processor pipeline - # using the fake stack frame set up earlier - # and reload CS register + /* + * make intersegment jmp to flush the processor pipeline + * using the fake stack frame set up earlier + * and reload CS register + */ lret xreal: - # we are in real mode now - # set up the real mode segment registers : DS, SS, ES + /* + * we are in real mode now + * set up the real mode segment registers : DS, SS, ES + */ movw %cs, %ax movw %ax, %ds movw %ax, %ss movw %ax, %es #ifdef BDE_DEBUGGER - # load idtr so we can debug + /* load idtr so we can debug */ addr32 data32 lidt EXT(Idtr_real) #endif data32 ret /* -# -# startprog(phyaddr) -# start the program on protected mode where phyaddr is the entry point -# -*/ + * startprog(phyaddr) + * start the program on protected mode where phyaddr is the entry point + */ ENTRY(startprog) push %ebp mov %esp, %ebp - # get things we need into registers - movl 0x8(%ebp), %ecx # entry offset - movl 0x0c(%ebp), %eax # &argv + /* get things we need into registers */ + movl 0x8(%ebp), %ecx /* entry offset */ + movl 0x0c(%ebp), %eax /* &argv */ - # make a new stack at 0:0xa0000 (big segs) + /* make a new stack at 0:0xa0000 (big segs) */ mov $0x10, %ebx movw %bx, %ss movl $0xa0000, %ebx movl %ebx, %esp - # push some number of args onto the stack - pushl $0 # nominally a cyl offset in the boot. - pushl 0x8(%eax) # argv[2] = bootdev - pushl 0x4(%eax) # argv[1] = howto - pushl $0 # dummy 'return' address + /* push some number of args onto the stack */ + pushl $0 /* was a cyl offset in the boot. */ + pushl 0x8(%eax) /* argv[2] = bootdev */ + pushl 0x4(%eax) /* argv[1] = howto */ + pushl $0 /* dummy 'return' address */ - # push on our entry address - mov $0x08, %ebx # segment + /* push on our entry address */ + mov $0x08, %ebx /* segment */ pushl %ebx pushl %ecx - # convert over the other data segs + /* convert over the other data segs */ mov $0x10, %ebx movw %bx, %ds movw %bx, %es - # convert the PC (and code seg) + /* convert the PC (and code seg) */ lret /* -# -# pbzero( dst, cnt) -# where src is a virtual address and dst is a physical address -*/ + * + * pbzero( dst, cnt) + * where src is a virtual address and dst is a physical address + */ ENTRY(pbzero) push %ebp mov %esp, %ebp push %es push %esi push %edi push %ecx cld - # set %es to point at the flat segment + /* set %es to point at the flat segment */ mov $0x10, %eax movw %ax, %es - mov 0x8(%ebp), %edi # destination - mov 0xc(%ebp), %ecx # count - mov $0x0, %eax # value + mov 0x8(%ebp), %edi /* destination */ + mov 0xc(%ebp), %ecx /* count */ + mov $0x0, %eax /* value */ rep stosb pop %ecx pop %edi pop %esi pop %es pop %ebp ret /* -# -# pcpy(src, dst, cnt) -# where src is a virtual address and dst is a physical address -# -*/ + * pcpy(src, dst, cnt) + * where src is a virtual address and dst is a physical address + */ ENTRY(pcpy) push %ebp mov %esp, %ebp push %es push %esi push %edi push %ecx cld - # set %es to point at the flat segment + /* set %es to point at the flat segment */ mov $0x10, %eax movw %ax, %es - mov 0x8(%ebp), %esi # source - mov 0xc(%ebp), %edi # destination - mov 0x10(%ebp), %ecx # count + mov 0x8(%ebp), %esi /* source */ + mov 0xc(%ebp), %edi /* destination */ + mov 0x10(%ebp), %ecx /* count */ rep movsb pop %ecx pop %edi pop %esi pop %es pop %ebp ret Index: head/sys/i386/boot/biosboot/bios.S =================================================================== --- head/sys/i386/boot/biosboot/bios.S (revision 3292) +++ head/sys/i386/boot/biosboot/bios.S (revision 3293) @@ -1,329 +1,332 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:34:26 rpd - * $Id$ + * $Id: bios.S,v 1.2 1993/10/16 19:11:30 rgrimes Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ .file "bios.s" #include "asm.h" .text /* -# biosread(dev, cyl, head, sec, nsec, offset) -# Read "nsec" sectors from disk to offset "offset" in boot segment -# BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory -# Call with %ah = 0x2 -# %al = number of sectors -# %ch = cylinder -# %cl = sector -# %dh = head -# %dl = drive (0x80 for hard disk, 0x0 for floppy disk) -# %es:%bx = segment:offset of buffer -# Return: -# %al = 0x0 on success; err code on failure -*/ + * biosread(dev, cyl, head, sec, nsec, offset) + * Read "nsec" sectors from disk to offset "offset" in boot segment + * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory + * Call with %ah = 0x2 + * %al = number of sectors + * %ch = cylinder + * %cl = sector + * %dh = head + * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) + * %es:%bx = segment:offset of buffer + * Return: + * %al = 0x0 on success; err code on failure + */ ENTRY(biosread) push %ebp mov %esp, %ebp push %ebx push %ecx push %edx push %es movb 0x10(%ebp), %dh movw 0x0c(%ebp), %cx - xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl + /* cylinder; the highest 2 bits of cyl is in %cl */ + xchgb %ch, %cl rorb $2, %cl movb 0x14(%ebp), %al orb %al, %cl - incb %cl # sector; sec starts from 1, not 0 - movb 0x8(%ebp), %dl # device - movl 0x1c(%ebp), %ebx # offset - # prot_to_real will set %es to BOOTSEG + incb %cl /* sector; sec starts from 1, not 0 */ + movb 0x8(%ebp), %dl /* device */ + movl 0x1c(%ebp), %ebx /* offset */ - call EXT(prot_to_real) # enter real mode - movb $0x2, %ah # subfunction + /* prot_to_real will set %es to BOOTSEG */ + call EXT(prot_to_real) /* enter real mode */ + movb $0x2, %ah /* subfunction */ addr32 - movb 0x18(%ebp), %al # number of sectors + movb 0x18(%ebp), %al /* number of sectors */ sti int $0x13 cli - mov %eax, %ebx # save return value (actually movw %ax, %bx) + /* save return value (actually movw %ax, %bx) */ + mov %eax, %ebx data32 - call EXT(real_to_prot) # back to protected mode + call EXT(real_to_prot) /* back to protected mode */ xor %eax, %eax - movb %bh, %al # return value in %ax + movb %bh, %al /* return value in %ax */ pop %es pop %edx pop %ecx pop %ebx pop %ebp ret /* -# putc(ch) -# BIOS call "INT 10H Function 0Eh" to write character to console -# Call with %ah = 0x0e -# %al = character -# %bh = page -# %bl = foreground color ( graphics modes) -*/ + * putc(ch) + * BIOS call "INT 10H Function 0Eh" to write character to console + * Call with %ah = 0x0e + * %al = character + * %bh = page + * %bl = foreground color ( graphics modes) + */ ENTRY(putc) push %ebp mov %esp, %ebp push %ebx push %ecx movb 0x8(%ebp), %cl call EXT(prot_to_real) data32 - mov $0x1, %ebx # %bh=0, %bl=1 (blue) + mov $0x1, %ebx /* %bh=0, %bl=1 (blue) */ movb $0xe, %ah movb %cl, %al sti - int $0x10 # display a byte + int $0x10 /* display a byte */ cli data32 call EXT(real_to_prot) pop %ecx pop %ebx pop %ebp ret /* -# getc() -# BIOS call "INT 16H Function 00H" to read character from keyboard -# Call with %ah = 0x0 -# Return: %ah = keyboard scan code -# %al = ASCII character -*/ + * getc() + * BIOS call "INT 16H Function 00H" to read character from keyboard + * Call with %ah = 0x0 + * Return: %ah = keyboard scan code + * %al = ASCII character + */ ENTRY(getc) push %ebp mov %esp, %ebp - push %ebx # save %ebx + push %ebx /* save %ebx */ call EXT(prot_to_real) movb $0x0, %ah sti int $0x16 cli - movb %al, %bl # real_to_prot uses %eax + movb %al, %bl /* real_to_prot uses %eax */ data32 call EXT(real_to_prot) xor %eax, %eax movb %bl, %al pop %ebx pop %ebp ret /* -# ischar() -# if there is a character pending, return it; otherwise return 0 -# BIOS call "INT 16H Function 01H" to check whether a character is pending -# Call with %ah = 0x1 -# Return: -# If key waiting to be input: -# %ah = keyboard scan code -# %al = ASCII character -# Zero flag = clear -# else -# Zero flag = set -*/ + * ischar() + * if there is a character pending, return it; otherwise return 0 + * BIOS call "INT 16H Function 01H" to check whether a character is pending + * Call with %ah = 0x1 + * Return: + * If key waiting to be input: + * %ah = keyboard scan code + * %al = ASCII character + * Zero flag = clear + * else + * Zero flag = set + */ ENTRY(ischar) push %ebp mov %esp, %ebp push %ebx - call EXT(prot_to_real) # enter real mode + call EXT(prot_to_real) /* enter real mode */ xor %ebx, %ebx movb $0x1, %ah sti int $0x16 cli data32 jz nochar movb %al, %bl nochar: data32 call EXT(real_to_prot) xor %eax, %eax movb %bl, %al pop %ebx pop %ebp ret /* -# -# get_diskinfo(): return a word that represents the -# max number of sectors and heads and drives for this device -# -*/ + * + * get_diskinfo(): return a word that represents the + * max number of sectors and heads and drives for this device + * + */ ENTRY(get_diskinfo) push %ebp mov %esp, %ebp push %es push %ebx push %ecx push %edx - movb 0x8(%ebp), %dl # diskinfo(drive #) - call EXT(prot_to_real) # enter real mode + movb 0x8(%ebp), %dl /* diskinfo(drive #) */ + call EXT(prot_to_real) /* enter real mode */ - movb $0x8, %ah # ask for disk info + movb $0x8, %ah /* ask for disk info */ sti int $0x13 cli jnc ok /* * Urk. Call failed. It is not supported for floppies by old BIOS's. * Guess it's a 15-sector floppy. Initialize all the registers for * documentation, although we only need head and sector counts. */ - subb %ah, %ah # %ax = 0 + subb %ah, %ah /* %ax = 0 */ movb %al, %al - movb %ah, %bh # %bh = 0 - movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M - movb $79, %ch # max track - movb $15, %cl # max sector - movb $1, %dh # max head - movb $1, %dl # # floppy drives installed - # es:di = parameter table - # carry = 0 + movb %ah, %bh /* %bh = 0 */ + movb $2, %bl /* %bl bits 0-3 = drive type, + bit 2 = 1.2M */ + movb $79, %ch /* max track */ + movb $15, %cl /* max sector */ + movb $1, %dh /* max head */ + movb $1, %dl /* # floppy drives installed */ + /* es:di = parameter table */ + /* carry = 0 */ ok: data32 - call EXT(real_to_prot) # back to protected mode + call EXT(real_to_prot) /* back to protected mode */ xor %eax, %eax - /*form a longword representing all this gunk*/ - movb %dh, %ah # max head - andb $0x3f, %cl # mask of cylinder gunk - movb %cl, %al # max sector (and # sectors) + /* form a longword representing all this gunk */ + movb %dh, %ah /* max head */ + andb $0x3f, %cl /* mask of cylinder gunk */ + movb %cl, %al /* max sector (and # sectors) */ pop %edx pop %ecx pop %ebx pop %es pop %ebp ret /* -# -# memsize(i) : return the memory size in KB. i == 0 for conventional memory, -# i == 1 for extended memory -# BIOS call "INT 12H" to get conventional memory size -# BIOS call "INT 15H, AH=88H" to get extended memory size -# Both have the return value in AX. -# -*/ + * + * memsize(i) : return the memory size in KB. i == 0 for conventional memory, + * i == 1 for extended memory + * BIOS call "INT 12H" to get conventional memory size + * BIOS call "INT 15H, AH=88H" to get extended memory size + * Both have the return value in AX. + * + */ ENTRY(memsize) push %ebp mov %esp, %ebp push %ebx mov 8(%ebp), %ebx - call EXT(prot_to_real) # enter real mode + call EXT(prot_to_real) /* enter real mode */ cmpb $0x1, %bl data32 je xext sti int $0x12 cli data32 jmp xdone xext: movb $0x88, %ah sti int $0x15 cli xdone: mov %eax, %ebx data32 call EXT(real_to_prot) mov %ebx, %eax pop %ebx pop %ebp ret Index: head/sys/i386/boot/biosboot/start.S =================================================================== --- head/sys/i386/boot/biosboot/start.S (revision 3292) +++ head/sys/i386/boot/biosboot/start.S (revision 3293) @@ -1,292 +1,294 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:36:29 rpd - * $Id: start.S,v 1.2 1993/10/16 19:11:38 rgrimes Exp $ + * $Id: start.S,v 1.3 1994/06/13 19:27:52 jkh Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "asm.h" .file "start.s" -BOOTSEG = 0x9000 # boot will be loaded here (below 640K) -BOOTSTACK = 0xe000 # boot stack -SIGNATURE = 0xaa55 -LOADSZ = 15 # size of unix boot -PARTSTART = 0x1be # starting address of partition table -NUMPART = 4 # number of partitions in partition table -PARTSZ = 16 # each partition table entry is 16 bytes -BSDPART = 0xA5 # value of boot_ind, means bootable partition -BOOTABLE = 0x80 # value of boot_ind, means bootable partition +BOOTSEG= 0x9000 /* boot will be loaded here (below 640K) */ +BOOTSTACK= 0xe000 /* boot stack */ +SIGNATURE= 0xaa55 +LOADSZ= 15 /* size of unix boot */ +PARTSTART= 0x1be /* starting address of partition table */ +NUMPART= 4 /* number of partitions in partition table */ +PARTSZ= 16 /* each partition table entry is 16 bytes */ +BSDPART= 0xA5 /* value of boot_ind, means bootable partition */ +BOOTABLE= 0x80 /* value of boot_ind, means bootable partition */ .text ENTRY(boot1) - # start (aka boot1) is loaded at 0x0:0x7c00 but we want 0x7c0:0 - # ljmp to the next instruction to adjust %cs + /* + * start (aka boot1) is loaded at 0x0:0x7c00 but we want 0x7c0:0 + * ljmp to the next instruction to adjust %cs + */ data32 ljmp $0x7c0, $start start: - # set up %ds + /* set up %ds */ mov %cs, %ax mov %ax, %ds - # set up %ss and %esp + /* set up %ss and %esp */ data32 mov $BOOTSEG, %eax mov %ax, %ss data32 mov $BOOTSTACK, %esp - /*** set up %es, (where we will load boot2 to) ***/ + /* set up %es, (where we will load boot2 to) */ mov %ax, %es #ifdef DEBUG data32 mov $one, %esi data32 call message #endif - # bootstrap passes us drive number in %dl + /* bootstrap passes us drive number in %dl */ cmpb $0x80, %dl data32 jae hd fd: mov $0x0, %dl -# reset the disk system + /* reset the disk system */ #ifdef DEBUG data32 mov $two, %esi data32 call message #endif movb $0x0, %ah int $0x13 data32 - mov $0x0001, %ecx # cyl 0, sector 1 - movb $0, %dh # head + mov $0x0001, %ecx /* cyl 0, sector 1 */ + movb $0, %dh /* head */ #ifdef DEBUG data32 mov $three, %esi data32 call message #endif data32 jmp load hd: /**** load sector 0 into the BOOTSEG ****/ #ifdef DEBUG data32 mov $four, %esi data32 call message #endif data32 mov $0x0201, %eax - xor %ebx, %ebx # %bx = 0 + xor %ebx, %ebx /* %bx = 0 */ data32 mov $0x0001, %ecx #ifdef DEBUG data32 mov $five, %esi data32 call message #endif data32 andl $0xff, %edx /*mov $0x0080, %edx*/ int $0x13 data32 jb read_error - /***# find the first 386BSD partition *****/ + /* find the first 386BSD partition */ data32 mov $PARTSTART, %ebx data32 mov $NUMPART, %ecx again: addr32 - movb %es:4(%ebx), %al + movb %es:4(%ebx), %al cmpb $BSDPART, %al data32 je found data32 add $PARTSZ, %ebx data32 loop again data32 mov $enoboot, %esi data32 jmp err_stop /* -# BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory -# Call with %ah = 0x2 -# %al = number of sectors -# %ch = cylinder -# %cl = sector -# %dh = head -# %dl = drive (0x80 for hard disk, 0x0 for floppy disk) -# %es:%bx = segment:offset of buffer -# Return: -# %al = 0x0 on success; err code on failure -*/ + * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory + * Call with %ah = 0x2 + * %al = number of sectors + * %ch = cylinder + * %cl = sector + * %dh = head + * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) + * %es:%bx = segment:offset of buffer + * Return: + * %al = 0x0 on success; err code on failure + */ found: addr32 movb %es:1(%ebx), %dh /* head */ addr32 movl %es:2(%ebx), %ecx /*sect, cyl (+ 2 bytes junk in top word) */ load: movb $0x2, %ah /* function 2 */ movb $LOADSZ, %al /* number of blocks */ xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */ int $0x13 data32 jb read_error - # ljmp to the second stage boot loader (boot2). - # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used - # as an internal buffer "intbuf". + /* + * ljmp to the second stage boot loader (boot2). + * After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used + * as an internal buffer "intbuf". + */ #ifdef DEBUG data32 mov $six, %esi data32 call message #endif data32 ljmp $BOOTSEG, $ EXT(boot2) -# -# read_error -# - +/* + * read_error + */ read_error: data32 mov $eread, %esi err_stop: data32 call message data32 jmp stop -# -# message: write the error message in %ds:%esi to console -# - -message: /* - # Use BIOS "int 10H Function 0Eh" to write character in teletype mode - # %ah = 0xe %al = character - # %bh = page %bl = foreground color (graphics modes) -*/ + * message: write the error message in %ds:%esi to console + */ +message: + /* + * Use BIOS "int 10H Function 0Eh" to write character in teletype mode + * %ah = 0xe %al = character + * %bh = page %bl = foreground color (graphics modes) + */ data32 push %eax data32 push %ebx data32 mov $0x0001, %ebx cld nextb: - lodsb # load a byte into %al + lodsb /* load a byte into %al */ cmpb $0x0, %al data32 je done movb $0xe, %ah - int $0x10 # display a byte + int $0x10 /* display a byte */ data32 jmp nextb done: data32 pop %ebx data32 pop %eax data32 ret stop: hlt data32 - jmp stop # halt doesnt actually halt forever + jmp stop /* halt doesnt actually halt forever */ /* error messages */ #ifdef DEBUG one: String "1\r\n\0" two: String "2\r\n\0" three: String "3\r\n\0" four: String "4\r\n\0" five: String "5\r\n\0" six: String "6\r\n\0" seven: String "7\r\n\0" #endif DEBUG eread: String "Read error\r\n\0" enoboot: String "No bootable partition\r\n\0" endofcode: /* throw in a partition in case we are block0 as well */ /* flag, head, sec, cyl, typ, ehead, esect, ecyl, start, len */ . = EXT(boot1) + PARTSTART .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte BOOTABLE,0,1,0,BSDPART,255,255,255 .long 0,50000 /* the last 2 bytes in the sector 0 contain the signature */ . = EXT(boot1) + 0x1fe .value SIGNATURE ENTRY(disklabel) . = EXT(boot1) + 0x400 Index: head/sys/i386/boot/start.S =================================================================== --- head/sys/i386/boot/start.S (revision 3292) +++ head/sys/i386/boot/start.S (revision 3293) @@ -1,292 +1,294 @@ /* * Mach Operating System * Copyright (c) 1992, 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:36:29 rpd - * $Id: start.S,v 1.2 1993/10/16 19:11:38 rgrimes Exp $ + * $Id: start.S,v 1.3 1994/06/13 19:27:52 jkh Exp $ */ /* Copyright 1988, 1989, 1990, 1991, 1992 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "asm.h" .file "start.s" -BOOTSEG = 0x9000 # boot will be loaded here (below 640K) -BOOTSTACK = 0xe000 # boot stack -SIGNATURE = 0xaa55 -LOADSZ = 15 # size of unix boot -PARTSTART = 0x1be # starting address of partition table -NUMPART = 4 # number of partitions in partition table -PARTSZ = 16 # each partition table entry is 16 bytes -BSDPART = 0xA5 # value of boot_ind, means bootable partition -BOOTABLE = 0x80 # value of boot_ind, means bootable partition +BOOTSEG= 0x9000 /* boot will be loaded here (below 640K) */ +BOOTSTACK= 0xe000 /* boot stack */ +SIGNATURE= 0xaa55 +LOADSZ= 15 /* size of unix boot */ +PARTSTART= 0x1be /* starting address of partition table */ +NUMPART= 4 /* number of partitions in partition table */ +PARTSZ= 16 /* each partition table entry is 16 bytes */ +BSDPART= 0xA5 /* value of boot_ind, means bootable partition */ +BOOTABLE= 0x80 /* value of boot_ind, means bootable partition */ .text ENTRY(boot1) - # start (aka boot1) is loaded at 0x0:0x7c00 but we want 0x7c0:0 - # ljmp to the next instruction to adjust %cs + /* + * start (aka boot1) is loaded at 0x0:0x7c00 but we want 0x7c0:0 + * ljmp to the next instruction to adjust %cs + */ data32 ljmp $0x7c0, $start start: - # set up %ds + /* set up %ds */ mov %cs, %ax mov %ax, %ds - # set up %ss and %esp + /* set up %ss and %esp */ data32 mov $BOOTSEG, %eax mov %ax, %ss data32 mov $BOOTSTACK, %esp - /*** set up %es, (where we will load boot2 to) ***/ + /* set up %es, (where we will load boot2 to) */ mov %ax, %es #ifdef DEBUG data32 mov $one, %esi data32 call message #endif - # bootstrap passes us drive number in %dl + /* bootstrap passes us drive number in %dl */ cmpb $0x80, %dl data32 jae hd fd: mov $0x0, %dl -# reset the disk system + /* reset the disk system */ #ifdef DEBUG data32 mov $two, %esi data32 call message #endif movb $0x0, %ah int $0x13 data32 - mov $0x0001, %ecx # cyl 0, sector 1 - movb $0, %dh # head + mov $0x0001, %ecx /* cyl 0, sector 1 */ + movb $0, %dh /* head */ #ifdef DEBUG data32 mov $three, %esi data32 call message #endif data32 jmp load hd: /**** load sector 0 into the BOOTSEG ****/ #ifdef DEBUG data32 mov $four, %esi data32 call message #endif data32 mov $0x0201, %eax - xor %ebx, %ebx # %bx = 0 + xor %ebx, %ebx /* %bx = 0 */ data32 mov $0x0001, %ecx #ifdef DEBUG data32 mov $five, %esi data32 call message #endif data32 andl $0xff, %edx /*mov $0x0080, %edx*/ int $0x13 data32 jb read_error - /***# find the first 386BSD partition *****/ + /* find the first 386BSD partition */ data32 mov $PARTSTART, %ebx data32 mov $NUMPART, %ecx again: addr32 - movb %es:4(%ebx), %al + movb %es:4(%ebx), %al cmpb $BSDPART, %al data32 je found data32 add $PARTSZ, %ebx data32 loop again data32 mov $enoboot, %esi data32 jmp err_stop /* -# BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory -# Call with %ah = 0x2 -# %al = number of sectors -# %ch = cylinder -# %cl = sector -# %dh = head -# %dl = drive (0x80 for hard disk, 0x0 for floppy disk) -# %es:%bx = segment:offset of buffer -# Return: -# %al = 0x0 on success; err code on failure -*/ + * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory + * Call with %ah = 0x2 + * %al = number of sectors + * %ch = cylinder + * %cl = sector + * %dh = head + * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) + * %es:%bx = segment:offset of buffer + * Return: + * %al = 0x0 on success; err code on failure + */ found: addr32 movb %es:1(%ebx), %dh /* head */ addr32 movl %es:2(%ebx), %ecx /*sect, cyl (+ 2 bytes junk in top word) */ load: movb $0x2, %ah /* function 2 */ movb $LOADSZ, %al /* number of blocks */ xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */ int $0x13 data32 jb read_error - # ljmp to the second stage boot loader (boot2). - # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used - # as an internal buffer "intbuf". + /* + * ljmp to the second stage boot loader (boot2). + * After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used + * as an internal buffer "intbuf". + */ #ifdef DEBUG data32 mov $six, %esi data32 call message #endif data32 ljmp $BOOTSEG, $ EXT(boot2) -# -# read_error -# - +/* + * read_error + */ read_error: data32 mov $eread, %esi err_stop: data32 call message data32 jmp stop -# -# message: write the error message in %ds:%esi to console -# - -message: /* - # Use BIOS "int 10H Function 0Eh" to write character in teletype mode - # %ah = 0xe %al = character - # %bh = page %bl = foreground color (graphics modes) -*/ + * message: write the error message in %ds:%esi to console + */ +message: + /* + * Use BIOS "int 10H Function 0Eh" to write character in teletype mode + * %ah = 0xe %al = character + * %bh = page %bl = foreground color (graphics modes) + */ data32 push %eax data32 push %ebx data32 mov $0x0001, %ebx cld nextb: - lodsb # load a byte into %al + lodsb /* load a byte into %al */ cmpb $0x0, %al data32 je done movb $0xe, %ah - int $0x10 # display a byte + int $0x10 /* display a byte */ data32 jmp nextb done: data32 pop %ebx data32 pop %eax data32 ret stop: hlt data32 - jmp stop # halt doesnt actually halt forever + jmp stop /* halt doesnt actually halt forever */ /* error messages */ #ifdef DEBUG one: String "1\r\n\0" two: String "2\r\n\0" three: String "3\r\n\0" four: String "4\r\n\0" five: String "5\r\n\0" six: String "6\r\n\0" seven: String "7\r\n\0" #endif DEBUG eread: String "Read error\r\n\0" enoboot: String "No bootable partition\r\n\0" endofcode: /* throw in a partition in case we are block0 as well */ /* flag, head, sec, cyl, typ, ehead, esect, ecyl, start, len */ . = EXT(boot1) + PARTSTART .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte 0x0,0,0,0,0,0,0,0 .long 0,0 .byte BOOTABLE,0,1,0,BSDPART,255,255,255 .long 0,50000 /* the last 2 bytes in the sector 0 contain the signature */ . = EXT(boot1) + 0x1fe .value SIGNATURE ENTRY(disklabel) . = EXT(boot1) + 0x400