From f7710986e2409ce75b4cca37d126f55f783cc374 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Tue, 13 Jul 1993 18:15:32 +0000 Subject: [PATCH] New boot blocks, from Bruce Evans, and NetBSD fixes. Allows kernel to be loaded above 1MB. Same boot code for floppies now. Speed improvements. etc etc etc. (I don't have much history on this, but then have been tested) --- sys/i386/boot/Makefile | 116 +++++---- sys/i386/boot/README.MACH | 5 +- sys/i386/boot/asm.S | 292 ++++++++++++++++++++++ sys/i386/boot/asm.h | 34 ++- sys/i386/boot/bios.S | 363 +++++++++++++++++++++++++++ sys/i386/boot/biosboot/Makefile | 116 +++++---- sys/i386/boot/biosboot/README.MACH | 5 +- sys/i386/boot/biosboot/asm.S | 292 ++++++++++++++++++++++ sys/i386/boot/biosboot/asm.h | 34 ++- sys/i386/boot/biosboot/bios.S | 363 +++++++++++++++++++++++++++ sys/i386/boot/biosboot/boot.c | 99 +++++--- sys/i386/boot/biosboot/boot.h | 5 +- sys/i386/boot/biosboot/boot2.S | 214 ++++++++++++++++ sys/i386/boot/biosboot/disk.c | 50 +++- sys/i386/boot/biosboot/io.c | 38 ++- sys/i386/boot/biosboot/start.S | 380 +++++++++++++++++++++++++++++ sys/i386/boot/biosboot/sys.c | 5 +- sys/i386/boot/biosboot/table.c | 74 ++++-- sys/i386/boot/boot.c | 99 +++++--- sys/i386/boot/boot.h | 5 +- sys/i386/boot/boot2.S | 214 ++++++++++++++++ sys/i386/boot/disk.c | 50 +++- sys/i386/boot/io.c | 38 ++- sys/i386/boot/rmaouthdr | 5 +- sys/i386/boot/start.S | 380 +++++++++++++++++++++++++++++ sys/i386/boot/sys.c | 5 +- sys/i386/boot/table.c | 74 ++++-- 27 files changed, 3146 insertions(+), 209 deletions(-) create mode 100644 sys/i386/boot/asm.S create mode 100644 sys/i386/boot/bios.S create mode 100644 sys/i386/boot/biosboot/asm.S create mode 100644 sys/i386/boot/biosboot/bios.S create mode 100644 sys/i386/boot/biosboot/boot2.S create mode 100644 sys/i386/boot/biosboot/start.S create mode 100644 sys/i386/boot/boot2.S create mode 100644 sys/i386/boot/start.S diff --git a/sys/i386/boot/Makefile b/sys/i386/boot/Makefile index bebd8bcc0341..3fd9155f93fd 100644 --- a/sys/i386/boot/Makefile +++ b/sys/i386/boot/Makefile @@ -25,51 +25,83 @@ # # HISTORY # $Log: Makefile,v $ -# Revision 2.2 92/04/04 11:33:46 rpd -# Fabricated for MACH 3.0 -# [92/03/30 mg32] +# Revision 1.6 1993/07/11 12:02:17 andrew +# Fixes from bde, including support for loading @ any MB boundary (e.g. a +# kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +# buffering to speed booting from floppies. Also works with aha174x +# controllers in enhanced mode. +# +# Revision 1.5 1993/07/04 14:03:03 cgd +# do the right thing, so things aren't built in /usr/src/sys +# +# Revision 1.4 1993/06/18 08:03:14 cgd +# install floppy boot block, too. +# +# Revision 1.3 1993/06/08 03:36:39 deraadt +# makes more sense if src is mounted readonly +# +# Revision 1.2 1993/04/28 08:45:51 deraadt +# Ensure the rmaouthdr shell script is executable before running it! +# +# Revision 1.1 1993/03/21 18:08:11 cgd +# after 0.2.2 "stable" patches applied +# +# +# 93/06/30 bde +# fd boot is now fast enough. +# (Safe) target fd0 and (unsafe) target wd0 to temporarily avoid +# updating /use/mdec. +# +# 93/06/29 bde +# Deleted weirdness for not-really-separate code and data segments. +# It is not necessary now that the GDT is dynamically initialized. +# table.o doesn't need to be early any more. boot.sed is not used +# any more (delete it). The shell commands that failed with status +# 0 no longer exist so the 93/06/28 fixes got deleted. +# +# Use .S extension for asm files to get (g)cc to preprocess them +# automatically. +# +# 93/06/28 bde +# Don't exit 0 from failing shell commands. # # Thu Sep 10 22:40:23 PDT 1992 # Ported to 386BSD by Julian Elischer # julian@tfs.com # +# Revision 2.2 92/04/04 11:33:46 rpd +# Fabricated for MACH 3.0 +# [92/03/30 mg32] +# +wd0: + dd if=boot of=biosboot count=1 + dd if=boot of=bootbios skip=1 + disklabel -r -w wd0 nec5655 newboot biosboot bootbios + rm biosboot bootbios -CFLAGS = -O -DDO_BAD144 +NOPROG= noprog +NOMAN= noman + +CFLAGS = -O -DDO_BAD144 -I${.CURDIR} LIBS= -lc -INC= -I../.. +INC= -I${.CURDIR}/../.. -# start.o should be first, table.o should be second +# start.o should be first OBJS = start.o table.o boot2.o boot.o asm.o bios.o io.o disk.o sys.o -.SUFFIXES: .s .c .o +.SUFFIXES: .S .c .o -# These are wierd because we don't want separate code and data segments.. ok? .c.o: - @echo $(CC) -c $(CFLAGS) $(INC) $*.c - -@trap "/bin/rm -f $*.i $*.s; exit 0" 0 1 2 3 10 15; \ - $(CC) $(CFLAGS) $(INC) -S $<; \ - if [ $$? != 0 ]; then :; else \ - sed -f boot.sed $*.s > $*.i; \ - $(AS) $*.i -o $@; \ - fi + $(CC) $(CFLAGS) $(INC) -c $< -.s.o: - @echo $(AS) -o $*.o $< - -@trap "/bin/rm -f $*.i X$*.c; exit 0" 0 1 2 3 10 15; \ - /bin/rm -f X$*.c; \ - ln $*.s X$*.c; \ - $(CC) -E $(CFLAGS) X$*.c > $*.i; \ - if [ $$? != 0 ]; then :; \ - else \ - $(AS) $*.i -o $@; \ - fi +.S.o: + $(CC) $(CFLAGS) -c $< - -boot: boot.sed $(OBJS) +boot: $(OBJS) $(LD) -N -T 0 -o boot $(OBJS) $(LIBS) cp boot boot.sym @strip boot - @./rmaouthdr boot boot.tmp + @sh ${.CURDIR}/rmaouthdr boot boot.tmp @mv -f boot.tmp boot @ls -l boot @@ -105,27 +137,17 @@ sd: /usr/mdec/bootsd /usr/mdec/sdboot wd: /usr/mdec/bootwd /usr/mdec/wdboot fd: /usr/mdec/bootfd /usr/mdec/fdboot -#wd0: /usr/mdec/bootwd /usr/mdec/wdboot -# disklabel -r -w wd0 julian julian5 /usr/mdec/wdboot /usr/mdec/bootwd -# +all: biosboot bootbios -sd0: /usr/mdec/bootsd /usr/mdec/sdboot - disklabel -r -w sd0 XT-8760 scsitest /usr/mdec/sdboot /usr/mdec/bootsd +fd0: + dd if=boot of=biosboot count=1 + dd if=boot of=bootbios skip=1 + disklabel -r -w fd0 floppy bootflpy biosboot bootbios + rm biosboot bootbios +install: wd sd fd -#fd0: /usr/mdec/bootfd /usr/mdec/fdboot -# disklabel -r -w fd0 floppy5 bootflpy /usr/mdec/fdboot /usr/mdec/bootfd -# - -install: wd sd -# you should use the old floppy booter, it's MUCH faster -# This one works but it's too slow. -# besides how many kernels can you fit on a floppy? -# only use this one if you want to boot a kernel -# from a hard disk 2 when you've trashed hard disk 1 -#install: wd sd fd - -clean: +clean cleandir: /bin/rm -f *.o *.d boot bootbios biosboot boot.sym - +.include diff --git a/sys/i386/boot/README.MACH b/sys/i386/boot/README.MACH index d11f3e420372..a94c720327b6 100644 --- a/sys/i386/boot/README.MACH +++ b/sys/i386/boot/README.MACH @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: README,v $ + * $Log: README.MACH,v $ +Revision 1.1 1993/03/21 18:08:16 cgd +after 0.2.2 "stable" patches applied + * Revision 2.2 92/04/04 11:33:55 rpd * From 2.5 * [92/03/30 mg32] diff --git a/sys/i386/boot/asm.S b/sys/i386/boot/asm.S new file mode 100644 index 000000000000..55ce675a0eb0 --- /dev/null +++ b/sys/i386/boot/asm.S @@ -0,0 +1,292 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: asm.S,v $ +Revision 1.2 1993/07/11 12:02:19 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/06/28 bde + * Switch IDT for debugger. + * + * Change all addr16's to addr32's and all data16's to data32's. + * + * 93/06/26 bde + * Avoid "pushw $xreal". Gas botches it even for 32-bit mode. + * +Revision 1.1 1993/03/21 18:08:21 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:34:13 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * From 2.5 boot: pruned inb(), outb(), and pzero(). + * [92/03/30 rvb] + * + * Revision 2.2 91/04/02 14:35:10 mbj + * Added _sp() => where is the stack at. [kupfer] + * Add Intel copyright + * [90/02/09 rvb] + * + */ + +/* + 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. +*/ + +ENTRY(real_to_prot) + # guarantee that interrupt is disabled when in prot mode + cli + + # load the gdtr + addr32 + data32 + lgdt EXT(Gdtr) + + # 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 + data32 + ljmp $0x18, $xprot + +xprot: + # 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 + + # load idtr so we can debug + lidt EXT(Idtr_prot) + + ret + +/* +# +# 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. + 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) + + # Change to use16 mode. + ljmp $0x28, $x16 + +x16: + # 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 + lret + +xreal: + # 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 + + # load idtr so we can debug + addr32 + data32 + lidt EXT(Idtr_real) + + data32 + ret + +/* +# +# 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 + + # 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 on our entry address + mov $0x08, %ebx # segment + pushl %ebx + pushl %ecx + + # convert over the other data segs + mov $0x10, %ebx + movw %bx, %ds + movw %bx, %es + + # convert the PC (and code seg) + lret +/* +# +# 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 + mov $0x10, %eax + movw %ax, %es + + 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 +# +*/ + +ENTRY(pcpy) + push %ebp + mov %esp, %ebp + push %es + push %esi + push %edi + push %ecx + + cld + + # 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 + + rep + movsb + + pop %ecx + pop %edi + pop %esi + pop %es + pop %ebp + + ret + diff --git a/sys/i386/boot/asm.h b/sys/i386/boot/asm.h index 9b86637f4ace..9b1b303ff156 100644 --- a/sys/i386/boot/asm.h +++ b/sys/i386/boot/asm.h @@ -27,7 +27,34 @@ */ /* * HISTORY - * $Log: asm.h,v $ + * $Log: asm.h,v $ + * Revision 1.2 1993/07/11 12:02:19 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * + * 93/06/28 bde + * Deleted addr16 and data16. These produce the same prefix bytes as + * addr32 and data32 but have confusing names. There is no way to make + * gas produce 16-bit addresses or operand sizes. Instead, we let it + * produce 32-bit addresses and operand sizes and explicitly code the + * correct prefix(es) to make the address modes and operand sizes what + * gas thinks they are. It would be safer to use prefixes before + * _every_ instruction (there are alleady a lot of unnecessary data32's + * before short jumps in case the jumps are actually long). We must + * avoid "word" instructions becuase gas would produce the wrong prefix + * and there is no way to cancel a prefix. We sometimes avoid adding + * a prefix using kludges like + * "xorl %eax, %eax # actually xorw %ax, %ax". + * + * 93/06/28 bde + * Added addr32. + * + * Revision 1.1 1993/03/21 18:08:18 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.7 92/02/29 15:33:41 rpd * Added ENTRY2. * [92/02/28 rpd] @@ -139,11 +166,8 @@ #endif wheeze +#define addr32 .byte 0x67 #define data32 .byte 0x66 -#define data16 .byte 0x66 -#define addr16 .byte 0x67 - - #ifdef GPROF #ifdef __STDC__ diff --git a/sys/i386/boot/bios.S b/sys/i386/boot/bios.S new file mode 100644 index 000000000000..c4ad6ad62530 --- /dev/null +++ b/sys/i386/boot/bios.S @@ -0,0 +1,363 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: bios.S,v $ +Revision 1.2 1993/07/11 12:02:20 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/06/28 bde + * Guess the disk size when the BIOS doesn't support the diskinfo + * interrupt. + * + * Change biosread() interface. Sector count and io address are now + * args. + * + * Change all data16's to data32's. + * +Revision 1.1 1993/03/21 18:08:23 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:34:26 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * From 2.5 version + * [92/03/30 mg32] + * + * Revision 2.2 91/04/02 14:35:21 mbj + * Add Intel copyright + * [90/02/09 rvb] + * + */ + + +/* + 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 +*/ + +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 + 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 + + call EXT(prot_to_real) # enter real mode + movb $0x2, %ah # subfunction + addr32 + movb 0x18(%ebp), %al # number of sectors + + sti + int $0x13 + cli + + mov %eax, %ebx # save return value (actually movw %ax, %bx) + + data32 + call EXT(real_to_prot) # back to protected mode + + xor %eax, %eax + 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) +*/ + + +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) + movb $0xe, %ah + movb %cl, %al + sti + 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 +*/ + +ENTRY(getc) + push %ebp + mov %esp, %ebp + push %ebx # save %ebx + + call EXT(prot_to_real) + + movb $0x0, %ah + sti + int $0x16 + cli + + 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 +*/ +ENTRY(ischar) + push %ebp + mov %esp, %ebp + push %ebx + + 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 +# +*/ + +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, %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 + 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 +ok: + + data32 + 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) + + 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. +# +*/ + +ENTRY(memsize) + push %ebp + mov %esp, %ebp + push %ebx + + mov 8(%ebp), %ebx + + 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 diff --git a/sys/i386/boot/biosboot/Makefile b/sys/i386/boot/biosboot/Makefile index bebd8bcc0341..3fd9155f93fd 100644 --- a/sys/i386/boot/biosboot/Makefile +++ b/sys/i386/boot/biosboot/Makefile @@ -25,51 +25,83 @@ # # HISTORY # $Log: Makefile,v $ -# Revision 2.2 92/04/04 11:33:46 rpd -# Fabricated for MACH 3.0 -# [92/03/30 mg32] +# Revision 1.6 1993/07/11 12:02:17 andrew +# Fixes from bde, including support for loading @ any MB boundary (e.g. a +# kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +# buffering to speed booting from floppies. Also works with aha174x +# controllers in enhanced mode. +# +# Revision 1.5 1993/07/04 14:03:03 cgd +# do the right thing, so things aren't built in /usr/src/sys +# +# Revision 1.4 1993/06/18 08:03:14 cgd +# install floppy boot block, too. +# +# Revision 1.3 1993/06/08 03:36:39 deraadt +# makes more sense if src is mounted readonly +# +# Revision 1.2 1993/04/28 08:45:51 deraadt +# Ensure the rmaouthdr shell script is executable before running it! +# +# Revision 1.1 1993/03/21 18:08:11 cgd +# after 0.2.2 "stable" patches applied +# +# +# 93/06/30 bde +# fd boot is now fast enough. +# (Safe) target fd0 and (unsafe) target wd0 to temporarily avoid +# updating /use/mdec. +# +# 93/06/29 bde +# Deleted weirdness for not-really-separate code and data segments. +# It is not necessary now that the GDT is dynamically initialized. +# table.o doesn't need to be early any more. boot.sed is not used +# any more (delete it). The shell commands that failed with status +# 0 no longer exist so the 93/06/28 fixes got deleted. +# +# Use .S extension for asm files to get (g)cc to preprocess them +# automatically. +# +# 93/06/28 bde +# Don't exit 0 from failing shell commands. # # Thu Sep 10 22:40:23 PDT 1992 # Ported to 386BSD by Julian Elischer # julian@tfs.com # +# Revision 2.2 92/04/04 11:33:46 rpd +# Fabricated for MACH 3.0 +# [92/03/30 mg32] +# +wd0: + dd if=boot of=biosboot count=1 + dd if=boot of=bootbios skip=1 + disklabel -r -w wd0 nec5655 newboot biosboot bootbios + rm biosboot bootbios -CFLAGS = -O -DDO_BAD144 +NOPROG= noprog +NOMAN= noman + +CFLAGS = -O -DDO_BAD144 -I${.CURDIR} LIBS= -lc -INC= -I../.. +INC= -I${.CURDIR}/../.. -# start.o should be first, table.o should be second +# start.o should be first OBJS = start.o table.o boot2.o boot.o asm.o bios.o io.o disk.o sys.o -.SUFFIXES: .s .c .o +.SUFFIXES: .S .c .o -# These are wierd because we don't want separate code and data segments.. ok? .c.o: - @echo $(CC) -c $(CFLAGS) $(INC) $*.c - -@trap "/bin/rm -f $*.i $*.s; exit 0" 0 1 2 3 10 15; \ - $(CC) $(CFLAGS) $(INC) -S $<; \ - if [ $$? != 0 ]; then :; else \ - sed -f boot.sed $*.s > $*.i; \ - $(AS) $*.i -o $@; \ - fi + $(CC) $(CFLAGS) $(INC) -c $< -.s.o: - @echo $(AS) -o $*.o $< - -@trap "/bin/rm -f $*.i X$*.c; exit 0" 0 1 2 3 10 15; \ - /bin/rm -f X$*.c; \ - ln $*.s X$*.c; \ - $(CC) -E $(CFLAGS) X$*.c > $*.i; \ - if [ $$? != 0 ]; then :; \ - else \ - $(AS) $*.i -o $@; \ - fi +.S.o: + $(CC) $(CFLAGS) -c $< - -boot: boot.sed $(OBJS) +boot: $(OBJS) $(LD) -N -T 0 -o boot $(OBJS) $(LIBS) cp boot boot.sym @strip boot - @./rmaouthdr boot boot.tmp + @sh ${.CURDIR}/rmaouthdr boot boot.tmp @mv -f boot.tmp boot @ls -l boot @@ -105,27 +137,17 @@ sd: /usr/mdec/bootsd /usr/mdec/sdboot wd: /usr/mdec/bootwd /usr/mdec/wdboot fd: /usr/mdec/bootfd /usr/mdec/fdboot -#wd0: /usr/mdec/bootwd /usr/mdec/wdboot -# disklabel -r -w wd0 julian julian5 /usr/mdec/wdboot /usr/mdec/bootwd -# +all: biosboot bootbios -sd0: /usr/mdec/bootsd /usr/mdec/sdboot - disklabel -r -w sd0 XT-8760 scsitest /usr/mdec/sdboot /usr/mdec/bootsd +fd0: + dd if=boot of=biosboot count=1 + dd if=boot of=bootbios skip=1 + disklabel -r -w fd0 floppy bootflpy biosboot bootbios + rm biosboot bootbios +install: wd sd fd -#fd0: /usr/mdec/bootfd /usr/mdec/fdboot -# disklabel -r -w fd0 floppy5 bootflpy /usr/mdec/fdboot /usr/mdec/bootfd -# - -install: wd sd -# you should use the old floppy booter, it's MUCH faster -# This one works but it's too slow. -# besides how many kernels can you fit on a floppy? -# only use this one if you want to boot a kernel -# from a hard disk 2 when you've trashed hard disk 1 -#install: wd sd fd - -clean: +clean cleandir: /bin/rm -f *.o *.d boot bootbios biosboot boot.sym - +.include diff --git a/sys/i386/boot/biosboot/README.MACH b/sys/i386/boot/biosboot/README.MACH index d11f3e420372..a94c720327b6 100644 --- a/sys/i386/boot/biosboot/README.MACH +++ b/sys/i386/boot/biosboot/README.MACH @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: README,v $ + * $Log: README.MACH,v $ +Revision 1.1 1993/03/21 18:08:16 cgd +after 0.2.2 "stable" patches applied + * Revision 2.2 92/04/04 11:33:55 rpd * From 2.5 * [92/03/30 mg32] diff --git a/sys/i386/boot/biosboot/asm.S b/sys/i386/boot/biosboot/asm.S new file mode 100644 index 000000000000..55ce675a0eb0 --- /dev/null +++ b/sys/i386/boot/biosboot/asm.S @@ -0,0 +1,292 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: asm.S,v $ +Revision 1.2 1993/07/11 12:02:19 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/06/28 bde + * Switch IDT for debugger. + * + * Change all addr16's to addr32's and all data16's to data32's. + * + * 93/06/26 bde + * Avoid "pushw $xreal". Gas botches it even for 32-bit mode. + * +Revision 1.1 1993/03/21 18:08:21 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:34:13 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * From 2.5 boot: pruned inb(), outb(), and pzero(). + * [92/03/30 rvb] + * + * Revision 2.2 91/04/02 14:35:10 mbj + * Added _sp() => where is the stack at. [kupfer] + * Add Intel copyright + * [90/02/09 rvb] + * + */ + +/* + 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. +*/ + +ENTRY(real_to_prot) + # guarantee that interrupt is disabled when in prot mode + cli + + # load the gdtr + addr32 + data32 + lgdt EXT(Gdtr) + + # 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 + data32 + ljmp $0x18, $xprot + +xprot: + # 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 + + # load idtr so we can debug + lidt EXT(Idtr_prot) + + ret + +/* +# +# 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. + 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) + + # Change to use16 mode. + ljmp $0x28, $x16 + +x16: + # 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 + lret + +xreal: + # 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 + + # load idtr so we can debug + addr32 + data32 + lidt EXT(Idtr_real) + + data32 + ret + +/* +# +# 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 + + # 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 on our entry address + mov $0x08, %ebx # segment + pushl %ebx + pushl %ecx + + # convert over the other data segs + mov $0x10, %ebx + movw %bx, %ds + movw %bx, %es + + # convert the PC (and code seg) + lret +/* +# +# 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 + mov $0x10, %eax + movw %ax, %es + + 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 +# +*/ + +ENTRY(pcpy) + push %ebp + mov %esp, %ebp + push %es + push %esi + push %edi + push %ecx + + cld + + # 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 + + rep + movsb + + pop %ecx + pop %edi + pop %esi + pop %es + pop %ebp + + ret + diff --git a/sys/i386/boot/biosboot/asm.h b/sys/i386/boot/biosboot/asm.h index 9b86637f4ace..9b1b303ff156 100644 --- a/sys/i386/boot/biosboot/asm.h +++ b/sys/i386/boot/biosboot/asm.h @@ -27,7 +27,34 @@ */ /* * HISTORY - * $Log: asm.h,v $ + * $Log: asm.h,v $ + * Revision 1.2 1993/07/11 12:02:19 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * + * 93/06/28 bde + * Deleted addr16 and data16. These produce the same prefix bytes as + * addr32 and data32 but have confusing names. There is no way to make + * gas produce 16-bit addresses or operand sizes. Instead, we let it + * produce 32-bit addresses and operand sizes and explicitly code the + * correct prefix(es) to make the address modes and operand sizes what + * gas thinks they are. It would be safer to use prefixes before + * _every_ instruction (there are alleady a lot of unnecessary data32's + * before short jumps in case the jumps are actually long). We must + * avoid "word" instructions becuase gas would produce the wrong prefix + * and there is no way to cancel a prefix. We sometimes avoid adding + * a prefix using kludges like + * "xorl %eax, %eax # actually xorw %ax, %ax". + * + * 93/06/28 bde + * Added addr32. + * + * Revision 1.1 1993/03/21 18:08:18 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.7 92/02/29 15:33:41 rpd * Added ENTRY2. * [92/02/28 rpd] @@ -139,11 +166,8 @@ #endif wheeze +#define addr32 .byte 0x67 #define data32 .byte 0x66 -#define data16 .byte 0x66 -#define addr16 .byte 0x67 - - #ifdef GPROF #ifdef __STDC__ diff --git a/sys/i386/boot/biosboot/bios.S b/sys/i386/boot/biosboot/bios.S new file mode 100644 index 000000000000..c4ad6ad62530 --- /dev/null +++ b/sys/i386/boot/biosboot/bios.S @@ -0,0 +1,363 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: bios.S,v $ +Revision 1.2 1993/07/11 12:02:20 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/06/28 bde + * Guess the disk size when the BIOS doesn't support the diskinfo + * interrupt. + * + * Change biosread() interface. Sector count and io address are now + * args. + * + * Change all data16's to data32's. + * +Revision 1.1 1993/03/21 18:08:23 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:34:26 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * From 2.5 version + * [92/03/30 mg32] + * + * Revision 2.2 91/04/02 14:35:21 mbj + * Add Intel copyright + * [90/02/09 rvb] + * + */ + + +/* + 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 +*/ + +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 + 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 + + call EXT(prot_to_real) # enter real mode + movb $0x2, %ah # subfunction + addr32 + movb 0x18(%ebp), %al # number of sectors + + sti + int $0x13 + cli + + mov %eax, %ebx # save return value (actually movw %ax, %bx) + + data32 + call EXT(real_to_prot) # back to protected mode + + xor %eax, %eax + 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) +*/ + + +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) + movb $0xe, %ah + movb %cl, %al + sti + 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 +*/ + +ENTRY(getc) + push %ebp + mov %esp, %ebp + push %ebx # save %ebx + + call EXT(prot_to_real) + + movb $0x0, %ah + sti + int $0x16 + cli + + 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 +*/ +ENTRY(ischar) + push %ebp + mov %esp, %ebp + push %ebx + + 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 +# +*/ + +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, %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 + 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 +ok: + + data32 + 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) + + 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. +# +*/ + +ENTRY(memsize) + push %ebp + mov %esp, %ebp + push %ebx + + mov 8(%ebp), %ebx + + 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 diff --git a/sys/i386/boot/biosboot/boot.c b/sys/i386/boot/biosboot/boot.c index 805303e6dab2..83801e10e7b0 100644 --- a/sys/i386/boot/biosboot/boot.c +++ b/sys/i386/boot/biosboot/boot.c @@ -24,20 +24,53 @@ * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. - * - * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE - * -------------------- ----- ---------------------- - * CURRENT PATCH LEVEL: 1 00159 - * -------------------- ----- ---------------------- - * - * 23 May 93 Rodney W. Grimes Added pad to kernel size for structs - * allocated by locore.s */ /* * HISTORY - * $Log: boot.c,v $ + * $Log: boot.c,v $ + * Revision 1.8 1993/07/11 12:02:21 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.7 1993/06/18 06:50:52 cgd + * convert magic numbers to network byte order, and attendent changes + * + * Revision 1.6 1993/06/14 00:47:08 deraadt + * *whoops*. The previous commit killed a few important characters of code. + * + * Revision 1.5 1993/06/05 22:52:11 cgd + * make sure kernel is small enough; this is a really weird fix from + * rod, pk patch #159. the comment is: + * + * The +28672 is for memory allocated by locore.s that must fit in the bss! + * + * this seems way wrong to me, but i'm not going to fix it in locore right + * now... + * + * Revision 1.4 1993/05/04 10:22:39 deraadt + * if we timeout asking for kernel name, print a \n before proceeding. + * Funny how one character can bug ya so much, eh? + * + * Revision 1.3 1993/04/28 06:37:58 cgd + * bsd->netbsd + * + * Revision 1.2 1993/04/28 05:32:55 cgd + * new kernel name is "bsd" also, add "o*" to list of kernels to boot. + * + * Revision 1.1 1993/03/21 18:08:26 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:34:37 rpd + * + * 93/07/03 bde + * Write first 4096 bytes to load address, not always to address 0. + * + * 93/06/29 bde + * Don't clobber BIOS variables. + * * Change date in banner. * [92/04/03 16:51:14 rvb] * @@ -76,13 +109,12 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include - struct exec head; int argv[10], esym; char *name; char *names[] = { - "/386bsd", "/386bsd.old", - "/vmunix", "/vmunix.old" + "/386bsd", "/o386bsd", "/386bsd.old", + "/vmunix", "/ovmunix", "/vmunix.old" }; #define NUMNAMES (sizeof(names)/sizeof(char *)) @@ -91,10 +123,13 @@ boot(drive) int drive; { int loadflags, currname = 0; - printf("\n>> 386bsd BOOT @ 0x%x: %d/%d k of memory [20/9/92]\n", + char *t; + + printf("\n>> 386BSD BOOT @ 0x%x: %d/%d k of memory [%s]\n", ouraddr, argv[7] = memsize(0), - argv[8] = memsize(1)); + argv[8] = memsize(1), + "$Revision: 1.8 $"); printf("use options hd(1,...... to boot sd0 when wd0 is also installed\n"); gateA20(); loadstart: @@ -126,6 +161,7 @@ loadprog(howto) { long int startaddr; long int addr; /* physical address.. not directly useable */ + long int addr0; int i; static int (*x_entry)() = 0; unsigned char tmpbuf[4096]; /* we need to load the first 4k here */ @@ -133,18 +169,18 @@ loadprog(howto) argv[3] = 0; argv[4] = 0; read(&head, sizeof(head)); - if (head.a_magic == 0413 ) - { - poff = 4096; - } - else - { + if ( N_BADMAG(head)) { printf("Invalid format!\n"); return; } + poff = N_TXTOFF(head); + /*if(poff==0) + poff = 32;*/ + startaddr = (int)head.a_entry; addr = (startaddr & 0x00f00000); /* some MEG boundary */ + addr0 = addr; printf("Booting %s(%d,%c)%s @ 0x%x\n" , devs[maj] , unit @@ -160,7 +196,7 @@ loadprog(howto) } /* * The +28672 is for memory allocated by locore.s that must - * fit in the bss! + * fit in the bss! (XXX - cgd) */ if((addr + head.a_text + head.a_data + head.a_bss + 28672) > 0xa0000) { @@ -173,7 +209,7 @@ loadprog(howto) printf("loader overlaps bss, kernel must bzero\n"); } } - printf("text=0x%x", head.a_text); + printf("text=0x%x ", head.a_text); /********************************************************/ /* LOAD THE TEXT SEGMENT */ /* don't clobber the first 4k yet (BIOS NEEDS IT) */ @@ -189,7 +225,7 @@ loadprog(howto) while (addr & CLOFSET) *(char *)addr++ = 0; - printf(" data=0x%x", head.a_data); + printf("data=0x%x ", head.a_data); xread(addr, head.a_data); addr += head.a_data; @@ -197,7 +233,7 @@ loadprog(howto) /* Skip over the uninitialised data */ /* (but clear it) */ /********************************************************/ - printf(" bss=0x%x", head.a_bss); + printf("bss=0x%x ", head.a_bss); if( (addr < ouraddr) && ((addr + head.a_bss) > ouraddr)) { pbzero(addr,ouraddr - (int)addr); @@ -220,7 +256,7 @@ loadprog(howto) /********************************************************/ /* READ in the symbol table */ /********************************************************/ - printf(" symbols=[+0x%x", head.a_syms); + printf("symbols=[+0x%x", head.a_syms); xread(addr, head.a_syms); addr += head.a_syms; @@ -237,7 +273,7 @@ loadprog(howto) /********************************************************/ /* and that many bytes of (debug symbols?) */ /********************************************************/ - printf("+0x%x]", i); + printf("+0x%x] ", i); xread(addr, i); addr += i; } @@ -247,7 +283,7 @@ loadprog(howto) /********************************************************/ argv[4] = ((addr+sizeof(int)-1))&~(sizeof(int)-1); - printf(" total=0x%x",argv[4]); + printf("total=0x%x ",argv[4]); /* @@ -278,8 +314,10 @@ loadprog(howto) /****************************************************************/ /* copy that first page and overwrite any BIOS variables */ /****************************************************************/ - printf(" entry point=0x%x \n" ,((int)startaddr) & 0xffffff); - pcpy(tmpbuf, 0, 4096); + printf("entry point=0x%x\n" ,((int)startaddr) & 0xffffff); + /* Under no circumstances overwrite precious BIOS variables! */ + pcpy(tmpbuf, addr0, 0x400); + pcpy(tmpbuf + 0x500, addr0 + 0x500, 4096 - 0x500); startprog(((int)startaddr & 0xffffff),argv); } @@ -318,6 +356,7 @@ getbootdev(howto) *ptr++ = 0; } } - } + } else + printf("\n"); } diff --git a/sys/i386/boot/biosboot/boot.h b/sys/i386/boot/biosboot/boot.h index 28a7a220e52c..ae53305a9732 100644 --- a/sys/i386/boot/biosboot/boot.h +++ b/sys/i386/boot/biosboot/boot.h @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: boot.h,v $ + * $Log: boot.h,v $ + * Revision 1.1 1993/03/21 18:08:29 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:03 rpd * Fabricated from 3.0 bootstrap. But too many things are global. * [92/03/30 mg32] diff --git a/sys/i386/boot/biosboot/boot2.S b/sys/i386/boot/biosboot/boot2.S new file mode 100644 index 000000000000..435d820b9862 --- /dev/null +++ b/sys/i386/boot/biosboot/boot2.S @@ -0,0 +1,214 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: boot2.S,v $ +Revision 1.2 1993/07/11 12:02:22 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/07/06 bde + * Delete LOADMSG define (not used). + * + * 93/06/29 bde + * Use EXT. + * + * Initialize GDT and IDT pointers at boot time. + * + * Convert (drive | head | junk) to drive arg for boot() (not strictly + * necessary - boot() only uses drive & 0x80). + * + * 93/06/28 bde + * Initialize top bits of %eax for setting _ouraddr. start.s + * initialized them suitably, but this isn't documented, and the BIOS + * isn't documented to preserve them. + * + * Use addr32 for setting _ouraddr. Without this, there were extra bytes + * 0, 0 after the store. These decode as "add %al, (%bx,%si)" in 16-bit + * mode would clobber something (except %al is very likely to be 0 :-). + * + * Clear the bss. This may be unnecessary. Some is already cleared in + * the disk image. + * + * Loop if boot() returns. + * +Revision 1.1 1993/03/21 18:08:33 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:35:26 rpd + * From 2.5 + * [92/03/30 rvb] + * + * Revision 2.2 91/04/02 14:39:21 mbj + * Put into rcs tree + * [90/02/09 rvb] + * + */ + +#include "asm.h" + +/* Conventional GDT indexes. */ +#define BOOT_CS_INDEX 3 +#define BOOT_CS16_INDEX 5 +#define BOOT_DS_INDEX 4 +#define DB_CS_INDEX 14 +#define DB_CS16_INDEX 15 +#define DB_DS_INDEX 16 +#define GDT_INDEX 17 + +/* Vector numbers. */ +#define BREAKPOINT_VECTOR 3 +#define DEBUG_VECTOR 1 + +/* + * boot2() -- second stage boot + */ + +.globl EXT(ouraddr) + +ENTRY(boot2) + data32 + subl %eax, %eax + mov %cs, %ax + mov %ax, %ds + mov %ax, %es + data32 + shll $4, %eax + addr32 + data32 + movl %eax, EXT(ouraddr) + + /* fix up GDT entries for bootstrap */ +#define FIXUP(gdt_index) \ + addr32; \ + movl %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \ + addr32; \ + movb %bl, EXT(Gdt)+(8*gdt_index)+4 + + data32 + shld $16, %eax, %ebx + FIXUP(BOOT_CS_INDEX) + FIXUP(BOOT_CS16_INDEX) + FIXUP(BOOT_DS_INDEX) + + /* fix up GDT entry for GDT, and GDT and IDT pointers */ + data32 + movl %eax, %ecx + data32 + addl $ EXT(Gdt), %eax + data32 + shld $16, %eax, %ebx + FIXUP(GDT_INDEX) + addr32 + data32 + movl %eax, EXT(Gdtr)+2 + data32 + addl $ EXT(Idt), %ecx + addr32 + data32 + movl %ecx, EXT(Idtr_prot)+2 + + /* %es = vector table segment for a while */ + push %es + data32 + subl %eax, %eax + mov %ax, %es + + /* fix up GDT entries for bdb */ + data32 + movl $4*DEBUG_VECTOR, %esi + addr32 + movl %es: 2(%esi), %eax /* actually movw to %ax */ + data32 + shll $4, %eax + data32 + shld $16, %eax, %ebx + FIXUP(DB_CS_INDEX) + FIXUP(DB_CS16_INDEX) + FIXUP(DB_DS_INDEX) + + /* Fetch entry points of bdb's protected mode trap handlers. These + * are stored at 2 before the corresponding entry points for real mode. + */ + data32 + subl %ebx, %ebx + addr32 + movl %es: (%esi), %ebx /* actually movw to %bx */ + data32 + subl %ecx, %ecx + addr32 + movl %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx + /* actually movw to %cx */ + + /* %es = bdb segment for a while */ + data32 + shrl $4, %eax + mov %ax, %es + + /* fix up IDT entries for bdb */ + movl %es: -2(%ebx), %eax /* actually movw to %ax */ + addr32 + movl %eax, EXT(Idt)+8*DEBUG_VECTOR /* actually movw %ax */ + movl %es: -2(%ecx), %eax /* actually movw to %ax */ + addr32 + movl %eax, EXT(Idt)+8*BREAKPOINT_VECTOR /* actually movw %ax */ + + /* finished with groping in real mode segments */ + pop %es + + /* change to protected mode */ + data32 + call EXT(real_to_prot) + + /* clear the bss */ + movl $ EXT(edata), %edi /* no EXT(_edata) - krufty ld */ + movl $ EXT(end), %ecx /* or EXT(_end) */ + subl %edi, %ecx + subb %al, %al + rep + stosb + + movzbl %dl, %edx /* discard head (%dh) and random high bits */ + pushl %edx + call EXT(boot) +oops: + hlt + jmp oops + + .data + .align 2 +#if 0 /* XXX this would give losing "_ouraddr :". Better declared in C */ +EXT(ouraddr): +#else +_ouraddr: +#endif + .long 0 diff --git a/sys/i386/boot/biosboot/disk.c b/sys/i386/boot/biosboot/disk.c index 87b30b27fc2c..5be5723c7f6e 100644 --- a/sys/i386/boot/biosboot/disk.c +++ b/sys/i386/boot/biosboot/disk.c @@ -28,7 +28,19 @@ /* * HISTORY - * $Log: disk.c,v $ + * $Log: disk.c,v $ + * Revision 1.3 1993/07/11 12:02:23 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.2 1993/06/18 02:28:58 cgd + * make it *do* something when loading the kernel, a la sun twiddling-thing + * + * Revision 1.1 1993/03/21 18:08:36 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:49 rpd * Fabricated from 3.0 bootstrap and 2.5 boot disk.c: * with support for scsi @@ -174,14 +186,44 @@ devread() } } +#define I_ADDR ((void *) 0) /* XXX where all reads go */ + +/* Read ahead buffer large enough for one track on a 1440K floppy. For + * reading from floppies, the bootstrap has to be loaded on a 64K boundary + * to ensure that this buffer doesn't cross a 64K DMA boundary. + */ +#define RA_SECTORS 18 +static char ra_buf[RA_SECTORS * BPS]; +static int ra_end; +static int ra_first; + Bread(dosdev,sector) int dosdev,sector; { - int cyl = sector/spc, head = (sector%spc)/spt, secnum = sector%spt; - while (biosread(dosdev, cyl,head,secnum)) + if (sector < ra_first || sector >= ra_end) { - printf("Error: C:%d H:%d S:%d\n",cyl,head,secnum); + int cyl, head, sec, nsec; + + cyl = sector/spc; + head = (sector % spc) / spt; + sec = sector % spt; + nsec = spt - sec; + if (nsec > RA_SECTORS) + nsec = RA_SECTORS; + twiddle(); + if (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0) + { + nsec = 1; + twiddle(); + while (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0) { + printf("Error: C:%d H:%d S:%d\n", cyl, head, sec); + twiddle(); + } + } + ra_first = sector; + ra_end = sector + nsec; } + bcopy(ra_buf + (sector - ra_first) * BPS, I_ADDR, BPS); } badsect(dosdev, sector) diff --git a/sys/i386/boot/biosboot/io.c b/sys/i386/boot/biosboot/io.c index 237b21cc2cf0..5327f88a5c7e 100644 --- a/sys/i386/boot/biosboot/io.c +++ b/sys/i386/boot/biosboot/io.c @@ -28,7 +28,19 @@ /* * HISTORY - * $Log: io.c,v $ + * $Log: io.c,v $ + * Revision 1.3 1993/07/11 12:02:24 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.2 1993/06/18 02:28:59 cgd + * make it *do* something when loading the kernel, a la sun twiddling-thing + * + * Revision 1.1 1993/03/21 18:08:38 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:57 rpd * Fixed for IBM L40's A20 initialization. * [92/03/30 rvb] @@ -82,6 +94,8 @@ printf(format,data) { int *dataptr = &data; char c; + + reset_twiddle(); while (c = *format++) if (c != '%') putchar(c); @@ -187,3 +201,25 @@ int len; while (len-- > 0) *to++ = *from++; } + +static int tw_on; +static int tw_pos; +static char tw_chars[] = "|/-\\"; + +reset_twiddle() +{ + if (tw_on) + putchar('\b'); + tw_on = 0; + tw_pos = 0; +} + +twiddle() +{ + if (tw_on) + putchar('\b'); + else + tw_on = 1; + putchar(tw_chars[tw_pos++]); + tw_pos %= (sizeof(tw_chars) - 1); +} diff --git a/sys/i386/boot/biosboot/start.S b/sys/i386/boot/biosboot/start.S new file mode 100644 index 000000000000..88bd1ba3174d --- /dev/null +++ b/sys/i386/boot/biosboot/start.S @@ -0,0 +1,380 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: start.S,v $ +Revision 1.2 1993/07/11 12:02:24 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/07/06 bde + * Restored BOOTSEG to 0x9000 for distribution. It should be decided + * at boot time to locate the bootstrap immediately underneath the + * debugger or whatever is in high memory. This isn't safe yet, + * because it might make the read-ahead buffer might lie across a 64K + * DMA boundary. + * + * 93/07/03 bde + * Some floppy BIOS's can only handle reads of one track, so a LOADSZ + * of 16 doesn't work. 15 will do for now. + * + * 93/06/29 bde + * LOADSZ is 16, not 14. The BIOS can handle a minimum of one floppy + * cylinder so it can always handle 16 sectors starting at head 0, + * sector 1. + * + * 93/06/28 bde + * Changed addr16's to addr32's. One before a useless "xor %ecx, %ecx" + * did nothing (removed both prefix and xor). + * + * Initialize head = %dh = 0 for floppy case. + * + * Fixed #ifdef DEBUG ... #endif that split data32; jmp load. If + * DEBUG is defined then the jmp doesn't get prefixed. This is fatal + * iff the jmp is long. Usually the jmp will be short and the prefix + * unnecessary. But it is more likely to be necessary if DEBUG is + * defined. + * + * 93/06/27 bde + * Removed bogus Int 21. There is no Int 21 BIOS call. The drive + * number is passed to here in %dl and the Int 21 is at best a nop. + * Some BIOS's treat Int 21 as a stray hardware interrupt and shut + * down all in-service interrupts. This should not be a problem + * because this are not an interrupt handler so there are no + * in-service interrupts, but ... + * + * Fixed fd/hd decision. "%dl ge 0x80" (signed comparison) was always + * true, so fd's were treated as hd's. This was not a problem because + * the boot block has a partition table. + * + * Reduced BOOTSEG and added breakpoint so that debugger can look at + * this. Having a fixed boot address is bad because some machines don't + * have 640K and others have debuggers and/or BIOS stuff in high memory. + * + * 93/04/30 bde + * Commented out " # %". It's not C, and gcc-2's + * cpp doesn't allow it. "# identifier" isn't C either but works for now. + * + * Use $ EXT instead of $EXT to avoid broken DOLLARS_IN_IDENTIFIERS stuff + * in gcc-2.3.3. (Bug is still in gcc-2.4.5 but is avoided by using .S + * files.) + * +Revision 1.1 1993/03/21 18:08:42 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:36:29 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * Need to zero dh on hd path; at least for an adaptec card. + * [92/01/14 rvb] + * + * From 2.5 boot: + * Flush digit printing. + * Fuse floppy and hd boot by using Int 21 to tell + * boot type (slightly dubious since Int 21 is DOS + * not BIOS) + * [92/03/30 mg32] + * + * Revision 2.2 91/04/02 14:42:04 mbj + * Fix the BIG boot bug. We had missed a necessary data + * before a xor that was clearing a register used later + * as an index register. + * [91/03/01 rvb] + * Remember floppy type for swapgeneric + * Add Intel copyright + * [90/02/09 rvb] + * + */ + + +/* + 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 + + .text + +ENTRY(boot1) + # 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 + mov %cs, %ax + mov %ax, %ds + + # 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) ***/ + mov %ax, %es + +#ifdef DEBUG + data32 + mov $one, %esi + data32 + call message +#endif + + # bootstrap passes us drive number in %dl + cmpb $0x80, %dl + data32 + jae hd + +fd: +# 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 +#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 + 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 *****/ + data32 + mov $PARTSTART, %ebx + data32 + mov $NUMPART, %ecx +again: + addr32 + 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 +*/ + +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". + +#ifdef DEBUG + data32 + mov $six, %esi + data32 + call message +#endif + data32 + ljmp $BOOTSEG, $ EXT(boot2) + +# +# 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) +*/ + + data32 + push %eax + data32 + push %ebx + data32 + mov $0x0001, %ebx + cld + +nextb: + lodsb # load a byte into %al + cmpb $0x0, %al + data32 + je done + movb $0xe, %ah + 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 + +/* 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 diff --git a/sys/i386/boot/biosboot/sys.c b/sys/i386/boot/biosboot/sys.c index bb34340da482..1f3a9b32b6ec 100644 --- a/sys/i386/boot/biosboot/sys.c +++ b/sys/i386/boot/biosboot/sys.c @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: sys.c,v $ + * $Log: sys.c,v $ + * Revision 1.1 1993/03/21 18:08:45 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:36:34 rpd * Fabricated from 3.0 bootstrap and scratch. * [92/03/30 mg32] diff --git a/sys/i386/boot/biosboot/table.c b/sys/i386/boot/biosboot/table.c index c26490ad0643..fc14801978f6 100644 --- a/sys/i386/boot/biosboot/table.c +++ b/sys/i386/boot/biosboot/table.c @@ -28,7 +28,26 @@ /* * HISTORY - * $Log: table.c,v $ + * $Log: table.c,v $ + * Revision 1.2 1993/07/11 12:02:25 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * + * 93/06/28 bde + * Remove remaining magic numbers that depend on the load address. + * IDTs and many more GDT entries to support my debugger. + * + * 93/06/27 bde + * Remove unused Gdtr2. + * Remove some magic numbers from Gdtr and Gdt. The boot loader may + * override the ones related to the standard load address of 0x90000. + * + * Revision 1.1 1993/03/21 18:08:47 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:36:43 rpd * Fix Intel Copyright as per B. Davies authorization. * [92/04/03 rvb] @@ -64,9 +83,6 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define NGDTENT 6 -#define GDTLIMIT 48 /* NGDTENT * 8 */ - /* Segment Descriptor * * 31 24 19 16 7 0 @@ -85,21 +101,51 @@ struct seg_desc { unsigned short limit_15_0; unsigned short base_15_0; unsigned char base_23_16; - unsigned char bit_15_8; - unsigned char bit_23_16; + unsigned char p_dpl_type; + unsigned char g_b_a_limit; unsigned char base_31_24; }; +#define RUN 0 /* not really 0, but filled in at boot time */ -struct seg_desc Gdt[NGDTENT] = { +struct seg_desc Gdt[] = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 0x0 : null */ {0xFFFF, 0x0, 0x0, 0x9F, 0xCF, 0x0}, /* 0x08 : kernel code */ + /* 0x9E? */ {0xFFFF, 0x0, 0x0, 0x93, 0xCF, 0x0}, /* 0x10 : kernel data */ - {0xFFFF, 0x0000, 0x9, 0x9E, 0x40, 0x0}, /* 0x18 : boot code */ - {0xFFFF, 0x0000, 0x9, 0x92, 0x40, 0x0}, /* 0x20 : boot data */ - {0xFFFF, 0x0000, 0x9, 0x9E, 0x0, 0x0} /* 0x28 : boot code, 16 bits */ - }; + /* 0x92? */ + {0xFFFF, RUN, RUN, 0x9E, 0x40, 0x0}, /* 0x18 : boot code */ + {0xFFFF, RUN, RUN, 0x92, 0x40, 0x0}, /* 0x20 : boot data */ + {0xFFFF, RUN, RUN, 0x9E, 0x0, 0x0}, /* 0x28 : boot code, 16 bits */ + /* More for bdb. */ + {}, /* BIOS_CS_INDEX = 6 : null */ + {}, /* BIOS_TMP_INDEX = 7 : null */ + {}, /* TSS_INDEX = 8 : null */ + {0xFFFF, 0x0, 0x0, 0xB2, 0x40, 0x0}, /* DS_286_INDEX = 9 */ + {0xFFFF, 0x0, 0x0, 0xB2, 0x40, 0x0}, /* ES_286_INDEX = 10 */ + {}, /* Unused = 11 : null */ + {0x7FFF, 0x8000, 0xB, 0xB2, 0x40, 0x0}, /* COLOR_INDEX = 12 */ + {0x7FFF, 0x0, 0xB, 0xB2, 0x40, 0x0}, /* MONO_INDEX = 13 */ + {0xFFFF, RUN, RUN, 0x9A, 0x40, 0x0}, /* DB_CS_INDEX = 14 */ + {0xFFFF, RUN, RUN, 0x9A, 0x0, 0x0}, /* DB_CS16_INDEX = 15 */ + {0xFFFF, RUN, RUN, 0x92, 0x40, 0x0}, /* DB_DS_INDEX = 16 */ + {8*18-1, RUN, RUN, 0x92, 0x40, 0x0}, /* GDT_INDEX = 17 */ +}; +struct idt_desc { + unsigned short entry_15_0; + unsigned short selector; + unsigned char padding; + unsigned char p_dpl_type; + unsigned short entry_31_16; +}; + +struct idt_desc Idt[] = { + {}, /* Null (int 0) */ + {RUN, 0x70, 0, 0x8E, 0}, /* DEBUG_VECTOR = 1 */ + {}, /* Null (int 2) */ + {RUN, 0x70, 0, 0xEE, 0}, /* BREAKPOINT_VECTOR = 3 */ +}; struct pseudo_desc { unsigned short limit; @@ -107,6 +153,6 @@ struct pseudo_desc { unsigned short base_high; }; -struct pseudo_desc Gdtr = { GDTLIMIT, 0x0400, 9 }; -struct pseudo_desc Gdtr2 = { GDTLIMIT, 0xfe00, 9 }; - /* boot is loaded at 0x90000, Gdt is at boot+1024 */ +struct pseudo_desc Gdtr = { sizeof Gdt - 1, RUN, RUN }; +struct pseudo_desc Idtr_prot = { sizeof Idt - 1, RUN, RUN }; +struct pseudo_desc Idtr_real = { 0x400 - 1, 0x0, 0x0 }; diff --git a/sys/i386/boot/boot.c b/sys/i386/boot/boot.c index 805303e6dab2..83801e10e7b0 100644 --- a/sys/i386/boot/boot.c +++ b/sys/i386/boot/boot.c @@ -24,20 +24,53 @@ * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. - * - * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE - * -------------------- ----- ---------------------- - * CURRENT PATCH LEVEL: 1 00159 - * -------------------- ----- ---------------------- - * - * 23 May 93 Rodney W. Grimes Added pad to kernel size for structs - * allocated by locore.s */ /* * HISTORY - * $Log: boot.c,v $ + * $Log: boot.c,v $ + * Revision 1.8 1993/07/11 12:02:21 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.7 1993/06/18 06:50:52 cgd + * convert magic numbers to network byte order, and attendent changes + * + * Revision 1.6 1993/06/14 00:47:08 deraadt + * *whoops*. The previous commit killed a few important characters of code. + * + * Revision 1.5 1993/06/05 22:52:11 cgd + * make sure kernel is small enough; this is a really weird fix from + * rod, pk patch #159. the comment is: + * + * The +28672 is for memory allocated by locore.s that must fit in the bss! + * + * this seems way wrong to me, but i'm not going to fix it in locore right + * now... + * + * Revision 1.4 1993/05/04 10:22:39 deraadt + * if we timeout asking for kernel name, print a \n before proceeding. + * Funny how one character can bug ya so much, eh? + * + * Revision 1.3 1993/04/28 06:37:58 cgd + * bsd->netbsd + * + * Revision 1.2 1993/04/28 05:32:55 cgd + * new kernel name is "bsd" also, add "o*" to list of kernels to boot. + * + * Revision 1.1 1993/03/21 18:08:26 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:34:37 rpd + * + * 93/07/03 bde + * Write first 4096 bytes to load address, not always to address 0. + * + * 93/06/29 bde + * Don't clobber BIOS variables. + * * Change date in banner. * [92/04/03 16:51:14 rvb] * @@ -76,13 +109,12 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include - struct exec head; int argv[10], esym; char *name; char *names[] = { - "/386bsd", "/386bsd.old", - "/vmunix", "/vmunix.old" + "/386bsd", "/o386bsd", "/386bsd.old", + "/vmunix", "/ovmunix", "/vmunix.old" }; #define NUMNAMES (sizeof(names)/sizeof(char *)) @@ -91,10 +123,13 @@ boot(drive) int drive; { int loadflags, currname = 0; - printf("\n>> 386bsd BOOT @ 0x%x: %d/%d k of memory [20/9/92]\n", + char *t; + + printf("\n>> 386BSD BOOT @ 0x%x: %d/%d k of memory [%s]\n", ouraddr, argv[7] = memsize(0), - argv[8] = memsize(1)); + argv[8] = memsize(1), + "$Revision: 1.8 $"); printf("use options hd(1,...... to boot sd0 when wd0 is also installed\n"); gateA20(); loadstart: @@ -126,6 +161,7 @@ loadprog(howto) { long int startaddr; long int addr; /* physical address.. not directly useable */ + long int addr0; int i; static int (*x_entry)() = 0; unsigned char tmpbuf[4096]; /* we need to load the first 4k here */ @@ -133,18 +169,18 @@ loadprog(howto) argv[3] = 0; argv[4] = 0; read(&head, sizeof(head)); - if (head.a_magic == 0413 ) - { - poff = 4096; - } - else - { + if ( N_BADMAG(head)) { printf("Invalid format!\n"); return; } + poff = N_TXTOFF(head); + /*if(poff==0) + poff = 32;*/ + startaddr = (int)head.a_entry; addr = (startaddr & 0x00f00000); /* some MEG boundary */ + addr0 = addr; printf("Booting %s(%d,%c)%s @ 0x%x\n" , devs[maj] , unit @@ -160,7 +196,7 @@ loadprog(howto) } /* * The +28672 is for memory allocated by locore.s that must - * fit in the bss! + * fit in the bss! (XXX - cgd) */ if((addr + head.a_text + head.a_data + head.a_bss + 28672) > 0xa0000) { @@ -173,7 +209,7 @@ loadprog(howto) printf("loader overlaps bss, kernel must bzero\n"); } } - printf("text=0x%x", head.a_text); + printf("text=0x%x ", head.a_text); /********************************************************/ /* LOAD THE TEXT SEGMENT */ /* don't clobber the first 4k yet (BIOS NEEDS IT) */ @@ -189,7 +225,7 @@ loadprog(howto) while (addr & CLOFSET) *(char *)addr++ = 0; - printf(" data=0x%x", head.a_data); + printf("data=0x%x ", head.a_data); xread(addr, head.a_data); addr += head.a_data; @@ -197,7 +233,7 @@ loadprog(howto) /* Skip over the uninitialised data */ /* (but clear it) */ /********************************************************/ - printf(" bss=0x%x", head.a_bss); + printf("bss=0x%x ", head.a_bss); if( (addr < ouraddr) && ((addr + head.a_bss) > ouraddr)) { pbzero(addr,ouraddr - (int)addr); @@ -220,7 +256,7 @@ loadprog(howto) /********************************************************/ /* READ in the symbol table */ /********************************************************/ - printf(" symbols=[+0x%x", head.a_syms); + printf("symbols=[+0x%x", head.a_syms); xread(addr, head.a_syms); addr += head.a_syms; @@ -237,7 +273,7 @@ loadprog(howto) /********************************************************/ /* and that many bytes of (debug symbols?) */ /********************************************************/ - printf("+0x%x]", i); + printf("+0x%x] ", i); xread(addr, i); addr += i; } @@ -247,7 +283,7 @@ loadprog(howto) /********************************************************/ argv[4] = ((addr+sizeof(int)-1))&~(sizeof(int)-1); - printf(" total=0x%x",argv[4]); + printf("total=0x%x ",argv[4]); /* @@ -278,8 +314,10 @@ loadprog(howto) /****************************************************************/ /* copy that first page and overwrite any BIOS variables */ /****************************************************************/ - printf(" entry point=0x%x \n" ,((int)startaddr) & 0xffffff); - pcpy(tmpbuf, 0, 4096); + printf("entry point=0x%x\n" ,((int)startaddr) & 0xffffff); + /* Under no circumstances overwrite precious BIOS variables! */ + pcpy(tmpbuf, addr0, 0x400); + pcpy(tmpbuf + 0x500, addr0 + 0x500, 4096 - 0x500); startprog(((int)startaddr & 0xffffff),argv); } @@ -318,6 +356,7 @@ getbootdev(howto) *ptr++ = 0; } } - } + } else + printf("\n"); } diff --git a/sys/i386/boot/boot.h b/sys/i386/boot/boot.h index 28a7a220e52c..ae53305a9732 100644 --- a/sys/i386/boot/boot.h +++ b/sys/i386/boot/boot.h @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: boot.h,v $ + * $Log: boot.h,v $ + * Revision 1.1 1993/03/21 18:08:29 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:03 rpd * Fabricated from 3.0 bootstrap. But too many things are global. * [92/03/30 mg32] diff --git a/sys/i386/boot/boot2.S b/sys/i386/boot/boot2.S new file mode 100644 index 000000000000..435d820b9862 --- /dev/null +++ b/sys/i386/boot/boot2.S @@ -0,0 +1,214 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: boot2.S,v $ +Revision 1.2 1993/07/11 12:02:22 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/07/06 bde + * Delete LOADMSG define (not used). + * + * 93/06/29 bde + * Use EXT. + * + * Initialize GDT and IDT pointers at boot time. + * + * Convert (drive | head | junk) to drive arg for boot() (not strictly + * necessary - boot() only uses drive & 0x80). + * + * 93/06/28 bde + * Initialize top bits of %eax for setting _ouraddr. start.s + * initialized them suitably, but this isn't documented, and the BIOS + * isn't documented to preserve them. + * + * Use addr32 for setting _ouraddr. Without this, there were extra bytes + * 0, 0 after the store. These decode as "add %al, (%bx,%si)" in 16-bit + * mode would clobber something (except %al is very likely to be 0 :-). + * + * Clear the bss. This may be unnecessary. Some is already cleared in + * the disk image. + * + * Loop if boot() returns. + * +Revision 1.1 1993/03/21 18:08:33 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:35:26 rpd + * From 2.5 + * [92/03/30 rvb] + * + * Revision 2.2 91/04/02 14:39:21 mbj + * Put into rcs tree + * [90/02/09 rvb] + * + */ + +#include "asm.h" + +/* Conventional GDT indexes. */ +#define BOOT_CS_INDEX 3 +#define BOOT_CS16_INDEX 5 +#define BOOT_DS_INDEX 4 +#define DB_CS_INDEX 14 +#define DB_CS16_INDEX 15 +#define DB_DS_INDEX 16 +#define GDT_INDEX 17 + +/* Vector numbers. */ +#define BREAKPOINT_VECTOR 3 +#define DEBUG_VECTOR 1 + +/* + * boot2() -- second stage boot + */ + +.globl EXT(ouraddr) + +ENTRY(boot2) + data32 + subl %eax, %eax + mov %cs, %ax + mov %ax, %ds + mov %ax, %es + data32 + shll $4, %eax + addr32 + data32 + movl %eax, EXT(ouraddr) + + /* fix up GDT entries for bootstrap */ +#define FIXUP(gdt_index) \ + addr32; \ + movl %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \ + addr32; \ + movb %bl, EXT(Gdt)+(8*gdt_index)+4 + + data32 + shld $16, %eax, %ebx + FIXUP(BOOT_CS_INDEX) + FIXUP(BOOT_CS16_INDEX) + FIXUP(BOOT_DS_INDEX) + + /* fix up GDT entry for GDT, and GDT and IDT pointers */ + data32 + movl %eax, %ecx + data32 + addl $ EXT(Gdt), %eax + data32 + shld $16, %eax, %ebx + FIXUP(GDT_INDEX) + addr32 + data32 + movl %eax, EXT(Gdtr)+2 + data32 + addl $ EXT(Idt), %ecx + addr32 + data32 + movl %ecx, EXT(Idtr_prot)+2 + + /* %es = vector table segment for a while */ + push %es + data32 + subl %eax, %eax + mov %ax, %es + + /* fix up GDT entries for bdb */ + data32 + movl $4*DEBUG_VECTOR, %esi + addr32 + movl %es: 2(%esi), %eax /* actually movw to %ax */ + data32 + shll $4, %eax + data32 + shld $16, %eax, %ebx + FIXUP(DB_CS_INDEX) + FIXUP(DB_CS16_INDEX) + FIXUP(DB_DS_INDEX) + + /* Fetch entry points of bdb's protected mode trap handlers. These + * are stored at 2 before the corresponding entry points for real mode. + */ + data32 + subl %ebx, %ebx + addr32 + movl %es: (%esi), %ebx /* actually movw to %bx */ + data32 + subl %ecx, %ecx + addr32 + movl %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx + /* actually movw to %cx */ + + /* %es = bdb segment for a while */ + data32 + shrl $4, %eax + mov %ax, %es + + /* fix up IDT entries for bdb */ + movl %es: -2(%ebx), %eax /* actually movw to %ax */ + addr32 + movl %eax, EXT(Idt)+8*DEBUG_VECTOR /* actually movw %ax */ + movl %es: -2(%ecx), %eax /* actually movw to %ax */ + addr32 + movl %eax, EXT(Idt)+8*BREAKPOINT_VECTOR /* actually movw %ax */ + + /* finished with groping in real mode segments */ + pop %es + + /* change to protected mode */ + data32 + call EXT(real_to_prot) + + /* clear the bss */ + movl $ EXT(edata), %edi /* no EXT(_edata) - krufty ld */ + movl $ EXT(end), %ecx /* or EXT(_end) */ + subl %edi, %ecx + subb %al, %al + rep + stosb + + movzbl %dl, %edx /* discard head (%dh) and random high bits */ + pushl %edx + call EXT(boot) +oops: + hlt + jmp oops + + .data + .align 2 +#if 0 /* XXX this would give losing "_ouraddr :". Better declared in C */ +EXT(ouraddr): +#else +_ouraddr: +#endif + .long 0 diff --git a/sys/i386/boot/disk.c b/sys/i386/boot/disk.c index 87b30b27fc2c..5be5723c7f6e 100644 --- a/sys/i386/boot/disk.c +++ b/sys/i386/boot/disk.c @@ -28,7 +28,19 @@ /* * HISTORY - * $Log: disk.c,v $ + * $Log: disk.c,v $ + * Revision 1.3 1993/07/11 12:02:23 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.2 1993/06/18 02:28:58 cgd + * make it *do* something when loading the kernel, a la sun twiddling-thing + * + * Revision 1.1 1993/03/21 18:08:36 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:49 rpd * Fabricated from 3.0 bootstrap and 2.5 boot disk.c: * with support for scsi @@ -174,14 +186,44 @@ devread() } } +#define I_ADDR ((void *) 0) /* XXX where all reads go */ + +/* Read ahead buffer large enough for one track on a 1440K floppy. For + * reading from floppies, the bootstrap has to be loaded on a 64K boundary + * to ensure that this buffer doesn't cross a 64K DMA boundary. + */ +#define RA_SECTORS 18 +static char ra_buf[RA_SECTORS * BPS]; +static int ra_end; +static int ra_first; + Bread(dosdev,sector) int dosdev,sector; { - int cyl = sector/spc, head = (sector%spc)/spt, secnum = sector%spt; - while (biosread(dosdev, cyl,head,secnum)) + if (sector < ra_first || sector >= ra_end) { - printf("Error: C:%d H:%d S:%d\n",cyl,head,secnum); + int cyl, head, sec, nsec; + + cyl = sector/spc; + head = (sector % spc) / spt; + sec = sector % spt; + nsec = spt - sec; + if (nsec > RA_SECTORS) + nsec = RA_SECTORS; + twiddle(); + if (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0) + { + nsec = 1; + twiddle(); + while (biosread(dosdev, cyl, head, sec, nsec, ra_buf) != 0) { + printf("Error: C:%d H:%d S:%d\n", cyl, head, sec); + twiddle(); + } + } + ra_first = sector; + ra_end = sector + nsec; } + bcopy(ra_buf + (sector - ra_first) * BPS, I_ADDR, BPS); } badsect(dosdev, sector) diff --git a/sys/i386/boot/io.c b/sys/i386/boot/io.c index 237b21cc2cf0..5327f88a5c7e 100644 --- a/sys/i386/boot/io.c +++ b/sys/i386/boot/io.c @@ -28,7 +28,19 @@ /* * HISTORY - * $Log: io.c,v $ + * $Log: io.c,v $ + * Revision 1.3 1993/07/11 12:02:24 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * Revision 1.2 1993/06/18 02:28:59 cgd + * make it *do* something when loading the kernel, a la sun twiddling-thing + * + * Revision 1.1 1993/03/21 18:08:38 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:35:57 rpd * Fixed for IBM L40's A20 initialization. * [92/03/30 rvb] @@ -82,6 +94,8 @@ printf(format,data) { int *dataptr = &data; char c; + + reset_twiddle(); while (c = *format++) if (c != '%') putchar(c); @@ -187,3 +201,25 @@ int len; while (len-- > 0) *to++ = *from++; } + +static int tw_on; +static int tw_pos; +static char tw_chars[] = "|/-\\"; + +reset_twiddle() +{ + if (tw_on) + putchar('\b'); + tw_on = 0; + tw_pos = 0; +} + +twiddle() +{ + if (tw_on) + putchar('\b'); + else + tw_on = 1; + putchar(tw_chars[tw_pos++]); + tw_pos %= (sizeof(tw_chars) - 1); +} diff --git a/sys/i386/boot/rmaouthdr b/sys/i386/boot/rmaouthdr index d69d3917c1f4..99f76a4d627c 100644 --- a/sys/i386/boot/rmaouthdr +++ b/sys/i386/boot/rmaouthdr @@ -3,7 +3,10 @@ # # # HISTORY -# $Log: rmaouthdr,v $ +# $Log: rmaouthdr,v $ +# Revision 1.1 1993/03/21 18:08:40 cgd +# after 0.2.2 "stable" patches applied +# # Revision 2.2 92/04/04 11:36:01 rpd # From 2.5 boot # [92/03/30 mg32] diff --git a/sys/i386/boot/start.S b/sys/i386/boot/start.S new file mode 100644 index 000000000000..88bd1ba3174d --- /dev/null +++ b/sys/i386/boot/start.S @@ -0,0 +1,380 @@ +/* + * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + * + * 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. + */ + +/* + * HISTORY + * $Log: start.S,v $ +Revision 1.2 1993/07/11 12:02:24 andrew +Fixes from bde, including support for loading @ any MB boundary (e.g. a +kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead +buffering to speed booting from floppies. Also works with aha174x +controllers in enhanced mode. + + * + * 93/07/06 bde + * Restored BOOTSEG to 0x9000 for distribution. It should be decided + * at boot time to locate the bootstrap immediately underneath the + * debugger or whatever is in high memory. This isn't safe yet, + * because it might make the read-ahead buffer might lie across a 64K + * DMA boundary. + * + * 93/07/03 bde + * Some floppy BIOS's can only handle reads of one track, so a LOADSZ + * of 16 doesn't work. 15 will do for now. + * + * 93/06/29 bde + * LOADSZ is 16, not 14. The BIOS can handle a minimum of one floppy + * cylinder so it can always handle 16 sectors starting at head 0, + * sector 1. + * + * 93/06/28 bde + * Changed addr16's to addr32's. One before a useless "xor %ecx, %ecx" + * did nothing (removed both prefix and xor). + * + * Initialize head = %dh = 0 for floppy case. + * + * Fixed #ifdef DEBUG ... #endif that split data32; jmp load. If + * DEBUG is defined then the jmp doesn't get prefixed. This is fatal + * iff the jmp is long. Usually the jmp will be short and the prefix + * unnecessary. But it is more likely to be necessary if DEBUG is + * defined. + * + * 93/06/27 bde + * Removed bogus Int 21. There is no Int 21 BIOS call. The drive + * number is passed to here in %dl and the Int 21 is at best a nop. + * Some BIOS's treat Int 21 as a stray hardware interrupt and shut + * down all in-service interrupts. This should not be a problem + * because this are not an interrupt handler so there are no + * in-service interrupts, but ... + * + * Fixed fd/hd decision. "%dl ge 0x80" (signed comparison) was always + * true, so fd's were treated as hd's. This was not a problem because + * the boot block has a partition table. + * + * Reduced BOOTSEG and added breakpoint so that debugger can look at + * this. Having a fixed boot address is bad because some machines don't + * have 640K and others have debuggers and/or BIOS stuff in high memory. + * + * 93/04/30 bde + * Commented out " # %". It's not C, and gcc-2's + * cpp doesn't allow it. "# identifier" isn't C either but works for now. + * + * Use $ EXT instead of $EXT to avoid broken DOLLARS_IN_IDENTIFIERS stuff + * in gcc-2.3.3. (Bug is still in gcc-2.4.5 but is avoided by using .S + * files.) + * +Revision 1.1 1993/03/21 18:08:42 cgd +after 0.2.2 "stable" patches applied + + * Revision 2.2 92/04/04 11:36:29 rpd + * Fix Intel Copyright as per B. Davies authorization. + * [92/04/03 rvb] + * Need to zero dh on hd path; at least for an adaptec card. + * [92/01/14 rvb] + * + * From 2.5 boot: + * Flush digit printing. + * Fuse floppy and hd boot by using Int 21 to tell + * boot type (slightly dubious since Int 21 is DOS + * not BIOS) + * [92/03/30 mg32] + * + * Revision 2.2 91/04/02 14:42:04 mbj + * Fix the BIG boot bug. We had missed a necessary data + * before a xor that was clearing a register used later + * as an index register. + * [91/03/01 rvb] + * Remember floppy type for swapgeneric + * Add Intel copyright + * [90/02/09 rvb] + * + */ + + +/* + 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 + + .text + +ENTRY(boot1) + # 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 + mov %cs, %ax + mov %ax, %ds + + # 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) ***/ + mov %ax, %es + +#ifdef DEBUG + data32 + mov $one, %esi + data32 + call message +#endif + + # bootstrap passes us drive number in %dl + cmpb $0x80, %dl + data32 + jae hd + +fd: +# 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 +#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 + 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 *****/ + data32 + mov $PARTSTART, %ebx + data32 + mov $NUMPART, %ecx +again: + addr32 + 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 +*/ + +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". + +#ifdef DEBUG + data32 + mov $six, %esi + data32 + call message +#endif + data32 + ljmp $BOOTSEG, $ EXT(boot2) + +# +# 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) +*/ + + data32 + push %eax + data32 + push %ebx + data32 + mov $0x0001, %ebx + cld + +nextb: + lodsb # load a byte into %al + cmpb $0x0, %al + data32 + je done + movb $0xe, %ah + 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 + +/* 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 diff --git a/sys/i386/boot/sys.c b/sys/i386/boot/sys.c index bb34340da482..1f3a9b32b6ec 100644 --- a/sys/i386/boot/sys.c +++ b/sys/i386/boot/sys.c @@ -28,7 +28,10 @@ /* * HISTORY - * $Log: sys.c,v $ + * $Log: sys.c,v $ + * Revision 1.1 1993/03/21 18:08:45 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:36:34 rpd * Fabricated from 3.0 bootstrap and scratch. * [92/03/30 mg32] diff --git a/sys/i386/boot/table.c b/sys/i386/boot/table.c index c26490ad0643..fc14801978f6 100644 --- a/sys/i386/boot/table.c +++ b/sys/i386/boot/table.c @@ -28,7 +28,26 @@ /* * HISTORY - * $Log: table.c,v $ + * $Log: table.c,v $ + * Revision 1.2 1993/07/11 12:02:25 andrew + * Fixes from bde, including support for loading @ any MB boundary (e.g. a + * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead + * buffering to speed booting from floppies. Also works with aha174x + * controllers in enhanced mode. + * + * + * 93/06/28 bde + * Remove remaining magic numbers that depend on the load address. + * IDTs and many more GDT entries to support my debugger. + * + * 93/06/27 bde + * Remove unused Gdtr2. + * Remove some magic numbers from Gdtr and Gdt. The boot loader may + * override the ones related to the standard load address of 0x90000. + * + * Revision 1.1 1993/03/21 18:08:47 cgd + * after 0.2.2 "stable" patches applied + * * Revision 2.2 92/04/04 11:36:43 rpd * Fix Intel Copyright as per B. Davies authorization. * [92/04/03 rvb] @@ -64,9 +83,6 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define NGDTENT 6 -#define GDTLIMIT 48 /* NGDTENT * 8 */ - /* Segment Descriptor * * 31 24 19 16 7 0 @@ -85,21 +101,51 @@ struct seg_desc { unsigned short limit_15_0; unsigned short base_15_0; unsigned char base_23_16; - unsigned char bit_15_8; - unsigned char bit_23_16; + unsigned char p_dpl_type; + unsigned char g_b_a_limit; unsigned char base_31_24; }; +#define RUN 0 /* not really 0, but filled in at boot time */ -struct seg_desc Gdt[NGDTENT] = { +struct seg_desc Gdt[] = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 0x0 : null */ {0xFFFF, 0x0, 0x0, 0x9F, 0xCF, 0x0}, /* 0x08 : kernel code */ + /* 0x9E? */ {0xFFFF, 0x0, 0x0, 0x93, 0xCF, 0x0}, /* 0x10 : kernel data */ - {0xFFFF, 0x0000, 0x9, 0x9E, 0x40, 0x0}, /* 0x18 : boot code */ - {0xFFFF, 0x0000, 0x9, 0x92, 0x40, 0x0}, /* 0x20 : boot data */ - {0xFFFF, 0x0000, 0x9, 0x9E, 0x0, 0x0} /* 0x28 : boot code, 16 bits */ - }; + /* 0x92? */ + {0xFFFF, RUN, RUN, 0x9E, 0x40, 0x0}, /* 0x18 : boot code */ + {0xFFFF, RUN, RUN, 0x92, 0x40, 0x0}, /* 0x20 : boot data */ + {0xFFFF, RUN, RUN, 0x9E, 0x0, 0x0}, /* 0x28 : boot code, 16 bits */ + /* More for bdb. */ + {}, /* BIOS_CS_INDEX = 6 : null */ + {}, /* BIOS_TMP_INDEX = 7 : null */ + {}, /* TSS_INDEX = 8 : null */ + {0xFFFF, 0x0, 0x0, 0xB2, 0x40, 0x0}, /* DS_286_INDEX = 9 */ + {0xFFFF, 0x0, 0x0, 0xB2, 0x40, 0x0}, /* ES_286_INDEX = 10 */ + {}, /* Unused = 11 : null */ + {0x7FFF, 0x8000, 0xB, 0xB2, 0x40, 0x0}, /* COLOR_INDEX = 12 */ + {0x7FFF, 0x0, 0xB, 0xB2, 0x40, 0x0}, /* MONO_INDEX = 13 */ + {0xFFFF, RUN, RUN, 0x9A, 0x40, 0x0}, /* DB_CS_INDEX = 14 */ + {0xFFFF, RUN, RUN, 0x9A, 0x0, 0x0}, /* DB_CS16_INDEX = 15 */ + {0xFFFF, RUN, RUN, 0x92, 0x40, 0x0}, /* DB_DS_INDEX = 16 */ + {8*18-1, RUN, RUN, 0x92, 0x40, 0x0}, /* GDT_INDEX = 17 */ +}; +struct idt_desc { + unsigned short entry_15_0; + unsigned short selector; + unsigned char padding; + unsigned char p_dpl_type; + unsigned short entry_31_16; +}; + +struct idt_desc Idt[] = { + {}, /* Null (int 0) */ + {RUN, 0x70, 0, 0x8E, 0}, /* DEBUG_VECTOR = 1 */ + {}, /* Null (int 2) */ + {RUN, 0x70, 0, 0xEE, 0}, /* BREAKPOINT_VECTOR = 3 */ +}; struct pseudo_desc { unsigned short limit; @@ -107,6 +153,6 @@ struct pseudo_desc { unsigned short base_high; }; -struct pseudo_desc Gdtr = { GDTLIMIT, 0x0400, 9 }; -struct pseudo_desc Gdtr2 = { GDTLIMIT, 0xfe00, 9 }; - /* boot is loaded at 0x90000, Gdt is at boot+1024 */ +struct pseudo_desc Gdtr = { sizeof Gdt - 1, RUN, RUN }; +struct pseudo_desc Idtr_prot = { sizeof Idt - 1, RUN, RUN }; +struct pseudo_desc Idtr_real = { 0x400 - 1, 0x0, 0x0 };