diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2003-04-17 03:43:20 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2003-04-17 03:43:20 +0000 |
commit | 6bb480fd6df5d8e084142751e0b25183459561d6 (patch) | |
tree | baf77d01ee85f750e1cf66d7c3c5fd85b7b5bc07 | |
parent | d36015cb7ad92f7024a5754fc18618f0b0e13139 (diff) |
i386 ELF bootloader. developed with weingart@
-rw-r--r-- | sys/arch/i386/stand/Makefile.inc | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/biosboot/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/biosboot/biosboot.S | 205 | ||||
-rw-r--r-- | sys/arch/i386/stand/boot/Makefile | 14 | ||||
-rw-r--r-- | sys/arch/i386/stand/boot/conf.c | 8 | ||||
-rw-r--r-- | sys/arch/i386/stand/boot/srt0.S | 44 | ||||
-rw-r--r-- | sys/arch/i386/stand/installboot/installboot.c | 54 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/Makefile | 6 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/alloca.S | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/biosdev.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/debug_i386.S | 10 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/exec_i386.c | 31 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/gidt.S | 219 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/libsa.h | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/machdep.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/mbr/Makefile | 6 | ||||
-rw-r--r-- | sys/arch/i386/stand/mbr/mbr.S | 40 |
17 files changed, 289 insertions, 372 deletions
diff --git a/sys/arch/i386/stand/Makefile.inc b/sys/arch/i386/stand/Makefile.inc index 7b6147b3e42..4d6274e7534 100644 --- a/sys/arch/i386/stand/Makefile.inc +++ b/sys/arch/i386/stand/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.30 2002/12/02 09:00:23 miod Exp $ +# $OpenBSD: Makefile.inc,v 1.31 2003/04/17 03:43:13 drahn Exp $ CFLAGS=${DEBUG} -Os -Wall -Werror CFLAGS+= -fno-stack-protector @@ -15,7 +15,7 @@ DEBUGFLAGS= # DEBUGFLAGS+=-DUNIX_DEBUG # DEBUGFLAGS+=-DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG # DEBUGFLAGS+=-DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -LINKADDR=0x40000 +LINKADDR=0x40120 LOADADDR=0x40000 HEAP_LIMIT=0x90000 BOOTREL=0x60000 diff --git a/sys/arch/i386/stand/biosboot/Makefile b/sys/arch/i386/stand/biosboot/Makefile index c28d8f01c72..853b57203c3 100644 --- a/sys/arch/i386/stand/biosboot/Makefile +++ b/sys/arch/i386/stand/biosboot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.20 2000/06/08 00:56:07 mickey Exp $ +# $OpenBSD: Makefile,v 1.21 2003/04/17 03:43:18 drahn Exp $ MAN= biosboot.8 @@ -15,7 +15,7 @@ ${PROG}: $(OBJS) $(DPADD) $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDADD) @size $(PROG) -CPPFLAGS+=-DLOADADDR=$(LOADADDR) -DBOOTMAGIC=$(BOOTMAGIC) +CPPFLAGS+=-DLOADADDR=$(LOADADDR) -DLINKADDR=$(LINKADDR) -DBOOTMAGIC=$(BOOTMAGIC) CPPFLAGS+=${DEBUGFLAGS} #AFLAGS+=-Wa,-a .else diff --git a/sys/arch/i386/stand/biosboot/biosboot.S b/sys/arch/i386/stand/biosboot/biosboot.S index b32c8cf991b..de4cc68590c 100644 --- a/sys/arch/i386/stand/biosboot/biosboot.S +++ b/sys/arch/i386/stand/biosboot/biosboot.S @@ -1,4 +1,4 @@ -/* $OpenBSD: biosboot.S,v 1.32 2002/08/28 20:15:34 mickey Exp $ */ +/* $OpenBSD: biosboot.S,v 1.33 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff, Tobias Weingartner @@ -36,40 +36,35 @@ #include <machine/asm.h> #include <assym.h> -#define addr32 .byte 0x67 -#define data32 .byte 0x66 - -#define BLKCNT 12 +#define BLKCNT 52 #define BOOTSEG 0x07c0 /* boot loaded here */ #define BOOTSTACK 0xfffc /* stack starts here */ -#define ZMAGIC 0x0b01 /* ZMAGIC */ +#define LFMAGIC 0x464c /* LFMAGIC (only uses two bytes of \7fELF */ /* Clobbers %al - maybe more */ #define putc(c) \ movb $c, %al; \ - .byte 0xe8; \ - .word Lchr - . - 2 + call Lchr; /* Clobbers %esi - maybe more */ #define puts(s) \ - data32; \ - movl $s, %esi; \ - .byte 0xe8; \ - .word Lmessage - . - 2 + mov $s, %si; \ + call Lmessage .text - .globl start -start: + .code16 + .globl _start +_start: jmp 1f nop - . = start + 3 + . = _start + 3 .asciz "OpenBSD" /* BPB */ - . = start + 0x0b + . = _start + 0x0b bpb: .word DEV_BSIZE /* sector size */ .byte 1 /* sectors/cluster */ .word 0 /* reserved sectors */ @@ -82,7 +77,7 @@ bpb: .word DEV_BSIZE /* sector size */ .word 0 /* # of heads */ /* EBPB */ - . = start + 0x1c + . = _start + 0x1c ebpb: .long 16 /* hidden sectors */ .long 0 /* large sectors */ .word 0 /* physical disk */ @@ -92,12 +87,11 @@ ebpb: .long 16 /* hidden sectors */ .asciz "UFS 4.4" /* boot code */ - . = start + 0x3e + . = _start + 0x3e 1: /* Fix up %cs just in case */ - data32 - ljmp $BOOTSEG, $1f + data32 ljmp $BOOTSEG, $1f load_msg: .asciz "reading boot" @@ -105,32 +99,25 @@ load_msg: 1: /* set up stack (%ss:%esp) */ cli /* disable interrupts w/o stack */ - xorl %ax, %ax - movl %ax, %ss - data32 + xor %ax, %ax + mov %ax, %ss movl $BOOTSTACK, %esp sti /* we have stack, do ints */ /* Set up other segment regs */ - # movw $BOOTSEG, %ax - .byte 0xb8 - .word BOOTSEG - movl %ax, %ds - movl %ax, %es - movl %ax, %fs - movl %ax, %gs + mov $BOOTSEG, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs #ifdef SERIAL # Initialize the serial port to 9600 baud, 8N1. - pushl %dx - # movw $0x00e3, %ax - .byte 0xb8 - .word 0x00e3 - # movw SERIAL, %dx - .byte 0xba - .word SERIAL + push %dx + mov $0x00e3, %ax + mov SERIAL, %dx int $0x14 - popl %dx + pop %dx #endif #ifdef BDEBUG @@ -141,31 +128,25 @@ load_msg: puts(load_msg) /* set up %es, (where we will load /boot to) */ - # movw $(LOADADDR >> 4), %ax - .byte 0xb8 - .word LOADADDR >> 4 - movl %ax, %es + mov $(LOADADDR >> 4), %ax + mov %ax, %es - data32 xorl %ebx, %ebx /* put it at %es:0 */ - addr32 - movb _block_count, %cl /* how many to read */ + movb block_count, %cl /* how many to read */ movzbl %cl, %ecx - # movw $_block_table, %si - .byte 0xbe - .word _block_table + movw $block_table, %si 1: - pushl %cx + push %cx putc('.') /* show progress indicator */ cld - lodsl /* word */ /* cylinder/sector */ - movl %ax, %cx + lodsw /* word */ /* cylinder/sector */ + mov %ax, %cx lodsb /* head */ movb %al, %dh lodsb /* # of sectors to load */ movb $0x2, %ah - pushl %ax + push %ax int $0x13 jnc 3f @@ -176,29 +157,28 @@ load_msg: 3: /* read next block */ - popl %ax - data32 + pop %ax movzbl %al, %eax - shll $9, %ax /* 512 bytes sectors */ - addl %ax, %bx - popl %cx + shl $9, %ax /* 512 bytes sectors */ + add %ax, %bx + pop %cx loop 1b puts(2f) - xorl %si, %si + xor %si, %si cld /* check /boot magic */ - es;lodsl;es;lodsl /* no need for high word */ - # cmpw $ZMAGIC, %ax - .byte 0x3d - .word ZMAGIC + es;lodsw;es;lodsw /* no need for high word */ + cmp $LFMAGIC, %ax je 3f puts(1f) halt: cli +99: hlt + jmp 99b 1: .ascii "Bad magic" 2: .asciz "\r\n" @@ -212,40 +192,6 @@ halt: putc('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, $(BOOTSEG << 4) + 1f - -1: /* - * 32bit mode - * set up %ds, %ss, %es, etc - */ - movl $0x10, %eax - movl %ax, %ds - movl %ax, %ss - movl %ax, %es - movl %ax, %fs - movl %ax, %gs - movl $BOOTSTACK, %esp - #ifdef BDEBUG movl $0xb8004, %ebx movl $0x074f0747, (%ebx) @@ -256,84 +202,59 @@ halt: pushl $BOOTMAGIC /* use some magic */ /* jmp /boot */ - ljmp $8, $(LOADADDR + 0x20) + /* data32 */ + ljmp $(LINKADDR >> 4), $0 /* not reached */ /* * Display string */ Lmessage: - data32 - pushl %eax + push %ax cld 1: lodsb # load a byte into %al testb %al, %al jz 1f - # call Lchr - .byte 0xe8 - .word Lchr - . - 2 + call Lchr jmp 1b # # Lchr: write the character in %al to console # Lchr: - data32 - pushl %eax + push %ax #ifndef SERIAL - data32 - pushl %ebx + push %bx movb $0x0e, %ah - xorl %bx, %bx - incl %bx /* movw $0x01, %bx */ + xor %bx, %bx + inc %bx /* movw $0x01, %bx */ int $0x10 - data32 - popl %ebx + pop %bx #else - data32 - pushl %edx + push %dx movb $0x01, %ah - xorl %dx, %dx + xor %dx, %dx movb SERIAL, %dl int $0x14 - data32 - popl %edx + pop %dx #endif 1: - data32 - popl %eax + pop %ax ret - .align 3 -1: /* 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 -Gdtr: .word . - 1b - .long (BOOTSEG << 4) + 1b - - .globl _block_table, _block_count -_block_count: - .byte BLKCNT /* entries in _block_table */ -_block_table: + #.data + .globl block_table, block_count + .type block_count, @function + .type block_table, @function +block_count: + .byte BLKCNT /* entries in block_table */ +block_table: .word 0 /* cylinder/sector */ .byte 0 /* head */ .byte 0 /* nsect */ - . = _block_table + BLKCNT*4 + . = block_table + BLKCNT*4 . = 0x200 - 2 /* a little signature */ diff --git a/sys/arch/i386/stand/boot/Makefile b/sys/arch/i386/stand/boot/Makefile index d306ee0f6f3..d3b62e77fb3 100644 --- a/sys/arch/i386/stand/boot/Makefile +++ b/sys/arch/i386/stand/boot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.29 2000/10/19 17:14:01 fgsch Exp $ +# $OpenBSD: Makefile,v 1.30 2003/04/17 03:43:18 drahn Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -15,12 +15,12 @@ LDFLAGS+=-nostdlib -Bstatic CLEANFILES+= srt0.o SRCS= crt0.c .else -LDFLAGS+=-Ttext $(LINKADDR) -z -x +LDFLAGS+=-Ttext $(LINKADDR) -N -x -noinhibit-exec CLEANFILES+= crt0.o SRCS= srt0.S .endif -SRCS+= boot.c cmd.c vars.c bootarg.c conf.c +SRCS+= boot_loadfile.c cmd.c vars.c bootarg.c conf.c S =${.CURDIR}/../../../.. SADIR= ${.CURDIR}/.. @@ -29,9 +29,12 @@ DPADD= ${LIBSA} ${LIBZ} .PATH: ${S}/stand/boot +boot.bin: boot + objcopy -v -O binary ${PROG} boot.bin + ${PROG}: $(OBJS) $(DPADD) - $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDADD) - @$(SIZE) $(PROG) + $(LD) $(LDFLAGS) -o ${PROG} $(OBJS) $(LDADD) + @$(SIZE) ${PROG} .else NOPROG= @@ -40,6 +43,7 @@ NOPROG= .include <bsd.prog.mk> CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC) ${DEBUGFLAGS} +CPPFLAGS+=-DLINKADDR=${LINKADDR} CFLAGS+=$(SACFLAGS) #AFLAGS+=-Wa,-R # AFLAGS+=-Wa,-a diff --git a/sys/arch/i386/stand/boot/conf.c b/sys/arch/i386/stand/boot/conf.c index 4a55c8a80a5..3be0b2704cb 100644 --- a/sys/arch/i386/stand/boot/conf.c +++ b/sys/arch/i386/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.19 2002/06/21 21:02:57 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.20 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -48,13 +48,9 @@ #include <dev/cons.h> #include <lib/libsa/exec.h> -const char version[] = "1.29"; +const char version[] = "2.00"; int debug = 1; -const struct x_sw execsw[] = { - { "aout", aout_probe, aout_load, aout_ldsym }, - { "", NULL, NULL, NULL }, -}; struct fs_ops file_system[] = { { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, diff --git a/sys/arch/i386/stand/boot/srt0.S b/sys/arch/i386/stand/boot/srt0.S index f8498632e56..b835bfa5e9a 100644 --- a/sys/arch/i386/stand/boot/srt0.S +++ b/sys/arch/i386/stand/boot/srt0.S @@ -1,4 +1,4 @@ -/* $OpenBSD: srt0.S,v 1.10 1998/05/14 20:59:12 mickey Exp $ */ +/* $OpenBSD: srt0.S,v 1.11 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -32,33 +32,55 @@ * */ #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 _ASM_LABEL(pmm_init) + .globl Gdtr .text - .globl start -start: + .code16 + .globl _start +_start: + popl %eax + cmpl $BOOTMAGIC, %eax + je 1f #ifdef DEBUG movl $0xb80a0, %ebx 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 + + /* Now do it all */ call _ASM_LABEL(pmm_init) #ifdef DEBUG movl $0xb80a4, %ebx movl $0x07520752, (%ebx) #endif - popl %eax - cmpl $BOOTMAGIC, %eax - je 1f -#ifdef DEBUG - movl $0xb80a8, %ebx - movl $0xcf41cf4d, (%ebx) -#endif -1: /* zero .bss */ xorl %eax, %eax movl $_C_LABEL(end), %ecx diff --git a/sys/arch/i386/stand/installboot/installboot.c b/sys/arch/i386/stand/installboot/installboot.c index e3ee3ce9366..521273c77ab 100644 --- a/sys/arch/i386/stand/installboot/installboot.c +++ b/sys/arch/i386/stand/installboot/installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.c,v 1.37 2002/05/03 13:59:08 espie Exp $ */ +/* $OpenBSD: installboot.c,v 1.38 2003/04/17 03:43:18 drahn Exp $ */ /* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */ /* @@ -52,6 +52,7 @@ #include <err.h> #include <a.out.h> +#include <sys/exec_elf.h> #include <fcntl.h> #include <nlist.h> #include <stdlib.h> @@ -170,7 +171,7 @@ main(argc, argv) /* XXX - Paranoia: Make sure size is aligned! */ if (protosize & (DEV_BSIZE - 1)) - err(1, "proto bootblock bad size=%ld", protosize); + err(1, "proto %s bad size=%ld", proto, protosize); /* Write patched proto bootblocks into the superblock */ if (protosize > SBSIZE - DEV_BSIZE) @@ -258,7 +259,9 @@ loadprotoblocks(fname, size) size_t tdsize; /* text+data size */ char *bp; struct nlist *nlp; - struct exec eh; + Elf_Ehdr eh; + Elf_Word phsize; + Elf_Phdr *ph; fd = -1; bp = NULL; @@ -270,8 +273,9 @@ loadprotoblocks(fname, size) } /* Validate symbol types (global data). */ for (nlp = nl; nlp->n_un.n_name; nlp++) { - if (nlp->n_type != (N_TEXT | N_EXT)) { - warnx("nlist: %s: wrong type", nlp->n_un.n_name); + if (nlp->n_type != (N_TEXT)) { + warnx("nlist: %s: wrong type %x", nlp->n_un.n_name, + nlp->n_type); return NULL; } } @@ -284,16 +288,35 @@ loadprotoblocks(fname, size) warn("read: %s", fname); goto bad; } - if (N_GETMAGIC(eh) != OMAGIC) { - warn("bad magic: 0x%x", eh.a_midmag); - goto bad; + if (!IS_ELF(eh)) { + errx(1, "%s: bad magic: 0x%02x%02x%02x%02x", + boot, + eh.e_ident[EI_MAG0], eh.e_ident[EI_MAG1], + eh.e_ident[EI_MAG2], eh.e_ident[EI_MAG3]); } /* * We have to include the exec header in the beginning of * the buffer, and leave extra space at the end in case * the actual write to disk wants to skip the header. */ - tdsize = eh.a_text + eh.a_data; + + /* program load header */ + if (eh.e_phnum != 1) { + errx(1, "%s: only supports one ELF load section\n", boot); + } + phsize = eh.e_phnum * sizeof(Elf_Phdr); + ph = malloc(phsize); + if (ph == NULL) { + errx(1, "%s: unable to allocate program header space\n", + boot); + } + lseek(fd, eh.e_phoff, SEEK_SET); + + if (read(fd, ph, phsize) != phsize) { + errx(1, "%s: unable to read program header space\n", boot); + } + + tdsize = ph->p_filesz; /* * Allocate extra space here because the caller may copy @@ -305,6 +328,7 @@ loadprotoblocks(fname, size) goto bad; } /* Read the rest of the file. */ + lseek(fd, ph->p_offset, SEEK_SET); if (read(fd, bp, tdsize) != tdsize) { warn("read: %s", fname); goto bad; @@ -318,7 +342,7 @@ loadprotoblocks(fname, size) maxblocknum = *block_count_p; if (verbose) { - fprintf(stderr, "%s: entry point %#x\n", fname, eh.a_entry); + fprintf(stderr, "%s: entry point %#x\n", fname, eh.e_entry); fprintf(stderr, "proto bootblock size %ld\n", *size); fprintf(stderr, "room for %d filesystem blocks at %#lx\n", maxblocknum, nl[X_BLOCK_TABLE].n_value); @@ -368,7 +392,6 @@ loadblocknums(boot, devfd, dl) struct dinode *ip; int ndb; u_int8_t *bt; - struct exec eh; int mib[4]; size_t size; dev_t dev; @@ -392,13 +415,18 @@ loadblocknums(boot, devfd, dl) errx(1, "%s: must be on an FFS filesystem", boot); } +#if 0 if (read(fd, &eh, sizeof(eh)) != sizeof(eh)) { errx(1, "read: %s", boot); } - if (N_GETMAGIC(eh) != ZMAGIC) { - errx(1, "%s: bad magic: 0x%x", boot, eh.a_midmag); + if (!IS_ELF(eh)) { + errx(1, "%s: bad magic: 0x%02x%02x%02x%02x", + boot, + eh.e_ident[EI_MAG0], eh.e_ident[EI_MAG1], + eh.e_ident[EI_MAG2], eh.e_ident[EI_MAG3]); } +#endif if (fsync(fd) != 0) err(1, "fsync: %s", boot); diff --git a/sys/arch/i386/stand/libsa/Makefile b/sys/arch/i386/stand/libsa/Makefile index 9072d80f629..a40af3711b4 100644 --- a/sys/arch/i386/stand/libsa/Makefile +++ b/sys/arch/i386/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.39 2002/06/20 20:22:58 weingart Exp $ +# $OpenBSD: Makefile,v 1.40 2003/04/17 03:43:18 drahn Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -10,7 +10,7 @@ DIR_SA= $S/lib/libsa DIR_KERN=$S/lib/libkern # i386 stuff (so, it will possibly load in the same 64k) -SRCS+= machdep.c dev_i386.c exec_i386.c cmd_i386.c +SRCS+= machdep.c dev_i386.c exec_i386.c cmd_i386.c loadfile.c .if defined(DEBUGFLAGS) && !empty(DEBUGFLAGS:M-D_TEST) SRCS+= unixdev.c unixsys.S nullfs.c memprobe.c @@ -29,7 +29,7 @@ CLEANFILES+= unixdev.o unixsys.o nullfs.o # 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 strerror.c strncpy.c \ - strtol.c ctime.c exec.new.c exec_aout.c + strtol.c ctime.c # io routines SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fstat.c ioctl.c lseek.c \ diff --git a/sys/arch/i386/stand/libsa/alloca.S b/sys/arch/i386/stand/libsa/alloca.S index d6b2cc40f84..ac663e5cd1c 100644 --- a/sys/arch/i386/stand/libsa/alloca.S +++ b/sys/arch/i386/stand/libsa/alloca.S @@ -38,7 +38,7 @@ #if defined(LIBC_SCCS) .text - .asciz "$OpenBSD: alloca.S,v 1.2 1998/02/24 22:06:43 weingart Exp $" + .asciz "$OpenBSD: alloca.S,v 1.3 2003/04/17 03:43:18 drahn Exp $" #endif /* like alloc, but automatic free in return */ @@ -55,4 +55,4 @@ ENTRY(alloca) pushl 4(%ecx) pushl 0(%ecx) pushl %eax /* dummy to pop at callsite */ - jmp %edx /* "return" */ + jmp *%edx /* "return" */ diff --git a/sys/arch/i386/stand/libsa/biosdev.c b/sys/arch/i386/stand/libsa/biosdev.c index 46f7faa2ccb..937368404d0 100644 --- a/sys/arch/i386/stand/libsa/biosdev.c +++ b/sys/arch/i386/stand/libsa/biosdev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: biosdev.c,v 1.54 2002/03/14 03:15:54 millert Exp $ */ +/* $OpenBSD: biosdev.c,v 1.55 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -189,7 +189,7 @@ biosd_rw(rw, dev, cyl, head, sect, nsect, buf) "xchgb %%ch, %%cl\n\t" "rorb $2, %%cl\n\t" "orb %b5, %%cl\n\t" - "incl %%cx\n\t" + "inc %%cx\n\t" DOINT(0x13) "\n\t" "setc %b0" : "=a" (rv) diff --git a/sys/arch/i386/stand/libsa/debug_i386.S b/sys/arch/i386/stand/libsa/debug_i386.S index ffce538bade..660ca8b2144 100644 --- a/sys/arch/i386/stand/libsa/debug_i386.S +++ b/sys/arch/i386/stand/libsa/debug_i386.S @@ -1,4 +1,4 @@ -/* $OpenBSD: debug_i386.S,v 1.9 1998/04/18 07:39:46 deraadt Exp $ */ +/* $OpenBSD: debug_i386.S,v 1.10 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -89,9 +89,9 @@ ENTRY(check_regs) movl $0x47334732, (%edi) #endif movl $0x10, %eax - movl %ax, %ds - movl %ax, %es - movl $_reg, %edi + mov %ax, %ds + mov %ax, %es + movl $reg, %edi cld movl 0x0c*4(%esp), %eax; stosl /* %eax */ movl 0x0b*4(%esp), %eax; stosl /* %ecx */ @@ -104,7 +104,7 @@ ENTRY(check_regs) movl 0x0f*4(%esp), %eax; stosl /* %eip */ movl 0x11*4(%esp), %eax; stosl /* %eflags */ movl 0x10*4(%esp), %eax; stosl /* %cs */ - movl %ss, %ax ; stosl /* %ss */ + mov %ss, %ax ; stosl /* %ss */ movl 0x04*4(%esp), %eax; stosl /* %ds */ movl 0x03*4(%esp), %eax; stosl /* %es */ movl 0x02*4(%esp), %eax; stosl /* %fs */ diff --git a/sys/arch/i386/stand/libsa/exec_i386.c b/sys/arch/i386/stand/libsa/exec_i386.c index c56a613d8cd..139ce9d7c06 100644 --- a/sys/arch/i386/stand/libsa/exec_i386.c +++ b/sys/arch/i386/stand/libsa/exec_i386.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_i386.c,v 1.26 2000/03/05 18:40:59 niklas Exp $ */ +/* $OpenBSD: exec_i386.c,v 1.27 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1997-1998 Michael Shalayeff @@ -41,17 +41,15 @@ #include <sys/disklabel.h> #include "disk.h" #include "libsa.h" -#include <lib/libsa/exec.h> +#include <lib/libsa/loadfile.h> typedef void (*startfuncp)(int, int, int, int, int, int, int, int) __attribute__ ((noreturn)); void -machdep_exec(xp, howto, loadaddr) - struct x_param *xp; - int howto; - void *loadaddr; +run_loadfile(u_long *marks, int howto) { + u_long entry; #ifndef _TEST #ifdef EXEC_DEBUG extern int debug; @@ -71,25 +69,12 @@ machdep_exec(xp, howto, loadaddr) makebootargs(av, &ac); -#ifdef EXEC_DEBUG - if (debug) { - struct exec *x = (void *)loadaddr; - printf("exec {\n\ta_midmag = %x\n\ta_text = %x\n\ta_data = %x\n" - "\ta_bss = %x\n\ta_syms = %x\n\ta_entry = %x\n" - "\ta_trsize = %x\n\ta_drsize = %x\n}\n", - x->a_midmag, x->a_text, x->a_data, x->a_bss, x->a_syms, - x->a_entry, x->a_trsize, x->a_drsize); - - printf("/bsd(%x,%u,%p)\n", BOOTARG_APIVER, ac, av); - getchar(); - } -#endif - xp->xp_entry &= 0xffffff; + entry = marks[MARK_ENTRY] & 0x0fffffff; - printf("entry point at 0x%x\n", xp->xp_entry); + printf("entry point at 0x%x\n", (int) entry); /* stack and the gung is ok at this point, so, no need for asm setup */ - (*(startfuncp)xp->xp_entry)(howto, bootdev, BOOTARG_APIVER, - xp->xp_end, extmem, cnvmem, ac, (int)av); + (*(startfuncp)entry)(howto, bootdev, BOOTARG_APIVER, + marks[MARK_END], extmem, cnvmem, ac, (int)av); /* not reached */ #endif } diff --git a/sys/arch/i386/stand/libsa/gidt.S b/sys/arch/i386/stand/libsa/gidt.S index 6faa27cfb73..85a32bb55bd 100644 --- a/sys/arch/i386/stand/libsa/gidt.S +++ b/sys/arch/i386/stand/libsa/gidt.S @@ -1,4 +1,4 @@ -/* $OpenBSD: gidt.S,v 1.24 2001/09/17 13:10:09 deraadt Exp $ */ +/* $OpenBSD: gidt.S,v 1.25 2003/04/17 03:43:18 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -41,9 +41,6 @@ #undef _LOCORE #include <assym.h> -#define addr32 .byte 0x67 -#define data32 .byte 0x66 - #define SNULL 0x00 #define S32TEXT 0x08 #define S32DATA 0x10 @@ -52,26 +49,17 @@ #ifdef GIDT_DEBUG #define gidt_debug0 ; \ - movl $0xb8000, %eax ; \ - movl $0x47314730, (%eax) + mov $0xb8000, %eax ; \ + mov $0x47314730, (%eax) #define gidt_debug1 ; \ - data32 ; \ - movl $(0xb8000 - LINKADDR), %eax ; \ - data32 ; \ - addr32 ; \ - movl $0x4f314f30, (%eax) + mov $(0xb8000 - LINKADDR), %eax ; \ + mov $0x4f314f30, (%eax) #define gidt_debug2 ; \ - data32 ; \ - movl $0xb8004, %eax ; \ - data32 ; \ - addr32 ; \ - movl $0x47334732, (%eax) + mov $0xb8004, %eax ; \ + mov $0x47334732, (%eax) #define gidt_debug3 ; \ - data32 ; \ - movl $0xb8004, %eax ; \ - data32 ; \ - addr32 ; \ - movl $0x4f334f32, (%eax) + mov $0xb8004, %eax ; \ + mov $0x4f334f32, (%eax) #define gidt_debug4 ; \ movl $0xb8008, %eax ; \ movl $0x47344733, (%eax) @@ -86,58 +74,47 @@ #define prot2real \ gidt_debug0; \ \ - movl $S16DATA, %ax; \ - /* ljmp $S16TEXT, $1f */; \ - .byte 0xea; /* Change to 16bit mode */ \ - .long 1f - LINKADDR; \ - .word S16TEXT; \ + ljmp $S16TEXT, $1f - LINKADDR; \ 1: \ - movl %ax, %ds; \ - movl %ax, %es; \ + .code16; \ + movw $S16DATA, %ax; \ + mov %ax, %ds; \ + mov %ax, %es; \ gidt_debug1; \ \ movl %cr0, %eax; /* disable pmmm */ \ - data32; \ andl $~CR0_PE, %eax; \ movl %eax, %cr0; \ \ - /* ljmp (LINKADDR >> 4), $1f */; \ - .byte 0xea; /* load real mode cs:ip */ \ - .word 1f; \ - .word (LINKADDR >> 4); \ + /* reload real cs:ip */ \ + data32 ljmp $(LINKADDR >> 4), $1f - LINKADDR; \ 1: \ - data32; \ - xorl %eax, %eax; /* setup: %ds, %es, %ss */ \ - movl %ax, %ds; \ - movl %ax, %es; \ - movl %ax, %ss; \ + xor %ax, %ax; /* setup: %ds, %es, %ss */ \ + mov %ax, %ds; \ + mov %ax, %es; \ + mov %ax, %ss; \ \ gidt_debug2; \ \ - addr32; \ - data32; \ - lidt Idtr_real; /* load idtr for real mode */ + data32 addr32 lidt Idtr_real; /* load idtr for real mode */ #define real2prot \ gidt_debug3; \ \ - addr32; \ - data32; \ - lgdt Gdtr; /* load the gdtr */ \ + data32 addr32 lgdt Gdtr; /* load the gdtr */ \ \ movl %cr0, %eax; /* enable pmmm */ \ - data32; \ orl $CR0_PE, %eax; \ movl %eax, %cr0; \ \ - data32; \ - ljmp $S32TEXT, $1f; /* reload %cs,flush pipeline */\ + data32 ljmp $S32TEXT, $1f; /* reload %cs,flush pipeline */\ 1: \ + .code32; \ /* reload 32bit %ds, %ss, %es */ \ - movl $S32DATA, %eax; \ - movl %ax, %ds; \ - movl %ax, %ss; \ - movl %ax, %es; \ + mov $S32DATA, %eax; \ + mov %ax, %ds; \ + mov %ax, %ss; \ + mov %ax, %es; \ \ gidt_debug4; \ \ @@ -148,6 +125,7 @@ .globl _C_LABEL(BIOS_regs) .text + .code32 .globl _ASM_LABEL(pmm_init) .globl _C_LABEL(_rtt) @@ -187,30 +165,21 @@ ENTRY(_rtt) movl $0, %esp /* segment violation */ ret - .align 3, 0x90 + .align 8, 0x90 pmm_init: - /* reload new gdt */ - lgdt Gdtr - ljmp $S32TEXT, $1f -1: - movl $S32DATA, %eax - movl %eax, %ds - movl %eax, %ss - movl %eax, %es - movl %eax, %fs - movl %eax, %gs - /* load idtr for interrupts */ lidt Idtr ret + #define IPROC(n) X/**/n #define IEMU(n) IPROC(emu/**/n) - .align 3 + .align 8, 0x90 idt: #define idte(e) \ - .word IPROC(e), S32TEXT, (0x80|SDT_SYS386TGT) << 8, (LINKADDR >> 16) - /* internal (0-31) */ + .short IPROC(e); .short (S32TEXT); \ + .short ((0x80|SDT_SYS386TGT) << 8); .short (LINKADDR >> 16) +/* internal (0-31) */ idte(de); idte(db); idte(nmi); idte(bp); idte(of); idte(br) idte(ud); idte(nm); idte(df); idte(fo); idte(ts); idte(np) idte(ss); idte(gp); idte(pf); idte(xx); idte(mf); idte(ac) @@ -235,15 +204,15 @@ Idtr: .word . - idt - 1 .long idt .word 0 - .align 3 + .align 8 Idtr_real: .word 1023 .long 0 .word 0 - .align 3 + .align 8 Idtr_reset: .long 0, 0 - .align 3 + .align 8 gdt: /* 0x00 : null */ .space 8 @@ -276,6 +245,7 @@ gdt: .byte 0xf | 0 | 0 | 0 # hilimit, xx, 16bit, byte granularity .byte (LINKADDR >> 20) & 0xff # hibase +.globl Gdtr Gdtr: .word . - gdt - 1 .long gdt .word 0 @@ -344,109 +314,100 @@ IEMUENT(44); IEMUENT(45); IEMUENT(46); IEMUENT(47) * */ .globl EMUh - .align 3, 0x90 + .align 8, 0x90 EMUh: /* save %eax */ - movl %eax, 3f - popl %eax + mov %eax, 3f + pop %eax - pushal - pushl %ds - pushl %es - pushl %fs - pushl %gs + pusha + push %ds + push %es + push %fs + push %gs /* save BIOS int vector */ - movb %al, intno + mov %al, intno prot2real - pushl %ds + push %ds - addr32 - movl _C_LABEL(BIOS_regs)+(BIOSR_ES), %eax - movl %ax, %es - addr32 - movl _C_LABEL(BIOS_regs)+(BIOSR_DS), %eax - movl %ax, %ds + addr32 mov _C_LABEL(BIOS_regs)+(BIOSR_ES), %eax + mov %ax, %es + addr32 mov _C_LABEL(BIOS_regs)+(BIOSR_DS), %eax + mov %ax, %ds - data32 - # movl $Leax, %eax - .byte 0xb8 -3: .long 0x90909090 /* restore %eax */ + # data32 movl $Leax, %eax + .byte 0x66, 0xb8 +3: .long 0x90909090 ;sti int $0 intno = . - 1 ;cli - popl %ds + pop %ds - addr32 - data32 - movl %ebx, _C_LABEL(BIOS_regs)+(BIOSR_BX) - movl %es, %bx - addr32 - movl %bx, _C_LABEL(BIOS_regs)+(BIOSR_ES) - movb %ah, %bh /* save flags to return to caller */ + addr32 mov %ebx, _C_LABEL(BIOS_regs)+(BIOSR_BX) + mov %es, %bx + addr32 mov %ebx, _C_LABEL(BIOS_regs)+(BIOSR_ES) + movb %ah, %bh lahf xchgb %ah, %bh - addr32 - data32 - movl %eax, 2f /* save %eax */ + addr32 mov %eax, 2f real2prot - # movl $Leax, %eax - .byte 0xb8 -2: .long 0x90909090 /* eax */ + # movl $Leax, %eax + .byte 0xb8 +2: .long 0x90909090 /* pass BIOS return values back to caller */ - movl %eax, 0xb*4(%esp) - movl %ecx, 0xa*4(%esp) - movl %edx, 0x9*4(%esp) + mov %eax, 0xb*4(%esp) + mov %ecx, 0xa*4(%esp) + mov %edx, 0x9*4(%esp) movb %bh , 0xe*4(%esp) /* clear NT flag in eflags */ /* Martin Fredriksson <martin@gbg.netman.se> */ pushf - popl %eax - andl $0xffffbfff, %eax - pushl %eax + pop %eax + and $0xffffbfff, %eax + push %eax popf /* save registers into save area */ - movl %eax, _C_LABEL(BIOS_regs)+BIOSR_AX - movl %ecx, _C_LABEL(BIOS_regs)+BIOSR_CX - movl %edx, _C_LABEL(BIOS_regs)+BIOSR_DX - movl %ebp, _C_LABEL(BIOS_regs)+BIOSR_BP - movl %esi, _C_LABEL(BIOS_regs)+BIOSR_SI - movl %edi, _C_LABEL(BIOS_regs)+BIOSR_DI - - popl %gs - popl %fs - popl %es - popl %ds - popal + mov %eax, _C_LABEL(BIOS_regs)+BIOSR_AX + mov %ecx, _C_LABEL(BIOS_regs)+BIOSR_CX + mov %edx, _C_LABEL(BIOS_regs)+BIOSR_DX + mov %ebp, _C_LABEL(BIOS_regs)+BIOSR_BP + mov %esi, _C_LABEL(BIOS_regs)+BIOSR_SI + mov %edi, _C_LABEL(BIOS_regs)+BIOSR_DI + + pop %gs + pop %fs + pop %es + pop %ds + popa iret /* Call buffer at 07c0:0000 in real mode to simulate a BIOS boot */ ENTRY(bootbuf) - popl %eax /* Don't need return address */ - popl %esi /* Buffer */ - popl %edx /* Device */ + pop %eax /* Don't need return address */ + pop %esi /* Buffer */ + pop %edx /* Device */ prot2real /* Switch */ /* Set up stack */ cli - xorl %ax, %ax - movl %ax, %ss - data32 - movl $0xfffc, %esp + xor %ax, %ax + mov %ax, %ss + mov $0xfffc, %esp sti /* Jump to buffer */ - addr32 ljmp $0x0, $0x7c00 + .end diff --git a/sys/arch/i386/stand/libsa/libsa.h b/sys/arch/i386/stand/libsa/libsa.h index 3e8499f4255..fb09f037ff5 100644 --- a/sys/arch/i386/stand/libsa/libsa.h +++ b/sys/arch/i386/stand/libsa/libsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libsa.h,v 1.35 2002/06/20 20:22:58 weingart Exp $ */ +/* $OpenBSD: libsa.h,v 1.36 2003/04/17 03:43:19 drahn Exp $ */ /* * Copyright (c) 1996-1999 Michael Shalayeff @@ -34,7 +34,7 @@ #include <lib/libsa/stand.h> #include <machine/biosvar.h> -#define EXEC_AOUT +#define EXEC_ELF #define DEFAULT_KERNEL_ADDRESS 0x100000 diff --git a/sys/arch/i386/stand/libsa/machdep.c b/sys/arch/i386/stand/libsa/machdep.c index 95a26f5491c..fd2b2f7a5ee 100644 --- a/sys/arch/i386/stand/libsa/machdep.c +++ b/sys/arch/i386/stand/libsa/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.31 2001/08/18 15:34:17 mickey Exp $ */ +/* $OpenBSD: machdep.c,v 1.32 2003/04/17 03:43:19 drahn Exp $ */ /* * Copyright (c) 1997-1999 Michael Shalayeff @@ -37,7 +37,7 @@ #include "debug.h" #include "ps2probe.h" -struct BIOS_regs BIOS_regs; +volatile struct BIOS_regs BIOS_regs; #if defined(DEBUG) && !defined(_TEST) #define CKPT(c) (*(u_int16_t*)0xb8148 = 0x4700 + (c)) diff --git a/sys/arch/i386/stand/mbr/Makefile b/sys/arch/i386/stand/mbr/Makefile index 6b390098dac..f69b5c19828 100644 --- a/sys/arch/i386/stand/mbr/Makefile +++ b/sys/arch/i386/stand/mbr/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.13 2000/06/08 00:56:08 mickey Exp $ +# $OpenBSD: Makefile,v 1.14 2003/04/17 03:43:19 drahn Exp $ # PROG= mbr SRCS= mbr.S AFLAGS+=-I${.CURDIR} -I${.CURDIR}/../../.. #-Wa,-a LD=ld -LDFLAGS=-nostdlib -Ttext 0 -x -N -s -Bstatic +LDFLAGS=-nostdlib -Ttext 0 -x -N -s -Bstatic -e start NOMAN= #MAN+= mbr.8 @@ -21,7 +21,7 @@ ${PROG}: $(OBJS) $(DPADD) $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDADD) @size $(PROG) @if [ -x ${.OBJDIR}/${PROG} ]; then \ - dd if=${.OBJDIR}/${PROG} of=${.OBJDIR}/.tmp ibs=32 skip=1 2>/dev/null; \ + objcopy -O binary ${PROG} ${.OBJDIR}/.tmp;\ mv -f ${.OBJDIR}/.tmp ${.OBJDIR}/${PROG}; \ ls -l ${.OBJDIR}/${PROG}; \ fi diff --git a/sys/arch/i386/stand/mbr/mbr.S b/sys/arch/i386/stand/mbr/mbr.S index 42ebaad6ebe..d9d4320a5cb 100644 --- a/sys/arch/i386/stand/mbr/mbr.S +++ b/sys/arch/i386/stand/mbr/mbr.S @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.S,v 1.16 2002/01/08 23:14:51 kjell Exp $ */ +/* $OpenBSD: mbr.S,v 1.17 2003/04/17 03:43:19 drahn Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff and Tobias Weingartner @@ -83,21 +83,21 @@ start: ljmp $BOOTBIOS, $1f 1: /* Set up stack */ - movl %cs, %ax + movl %cs, %eax cli - movl %ax, %ss + mov %ax, %ss data32 movl $0xfffc, %esp sti /* Set up data segment */ - movl %ax, %ds + mov %ax, %ds DBGMSG(CHAR_S) /* Relocate 512 bytes so we can load PBS here */ data32 movl $BOOTRELOC, %eax - movl %ax, %es + movl %eax, %es data32 xorl %esi, %esi data32 @@ -133,7 +133,7 @@ reloc: * * --Toby. */ - xorl %ax, %ax + xorl %eax, %eax movb $0xe3, %ax data32 movl $SERIAL, %dx @@ -185,7 +185,7 @@ reloc: * can recover anyways. The message might be nice * for the (l)user though. */ -1: xorl %bx, %bx +1: xor %bx, %bx # cmpw $DOSMBR_SIGNATURE, (%bx) .byte 0x81, 0xbf .word signature @@ -227,25 +227,25 @@ err_stop: /* Found bootable partition */ found: DBGMSG(CHAR_B) - pushl %ax + pushl %eax /* Save drive and partition */ - movl %dx, %ax - andl $0x0F, %ax - orl $0x30, %ax + movl %edx, %eax + andl $0x0F, %eax + orl $0x30, %eax #movb %al, adrive .byte 0xA2 .word adrive - movl %cx, %ax - decl %ax - xor $0x03, %ax - andl $0x0F, %ax - orl $0x30, %ax + movl %ecx, %eax + decl %eax + xorl $0x03, %eax + andl $0x0F, %eax + orl $0x30, %eax #movb %al, aprtn .byte 0xA2 .word aprtn - popl %ax + popl %eax /* Load values from active partition table entry */ # movb 1(%si), %dh # head @@ -269,7 +269,7 @@ found: */ data32 movl $0x200 | 1, %eax /* number of blocks */ - xorl %bx, %bx /* put it at %es:0 */ + xor %bx, %bx /* put it at %es:0 */ int $0x13 jnc 1f puts(eread) @@ -308,8 +308,8 @@ Lchr: #ifndef SERIAL pushl %ebx movb $0x0e, %ah - xorl %bx, %bx - incl %bx /* movw $0x01, %bx */ + xor %bx, %bx + inc %bx /* movw $0x01, %bx */ int $0x10 popl %ebx #else |