diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2004-02-03 12:09:48 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2004-02-03 12:09:48 +0000 |
commit | ee64ff9774a8a97d8ac9159076e5aa096f4b0465 (patch) | |
tree | 56c0a44d5a11182f89b55b68c79f750f9a093bc6 /sys/arch/amd64/stand/boot | |
parent | 74d9ef0d94f422fd01f5c329723d4a06537c0884 (diff) |
das boot; das cloned das from das i386
Diffstat (limited to 'sys/arch/amd64/stand/boot')
-rw-r--r-- | sys/arch/amd64/stand/boot/Makefile | 60 | ||||
-rw-r--r-- | sys/arch/amd64/stand/boot/boot.8 | 375 | ||||
-rw-r--r-- | sys/arch/amd64/stand/boot/conf.c | 77 | ||||
-rw-r--r-- | sys/arch/amd64/stand/boot/srt0.S | 92 |
4 files changed, 604 insertions, 0 deletions
diff --git a/sys/arch/amd64/stand/boot/Makefile b/sys/arch/amd64/stand/boot/Makefile new file mode 100644 index 00000000000..82eb17fdc51 --- /dev/null +++ b/sys/arch/amd64/stand/boot/Makefile @@ -0,0 +1,60 @@ +# $OpenBSD: Makefile,v 1.1 2004/02/03 12:09:47 mickey Exp $ + +.include "${.CURDIR}/../Makefile.inc" + +MAN= boot.8 +MLINKS= boot.8 boot.conf.8 + +.if ${MACHINE} == "amd64" +S =${.CURDIR}/../../../.. +SADIR= ${.CURDIR}/.. + +PROG= boot +SRCS= srt0.S conf.c +LD?= ld +SIZE?= size +LDFLAGS+=-melf_i386 -nostdlib -Bstatic -Ttext $(LINKADDR) -N -x -noinhibit-exec + +.PATH: ${SADIR}/libsa +# i386 stuff (so, it will possibly load in the same 64k) +SRCS+= machdep.c dev_i386.c exec_i386.c cmd_i386.c +SRCS+= gidt.S alloca.S biosdev.c bioscons.c gateA20.c \ + memprobe.c diskprobe.c time.c biosprobe.c + +.PATH: ${S}/stand/boot +SRCS+= boot.c cmd.c vars.c bootarg.c + +.PATH: ${S}/lib/libsa +.PATH: ${S}/lib/libkern # for strl* +# stand routines +SRCS+= alloc.c exit.c getfile.c gets.c globals.c strcmp.c strlen.c \ + strncmp.c memcmp.c memcpy.c memset.c printf.c snprintf.c \ + strerror.c strncpy.c strtol.c ctime.c strlcpy.c strlcat.c +# io routines +SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fstat.c ioctl.c lseek.c \ + open.c read.c stat.c write.c cread.c readdir.c cons.c loadfile.c +# boot filesystems +SRCS+= ufs.c + +.PATH: ${S}/lib/libz +SRCS+= adler32.c crc32.c inflate.c inftrees.c + +boot.bin: boot + objcopy -v -O binary ${PROG} boot.bin + +${PROG}: $(OBJS) + $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) + #@$(SIZE) ${PROG} + +.else +NOPROG= +.endif + +.include <bsd.prog.mk> + +CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC) ${DEBUGFLAGS} -DLINKADDR=${LINKADDR} +CPPFLAGS+=-DSLOW -DSMALL -DNOBYFOUR -DNO_GZIP -DDYNAMIC_CRC_TABLE +CPPFLAGS+=-DHEAP_LIMIT=${HEAP_LIMIT} -I${S}/stand/boot #-DCOMPAT_UFS +CFLAGS+=-m32 $(SACFLAGS) -D__INTERNAL_LIBSA_CREAD +AFLAGS+=-m32 # -Wa,-R +# AFLAGS+=-Wa,-a diff --git a/sys/arch/amd64/stand/boot/boot.8 b/sys/arch/amd64/stand/boot/boot.8 new file mode 100644 index 00000000000..d9085add665 --- /dev/null +++ b/sys/arch/amd64/stand/boot/boot.8 @@ -0,0 +1,375 @@ +.\" $OpenBSD: boot.8,v 1.1 2004/02/03 12:09:47 mickey Exp $ +.\" +.\" Copyright (c) 1997-2001 Michael Shalayeff +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR OR HIS RELATIVES 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 MIND, 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. +.\" +.\" +.Dd September 1, 1997 +.Dt BOOT 8 i386 +.Os +.Sh NAME +.Nm boot , +.Nm boot.conf +.Nd +i386-specific second-stage bootstrap +.Sh DESCRIPTION +The main purpose of this program is to load the system kernel while dealing +with the downfalls of the PC BIOS architecture. +.Pp +As described in +.Xr boot_i386 8 , +this program is loaded by the +.Xr biosboot 8 +primary bootstrap loader and provides a convenient way to load the kernel. +This program acts as an enhanced boot monitor for PC systems, providing +a common interface for the kernel to start from. +.Pp +Basic operations include: +.Pp +.Bl -bullet -compact +.It +Detecting and switching between multiple consoles. +.It +Loading kernels from any device supported by your system BIOS. +.It +Loading kernels compressed by +.Xr gzip 1 . +.It +Passing system parameters queried from the BIOS to the kernel. +.It +Providing an interactive command line. +.El +.Pp +The sequence of its operation is as follows: initialization, +parsing the configuration file, then an interactive command line. +While at the command line you have 5 seconds to type any commands, if needed. +If time expires, the kernel will be loaded according to +the current variable settings (see the +.Nm set +command). +Each time a kernel load fails, the timeout is increased by one second. +The sequence of +.Nm +operations is as follows: +.Bl -enum +.It +Set up a protected mode environment which catches and reports processor +exceptions and provides a simple protected-mode BIOS interface. +.It +Probe for console devices, which includes the (default) PC VGA+Keyboard +console +.Pq Li pc0 +and up to four serial consoles +.Pf ( Li com0 +through +.Li com3 ) +connected to the serial ports. +Display messages to the default console about the devices found. +.It +Detect memory. +Conventional memory is detected by querying the BIOS. +Extended memory is detected by probing page-by-page through the address +space, rather than asking the BIOS; many BIOS's cannot report larger than +64M of memory. +All memory found is reported to the default console device. +.It +Probe for APM support in the BIOS. +Display a message if support is present. +.It +If the file +.Pa /etc/boot.conf +exists on the filesystem +.Nm +was loaded from, open and parse it. +This file may contain any commands +.Nm +accepts at the interactive prompt. +Though default settings usually suffice, they can be changed here. +.It +The header line +.Pp +.Dl >> OpenBSD/i386 BOOT [x.xx] +.Pp +is displayed to the active console, where +.Ar x.xx +is the version number of the +.Nm +program, followed by the +.Pp +.Dl boot> +.Pp +prompt, which means you are in interactive mode and may enter commands. +If you do not, +.Nm +will proceed to load the kernel with the current parameters after the +timeout period has expired. +.El +.Pp +By default, +.Nm +attempts to load the kernel executable +.Pa /bsd . +If that fails, it will attempt to load +.Pa /obsd +and then +.Pa /bsd.old . +If it fails to find any of these files, +and no alternative kernel image has been specified, +the system will be unable to boot. +.Sh COMMANDS +The following commands are accepted at the +.Nm +prompt: +.Bl -tag -width shorten +.It boot Op Ar image Op Fl acds +Boots the kernel image specified by +.Ar image +with any options given. +Image specification consists of a pair +.Ar device : Ns Ar filename ; +either or both can be omitted (`:' is not needed if both are omitted), +in which case values from +.Nm +variables will be used. +.Pp +When selecting the +.Ar device +to boot from, +.Nm +makes no distinction between SCSI and IDE type drives; +they are detected as +.Sq hd +devices. +Therefore, to boot kernel +.Pa /bsd +from slice +.Sq a +on the first hard drive +.Pq irrespective of device type , +specify +.Dq boot hd0a:/bsd . +.Bl -tag -width _a_ +.It Fl a +Causes the kernel to ask for the +.Nm root +device to use. +.It Fl c +Causes the kernel to go into +.Xr boot_config 8 +before performing +.Xr autoconf 4 +procedures. +.It Fl d +Causes the kernel to drop into +.Xr ddb 4 +at the earliest convenient point. +.It Fl s +Causes the kernel to boot single-user. +.El +.It echo Op Ar args +Displays +.Ar args +on the console device. +.It help +Prints a list of available commands and machine dependent +commands, if any. +.It machine Op Ar command +Issues machine-dependent commands. +These are defined for i386 architecture: +.Bl -tag -width diskinfo +.It Nm diskinfo +Prints a list of hard disks installed on your system including: +BIOS device number, and the BIOS geometry. +.It Nm memory +If used without any arguments this command will print out +the memory configuration as determined through BIOS routines. +Otherwise the arguments would specify the expressions to modify the +memory configuration. +The expression would have a form of: +.Pp +.Dl [+-]<size>@<address> +.Pp +Meaning to add(+) or exempt(-) the specified by the +.Ar <size> +amount of memory at the location specified by the +.Ar <address> +argument. +Both size and base address could be specified as octal, +decimal, or hexadecimal numbers, as accepted by the +.Xr strtoul 3 +routine. +Memory segments are not required to be adjacent to each other, +the only requirement is that there is real physical memory under +the range added. +For example: +.Bd -unfilled -offset indent +machine mem +0x2000000@0x1000000 +.Ed +.Pp +would add 32M of memory right after the first 16M. +The other useful command would be to withdraw a range +of memory from OS usage (might be wrongfully reported as +useful by the BIOS). +.Bd -unfilled -offset indent +machine mem -0x100000@0xf00000 +.Ed +.Pp +which effectively excludes 15-16M range from the map of useful memory. +.It Nm regs +Prints contents of processor registers if compiled with +.Em DEBUG . +.El +.It ls Op Ar directory +Prints contents of the specified +.Ar directory +in long format including: attributes and file type, owner, group, +size, filename. +.It reboot +Reboots the machine by initiating a warm boot procedure. +.It set Op Ar varname Op Ar value +If invoked without arguments, prints a list of variables and their values. +If only +.Ar varname +is specified, displays contents of that variable. +If +.Ar varname +and +.Ar value +are both specified, sets that variable to the given value. +Variables include: +.Pp +.Bl -tag -compact -width boothow +.It Nm addr +Address at which to load the kernel. +.It Nm debug +Debug flag if +.Nm +was compiled with DEBUG defined. +.It Nm device +Boot device name (e.g., +.Li fd0a , +.Li hd0a ) . +.It Nm howto +Options to pass to the loaded kernel. +.It Nm image +File name containing the kernel image. +.It Nm timeout +Number of seconds boot will wait for human intervention before +booting the default kernel image. +.It Nm tty +Active console device name (e.g., +.Li com0 , +.Li com1 , +.Li pc0 ) . +Currently, only the first serial port +.Pq Li com0 +is supported for console on i386. +.El +.It stty Op Ar device Op Ar speed +Displays or sets the +.Ar speed +for a console +.Ar device . +If changing the baudrate for the currently active console, +.Nm +offers you five seconds of grace time before committing the change +to allow you to change your terminal's speed to match. +If changing speed +.Em not +for the active console, the baudrate is set for the +.Em next +time you switch to a serial console. +The baudrate value is not used for the +.Li pc0 +console. +.Pp +The default baudrate is 9600bps. +.It time +Displays system time and date. +.El +.Sh FILES +.Bl -tag -width /usr/mdec/biosbootxx -compact +.It Pa /usr/mdec/biosboot +first stage bootstrap +.It Pa /boot +system bootstrap +.It Pa /etc/boot.conf +system bootstrap's startup file +.It Pa /bsd +kernel image +.El +.Sh EXAMPLES +Boot the default kernel: +.Pp +.Dl boot> boot +.Pp +Remove the 5 second pause at boot-time permanently, causing +.Nm +to load the kernel immediately without prompting: +.Pp +.Dl # echo \&"boot\&" > /etc/boot.conf +.Pp +Use serial console. +A null modem cable should connect the specified serial port to a terminal. +Useful for debugging. +.Pp +.Dl boot> set tty com0 +.Pp +Invoke the serial console at every boot: +.Pp +.Dl # echo \&"set tty com0\&" > /etc/boot.conf +.Pp +Boot the kernel named +.Pa /bsd +from the second hard disk in +.Dq User Kernel Configuration +mode (see +.Xr boot_config 8 ) . +This mechanism allows for the explicit enabling and disabling of devices +during the current boot sequence, as well as the modification +of device parameters. +Once booted, such changes can be made permanent by using +.Xr config 8 Ns 's +.Fl e +option. +.Pp +.Dl boot> boot hd1a:/bsd -c +.Sh SEE ALSO +.Xr gzip 1 , +.Xr autoconf 4 , +.Xr ddb 4 , +.Xr biosboot 8 , +.Xr boot_config 8 , +.Xr boot_i386 8 , +.Xr fdisk 8 , +.Xr installboot 8 , +.Xr reboot 8 +.Pp +RFC 1950 describes the zlib library interface. +.Pp +The official home page for the version of zlib used in this +operating system is at http://quest.jpl.nasa.gov/zlib/. +.Sh HISTORY +This program was written by Michael Shalayeff for +.Ox 2.1 . diff --git a/sys/arch/amd64/stand/boot/conf.c b/sys/arch/amd64/stand/boot/conf.c new file mode 100644 index 00000000000..9464b92e512 --- /dev/null +++ b/sys/arch/amd64/stand/boot/conf.c @@ -0,0 +1,77 @@ +/* $OpenBSD: conf.c,v 1.1 2004/02/03 12:09:47 mickey Exp $ */ + +/* + * Copyright (c) 1996 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. + * + */ + +#include <sys/types.h> +#include <netinet/in.h> +#include <libsa.h> +#include <lib/libsa/ufs.h> +#ifdef notdef +#include <lib/libsa/cd9660.h> +#include <lib/libsa/fat.h> +#include <lib/libsa/nfs.h> +#include <lib/libsa/tftp.h> +#include <lib/libsa/netif.h> +#endif +#include <lib/libsa/unixdev.h> +#include <biosdev.h> +#include <dev/cons.h> + +const char version[] = "2.05"; +int debug = 1; + + +struct fs_ops file_system[] = { + { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, + ufs_stat, ufs_readdir }, +#ifdef notdef + { fat_open, fat_close, fat_read, fat_write, fat_seek, + fat_stat, fat_readdir }, + { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, + nfs_stat, nfs_readdir }, + { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, + cd9660_stat, cd9660_readdir }, +#endif +}; +int nfsys = NENTS(file_system); + +struct devsw devsw[] = { + { "BIOS", biosstrategy, biosopen, biosclose, biosioctl }, +#if 0 + { "TFTP", tftpstrategy, tftpopen, tftpclose, tftpioctl }, +#endif +}; +int ndevs = NENTS(devsw); + +struct consdev constab[] = { + { pc_probe, pc_init, pc_getc, pc_putc }, + { com_probe, com_init, com_getc, com_putc }, + { NULL } +}; +struct consdev *cn_tab = constab; + diff --git a/sys/arch/amd64/stand/boot/srt0.S b/sys/arch/amd64/stand/boot/srt0.S new file mode 100644 index 00000000000..ccd3eff0ed2 --- /dev/null +++ b/sys/arch/amd64/stand/boot/srt0.S @@ -0,0 +1,92 @@ +/* $OpenBSD: srt0.S,v 1.1 2004/02/03 12:09:47 mickey Exp $ */ + +/* + * Copyright (c) 1997 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. + * + */ +#include <machine/asm.h> +#include <assym.h> + +#define BOOTSTACK 0xfffc + + .globl _C_LABEL(end) + .globl _C_LABEL(edata) + .globl _C_LABEL(boot) + .globl _C_LABEL(_rtt) + .globl _C_LABEL(bios_bootdev) + .globl _ASM_LABEL(pmm_init) + .globl Gdtr + + .text + .code16 + .globl _start +_start: + popl %eax + cmpl $BOOTMAGIC, %eax + je 1f +#ifdef DEBUG + movl $0xb80a0, %ebx + addr32 movl $0x07420742, (%ebx) +#endif +1: + popl %edx + cli + pushl %cs + popl %ds + addr32 data32 lgdt (Gdtr - LINKADDR) + movl %cr0, %eax + orl $CR0_PE, %eax + data32 movl %eax, %cr0 + data32 ljmp $8, $1f +1: + .code32 + movl $0x10,%eax + mov %ax,%ds + mov %ax,%ss + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + movl $BOOTSTACK,%esp + pushl %edx + movl %edx, _C_LABEL(bios_bootdev) + + /* Now do it all */ + call _ASM_LABEL(pmm_init) +#ifdef DEBUG + movl $0xb80a4, %ebx + movl $0x07520752, (%ebx) +#endif + /* zero .bss */ + xorl %eax, %eax + movl $_C_LABEL(end), %ecx + subl $_C_LABEL(edata),%ecx + movl $_C_LABEL(edata), %edi + cld + rep; stosb + + call _C_LABEL(boot) + + jmp _C_LABEL(_rtt) + |