summaryrefslogtreecommitdiff
path: root/sys/arch/i386/stand/biosboot
diff options
context:
space:
mode:
authorTobias Weingartner <weingart@cvs.openbsd.org>1997-03-31 03:12:20 +0000
committerTobias Weingartner <weingart@cvs.openbsd.org>1997-03-31 03:12:20 +0000
commitdb37cd8003c371210064ba9f9a9c279f13a175d2 (patch)
tree95a740b2174d900a416d0fd7fac0895c9e3972ab /sys/arch/i386/stand/biosboot
parent1dc40aae41ae95a97b3d0955f1cf85385b6de1a4 (diff)
Initial /boot stuff (from Mickey)
Diffstat (limited to 'sys/arch/i386/stand/biosboot')
-rw-r--r--sys/arch/i386/stand/biosboot/Makefile21
-rw-r--r--sys/arch/i386/stand/biosboot/biosboot.8130
-rw-r--r--sys/arch/i386/stand/biosboot/biosboot.S312
3 files changed, 463 insertions, 0 deletions
diff --git a/sys/arch/i386/stand/biosboot/Makefile b/sys/arch/i386/stand/biosboot/Makefile
new file mode 100644
index 00000000000..4d0ffbc8575
--- /dev/null
+++ b/sys/arch/i386/stand/biosboot/Makefile
@@ -0,0 +1,21 @@
+# $OpenBSD: Makefile,v 1.2 1997/03/31 03:12:00 weingart Exp $
+
+PROG= biosboot
+SRCS= biosboot.S
+AFLAGS+=-DREL=$(REL) #-Wa,-a
+LDFLAGS=-Wl,-T0,-N,-x -nostdlib
+STRIP=
+MAN= biosboot.8
+LINKS= ${BINDIR}/biosboot ${BINDIR}/fdboot \
+ ${BINDIR}/biosboot ${BINDIR}/wdboot \
+ ${BINDIR}/biosboot ${BINDIR}/sdboot \
+
+# XXX - Toby
+# These should not output anything, once /boot is loaded, let
+# it figure out who to talk to (probe the keyboard). That way
+# we will not need two different types of bootblocks...
+#
+# Uncomment this to make the boot block talk to a serial port.
+# CPPFLAGS+=-DSERIAL=0
+
+.include <bsd.prog.mk>
diff --git a/sys/arch/i386/stand/biosboot/biosboot.8 b/sys/arch/i386/stand/biosboot/biosboot.8
new file mode 100644
index 00000000000..270a099a72d
--- /dev/null
+++ b/sys/arch/i386/stand/biosboot/biosboot.8
@@ -0,0 +1,130 @@
+.\" $OpenBSD: biosboot.8,v 1.2 1997/03/31 03:12:00 weingart Exp $
+.\" $NetBSD: boot_i386.8,v 1.3 1995/04/23 10:33:35 cgd Exp $
+.\"
+.\" Copyright (c) 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software written and contributed
+.\" to Berkeley by William Jolitz.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)boot_i386.8 8.2 (Berkeley) 4/19/94
+.\"
+.Dd April 19, 1994
+.Dt BOOT 8 i386
+.Os
+.Sh NAME
+.Nm boot
+.Nd
+system bootstrapping procedures
+.Sh DESCRIPTION
+.Sy Power fail and crash recovery.
+Normally, the system will reboot itself at power-up or after crashes.
+An automatic consistency check of the file systems will be performed,
+and unless this fails, the system will resume multi-user operations.
+.Pp
+.Sy Cold starts.
+The 386
+.Tn "PC AT"
+clones attempt to boot the floppy disk drive A (otherwise known as drive
+0) first, and failing that, attempt to boot the hard disk C (otherwise
+known as hard disk controller 1, drive 0).
+The automatic boot will attempt to load
+.Pa bsd
+from partition A of either the floppy or the hard disk.
+This boot may be aborted by typing any character on the keyboard repeatedly
+(four or five times at least) during the operating system load phase, after
+which the bootstrap will prompt for the file that you wish to load instead.
+.Pp
+One exception to this is the
+.Ql d
+key, which will not abort the load but instead silently force the
+.Dv DEBUG
+boot flags.
+The boot flags for an autoboot are 0, and 3 for the successive boot after
+an aborted autoboot sequence.
+No other provison is made for setting boot flags (yet).
+A specific device or bootstrap file may be used; for example,
+.Pp
+The file specifications used for the boostrap
+when loaded with the
+.Dq askme
+flag
+(e.g. an aborted autoboot)
+are of the form:
+.Pp
+.Dl device unit partition:
+.Pp
+where
+.Ar device
+is the type of the device, assumed to be on the ISA bus, to be searched,
+.Ar unit
+is the unit number of the disk or tape,
+and
+.Ar partition
+is the disk partition or tape file number.
+Normal line editing characters can be used when typing the file specification.
+The following list of supported devices may vary from installation to
+installation:
+.Bd -unfilled -offset indent
+wd ST506, IDE, ESDI, RLL disks on a WD100[2367] or lookalike
+ controller
+fd 5 1/4" or 3 1/2" High density floppies
+.Ed
+.Pp
+For example,
+to boot from a file system which starts at cylinder 0
+of unit 0 of an IDE disk, type
+.Dq Li wd(0,a)/bsd
+to the boot prompt;
+.Dq Li fd(0,a)/bsd
+would specify a 3 1/2" floppy drive 0 .
+.Pp
+In an emergency, the bootstrap methods described in the paper
+.%T "Installing and Operating 4.3 BSD-Reno UNIX on the AT/386"
+can be used
+to boot from a distribution tape.
+.Sh FILES
+.Bl -tag -width /bsdxx -compact
+.It Pa /boot
+system bootstrap
+.It Pa /bsd
+system code
+.El
+.Sh SEE ALSO
+.Xr boot 8 ,
+.Xr halt 8 ,
+.Xr reboot 8 ,
+.Xr shutdown 8
+.Sh BUGS
+The disklabel format used by this version of
+.Bx
+is quite
+different from that of other architectures.
diff --git a/sys/arch/i386/stand/biosboot/biosboot.S b/sys/arch/i386/stand/biosboot/biosboot.S
new file mode 100644
index 00000000000..ef0e00f311a
--- /dev/null
+++ b/sys/arch/i386/stand/biosboot/biosboot.S
@@ -0,0 +1,312 @@
+/* $OpenBSD: biosboot.S,v 1.2 1997/03/31 03:12:01 weingart Exp $ */
+
+ .file "bootbios.S"
+
+#include <machine/asm.h>
+#include <machine/specialreg.h>
+#define _LOCORE
+#include <machine/segments.h>
+#undef _LOCORE
+
+#define addr32 .byte 0x67
+#define data32 .byte 0x66
+
+#ifdef DEBUG
+#define BLKCNT 32
+#else
+#define BLKCNT 48
+#endif
+
+#define BIOSSEG 0x07c0 /* boot loaded here */
+#define BOOTSEG 0x1000 /* /boot placement */
+#define BOOTSTACK 0xfffc /* /boot stack */
+#define ZMAGIC 0x0b01 /* ZMAGIC */
+
+#ifdef DEBUG
+#define DBGMSG(msg) \
+ movb $msg, %al; \
+ data32; \
+ call chr
+#define CHAR_M 'M' /* magic check */
+#define CHAR_P 'P' /* switch to protected mode */
+#else /* !DEBUG */
+#define DBGMSG(msg)
+#endif /* !DEBUG */
+
+ .text
+
+ .globl start
+start:
+ /* adjust %cs */
+ data32
+ ljmp $BIOSSEG, $2f
+1: .asciz "loading /boot"
+
+2: /* set up stack (%ss:%esp) */
+ cli /* disable interrupts w/o stack */
+ data32
+ movl $BOOTSEG, %ax
+ movl %ax, %ss
+ data32
+ movl $BOOTSTACK, %esp
+ sti /* we have stack, do ints */
+
+ /* set up %es, (where we will load /boot to) */
+ movl %ax, %es
+
+ /* set up %ds */
+ pushl %cs
+ popl %ds
+
+#ifdef SERIAL
+ # Initialize the serial port to 9600 baud, 8N1.
+ pushl %dx
+ movl $0x00e3, %ax
+ data32
+ movl SERIAL, %edx
+ int $0x14
+ popl %dx
+#endif
+
+ data32
+ movl $1b, %esi
+ data32
+ call message
+
+ data32
+ xorl %ebx, %ebx /* put it at %es:0 */
+ addr32
+ movb _block_count, %cl /* how many to read */
+ movzbl %cl, %ecx
+ data32
+ movl $_block_table, %esi
+
+1:
+ pushl %ecx
+ cld
+ lodsl /* word */ /* cylinder/sector */
+ movl %ax, %cx
+ lodsb /* head */
+ movb %al, %dh
+ lodsb /* # of sectors to load */
+ movb $0x2, %ah
+ pushl %ax
+ int $0x13
+ jnc 3f
+
+ /* read error */
+ data32
+ movl $2f, %esi
+ jmp halt
+2: .asciz "\r\nRead error\r\n"
+
+3: /* read next block */
+ movb $'.', %al
+ data32
+ call chr /* show progress indicator */
+
+ popl %ax
+ data32
+ movzbl %al, %eax
+ shll $9, %ax /* 512 bytes sectors */
+ addl %ax, %bx
+ popl %ecx
+ loop 1b
+
+ data32
+ movl $2f, %esi /* new line */
+ data32
+ call message
+
+#if 0
+ DBGMSG(CHAR_M)
+#endif
+
+ xorl %esi, %esi
+ cld
+ /* check /boot magic */
+ es;lodsl;es;lodsl /* no need for high word */
+ # cmpw $ZMAGIC, %ax
+ .byte 0x3d
+ .word ZMAGIC
+ je 3f
+
+ data32
+ movl $1f, %esi
+halt:
+ data32
+ call message
+ cli
+ hlt
+1: .ascii "Bad magic"
+2: .asciz "\r\n"
+3:
+#if notdef
+ data32;es;lodsl /* text size */
+ data32;es;lodsl /* data size */
+ data32;es;lodsl /* bss size */
+ data32;es;lodsl /* syms size */
+#endif
+#if 0
+ data32;addr32
+ addl 16(%esi), %edi /* entry */
+ data32
+ subl $REL, %edi
+#endif
+
+#if 0
+ DBGMSG(CHAR_P)
+#endif
+
+ /* change to protected mode */
+ /* guarantee that interrupts are disabled when in prot mode */
+ cli
+
+ /* load the gdtr */
+ addr32
+ data32
+ lgdt Gdtr
+
+ /* set the PE bit of CR0 */
+ movl %cr0, %eax
+ data32
+ orl $CR0_PE, %eax
+ movl %eax, %cr0
+
+ /*
+ * make intrasegment jump to flush the processor pipeline and
+ * reload CS register
+ */
+ data32
+ ljmp $8, $1f+(BIOSSEG << 4)
+
+1: /*
+ * 32bit mode
+ * set up %ds, %ss, %es
+ */
+ movl $0x10, %eax
+ movl %ax, %ds
+ movl %ax, %ss
+ movl %ax, %es
+ movl %ax, %fs
+ movl %ax, %gs
+ movl $BOOTSTACK, %esp
+
+#if 0
+#ifdef DEBUG
+ movl $0xb8000, %ebx
+ movl $0x074f0747, (%ebx)
+#endif
+#endif
+
+ movzbl %dl, %eax /* drive number is in the lowest byte */
+ pushl %eax
+
+#if 0
+#ifdef DEBUG
+ movl $0x10000, %ebx
+ movl (%ebx), %ecx
+ /* cmpw $ZMAGIC, %ax */
+ .byte 0x3d
+ .word ZMAGIC
+je 1f
+ movl $0xb8004, %ebx
+ movl $0x07500748, (%ebx)
+ jne 2f
+1:
+ movl $0xb8004, %ebx
+ movl $0x074f0747, (%ebx)
+2:
+#endif
+#endif
+
+ /* jmp /boot */
+ ljmp $0x8, $(REL << 4) + 0x20
+ /* not reached */
+
+#
+# chr: write the character in %al to console
+#
+chr:
+ data32
+ pushl %eax
+
+#ifndef SERIAL
+ data32
+ pushl %ebx
+ movb $0x0e, %ah
+ xorl %bx, %bx
+ incl %bx /* movw $0x01, %bx */
+ int $0x10
+ data32
+ popl %ebx
+#else
+ data32
+ pushl %edx
+ movb $0x01, %ah
+ xorl %dx, %dx
+ movb SERIAL, %dl
+ int $0x14
+ data32
+ popl %edx
+#endif
+ data32
+ popl %eax
+ data32
+ ret
+
+/*
+ * Display string
+ */
+message:
+ data32
+ pushl %eax
+ cld
+1:
+ lodsb # load a byte into %al
+ testb %al, %al
+ jz 1f
+ data32
+ call chr
+ jmp 1b
+1:
+ data32
+ popl %eax
+ data32
+ ret
+
+ .align 2
+Gdtr: .word 3 * 8 - 1
+ .long (BIOSSEG << 4) + 2f
+ .align 3
+2: /* 0x00 : null */
+ .long 0, 0
+ /* 0x08 : flat code */
+ .word 0xFFFF # lolimit
+ .word 0 # lobase
+ .byte 0 # midbase
+ .byte SDT_MEMERAC | 0 | 0x80 # RWXAC, dpl = 0, present
+ .byte 0xf | 0 | 0x40 | 0x80 # hilimit, xx, 32bit, 4k granularity
+ .byte 0 # hibase
+ /* 0x10 : flat data */
+ .word 0xFFFF # lolimit
+ .word 0 # lobase
+ .byte 0 # midbase
+ .byte SDT_MEMRWA | 0 | 0x80 # RWA, dpl = 0, present
+ .byte 0xf | 0 | 0x40 | 0x80 # hilimit, xx, 32bit, 4k granularity
+ .byte 0 # hibase
+
+ .globl _block_table
+_block_table:
+ .word 0 /* cyllinder/sector */
+ .byte 0 /* head */
+ .byte 0 /* nsect */
+ . = _block_table + BLKCNT*4
+ .globl _block_count
+_block_count:
+ .byte BLKCNT /* entries in _block_table */
+
+ . = 0x200 - 4
+ /* a little signature */
+ .ascii "boot"
+