# $NetBSD: Makefile,v 1.6 1996/02/01 22:31:28 mycroft Exp $
# @(#)Makefile 7.9 (Berkeley) 5/8/91
-DESTDIR=/usr
-LD=/usr/bin/ld
+S = ${.CURDIR}/../../..
+I386 = ${.CURDIR}/..
+RMHDR = ${.CURDIR}/../boot/rmaouthdr
STAND= /sys/stand
-INCPATH=-I/sys/sys -I/sys -I/sys/ufs -I${STAND}
+INCPATH=-I${.CURDIR} -I${S} -I${S}/arch -I${S}/ufs -I${S} -I${STAND}
VPATH= ${STAND}
-STANDDIR= ${DESTDIR}/mdec
+STANDDIR= ${DESTDIR}/usr/mdec
-CC= cc -traditional
-CPP= cpp -traditional ${INCPATH} -DSTANDALONE -DAT386
+AFLAGS+= -v -Wa,-a -D_LOCORE
+CFLAGS+= -m386 -O6 -D_STANDALONE -DAT386 -O ${INCPATH}
+CPPFLAGS+= ${INCPATH} -D_KERNEL -DRELOC=0x${RELOC}
+LDADD+= ${LIBC}
RELOC= 98000
RELOC2= 98200
-CFLAGS= -DSTANDALONE -DAT386 -O ${INCPATH}
+DRIVERS=cga.c fd.c kbd.c wd.c sd.c cd.c
+ZLIB= zlib.c
+BOOTS= fdbootblk.S wdbootblk.S sdbootblk.c cdbootblk.S
+SRCS= boot.c prf.c srt0.S ${BOOTS} ${ZLIB} ${DRIVERS}
-DRIVERS=cga.c fd.c kbd.c wd.c as.c
-SRCS= boot.c fdbootblk.c prf.c \
- srt0.c wdbootblk.c ${DRIVERS} ${SASRC}
+CLEANFILES+= *.o conf[fwsc]d.c bread[fwsc]d.c \
+ [fwsc]dboot boot[fwsc]d boot[fwsc]d.sym boot[fwsc]d.c
-ALL= wdboot bootwd fdboot bootfd asboot bootas
+WDOBJS= wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o wd.o breadwd.o clock.o
+FDOBJS= wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o fd.o breadfd.o clock.o
+SDOBJS= wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o sd.o breadsd.o clock.o
+CDOBJS= wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o cd.o breadcd.o clock.o
-all: ${ALL}
+.PATH: ${I386}/isa ${S}/net
-# startups
-
-srt0.o: srt0.c
- ${CPP} -E -D_LOCORE -DRELOC=0x${RELOC} srt0.c | ${AS} -o srt0.o
-
-wsrt0.o: srt0.c
- ${CPP} -E -D_LOCORE -DSMALL -DRELOC=0x${RELOC} -DREL srt0.c | \
- ${AS} -o wsrt0.o
+ALL= wdboot bootwd fdboot bootfd # sdboot bootsd cdboot bootcd
+all: ${ALL}
-relsrt0.o: srt0.c
- ${CPP} -E -D_LOCORE -DRELOC=0x${RELOC} -DREL srt0.c | ${AS} -o relsrt0.o
-
-# block 0 boots
-
-wdbootblk.o: wdbootblk.c
- ${CPP} -E -D_LOCORE -DRELOC=0x${RELOC} wdbootblk.c | ${AS} -o $@
+# startups
-fdbootblk.o: fdbootblk.c
- ${CPP} -E -D_LOCORE -DRELOC=0x${RELOC} fdbootblk.c | ${AS} -o $@
+wsrt0.o: ${.CURDIR}/srt0.S
+ ${CC} -c ${CPPFLAGS} ${AFLAGS} -DREL -DSMALL -o ${.TARGET} ${.CURDIR}/srt0.S
-asbootblk.o: asbootblk.c
- cc -c -O -DRELOC=0x${RELOC} ${INCPATH} asbootblk.c
+relsrt0.o: ${.CURDIR}/srt0.c
+ ${CC} -c ${CFLAGS} -DREL -o ${.TARGET} ${.CURDIR}/srt0.S
# getting booted from disc
-wdboot: wdbootblk.o trimhd
+wdboot: wdbootblk.o
${LD} -N -T ${RELOC} wdbootblk.o
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
-
-bootwd: wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o wd.o printf.o breadwd.o trimhd
- ${LD} -N -T ${RELOC2} wsrt0.o boot.o bmap.o cga.o kbd.o prf.o printf.o \
- breadwd.o fs.o wd.o -lc
+ rm -f ${.TARGET}
+ strip a.out
+ ${RMHDR} a.out ${.TARGET}
+ rm -f a.out
+ ls -l ${.TARGET}
+
+bootwd.sym bootwd: ${WDOBJS}
+ ${LD} -T ${RELOC2} ${WDOBJS} ${LDADD}
+ cp a.out bootwd.sym
size a.out
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
+ rm -f $@; strip a.out; ${RMHDR} a.out $@; rm -f a.out; ls -l $@
-fdboot: fdbootblk.o trimhd
+fdboot: fdbootblk.o
${LD} -N -T ${RELOC} fdbootblk.o
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
+ rm -f $@; strip a.out; ${RMHDR} a.out $@; rm -f a.out; ls -l $@
-bootfd: wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o fd.o printf.o breadfd.o trimhd
- ${LD} -N -T ${RELOC2} wsrt0.o boot.o bmap.o cga.o kbd.o prf.o printf.o \
- breadfd.o fs.o fd.o -lc
+bootfd.sym bootfd: ${FDOBJS}
+ ${LD} -N -T ${RELOC2} ${FDOBJS} ${LDADD}
+ cp a.out bootfd.sym
size a.out
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
+ rm -f $@; strip a.out; ${RMHDR} a.out $@; rm -f a.out; ls -l $@
-asboot: asbootblk.o trimhd
- ${LD} -N -T 7c00 asbootblk.o
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
+sdboot: sdbootblk.o
+ ${LD} -N -T 7c00 sdbootblk.o
+ rm -f $@; strip a.out; ${RMHDR} a.out $@; rm -f a.out; ls -l $@
-bootas: wsrt0.o boot.o bmap.o cga.o fs.o kbd.o prf.o as.o printf.o breadas.o trimhd
- ${LD} -N -T ${RELOC2} wsrt0.o boot.o bmap.o cga.o kbd.o prf.o printf.o \
- breadas.o fs.o as.o -lc
+bootsd.sym bootsd: ${SDOBJS}
+ ${LD} -N -T ${RELOC2} ${SDOBJS} ${LDADD}
+ cp a.out bootsd.sym
size a.out
- rm -f $@; strip a.out; trimhd 32 <a.out >$@; rm -f a.out; ls -l $@
-
+ rm -f $@; strip a.out; ${RMHDR} a.out $@; rm -f a.out; ls -l $@
breadwd.o: breadwd.c breadxx.o
breadfd.o: breadfd.c breadxx.o
-breadas.o: breadas.c breadxx.o
+breadsd.o: breadsd.c breadxx.o
breadxx.o:
touch breadxx.o
-breadwd.c: breadxx.c
- rm -f breadwd.c
- sed -e 's/XX/wd/' -e 's/xx/wd/g' < breadxx.c >> breadwd.c
+breadwd.c: ${.CURDIR}/breadxx.c
+ @rm -f breadwd.c
+ sed -e 's/XX/wd/' -e 's/xx/wd/g' < ${.CURDIR}/breadxx.c >> breadwd.c
-breadfd.c: breadxx.c
+breadfd.c: ${.CURDIR}/breadxx.c
rm -f breadfd.c
- sed -e 's/XX/fd/' -e 's/xx/fd/g' < breadxx.c >> breadfd.c
-
-breadas.c: breadxx.c
- rm -f breadas.c
- sed -e 's/XX/as/' -e 's/xx/as/g' < breadxx.c >> breadas.c
+ sed -e 's/XX/fd/' -e 's/xx/fd/g' < ${.CURDIR}/breadxx.c >> breadfd.c
-trimhd: trimhd.c
- ${CC} ${CFLAGS} -s -o trimhd trimhd.c
+breadsd.c: ${.CURDIR}/breadxx.c
+ rm -f breadsd.c
+ sed -e 's/XX/as/' -e 's/xx/as/g' < ${.CURDIR}/breadxx.c >> breadsd.c
-clean:
- rm -f *.o *.exe *.i sm_*.c trimhd
- rm -f a.out bfd bwd fdb wdb ${ALL}
- rm -f boot[a-wyz]? boot[a-wyz]?? boot[a-wyz]?.c boot[a-wyz]??.c \
- conf[a-wyz]?.c conf[a-wyz]??.c bread[a-wyz]?.c
+#clean:
-cleandir: clean
- rm -f ${MAN} tags .depend
+.MAKE: make.out
+make.out::
+ rm -f ${OBJS}
+ ${MAKE} ${.MAKEFLAGS} ${OBJS} > make.out
-depend: ${SRCS}
- mkdep ${INCPATH} -DSTANDALONE ${SRCS} ${DUMMIES}
install: ${ALL}
- cp ${ALL} ${STANDDIR}
+ install -c ${ALL} ${STANDDIR}
+
+.include <bsd.prog.mk>
+
* Pace Willisson pace@blitz.com April 8, 1992
*/
-#include "param.h"
-#include "disklabel.h"
-#include "i386/isa/asreg.h"
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <dev/isa/ahareg.h>
#include "saio.h"
#ifdef ASDEBUG
* as the master boot block.
*/
-#include "param.h"
-#include "disklabel.h"
-#include "i386/isa/asreg.h"
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <dev/isa/ahareg.h>
/* RELOC should be defined with a -D flag to cc */
* @(#)ufs_bmap.c 7.13 (Berkeley) 5/8/91
*/
-#include "param.h"
-#include "dinode.h"
-#include "fs.h"
-#include "errno.h"
+#include <sys/param.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+#include <errno.h>
/*
* Bmap converts a the logical block number of a file
static char rcsid[] = "$NetBSD: boot.c,v 1.6 1994/10/27 04:21:49 cgd Exp $";
#endif /* not lint */
-#include "param.h"
-#include "reboot.h"
+#include <sys/param.h>
+#include <sys/reboot.h>
#include <a.out.h>
#include "saio.h"
-#include "disklabel.h"
-#include "dinode.h"
+#include <sys/disklabel.h>
+#include <ufs/ufs/dinode.h>
/*
* Boot program, loaded by boot block from remaing 7.5K of boot area.
extern struct disklabel disklabel;
extern int bootdev, cyloffset;
static unsigned char *biosparams = (char *) 0x9ff00; /* XXX */
+/* XXX fake environ */
+char **environ = NULL;
+
+#ifndef HZ
+#define HZ 100
+#endif
+int hz = HZ;
/*
* Boot program... loads /boot out of filesystem indicated by arguements.
* We assume an autoboot unless we detect a misconfiguration.
*/
-main(dev, unit, off)
+boot(dev, unit, off)
{
register struct disklabel *lp;
register int io;
extern int scsisn; /* XXX */
+ /* init system clock */
+ startrtclock();
+
/* are we a disk, if so look at disklabel and do things */
lp = &disklabel;
+#if 0
if (lp->d_type == DTYPE_SCSI) /* XXX */
off = htonl(scsisn); /* XXX */
+#endif
/*printf("cyl %x %x hd %x sect %x ", biosparams[0], biosparams[1], biosparams[2], biosparams[0xe]);
printf("dev %x unit %x off %d\n", dev, unit, off);*/
/*printf("mode %o ", fil.di_mode);*/
i = iread(&fil, 0, (char *)&x, sizeof x);
off = sizeof x;
- if (i != sizeof x || x.a_magic != 0413) {
+ if (i != sizeof x || N_GETMAGIC(x) != ZMAGIC) {
printf("Not an executable format");
return;
}
addr += x.a_data;
- if (addr + x.a_bss > (unsigned) &fil) {
+ if ((void *)(addr + x.a_bss) > (void *)&fil) {
printf("Warning: bss overlaps bootstrap");
x.a_bss = (unsigned)addr - (unsigned)&fil;
}
/*
* Interface to driver to obtain a block off the disk drive.
*/
-#include "param.h"
+#include <sys/param.h>
#include "saio.h"
bread(bdev, off, addr, sz)
char *addr;
{
-
-/*printf("bread %d %d %x %d\n", bdev, off, addr, sz);*/
+#ifdef DEBUG
+ printf("bread %d %d %x %d\n", bdev, off, addr, sz);
+#endif
iobuf.i_dev = 0;
iobuf.i_adapt = 0;
iobuf.i_ctlr = 0;
* @(#)cga.c 5.3 (Berkeley) 4/28/91
*/
-#include "param.h"
+#include <sys/param.h>
#define COL 80
#define ROW 25
/****************************************************************************/
/* standalone fd driver */
/****************************************************************************/
-#include "param.h"
-#include "disklabel.h"
-#include "i386/isa/fdreg.h"
-#include "i386/isa/isa.h"
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <dev/isa/isareg.h>
+#include <i386/isa/fdreg.h>
#include "saio.h"
#define NUMRETRY 10
--- /dev/null
+/* $NetBSD: fdbootblk.c,v 1.6 1994/10/27 04:21:53 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)fdbootblk.c 7.2 (Berkeley) 5/4/91
+ */
+
+/*
+ * fdbootblk.s:
+ * Written 10/6/90 by William F. Jolitz
+ * Initial block boot for AT/386 with typical stupid NEC controller
+ *
+ * Goal is to read in sucessive 7.5Kbytes of bootstrap to
+ * execute.
+ *
+ * No attempt is made to handle disk errors.
+ */
+/*#include "/sys/i386/isa/isa.h"
+#include "/sys/i386/isa/fdreg.h"*/
+#define NOP inb $0x84,%al
+#define BIOSRELOC 0x7c00
+#define start RELOC+0x400
+
+ /* mumbo-jumbo to pacify DOS, in the hope of getting diskcopy to work */
+ jmp 1f
+ .asciz "NetBSD "
+ .byte 1 # sectors per allocation
+ .word 15 # additional sectors for bootstrap
+ .word 0 # number of DOS fat sectors
+ .word 0 # number of DOS rootdir entries
+ .byte 0xf0 # media descriptor
+ .word 0 # number of sectors per a DOS fat entry
+ .word 18 # number of sectors per track
+ .word 2 # number of heads
+ .long 0 # number of hidden sectors
+ .long 2880-18 # logical sectors per volume
+ .byte 0 # physical drive
+ .byte 0x29 # ?
+ .long 137 # binary id
+ .ascii "Release 0.1" # volume label
+ .space 5
+1:
+ /* step 0 force descriptors to bottom of address space */
+
+ cli
+ .byte 0xb8,0x30,0x00 /* mov $0x30,%ax */
+ mov %ax, %ss
+ .byte 0xbc,0x00,0x01 /* mov $0x100,%sp */
+
+ xorl %eax,%eax
+ movl %ax,%ds
+ movl %ax,%es
+
+ /* obtain BIOS parameters for hard disk XXX */
+ movb $0x9f,%ah /* write to 0x9ff00 XXX */
+ movb $0xf0,%al
+ mov %ax,%es
+ xor %edi,%edi
+
+ .byte 0xf, 0xb4, 0x36 ; .word 0x41*4 /* lfs 0x41*4, %si */
+ xorb %ch,%ch
+ movb $0x10,%cl
+ fs
+ rep
+ movsb
+
+ .byte 0xf, 0xb4, 0x36 ; .word 0x46*4 /* lfs 0x46*4, %si */
+ xorb %ch,%ch
+ movb $0x10,%cl
+ fs
+ rep
+ movsb
+
+ xorl %eax,%eax
+ movl %ax,%es
+
+ /* step 1 load new descriptor table */
+
+ .byte 0x2E,0x0F,1,0x16 /* word aword cs lgdt GDTptr */
+ .word BIOSRELOC+0xa4 #GDTptr
+
+ /* step 2 turn on protected mode */
+
+ smsw %ax
+ orb $1,%al
+ lmsw %ax
+ jmp 1f
+ nop
+
+ /* step 3 reload segment descriptors */
+
+ 1:
+ xorl %eax,%eax
+ movb $0x10,%al
+ movl %ax,%ds
+ movl %ax,%es
+ movl %ax,%ss
+ word
+ ljmp $0x8,$ BIOSRELOC+0xb3 /* would be nice if .-RELOC+0x7c00 worked */
+
+ /* Global Descriptor Table contains three descriptors:
+ * 0x00: Null: not used
+ * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
+ * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
+ * (overlays code)
+ */
+GDT:
+NullDesc: .word 0,0,0,0 # null descriptor - not used
+CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
+ .byte 0,0,0 # base at 0: (bits 23:0)
+ .byte 0x9f # present/priv level 0/code/conforming/readable
+ .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
+ .byte 0 # base at 0: (bits 31:24)
+DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
+ .byte 0,0,0 # base at 0: (bits 23:0)
+ .byte 0x93 # present/priv level 0/data/expand-up/writeable
+ .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
+ .byte 0 # base at 0: (bits 31:24)
+
+/* Global Descriptor Table pointer
+ * contains 6-byte pointer information for LGDT
+ */
+GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data)
+ .long BIOSRELOC+0x8c # GDT -- arrgh, gas again!
+readcmd: .byte 0xe6,0,0,0,0,2,18,0x1b,0xff
+
+ /* step 4 relocate to final bootstrap address. */
+reloc:
+ movl $ BIOSRELOC,%esi
+ movl $ RELOC,%edi
+ movl $512,%ecx
+ rep
+ movsb
+ movl $0xa0000, %esp
+ pushl $dodisk
+ ret
+
+ /* step 5 load remaining 15 sectors off disk */
+dodisk:
+ movl $ RELOC+0x200, %edi
+ xorl %ebx, %ebx
+ incb %bl # shl $1,%bl
+ incb %bl
+ movb $0x20,%al # do a eoi
+ outb %al,$0x20
+
+ NOP
+ movb $0xbf,%al # enable floppy interrupt, mask out rest
+ outb %al,$0x21
+ NOP
+ 8:
+ movb %bl,readcmd+4
+ movl %edi,%ecx
+
+ /* Set read/write bytes */
+ xorl %edx,%edx
+ movb $0x0c,%dl # outb(0xC,junk); outb(0xB,0x46);
+ outb %al,%dx # reset DMA controller first/last flip-flop
+ NOP
+ decb %dx
+ movb $0x46,%al # single mode, write mem, chan 2
+ outb %al,%dx # output DMA controller mode byte
+
+ /* Send start address */
+ movb $0x04,%dl # outb(0x4, addr);
+ movb %cl,%al
+ outb %al,%dx
+ NOP
+ movb %ch,%al # outb(0x4, addr>>8);
+ outb %al,%dx
+ NOP
+ rorl $8,%ecx # outb(0x81, addr>>16);
+ movb %ch,%al
+ outb %al,$0x81
+ NOP
+
+ /* Send count */
+ movb $0x05,%dl # outb(0x5, 0);
+ xorl %eax,%eax
+ outb %al,%dx
+ NOP
+ movb $2,%al # outb(0x5,2);
+ outb %al,%dx
+ NOP
+
+ /* set channel 2 */
+ movb $2,%al # outb(0x0A,2);
+ outb %al,$0x0A
+ NOP
+
+ /* issue read command to fdc */
+ movw $0x3f4,%dx
+ movl $readcmd,%esi
+ xorl %ecx,%ecx
+ movb $9,%cl
+
+ 2: NOP
+ inb %dx,%al
+ testb $0x80,%al
+ jz 2b
+
+ incb %dx
+ NOP
+ movl (%esi),%al
+ outb %al,%dx
+ NOP
+ incl %esi
+ decb %dx
+ loop 2b
+
+ /* watch the icu looking for an interrupt signalling completion */
+ xorl %edx,%edx
+ movb $0x20,%dl
+ 2:
+ NOP
+ movb $0xc,%al
+ outb %al,%dx
+ NOP
+ inb %dx,%al
+ andb $0x7f,%al
+ cmpb $6,%al
+ jne 2b
+ NOP
+ movb $0x20,%al # do a eoi
+ outb %al,%dx
+ NOP
+
+ movl $0x3f4,%edx
+ xorl %ecx,%ecx
+ movb $7,%cl
+ 2:
+ NOP
+ inb %dx,%al
+ andb $0xC0,%al
+ cmpb $0xc0,%al
+ jne 2b
+ incb %dx
+ inb %dx,%al
+ decb %dx
+ loop 2b
+
+ /* extract the status bytes after the read. must we do this? */
+ addw $0x200,%edi # next addr to load to
+ incb %bl
+ cmpb $15,%bl
+ jle 8b
+
+ /* for clever bootstrap, dig out boot unit and cylinder */
+ pushl $0
+ pushl $0
+
+ /* fd controller is major device 2 */
+ pushl $2 /* dev */
+
+ /* sorry, no flags at this point! */
+
+ movl $ start, %eax
+ call %eax /* main (dev, unit, off) */
+
+ebootblkcode:
+
+ /* remaining space usable for a disk label */
+
+ .org 0x1fe
+ .word 0xaa55 /* signature -- used by BIOS ROM */
+
+ebootblk: /* MUST BE EXACTLY 0x200 BIG FOR SURE */
+++ /dev/null
-/* $NetBSD: fdbootblk.c,v 1.6 1994/10/27 04:21:53 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)fdbootblk.c 7.2 (Berkeley) 5/4/91
- */
-
-/*
- * fdbootblk.s:
- * Written 10/6/90 by William F. Jolitz
- * Initial block boot for AT/386 with typical stupid NEC controller
- *
- * Goal is to read in sucessive 7.5Kbytes of bootstrap to
- * execute.
- *
- * No attempt is made to handle disk errors.
- */
-/*#include "/sys/i386/isa/isa.h"
-#include "/sys/i386/isa/fdreg.h"*/
-#define NOP inb $0x84,%al
-#define BIOSRELOC 0x7c00
-#define start RELOC+0x400
-
- /* mumbo-jumbo to pacify DOS, in the hope of getting diskcopy to work */
- jmp 1f
- .asciz "NetBSD "
- .byte 1 # sectors per allocation
- .word 15 # additional sectors for bootstrap
- .word 0 # number of DOS fat sectors
- .word 0 # number of DOS rootdir entries
- .byte 0xf0 # media descriptor
- .word 0 # number of sectors per a DOS fat entry
- .word 18 # number of sectors per track
- .word 2 # number of heads
- .long 0 # number of hidden sectors
- .long 2880-18 # logical sectors per volume
- .byte 0 # physical drive
- .byte 0x29 # ?
- .long 137 # binary id
- .ascii "Release 0.1" # volume label
- .space 5
-1:
- /* step 0 force descriptors to bottom of address space */
-
- cli
- .byte 0xb8,0x30,0x00 /* mov $0x30,%ax */
- mov %ax, %ss
- .byte 0xbc,0x00,0x01 /* mov $0x100,%sp */
-
- xorl %eax,%eax
- movl %ax,%ds
- movl %ax,%es
-
- /* obtain BIOS parameters for hard disk XXX */
- movb $0x9f,%ah /* write to 0x9ff00 XXX */
- movb $0xf0,%al
- mov %ax,%es
- xor %edi,%edi
-
- .byte 0xf, 0xb4, 0x36 ; .word 0x41*4 /* lfs 0x41*4, %si */
- xorb %ch,%ch
- movb $0x10,%cl
- fs
- rep
- movsb
-
- .byte 0xf, 0xb4, 0x36 ; .word 0x46*4 /* lfs 0x46*4, %si */
- xorb %ch,%ch
- movb $0x10,%cl
- fs
- rep
- movsb
-
- xorl %eax,%eax
- movl %ax,%es
-
- /* step 1 load new descriptor table */
-
- .byte 0x2E,0x0F,1,0x16 /* word aword cs lgdt GDTptr */
- .word BIOSRELOC+0xa4 #GDTptr
-
- /* step 2 turn on protected mode */
-
- smsw %ax
- orb $1,%al
- lmsw %ax
- jmp 1f
- nop
-
- /* step 3 reload segment descriptors */
-
- 1:
- xorl %eax,%eax
- movb $0x10,%al
- movl %ax,%ds
- movl %ax,%es
- movl %ax,%ss
- word
- ljmp $0x8,$ BIOSRELOC+0xb3 /* would be nice if .-RELOC+0x7c00 worked */
-
- /* Global Descriptor Table contains three descriptors:
- * 0x00: Null: not used
- * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
- * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
- * (overlays code)
- */
-GDT:
-NullDesc: .word 0,0,0,0 # null descriptor - not used
-CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
- .byte 0,0,0 # base at 0: (bits 23:0)
- .byte 0x9f # present/priv level 0/code/conforming/readable
- .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
- .byte 0 # base at 0: (bits 31:24)
-DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
- .byte 0,0,0 # base at 0: (bits 23:0)
- .byte 0x93 # present/priv level 0/data/expand-up/writeable
- .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
- .byte 0 # base at 0: (bits 31:24)
-
-/* Global Descriptor Table pointer
- * contains 6-byte pointer information for LGDT
- */
-GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data)
- .long BIOSRELOC+0x8c # GDT -- arrgh, gas again!
-readcmd: .byte 0xe6,0,0,0,0,2,18,0x1b,0xff
-
- /* step 4 relocate to final bootstrap address. */
-reloc:
- movl $ BIOSRELOC,%esi
- movl $ RELOC,%edi
- movl $512,%ecx
- rep
- movsb
- movl $0xa0000, %esp
- pushl $dodisk
- ret
-
- /* step 5 load remaining 15 sectors off disk */
-dodisk:
- movl $ RELOC+0x200, %edi
- xorl %ebx, %ebx
- incb %bl # shl $1,%bl
- incb %bl
- movb $0x20,%al # do a eoi
- outb %al,$0x20
-
- NOP
- movb $0xbf,%al # enable floppy interrupt, mask out rest
- outb %al,$0x21
- NOP
- 8:
- movb %bl,readcmd+4
- movl %edi,%ecx
-
- /* Set read/write bytes */
- xorl %edx,%edx
- movb $0x0c,%dl # outb(0xC,junk); outb(0xB,0x46);
- outb %al,%dx # reset DMA controller first/last flip-flop
- NOP
- decb %dx
- movb $0x46,%al # single mode, write mem, chan 2
- outb %al,%dx # output DMA controller mode byte
-
- /* Send start address */
- movb $0x04,%dl # outb(0x4, addr);
- movb %cl,%al
- outb %al,%dx
- NOP
- movb %ch,%al # outb(0x4, addr>>8);
- outb %al,%dx
- NOP
- rorl $8,%ecx # outb(0x81, addr>>16);
- movb %ch,%al
- outb %al,$0x81
- NOP
-
- /* Send count */
- movb $0x05,%dl # outb(0x5, 0);
- xorl %eax,%eax
- outb %al,%dx
- NOP
- movb $2,%al # outb(0x5,2);
- outb %al,%dx
- NOP
-
- /* set channel 2 */
- movb $2,%al # outb(0x0A,2);
- outb %al,$0x0A
- NOP
-
- /* issue read command to fdc */
- movw $0x3f4,%dx
- movl $readcmd,%esi
- xorl %ecx,%ecx
- movb $9,%cl
-
- 2: NOP
- inb %dx,%al
- testb $0x80,%al
- jz 2b
-
- incb %dx
- NOP
- movl (%esi),%al
- outb %al,%dx
- NOP
- incl %esi
- decb %dx
- loop 2b
-
- /* watch the icu looking for an interrupt signalling completion */
- xorl %edx,%edx
- movb $0x20,%dl
- 2:
- NOP
- movb $0xc,%al
- outb %al,%dx
- NOP
- inb %dx,%al
- andb $0x7f,%al
- cmpb $6,%al
- jne 2b
- NOP
- movb $0x20,%al # do a eoi
- outb %al,%dx
- NOP
-
- movl $0x3f4,%edx
- xorl %ecx,%ecx
- movb $7,%cl
- 2:
- NOP
- inb %dx,%al
- andb $0xC0,%al
- cmpb $0xc0,%al
- jne 2b
- incb %dx
- inb %dx,%al
- decb %dx
- loop 2b
-
- /* extract the status bytes after the read. must we do this? */
- addw $0x200,%edi # next addr to load to
- incb %bl
- cmpb $15,%bl
- jle 8b
-
- /* for clever bootstrap, dig out boot unit and cylinder */
- pushl $0
- pushl $0
-
- /* fd controller is major device 2 */
- pushl $2 /* dev */
-
- /* sorry, no flags at this point! */
-
- movl $ start, %eax
- call %eax /* main (dev, unit, off) */
-
-ebootblkcode:
-
- /* remaining space usable for a disk label */
-
- .org 0x1fe
- .word 0xaa55 /* signature -- used by BIOS ROM */
-
-ebootblk: /* MUST BE EXACTLY 0x200 BIG FOR SURE */
* Routines to sift through a BSD fast filesystem. -wfj
*/
-#include "param.h"
-#include "fs.h"
-#include "dir.h"
-#include "dinode.h"
+#include <sys/param.h>
+#include <ufs/ffs/fs.h>
+#include <ufs/ufs/dir.h>
+#include <ufs/ufs/dinode.h>
#include "saio.h"
int bdev;
fetchi(i, dip) struct dinode *dip; {
/*printf("fetchi %d %x\n", i, dip);*/
- bread(bdev, fsbtodb(fs, itod(fs, i)), abuf, fs->fs_bsize);
- bcopy (abuf + itoo(fs,i) * sizeof(struct dinode),
+ bread(bdev, fsbtodb(fs, ino_to_fsba(fs, i)), abuf, fs->fs_bsize);
+ bcopy (abuf + ino_to_fsbo(fs,i) * sizeof(struct dinode),
dip, sizeof(struct dinode));
/*printf("mode %o link %d uid %d gid %d size %d [ ",
dip->di_mode, dip->di_nlink, dip->di_uid, dip->di_gid, dip->di_size);
inb(0x60);
}
-#ifdef notdef;
+#ifdef notdef
u_char getchar() {
u_char c;
* @(#)prf.c 7.4 (Berkeley) 5/4/91
*/
-#include "types.h"
+#include <sys/types.h>
putchar(c)
char c;
int i_unit;
int i_cc;
int i_bn;
- int i_ma;
+ char *i_ma;
int i_boff;
int i_flgs;
#define F_WRITE 0x1
--- /dev/null
+/* $NetBSD: srt0.c,v 1.3 1994/10/27 04:21:59 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)srt0.c 5.3 (Berkeley) 4/28/91
+ */
+
+/*
+ * Startup code for standalone system
+ * Non-relocating version -- for programs which are loaded by boot
+ * Relocating version for boot
+ * Small relocating version for "micro" boot
+ */
+
+ .globl _end
+ .globl _edata
+ .globl _boot
+ .globl __rtt
+ .globl _exit
+ .globl _bootdev
+ .globl _cyloffset
+#define NOP inb $0x84,%al ; inb $0x84,%al
+
+#ifdef SMALL
+ /* where the disklabel goes if we have one */
+ .globl _disklabel
+_disklabel:
+ .space 512
+ #.set _scsisn, RELOC+0x60
+ #.globl _scsisn
+#endif
+
+ .globl entry
+ .set entry,0
+ .globl start
+
+#if defined(REL) && !defined(SMALL)
+
+ /* relocate program and enter at symbol "start" */
+
+ #movl $entry-RELOC,%esi # from beginning of ram
+ movl $0,%esi
+ #movl $entry,%edi # to relocated area
+ movl RELOC,%edi # to relocated area
+ # movl $_edata-RELOC,%ecx # this much
+ movl $64*1024,%ecx
+ cld
+ rep
+ movsb
+ # relocate program counter to relocation base
+ pushl $start
+ ret
+#endif
+
+start:
+
+ /* setup stack pointer */
+
+#ifdef REL
+ leal 4(%esp),%eax /* ignore old pc */
+ movl RELOC-3*4,%ebx
+ /* copy boot parameters */
+ pushl $3*4
+ pushl %ebx
+ pushl %eax
+ call _bcopy
+ movl %ebx,%esp
+#else
+ /* save old stack state */
+ movl %esp,savearea
+ movl %ebp,savearea+4
+ movl RELOC-0x2400,%esp
+#endif
+
+ /* clear memory as needed */
+
+ movl %esp,%esi
+#ifdef REL
+
+ /*
+ * Clear Bss and up to 64K heap
+ */
+ movl $64*1024,%ebx
+ movl $_end,%eax # should be movl $_end-_edata but ...
+ subl $_edata,%eax
+ #addl %ebx,%eax
+ pushl %eax
+ pushl $_edata
+ call _bzero
+
+ /*
+ * Clear 64K of stack
+ */
+ movl %esi,%eax
+ subl %ebx,%eax
+ subl $5*4,%ebx
+ pushl %ebx
+ pushl %eax
+ call _bzero
+#else
+ movl $_edata,%edx
+ movl %esp,%eax
+ subl %edx,%eax
+ pushl %edx
+ pushl %esp
+ call _bzero
+#endif
+
+ call _kbdreset /* resets keyboard and gatea20 brain damage */
+ movl %esi,%esp
+ call _boot
+ jmp 1f
+
+ .data
+_bootdev: .long 0
+_cyloffset: .long 0
+savearea: .long 0,0 # sp & bp to return to
+ .text
+ .globl _wait
+
+__rtt:
+ pushl $1000000
+ call _wait
+ popl %eax
+ movl $-7,%eax
+ jmp 1f
+
+_exit:
+ pushl $1000000
+ call _wait
+ popl %eax
+ movl 4(%esp),%eax
+1:
+#ifdef REL
+#ifndef SMALL
+ call _reset_cpu
+#endif
+ movw $0x1234,%ax
+ movw %ax,0x472 # warm boot
+ movl $0,%esp # segment violation
+ ret
+#else
+ movl savearea,%esp
+ movl savearea+4,%ebp
+ ret
+#endif
+
+ .globl _inb
+_inb: movl 4(%esp),%edx
+ subl %eax,%eax # clr eax
+ NOP
+ inb %dx,%al
+ ret
+
+ .globl _outb
+_outb: movl 4(%esp),%edx
+ NOP
+ movl 8(%esp),%eax
+ outb %al,%dx
+ ret
+
+ .globl ___udivsi3
+___udivsi3:
+ movl 4(%esp),%eax
+ xorl %edx,%edx
+ divl 8(%esp)
+ ret
+
+ .globl ___divsi3
+___divsi3:
+ movl 4(%esp),%eax
+ xorl %edx,%edx
+ cltd
+ idivl 8(%esp)
+ ret
+
+ #
+ # bzero (base,cnt)
+ #
+
+ .globl _bzero
+_bzero:
+ pushl %edi
+ movl 8(%esp),%edi
+ movl 12(%esp),%ecx
+ movb $0x00,%al
+ cld
+ rep
+ stosb
+ popl %edi
+ ret
+
+ #
+ # bcopy (src,dst,cnt)
+ # NOTE: does not (yet) handle overlapped copies
+ #
+
+ .globl _bcopy
+_bcopy:
+ pushl %esi
+ pushl %edi
+ movl 12(%esp),%esi
+ movl 16(%esp),%edi
+ movl 20(%esp),%ecx
+ cld
+ rep
+ movsb
+ popl %edi
+ popl %esi
+ ret
+
+ # insw(port,addr,cnt)
+ .globl _insw
+_insw:
+ pushl %edi
+ movw 8(%esp),%dx
+ movl 12(%esp),%edi
+ movl 16(%esp),%ecx
+ NOP
+ cld
+ nop
+ .byte 0x66,0xf2,0x6d # rep insw
+ nop
+ movl %edi,%eax
+ popl %edi
+ ret
+
+ # outsw(port,addr,cnt)
+ .globl _outsw
+_outsw:
+ pushl %esi
+ movw 8(%esp),%dx
+ movl 12(%esp),%esi
+ movl 16(%esp),%ecx
+ NOP
+ cld
+ nop
+ .byte 0x66,0xf2,0x6f # rep outsw
+ nop
+ movl %esi,%eax
+ popl %esi
+ ret
+++ /dev/null
-/* $NetBSD: srt0.c,v 1.3 1994/10/27 04:21:59 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)srt0.c 5.3 (Berkeley) 4/28/91
- */
-
-/*
- * Startup code for standalone system
- * Non-relocating version -- for programs which are loaded by boot
- * Relocating version for boot
- * Small relocating version for "micro" boot
- */
-
- .globl _end
- .globl _edata
- .globl _main
- .globl __rtt
- .globl _exit
- .globl _bootdev
- .globl _cyloffset
-#define NOP inb $0x84,%al ; inb $0x84,%al
-
-#ifdef SMALL
- /* where the disklabel goes if we have one */
- .globl _disklabel
-_disklabel:
- .space 512
- .globl _scsisn
- .set _scsisn, RELOC+0x60
-#endif
-
- .globl entry
- .set entry,0
- .globl start
-
-#if defined(REL) && !defined(SMALL)
-
- /* relocate program and enter at symbol "start" */
-
- #movl $entry-RELOC,%esi # from beginning of ram
- movl $0,%esi
- #movl $entry,%edi # to relocated area
- movl $ RELOC,%edi # to relocated area
- # movl $_edata-RELOC,%ecx # this much
- movl $64*1024,%ecx
- cld
- rep
- movsb
- # relocate program counter to relocation base
- pushl $start
- ret
-#endif
-
-start:
-
- /* setup stack pointer */
-
-#ifdef REL
- leal 4(%esp),%eax /* ignore old pc */
- movl $ RELOC-3*4,%ebx
- /* copy boot parameters */
- pushl $3*4
- pushl %ebx
- pushl %eax
- call _bcopy
- movl %ebx,%esp
-#else
- /* save old stack state */
- movl %esp,savearea
- movl %ebp,savearea+4
- movl $ RELOC-0x2400,%esp
-#endif
-
- /* clear memory as needed */
-
- movl %esp,%esi
-#ifdef REL
-
- /*
- * Clear Bss and up to 64K heap
- */
- movl $64*1024,%ebx
- movl $_end,%eax # should be movl $_end-_edata but ...
- subl $_edata,%eax
- #addl %ebx,%eax
- pushl %eax
- pushl $_edata
- call _bzero
-
- /*
- * Clear 64K of stack
- */
- movl %esi,%eax
- subl %ebx,%eax
- subl $5*4,%ebx
- pushl %ebx
- pushl %eax
- call _bzero
-#else
- movl $_edata,%edx
- movl %esp,%eax
- subl %edx,%eax
- pushl %edx
- pushl %esp
- call _bzero
-#endif
-
- call _kbdreset /* resets keyboard and gatea20 brain damage */
- movl %esi,%esp
- call _main
- jmp 1f
-
- .data
-_bootdev: .long 0
-_cyloffset: .long 0
-savearea: .long 0,0 # sp & bp to return to
- .text
- .globl _wait
-
-__rtt:
- pushl $1000000
- call _wait
- popl %eax
- movl $-7,%eax
- jmp 1f
-
-_exit:
- pushl $1000000
- call _wait
- popl %eax
- movl 4(%esp),%eax
-1:
-#ifdef REL
-#ifndef SMALL
- call _reset_cpu
-#endif
- movw $0x1234,%ax
- movw %ax,0x472 # warm boot
- movl $0,%esp # segment violation
- ret
-#else
- movl savearea,%esp
- movl savearea+4,%ebp
- ret
-#endif
-
- .globl _inb
-_inb: movl 4(%esp),%edx
- subl %eax,%eax # clr eax
- NOP
- inb %dx,%al
- ret
-
- .globl _outb
-_outb: movl 4(%esp),%edx
- NOP
- movl 8(%esp),%eax
- outb %al,%dx
- ret
-
- .globl ___udivsi3
-___udivsi3:
- movl 4(%esp),%eax
- xorl %edx,%edx
- divl 8(%esp)
- ret
-
- .globl ___divsi3
-___divsi3:
- movl 4(%esp),%eax
- xorl %edx,%edx
- cltd
- idivl 8(%esp)
- ret
-
- #
- # bzero (base,cnt)
- #
-
- .globl _bzero
-_bzero:
- pushl %edi
- movl 8(%esp),%edi
- movl 12(%esp),%ecx
- movb $0x00,%al
- cld
- rep
- stosb
- popl %edi
- ret
-
- #
- # bcopy (src,dst,cnt)
- # NOTE: does not (yet) handle overlapped copies
- #
-
- .globl _bcopy
-_bcopy:
- pushl %esi
- pushl %edi
- movl 12(%esp),%esi
- movl 16(%esp),%edi
- movl 20(%esp),%ecx
- cld
- rep
- movsb
- popl %edi
- popl %esi
- ret
-
- # insw(port,addr,cnt)
- .globl _insw
-_insw:
- pushl %edi
- movw 8(%esp),%dx
- movl 12(%esp),%edi
- movl 16(%esp),%ecx
- NOP
- cld
- nop
- .byte 0x66,0xf2,0x6d # rep insw
- nop
- movl %edi,%eax
- popl %edi
- ret
-
- # outsw(port,addr,cnt)
- .globl _outsw
-_outsw:
- pushl %esi
- movw 8(%esp),%dx
- movl 12(%esp),%esi
- movl 16(%esp),%ecx
- NOP
- cld
- nop
- .byte 0x66,0xf2,0x6f # rep outsw
- nop
- movl %esi,%eax
- popl %esi
- ret
+++ /dev/null
-/* $NetBSD: trimhd.c,v 1.3 1994/10/27 04:22:00 cgd Exp $ */
-
-/*
- * Copyright (c) 1989, 1990, 1991, 1992 William F. Jolitz, TeleMuse
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This software is a component of "386BSD" developed by
- William F. Jolitz, TeleMuse.
- * 4. Neither the name of the developer nor the name "386BSD"
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
- * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
- * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
- * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
- * NOT MAKE USE THIS WORK.
- *
- * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
- * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
- * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
- * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
- * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
- * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
- * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
- * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Trim off the start of a file.
- */
-
-main(argc, argv) char *argv[]; {
- int val, rv, buf;
-
- if (argc != 2) return(1);
- if ((val = atoi(argv[1]))<= 0) return(1);
-
- buf = malloc(1024);
- read (0, buf, val);
- do {
- rv = read (0, buf, 1024);
- if (rv > 0)
- rv = write(1, buf, rv);
- } while (rv == 1024);
- if(rv > 0)
- return (0);
- else
- return (1);
-}
/* device driver for winchester disk */
-#include "param.h"
-#include "dkbad.h"
-#include "disklabel.h"
-#include "i386/isa/isa.h"
-#include "i386/isa/wdreg.h"
+#include <sys/param.h>
+#include <sys/dkbad.h>
+#include <sys/disklabel.h>
+#include <dev/isa/isareg.h>
+#include <dev/isa/wdreg.h>
#include "saio.h"
#define SMALL
#endif
sector += io->i_boff;
- address = io->i_ma;
+ address = (char *)io->i_ma;
while (iosize > 0) {
if (wdio(func, unit, sector, address))
return(-1);
* See if the current block is in the bad block list.
*/
if (blknm > BBSIZE/DEV_BSIZE) /* should be BBSIZE */
- for (bt_ptr = dkbad[unit].bt_bad; bt_ptr->bt_cyl != -1; bt_ptr++) {
+ for (bt_ptr = dkbad[unit].bt_bad; bt_ptr->bt_cyl != 0xffff; bt_ptr++) {
if (bt_ptr->bt_cyl > cylin)
/* Sorted list, and we passed our cylinder. quit. */
break;
/* Set up the SDH register (select drive). */
outb(wdc+wd_sdh, WDSD_IBM | (unit<<4) | (head & 0xf));
- while ((inb(wdc+wd_status) & WDCS_READY) == 0) ;
+ while ((inb(wdc+wd_status) & WDCS_DRDY) == 0) ;
outb(wdc+wd_command, opcode);
- while (opcode == WDCC_READ && (inb(wdc+wd_status) & WDCS_BUSY))
+ while (opcode == WDCC_READ && (inb(wdc+wd_status) & WDCS_BSY))
;
/* Did we get an error? */
if (opcode == WDCC_READ && (inb(wdc+wd_status) & WDCS_ERR))
/* Check data request (should be done). */
if (inb(wdc+wd_status) & WDCS_DRQ) goto error;
- while (opcode == WDCC_WRITE && (inb(wdc+wd_status) & WDCS_BUSY)) ;
+ while (opcode == WDCC_WRITE && (inb(wdc+wd_status) & WDCS_BSY)) ;
if (inb(wdc+wd_status) & WDCS_ERR) goto error;
#endif
/* reset controller */
- outb(wdc+wd_ctlr,6);
+ outb(wdc+wd_ctlr, WDCTL_RST|WDCTL_IDS);
DELAY(1000);
- outb(wdc+wd_ctlr,2);
+ outb(wdc+wd_ctlr, WDCTL_IDS);
DELAY(1000);
- while(inb(wdc+wd_status) & WDCS_BUSY); /* 06 Sep 92*/
- outb(wdc+wd_ctlr,8);
+ while(inb(wdc+wd_status) & WDCS_BSY); /* 06 Sep 92*/
+ outb(wdc+wd_ctlr, WDCTL_4BIT);
/* set SDH, step rate, do restore to recalibrate drive */
tryagainrecal:
outb(wdc+wd_sdh, WDSD_IBM | (unit << 4));
wdwait();
- outb(wdc+wd_command, WDCC_RESTORE | WD_STEP);
+ /* outb(wdc+wd_command, WDCC_RESTORE | WD_STEP);
wdwait();
+ */
if ((i = inb(wdc+wd_status)) & WDCS_ERR) {
printf("wd%d: recal status %b error %b\n",
unit, i, WDCS_BITS, inb(wdc+wd_error), WDERR_BITS);
outb(wdc+wd_cyl_lo, 1224);
outb(wdc+wd_cyl_hi, 1224/256);
outb(wdc+wd_command, 0x91);
- while (inb(wdc+wd_status) & WDCS_BUSY) ;
+ while (inb(wdc+wd_status) & WDCS_BSY) ;
errcnt = 0;
retry:
outb(wdc+wd_sdh, WDSD_IBM | (unit << 4) + dd->d_ntracks-1);
outb(wdc+wd_seccnt, dd->d_nsectors);
outb(wdc+wd_command, 0x91);
- while (inb(wdc+wd_status) & WDCS_BUSY) ;
+ while (inb(wdc+wd_status) & WDCS_BSY) ;
dkbad[unit].bt_bad[0].bt_cyl = -1;
register wdc = wdcport;
register i = 0;
- while (inb(wdc+wd_status) & WDCS_BUSY)
+ while (inb(wdc+wd_status) & WDCS_BSY)
;
- while ((inb(wdc+wd_status) & WDCS_READY) == 0)
+ while ((inb(wdc+wd_status) & WDCS_DRDY) == 0)
if (i++ > 100000)
return(-1);
return(0);
--- /dev/null
+/* $NetBSD: wdbootblk.c,v 1.3 1994/10/27 04:22:02 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)wdbootblk.c 7.1 (Berkeley) 4/28/91
+ */
+
+/*
+ * wdbootblk.s:
+ * Written 7/6/90 by William F. Jolitz
+ * Initial block boot for AT/386 with typical Western Digital
+ * WD 1002-WA2 (or upwards compatable). Works either as
+ * first and sole partition bootstrap, or as loaded by a
+ * earlier BIOS boot when on an inner partition of the disk.
+ *
+ * Goal is to read in sucessive 7.5Kbytes of bootstrap to
+ * execute.
+ *
+ * No attempt is made to handle disk errors.
+ */
+
+#include <dev/isa/isareg.h>
+#include <dev/isa/wdreg.h>
+
+#define NOP inb $0x84,%al
+#define BIOSRELOC 0x7c00
+#define start RELOC+0x400
+
+ /* step 0 force descriptors to bottom of address space */
+
+ cli
+ .byte 0xb8,0x30,0x00 /* mov $0x30,%ax */
+ mov %ax, %ss
+ .byte 0xbc,0x00,0x01 /* mov $0x100,%sp */
+
+ xorl %eax,%eax
+ movl %ax,%ds
+ movl %ax,%es
+
+ /* obtain BIOS parameters for hard disk XXX */
+ movb $0x9f,%ah /* write to 0x9ff00 XXX */
+ movb $0xf0,%al
+ mov %ax,%es
+ xor %edi,%edi
+
+ .byte 0xf, 0xb4, 0x36 ; .word 0x41*4 /* lfs 0x41*4, %si */
+ xorb %ch,%ch
+ movb $0x10,%cl
+ fs
+ rep
+ movsb
+
+ .byte 0xf, 0xb4, 0x36 ; .word 0x46*4 /* lfs 0x46*4, %si */
+ xorb %ch,%ch
+ movb $0x10,%cl
+ fs
+ rep
+ movsb
+
+ xorl %eax,%eax
+ movl %ax,%es
+
+ /* step 1 load new descriptor table */
+
+ .byte 0x3E,0x0F,1,0x16
+ .word BIOSRELOC+0x6e #GDTptr
+ # word aword cs lgdt GDTptr
+
+ /* step 2 turn on protected mode */
+
+ smsw %ax
+ orb $1,%al
+ lmsw %ax
+ jmp 1f
+ nop
+
+ /* step 3 reload segment descriptors */
+
+1:
+ xorl %eax,%eax
+ movb $0x10,%al
+ movl %ax,%ds
+ movl %ax,%es
+ movl %ax,%ss
+ word
+ ljmp $0x8,$ BIOSRELOC+0x74 /* would be nice if .-RELOC+0x7c00 worked */
+
+ /* Global Descriptor Table contains three descriptors:
+ * 0x00: Null: not used
+ * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
+ * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
+ * (overlays code)
+ */
+GDT:
+NullDesc: .word 0,0,0,0 # null descriptor - not used
+CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
+ .byte 0,0,0 # base at 0: (bits 23:0)
+ .byte 0x9f # present/priv level 0/code/conforming/readable
+ .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
+ .byte 0 # base at 0: (bits 31:24)
+DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
+ .byte 0,0,0 # base at 0: (bits 23:0)
+ .byte 0x93 # present/priv level 0/data/expand-up/writeable
+ .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
+ .byte 0 # base at 0: (bits 31:24)
+
+/* Global Descriptor Table pointer
+ * contains 6-byte pointer information for LGDT
+ */
+GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data)
+ .long BIOSRELOC+0x56 # GDT -- arrgh, gas again!
+
+ /* step 4 relocate to final bootstrap address. */
+reloc:
+ movl $ BIOSRELOC,%esi
+ movl $ RELOC,%edi
+ movl $512,%ecx
+ rep
+ movsb
+ movl $0xa0000, %esp
+ pushl $dodisk
+ ret
+
+ /* step 5 load remaining 15 sectors off disk */
+dodisk:
+ movl $ IO_WD1+wd_seccnt,%edx
+ movb $ 15,%al
+ outb %al,%dx
+ NOP
+ movl $ IO_WD1+wd_sector,%edx
+ movb $ 2,%al
+ outb %al,%dx
+ NOP
+ #outb(wdc+wd_cyl_lo, (cyloffset & 0xff));
+ #outb(wdc+wd_cyl_hi, (cyloffset >> 8));
+ #outb(wdc+wd_sdh, WDSD_IBM | (unit << 4));
+
+ movl $ IO_WD1+wd_command,%edx
+ movb $ WDCC_READ,%al
+ outb %al,%dx
+ NOP
+ cld
+
+ /* check to make sure controller is not busy and we have data ready */
+readblk:
+ movl $ IO_WD1+wd_status,%edx
+ NOP
+ inb %dx,%al
+ testb $ WDCS_BSY,%al
+ jnz readblk
+ testb $ WDCS_DRQ,%al
+ jz readblk
+
+ /* read a block into final position in memory */
+
+ movl $ IO_WD1+wd_data,%edx
+ movl $ 256,%ecx
+ .byte 0x66,0xf2,0x6d # rep insw
+ NOP
+
+ /* need more blocks to be read in? */
+
+ cmpl $ RELOC+16*512-1,%edi
+ jl readblk
+
+ /* for clever bootstrap, dig out boot unit and cylinder */
+
+ movl $ IO_WD1+wd_cyl_lo,%edx
+ inb %dx,%al
+ xorl %ecx,%ecx
+ movb %al,%cl
+ incl %edx
+ NOP
+ inb %dx,%al /* cyl_hi */
+ movb %al,%ch
+ pushl %ecx /* cyloffset */
+
+ incl %edx
+ xorl %eax,%eax
+ NOP
+ inb %dx,%al /* sdh */
+ andb $0x10,%al /* isolate unit # bit */
+ shrb $4,%al
+ pushl %eax /* unit */
+
+ /* wd controller is major device 0 */
+ xorl %eax,%eax
+ pushl %eax /* bootdev */
+
+ /* sorry, no flags at this point! */
+
+ movl $ start, %eax
+ call %eax /* main (dev, unit, offset) */
+
+ebootblkcode:
+
+ /* remaining space usable for a disk label */
+
+ .org 0x1fe
+ .word 0xaa55 /* signature -- used by BIOS ROM */
+
+ebootblk: /* MUST BE EXACTLY 0x200 BIG FOR SURE */
+++ /dev/null
-/* $NetBSD: wdbootblk.c,v 1.3 1994/10/27 04:22:02 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)wdbootblk.c 7.1 (Berkeley) 4/28/91
- */
-
-/*
- * wdbootblk.s:
- * Written 7/6/90 by William F. Jolitz
- * Initial block boot for AT/386 with typical Western Digital
- * WD 1002-WA2 (or upwards compatable). Works either as
- * first and sole partition bootstrap, or as loaded by a
- * earlier BIOS boot when on an inner partition of the disk.
- *
- * Goal is to read in sucessive 7.5Kbytes of bootstrap to
- * execute.
- *
- * No attempt is made to handle disk errors.
- */
-#include "i386/isa/isa.h"
-#include "i386/isa/wdreg.h"
-#define NOP inb $0x84,%al
-#define BIOSRELOC 0x7c00
-#define start RELOC+0x400
-
- /* step 0 force descriptors to bottom of address space */
-
- cli
- .byte 0xb8,0x30,0x00 /* mov $0x30,%ax */
- mov %ax, %ss
- .byte 0xbc,0x00,0x01 /* mov $0x100,%sp */
-
- xorl %eax,%eax
- movl %ax,%ds
- movl %ax,%es
-
- /* obtain BIOS parameters for hard disk XXX */
- movb $0x9f,%ah /* write to 0x9ff00 XXX */
- movb $0xf0,%al
- mov %ax,%es
- xor %edi,%edi
-
- .byte 0xf, 0xb4, 0x36 ; .word 0x41*4 /* lfs 0x41*4, %si */
- xorb %ch,%ch
- movb $0x10,%cl
- fs
- rep
- movsb
-
- .byte 0xf, 0xb4, 0x36 ; .word 0x46*4 /* lfs 0x46*4, %si */
- xorb %ch,%ch
- movb $0x10,%cl
- fs
- rep
- movsb
-
- xorl %eax,%eax
- movl %ax,%es
-
- /* step 1 load new descriptor table */
-
- .byte 0x3E,0x0F,1,0x16
- .word BIOSRELOC+0x6e #GDTptr
- # word aword cs lgdt GDTptr
-
- /* step 2 turn on protected mode */
-
- smsw %ax
- orb $1,%al
- lmsw %ax
- jmp 1f
- nop
-
- /* step 3 reload segment descriptors */
-
-1:
- xorl %eax,%eax
- movb $0x10,%al
- movl %ax,%ds
- movl %ax,%es
- movl %ax,%ss
- word
- ljmp $0x8,$ BIOSRELOC+0x74 /* would be nice if .-RELOC+0x7c00 worked */
-
- /* Global Descriptor Table contains three descriptors:
- * 0x00: Null: not used
- * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
- * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
- * (overlays code)
- */
-GDT:
-NullDesc: .word 0,0,0,0 # null descriptor - not used
-CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
- .byte 0,0,0 # base at 0: (bits 23:0)
- .byte 0x9f # present/priv level 0/code/conforming/readable
- .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
- .byte 0 # base at 0: (bits 31:24)
-DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
- .byte 0,0,0 # base at 0: (bits 23:0)
- .byte 0x93 # present/priv level 0/data/expand-up/writeable
- .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
- .byte 0 # base at 0: (bits 31:24)
-
-/* Global Descriptor Table pointer
- * contains 6-byte pointer information for LGDT
- */
-GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data)
- .long BIOSRELOC+0x56 # GDT -- arrgh, gas again!
-
- /* step 4 relocate to final bootstrap address. */
-reloc:
- movl $ BIOSRELOC,%esi
- movl $ RELOC,%edi
- movl $512,%ecx
- rep
- movsb
- movl $0xa0000, %esp
- pushl $dodisk
- ret
-
- /* step 5 load remaining 15 sectors off disk */
-dodisk:
- movl $ IO_WD1+wd_seccnt,%edx
- movb $ 15,%al
- outb %al,%dx
- NOP
- movl $ IO_WD1+wd_sector,%edx
- movb $ 2,%al
- outb %al,%dx
- NOP
- #outb(wdc+wd_cyl_lo, (cyloffset & 0xff));
- #outb(wdc+wd_cyl_hi, (cyloffset >> 8));
- #outb(wdc+wd_sdh, WDSD_IBM | (unit << 4));
-
- movl $ IO_WD1+wd_command,%edx
- movb $ WDCC_READ,%al
- outb %al,%dx
- NOP
- cld
-
- /* check to make sure controller is not busy and we have data ready */
-readblk:
- movl $ IO_WD1+wd_status,%edx
- NOP
- inb %dx,%al
- testb $ WDCS_BUSY,%al
- jnz readblk
- testb $ WDCS_DRQ,%al
- jz readblk
-
- /* read a block into final position in memory */
-
- movl $ IO_WD1+wd_data,%edx
- movl $ 256,%ecx
- .byte 0x66,0xf2,0x6d # rep insw
- NOP
-
- /* need more blocks to be read in? */
-
- cmpl $ RELOC+16*512-1,%edi
- jl readblk
-
- /* for clever bootstrap, dig out boot unit and cylinder */
-
- movl $ IO_WD1+wd_cyl_lo,%edx
- inb %dx,%al
- xorl %ecx,%ecx
- movb %al,%cl
- incl %edx
- NOP
- inb %dx,%al /* cyl_hi */
- movb %al,%ch
- pushl %ecx /* cyloffset */
-
- incl %edx
- xorl %eax,%eax
- NOP
- inb %dx,%al /* sdh */
- andb $0x10,%al /* isolate unit # bit */
- shrb $4,%al
- pushl %eax /* unit */
-
- /* wd controller is major device 0 */
- xorl %eax,%eax
- pushl %eax /* bootdev */
-
- /* sorry, no flags at this point! */
-
- movl $ start, %eax
- call %eax /* main (dev, unit, offset) */
-
-ebootblkcode:
-
- /* remaining space usable for a disk label */
-
- .org 0x1fe
- .word 0xaa55 /* signature -- used by BIOS ROM */
-
-ebootblk: /* MUST BE EXACTLY 0x200 BIG FOR SURE */