diff options
Diffstat (limited to 'sys/arch/i386/stand/cdboot')
-rw-r--r-- | sys/arch/i386/stand/cdboot/Makefile | 46 | ||||
-rw-r--r-- | sys/arch/i386/stand/cdboot/cdboot.8 | 96 | ||||
-rw-r--r-- | sys/arch/i386/stand/cdboot/conf.c | 107 | ||||
-rw-r--r-- | sys/arch/i386/stand/cdboot/srt0.S | 243 |
4 files changed, 492 insertions, 0 deletions
diff --git a/sys/arch/i386/stand/cdboot/Makefile b/sys/arch/i386/stand/cdboot/Makefile new file mode 100644 index 00000000000..3adc18677f7 --- /dev/null +++ b/sys/arch/i386/stand/cdboot/Makefile @@ -0,0 +1,46 @@ +# $OpenBSD: Makefile,v 1.1 2004/06/23 00:21:49 tom Exp $ + +.include "${.CURDIR}/../Makefile.inc" + +MAN= cdboot.8 + +.if ${MACHINE} == "i386" +PROG= cdboot +LD?= ld +SIZE?= size +LDFLAGS+=-nostdlib -Bstatic +INSTALL_STRIP= + +LDFLAGS+=-Ttext $(LINKADDR) -N -x -noinhibit-exec +CLEANFILES+= crt0.o +SRCS= srt0.S + +SRCS+= boot.c cmd.c vars.c bootarg.c conf.c +S =${.CURDIR}/../../../.. +SADIR= ${.CURDIR}/.. + +LDADD= ${LIBSA} ${LIBZ} +DPADD= ${LIBSA} ${LIBZ} + +.PATH: ${S}/stand/boot + +${PROG}: $(OBJS) $(DPADD) + $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) $(LDADD) + @$(SIZE) ${PROG} + @if [ -x ${.OBJDIR}/${PROG} ]; then \ + objcopy -O binary ${PROG} ${.OBJDIR}/.tmp;\ + mv -f ${.OBJDIR}/.tmp ${.OBJDIR}/${PROG}; \ + ls -l ${.OBJDIR}/${PROG}; \ + fi + +.else +NOPROG= +.endif + +.include <bsd.prog.mk> + +CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC) ${DEBUGFLAGS} +CPPFLAGS+=-DLINKADDR=${LINKADDR} +CFLAGS+=${SACFLAGS} -D__INTERNAL_LIBSA_CREAD +#AFLAGS+=-Wa,-R +# AFLAGS+=-Wa,-a diff --git a/sys/arch/i386/stand/cdboot/cdboot.8 b/sys/arch/i386/stand/cdboot/cdboot.8 new file mode 100644 index 00000000000..1cad9712be3 --- /dev/null +++ b/sys/arch/i386/stand/cdboot/cdboot.8 @@ -0,0 +1,96 @@ +.\" $OpenBSD: cdboot.8,v 1.1 2004/06/23 00:21:49 tom Exp $ +.\" Copyright (c) 2004 Tom Cosgrove +.\" Copyright (c) 2003 Matthias Drochner +.\" Copyright (c) 1999 Doug White +.\" 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 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 AUTHOR 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. +.\" +.Dd June 13, 2004 +.Dt CDBOOT 8 i386 +.Os +.Sh NAME +.Nm cdboot +.Nd +i386-specific second-stage CD-specific bootstrap +.Sh DESCRIPTION +.Nm +is a modified version of the i386 second-stage bootstrap program, +.Xr boot 8 , +configured to be run by the +.Ox +El Torito CD-ROM boot sector +.Pa cdbr . +.Nm +will look for an +.Pa /etc/boot.conf +configuration +file on the CD-ROM. +If it finds one, it processes the commands within it. +.Pp +.Nm +then sits in a loop, +processing commands given by the user. +It accepts all the commands accepted by +.Xr boot 8 . +.Pp +If no commands are given for a short time, +.Nm +will then attempt to load an +.Ox +kernel +.Pa /bsd +from the CD. +It may be told to boot an alternative kernel, +either by commands in the +.Pa boot.conf +file, +or by commands typed by the user at the +.Ic boot> +prompt. +.Sh FILES +.Bl -tag -width /usr/mdec/cdbootxx -compact +.It Pa /usr/mdec/cdboot +CD-specific second-stage bootstrap +.It Pa /etc/boot.conf +.Nm +configuration file (read from CD) +.El +.Sh EXAMPLES +Boot the install kernel: +.Pp +.Dl boot> bsd.rd +.Sh SEE ALSO +.Xr boot 8 , +.Xr boot_i386 8 +.Rs +.%T "El Torito" Bootable CD-ROM Format Specification +.%N Version 1.0 +.%D January 25, 1995 +.%A Curtis E. Stevens, Phoenix Technologies +.%A Stan Merkin, IBM +.Re +.Sh HISTORY +The +.Nm +command first appeared in +.Ox 3.6 . diff --git a/sys/arch/i386/stand/cdboot/conf.c b/sys/arch/i386/stand/cdboot/conf.c new file mode 100644 index 00000000000..d51dd50e1e9 --- /dev/null +++ b/sys/arch/i386/stand/cdboot/conf.c @@ -0,0 +1,107 @@ +/* $OpenBSD: conf.c,v 1.1 2004/06/23 00:21:49 tom Exp $ */ + +/* + * Copyright (c) 2004 Tom Cosgrove + * 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> +#include <lib/libsa/cd9660.h> +#ifdef notdef +#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> +#include "debug.h" + +const char version[] = "1.00"; +int debug = 1; + +#undef _TEST + + +void (*sa_cleanup)(void) = NULL; + + +void (*i386_probe1[])(void) = { + ps2probe, gateA20on, debug_init, cninit, apmprobe, + pciprobe, /* smpprobe, */ memprobe +}; +void (*i386_probe2[])(void) = { + diskprobe, cdprobe +}; + +struct i386_boot_probes probe_list[] = { + { "probing", i386_probe1, NENTS(i386_probe1) }, + { "disk", i386_probe2, NENTS(i386_probe2) }, +}; +int nibprobes = NENTS(probe_list); + +struct fs_ops file_system[] = { + { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, + ufs_stat, ufs_readdir }, + { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek, + cd9660_stat, cd9660_readdir }, +#ifdef notdef + { tftp_open, tftp_close, tftp_read, tftp_write, tftp_seek, + tftp_stat, tftp_readdir }, + { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, + nfs_stat, nfs_readdir }, + { fat_open, fat_close, fat_read, fat_write, fat_seek, + fat_stat, fat_readdir }, +#endif +#ifdef _TEST + { null_open, null_close, null_read, null_write, null_seek, + null_stat, null_readdir } +#endif +}; +int nfsys = NENTS(file_system); + +struct devsw devsw[] = { +#ifdef _TEST + { "UNIX", unixstrategy, unixopen, unixclose, unixioctl }, +#else + { "BIOS", biosstrategy, biosopen, biosclose, biosioctl }, +#endif +}; +int ndevs = NENTS(devsw); + +struct consdev constab[] = { +#ifdef _TEST + { unix_probe, unix_init, unix_getc, unix_putc }, +#else + { pc_probe, pc_init, pc_getc, pc_putc }, + { com_probe, com_init, com_getc, com_putc }, +#endif + { NULL } +}; +struct consdev *cn_tab = constab; diff --git a/sys/arch/i386/stand/cdboot/srt0.S b/sys/arch/i386/stand/cdboot/srt0.S new file mode 100644 index 00000000000..261191b1e9f --- /dev/null +++ b/sys/arch/i386/stand/cdboot/srt0.S @@ -0,0 +1,243 @@ +/* $OpenBSD: srt0.S,v 1.1 2004/06/23 00:21:49 tom 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: +#ifdef DEBUG + movl $0xb80a0, %ebx + addr32 movl $0x07420742, (%ebx) +#endif + +/* Clobbers %ax, maybe more */ +#define putc(c) movb $c, %al; call Lchr + + /* + * We operate as a no emulation boot image, as defined by the + * El Torito Bootable CD-ROM Format Specification v1.0. We use + * a load segment of 0x07C0 (physical load address of 0x7C00). + * Like the standard /boot, we are linked to run at 0x40120 + * (load address 0x40000), so we relocate to there. + * + * From 0x7C00 to 0x40000 is 0x38400 (230400) bytes, so don't + * have to worry about an overlapping copy until cdboot is + * over 225 KB. + * + * Note that there are other reasons to be worried if + * sizeof(/boot) > 64 KB. So currently we copy a maximum of 64 KB. + * + * Our cdbr CD-ROM boot sector passes us the drive number to use + * in %dl. + */ +#define CDBOOTADDR 0x7c00 /* Address where BIOS loads up */ + xorw %ax, %ax + movw %ax, %ss /* CPU disables interrupts till... */ + movl $CDBOOTADDR-4, %esp /* after this instruction */ + + movw $(CDBOOTADDR >> 4), %ax + movw %ax, %ds + xorw %si, %si /* Where we're coming from */ + + movw $(LINKADDR >> 4), %ax + movw %ax, %es /* Set %es = 0x4000 */ + xorw %di, %di /* Where we're going to */ + + movl $_C_LABEL(end), %ecx + subl $_C_LABEL(_start), %ecx /* How big are we? */ + + cld + rep; movsb /* Copy into place */ + + jmpl $(LINKADDR >> 4), $(relocated-_start) /* Now relocate */ + +relocated: + /* + * In 16-bit mode, we have segment registers == 0x4012, and + * offsets work from here, with offset(_start) == 0. + * + * In 32-bit mode, we have a flat memory model, where + * offset(_start) == 0x40120. This is how we're linked. + * + * Now transition to protected mode. + * + * First, initialise the global descriptor table. + */ + cli + push %cs + pop %ds + addr32 data32 lgdt (Gdtr - LINKADDR) + + movl %cr0, %eax + orl $CR0_PE, %eax + data32 movl %eax, %cr0 + data32 ljmp $8, $1f /* Seg sel 0x08 is flat 32-bit code */ +1: + .code32 + movl $0x10, %eax /* Seg sel 0x10 is flat 32-bit data */ + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss + movl $BOOTSTACK, %esp +#ifdef DEBUG + movl $0xb8000, %ebx + movl $0x07420742, (%ebx) +#endif + + movzbl %dl, %eax + orl $0x100, %eax /* Indicate that it's a cd device */ + pushl %eax /* boot() takes this as a parameter */ + + /* Set up an interrupt descriptor table for protected mode. */ + 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 + + /* Set our program name ("CDBOOT", not "BOOT"). */ + movl $cd_progname, %eax + movl %eax, progname + + /* Put the boot device number into the globals that need it */ + popl %eax /* Get this back from the stack */ + pushl %eax /* boot() takes this as a parameter */ + movl %eax, _C_LABEL(bios_bootdev) + movl %eax, _C_LABEL(bios_cddev) + + /* + * Now call "main()". + * + * We run in flat 32-bit protected mode, with no address mapping. + */ +#ifdef DEBUG + movl $0xb8004, %ebx + movl $0x07410741, (%ebx) +#endif + call _C_LABEL(boot) + + /* boot() should not return. If it does, reset computer. */ + jmp _C_LABEL(_rtt) + +ENTRY(debugchar) + pushl %ebx + movl 8(%esp), %ebx + addl %ebx, %ebx + addl $0xb8000, %ebx + + xorl %eax, %eax + movb 12(%esp), %al + + andl $0xfffffffe, %ebx + movb %al, (%ebx) + popl %ebx + ret + + .code16 + +/* + * Display ASCIZ string at %si. Trashes %si. + */ +Lstr: + pushw %ax + cld +1: + lodsb /* %al = *%si++ */ + testb %al, %al + jz 1f + call Lchr + jmp 1b +1: popw %ax + ret + +/* + * Write out value in %ax in hex + */ +hex_word: + pushw %ax + mov %ah, %al + call hex_byte + popw %ax + /* fall thru */ +/* + * Write out value in %al in hex + */ +hex_byte: + pushw %ax + shrb $4, %al + call hex_nibble + popw %ax + /* fall thru */ + +/* Write out nibble in %al */ +hex_nibble: + and $0x0F, %al + add $'0', %al + cmpb $'9', %al + jbe Lchr + addb $'A'-'9'-1, %al + /* fall thru to Lchr */ +/* + * Lchr: write the character in %al to console + */ +Lchr: + pushw %bx + movb $0x0e, %ah + xorw %bx, %bx + incw %bx /* movw $0x01, %bx */ + int $0x10 + popw %bx + ret + +cd_progname: + .asciz "CDBOOT" + + .end |