+# $OpenBSD: Makefile.inc,v 1.3 1997/03/31 23:06:03 mickey Exp $
-CPPFLAGS+=-D_STANDALONE -DSAVE_MEMORY
+#CPPFLAGS+=-nostdinc -I/sys
+CPPFLAGS+=-Wall -Werror -I. -Imachine
+SACFLAGS+=-Wa,-R -fno-common -fpack-struct -fno-builtin -fomit-frame-pointer
+CPPFLAGS+=-D_STANDALONE
+CPPFLAGS+=-DNO_IDTR
+CPPFLAGS+=-DSAVE_MEMORY
CPPFLAGS+=-DDEBUG
-# -DALLOC_TRACE
-# -D_TEST
-# -DUNIX_DEBUG
-# -DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG
-# -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG
-REL=0x1000
+# CPPFLAGS+=-DBIOS_DEBUG
+# CPPFLAGS+=-DEXEC_DEBUG
+# CPPFLAGS+=-DALLOC_TRACE
+# CPPFLAFS+=-D_TEST
+# CPPFLAFS+=-DUNIX_DEBUG
+# CPPFLAFS+=-DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG
+# CPPFLAGS+=-DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG
+START=0x1000
+HEAP_START=0x10000
+HEAP_LIMIT=0x40000
+BOOTREL=0x3000
+BOOTMAGIC=0xdeadbeef
NO_NET=no_net
-SA_ZLIB=sa_zlib
BINDIR= /usr/mdec
-
-$OpenBSD: README,v 1.1 1997/03/31 03:11:59 weingart Exp $
+$OpenBSD: README,v 1.2 1997/03/31 23:06:04 mickey Exp $
Ok, just a couple quick pointers to people hacking on this stuff. These
biosboot: 512 bytes of the first sector on the disk/partition. This loads
/boot (or whatever you did with installboot) into ram.
-boot: relocates itself, and starts protected mode. There is some magic here
-in terms of the placement and size of the various segments, as this piece of
-code has to switch between real and protected mode many times to load the
-next piece of the puzzle, /bsd.gz.
+boot: starts protected mode, and process simple command line.
+There is some magic here in terms of the placement and size of the various
+segments, as this piece of code has to switch between real and protected
+mode many times to load the next piece of the puzzle, /bsd.gz.
bsd: The kernel itself, can be gzipped if ya want.
-# $OpenBSD: Makefile,v 1.2 1997/03/31 03:12:00 weingart Exp $
+# $OpenBSD: Makefile,v 1.3 1997/03/31 23:06:19 mickey Exp $
PROG= biosboot
SRCS= biosboot.S
-AFLAGS+=-DREL=$(REL) #-Wa,-a
+# AFLAGS+=-Wa,-a
+CPPFLAGS+=-DSTART=$(START) -DBOOTMAGIC=$(BOOTMAGIC) -DBOOTREL=$(BOOTREL)
LDFLAGS=-Wl,-T0,-N,-x -nostdlib
STRIP=
MAN= biosboot.8
${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
+all: machine-links
+
+machine-links:
+ @rm -f i386 machine
+ @ln -fs ${.CURDIR}/../.. i386
+ @ln -fs ${.CURDIR}/../../include machine
.include <bsd.prog.mk>
+
-/* $OpenBSD: biosboot.S,v 1.2 1997/03/31 03:12:01 weingart Exp $ */
+/* $OpenBSD: biosboot.S,v 1.3 1997/03/31 23:06:19 mickey Exp $ */
.file "bootbios.S"
#define BLKCNT 48
#endif
-#define BIOSSEG 0x07c0 /* boot loaded here */
-#define BOOTSEG 0x1000 /* /boot placement */
-#define BOOTSTACK 0xfffc /* /boot stack */
+#define BOOTSEG 0x07c0 /* boot loaded here */
+#define BOOTSTACK 0xfffc /* stack starts here */
#define ZMAGIC 0x0b01 /* ZMAGIC */
#ifdef DEBUG
movb $msg, %al; \
data32; \
call chr
-#define CHAR_M 'M' /* magic check */
-#define CHAR_P 'P' /* switch to protected mode */
+#define GO_RELOC 'R' /* running relocated code */
+#define REAL2PROT 'P' /* switch to protected mode */
#else /* !DEBUG */
#define DBGMSG(msg)
#endif /* !DEBUG */
.globl start
start:
- /* adjust %cs */
- data32
- ljmp $BIOSSEG, $2f
-1: .asciz "loading /boot"
-
-2: /* set up stack (%ss:%esp) */
+ /* set up stack (%ss:%esp) */
cli /* disable interrupts w/o stack */
- data32
- movl $BOOTSEG, %ax
+ # movw $BOOTREL, %ax
+ .byte 0xb8
+ .word BOOTREL
movl %ax, %ss
+ movl %ax, %es /* relocate there */
data32
movl $BOOTSTACK, %esp
sti /* we have stack, do ints */
- /* set up %es, (where we will load /boot to) */
- movl %ax, %es
+ # movw $BOOTSEG, %ax /* we are here */
+ .byte 0xb8
+ .word BOOTSEG
+ movl %ax, %ds
+ xorl %si, %si
+ xorl %di, %di
+ # movw $0x100, %cx /* 512 bytes to move */
+ .byte 0xb9
+ .word 0x100
+ cld
+ rep; movsl
+
+ /* jump to relocated code */
+ data32
+ ljmp $BOOTREL, $2f
+1: .asciz "loading /boot"
+
+2: DBGMSG(GO_RELOC)
/* set up %ds */
pushl %cs
popl %ds
+ /* set up %es, (where we will load /boot to) */
+ # movw $(START >> 4), %ax
+ .byte 0xb8
+ .word START >> 4
+ movl %ax, %es
+
#ifdef SERIAL
# Initialize the serial port to 9600 baud, 8N1.
pushl %dx
- movl $0x00e3, %ax
- data32
- movl SERIAL, %edx
+ # movw $0x00e3, %ax
+ .byte 0xb8
+ .word 0x00e3
+ # movw SERIAL, %dx
+ .byte 0xba
+ .word SERIAL
int $0x14
popl %dx
#endif
addr32
movb _block_count, %cl /* how many to read */
movzbl %cl, %ecx
- data32
- movl $_block_table, %esi
+ # movw $_block_table, %si
+ .byte 0xbe
+ .word _block_table
1:
- pushl %ecx
+ pushl %cx
cld
lodsl /* word */ /* cylinder/sector */
movl %ax, %cx
call chr /* show progress indicator */
popl %ax
- data32
- movzbl %al, %eax
+ movzbl %al, %ax
shll $9, %ax /* 512 bytes sectors */
addl %ax, %bx
- popl %ecx
+ popl %cx
loop 1b
data32
data32
call message
-#if 0
- DBGMSG(CHAR_M)
-#endif
-
- xorl %esi, %esi
+ xorl %si, %si
cld
/* check /boot magic */
es;lodsl;es;lodsl /* no need for high word */
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
+ addl 16(%esi), %edi /* entry */
-#if 0
- DBGMSG(CHAR_P)
-#endif
+ DBGMSG(REAL2PROT)
/* change to protected mode */
/* guarantee that interrupts are disabled when in prot mode */
* reload CS register
*/
data32
- ljmp $8, $1f+(BIOSSEG << 4)
+ ljmp $8, $1f+(BOOTREL << 4)
1: /*
* 32bit mode
* set up %ds, %ss, %es
*/
- movl $0x10, %eax
+ movw $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 $0xb8004, %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
+ pushl $BOOTMAGIC /* use some magic */
/* jmp /boot */
- ljmp $0x8, $(REL << 4) + 0x20
+ ljmp $8, $(START + 0x20)
/* not reached */
#
data32
ret
- .align 2
-Gdtr: .word 3 * 8 - 1
- .long (BIOSSEG << 4) + 2f
.align 3
-2: /* 0x00 : null */
+gdt: /* 0x00 : null */
.long 0, 0
/* 0x08 : flat code */
.word 0xFFFF # lolimit
.byte SDT_MEMRWA | 0 | 0x80 # RWA, dpl = 0, present
.byte 0xf | 0 | 0x40 | 0x80 # hilimit, xx, 32bit, 4k granularity
.byte 0 # hibase
+Gdtr: .word . - gdt
+ .long (BOOTREL << 4) + gdt
.globl _block_table
_block_table:
-# $OpenBSD: Makefile,v 1.2 1997/03/31 03:12:02 weingart Exp $
+# $OpenBSD: Makefile,v 1.3 1997/03/31 23:06:20 mickey Exp $
PROG= boot
-SRCS= srt0.S boot.c cmd.c conf.c version.c
-CFLAGS=-I${.CURDIR}/../../../../lib/libsa -I${.CURDIR}/../libsa
-AFLAGS+=-DREL=$(REL) #-Wa,-a
-CFLAGS+=-Wall -O
-LDFLAGS=-Wl,-T$(REL),-x,-z -e start_boot
-LDFLAGS+=-static -nostdlib
+SRCS= srt0.S boot.c cmd.c conf.c
+CFLAGS+=$(SACFLAGS) -I${.CURDIR}/../../../../lib/libsa -I${.CURDIR}/../libsa
+AFLAGS+=-Wa,-R
+# AFLAGS+=-Wa,-a
+LD=ld
+LDFLAGS+=-Ttext $(START) -z -x -e start_boot -Bstatic
MAN= boot.8
LDADD= -L../libsa -lsa -L../libz -lz
DPADD= ../libsa/libsa.a ../libz/libz.a
+all: machine-links
+
+machine-links:
+ @rm -f machine i386
+ @ln -fs ${.CURDIR}/../.. i386
+ @ln -fs ${.CURDIR}/../../include machine
+
+${PROG}: $(OBJS) $(DPADD)
+ $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDADD)
+ @size $(PROG)
+
.include <bsd.prog.mk>
+CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC)
.ifdef NO_NET
CPPFLAGS+=-DNO_NET
.endif
-/* $OpenBSD: boot.c,v 1.2 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: boot.c,v 1.3 1997/03/31 23:06:20 mickey Exp $ */
+
/*
* Copyright (c) 1997 Michael Shalayeff
* All rights reserved.
#include <sys/param.h>
#include <sys/reboot.h>
#include <sys/stat.h>
-#include <a.out.h>
-#include <sys/disklabel.h>
#include <libsa.h>
#include "cmd.h"
-/*
- * Boot program, loaded by boot block from remaing 7.5K of boot area.
- * Sifts through disklabel and attempts to load an program image of
- * a standalone program off the disk. If keyboard is hit during load,
- * or if an error is encounter, try alternate files.
- */
-
-char *kernels[] = {
- "bsd", "bsd.gz",
- "obsd", "obsd.gz",
- "bsd.old", "bsd.old.gz",
- NULL
-};
+char *kernels[] = { "bsd", "bsd.gz",
+ "obsd", "obsd.gz",
+ "bsd.old", "bsd.old.gz",
+ NULL };
-int retry = 0;
-extern char version[];
-extern dev_t bootdev;
-extern int boothowto;
-int cnvmem, extmem, probemem;
+extern const char version[];
+int boothowto;
+u_int cnvmem, extmem;
-void boot ();
-struct cmd_state cmd;
+void devboot __P((dev_t, char *));
-/*
- * Boot program... loads /boot out of filesystem indicated by arguements.
- * We assume an autoboot unless we detect a misconfiguration.
- */
void
-boot()
+boot(bootdev)
+ dev_t bootdev;
{
register char *bootfile = kernels[0];
+ register struct cmd_state *cmd;
register int i;
-
- /* Get memory size */
- cnvmem = memsize(0);
- extmem = memsize(1);
+#ifdef DEBUG
+ *(u_int16_t*)0xb8148 = 0x4730;
+#endif
gateA20(1);
- probemem = memprobe();
+#ifndef _TEST
+ memprobe();
+#endif
+#ifdef DEBUG
+ *(u_int16_t*)0xb8148 = 0x4f31;
+#endif
+ cons_probe();
+ printf("\n>> OpenBSD BOOT: %u/%u k [%s]\n", cnvmem, extmem, version);
/* XXX init cmd here to cut on .data !!! */
- strncpy(cmd.bootdev,
-#ifdef _TEST
- "/dev/rfd0a",
-#else
- "fd(0,a)",
-#endif
- sizeof(cmd.bootdev));
- cmd.image[0] = '\0';
- cmd.cwd[0] = '/';
- cmd.cwd[1] = '\0';
- cmd.addr = (void *)0x100000;
- cmd.timeout = 50000;
-
- printf("\n>> OpenBSD BOOT: %d/%d (%d) k [%s]\n",
- cnvmem, extmem, probemem, version);
+ cmd = (struct cmd_state *)alloc(sizeof(*cmd));
+ devboot(bootdev, cmd->bootdev);
+ cmd->image[0] = '\0';
+ cmd->cwd[0] = '/';
+ cmd->cwd[1] = '\0';
+ cmd->addr = (void *)0x100000;
+ cmd->timeout = 50;
for (i = 0;;) {
- strncpy(cmd.image, bootfile, sizeof(cmd.image));
+ strncpy(cmd->image, bootfile, sizeof(cmd->image));
do {
printf("boot> ");
- } while(!getcmd(&cmd) && !execmd(&cmd));
+ } while(!getcmd(cmd) && !execmd(cmd));
+
+ if (cmd->rc < 0)
+ break;
- sprintf(cmd.path, "%s%s%s", cmd.bootdev, cmd.cwd, bootfile);
- printf("\nbooting %s: ", cmd.path);
- exec (cmd.path, cmd.addr, boothowto);
+ printf("\nbooting %s: ", cmd->path);
+ exec (cmd->path, cmd->addr, boothowto);
if(kernels[++i] == NULL)
bootfile = kernels[i=0];
else
bootfile = kernels[i];
- cmd.timeout += 20;
+ cmd->timeout += 20;
printf(" failed(%d)\nwill try %s\n", errno, bootfile);
}
}
+void
+devboot(bootdev, p)
+ dev_t bootdev;
+ char *p;
+{
+#ifdef _TEST
+ *p++ = '/';
+ *p++ = 'd';
+ *p++ = 'e';
+ *p++ = 'v';
+ *p++ = '/';
+ *p++ = 'r';
+#endif
+ if (bootdev & 0x80)
+ *p++ = 'h';
+ else
+ *p++ = 'f';
+ *p++ = 'd';
+#ifndef _TEST
+ *p++ = '(';
+#endif
+ *p++ = '0' + (bootdev & 0x7f);
+#ifndef _TEST
+ *p++ = ',';
+#endif
+ *p++ = 'a';
+#ifndef _TEST
+ *p++ = ')';
+#endif
+ *p = '\0';
+}
+
#ifdef _TEST
int
main()
-/* $OpenBSD: cmd.c,v 1.1 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: cmd.c,v 1.2 1997/03/31 23:06:21 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
#include <string.h>
#include <libsa.h>
#include "cmd.h"
+#ifndef _TEST
+#include <biosdev.h>
+#endif
-static struct cmd_table {
+extern int debug;
+
+const struct cmd_table {
char *cmd_name;
int cmd_id;
} cmd_table[] = {
{"boot", CMD_BOOT},
{"cd", CMD_CD},
{"device", CMD_DEVICE},
+#ifdef DEBUG
+ {"debug", CMD_DEBUG},
+#endif
{"help", CMD_HELP},
{"image", CMD_IMAGE},
{"ls", CMD_LS},
{NULL, 0},
};
-extern char version[];
-void ls __P((char *, register struct stat *));
-char skipblnk __P((void));
+extern const char version[];
+static void ls __P((char *, register struct stat *));
+static char *skipblnk __P((register char *));
+static int readline __P((register char *, int));
-char cmd_buf[133];
+char *cmd_buf = NULL;
int
getcmd(cmd)
- register struct cmd_state *cmd;
+ struct cmd_state *cmd;
{
- register struct cmd_table *ct = cmd_table;
- register char *p = cmd_buf; /* input */
- register char ch;
- int len;
+ register const struct cmd_table *ct = cmd_table;
+ register char *p = cmd_buf, *q; /* input */
+
+ if (cmd_buf == NULL)
+ p = cmd_buf = alloc(133);
cmd->rc = 0;
cmd->argc = 1;
- for (len = cmd->timeout; len-- && !ischar(); );
-
- if (len < 0) {
+ if (!readline(cmd_buf, cmd->timeout)) {
cmd->cmd = CMD_BOOT;
cmd->argv[0] = cmd_table[CMD_BOOT].cmd_name;
cmd->argv[1] = NULL;
return 0;
}
- ch = skipblnk();
+ p = skipblnk(cmd_buf);
- for (len = 0; ch != '\n' &&
- ch != ' ' && ch != '\t'; len++, ch = getchar())
- *p++ = ch;
+ /* command */
+ for ( q = p; *p != '\0' && *p != ' ' && *p != '\t'; p++);
*p = '\0';
- if (len == 0 && ch == '\n') {
- cmd->cmd = CMD_NOPE;
- return 0;
- }
-
- while (ct->cmd_name != NULL &&
- strncmp(cmd_buf, ct->cmd_name, len))
+ while (ct->cmd_name != NULL && strncmp(q, ct->cmd_name, (p - q)))
ct++;
if (ct->cmd_name == NULL) {
- cmd->cmd = CMD_ERROR;
- cmd->argv[0] = ct->cmd_name;
+ cmd->cmd = CMD_BOOT;
+ cmd->argv[0] = cmd_table[CMD_BOOT].cmd_name;
+ cmd->argv[1] = skipblnk(cmd_buf);
+ cmd->argv[2] = NULL;
+ cmd->argc++;
return 0;
}
cmd->cmd = ct->cmd_id;
cmd->argv[0] = ct->cmd_name;
- if (ct->cmd_name != NULL) {
- while (ch != '\n') {
-
- ch = skipblnk();
-
- if (ch != '\n') {
- cmd->argv[cmd->argc] = p;
- *p++ = ch;
- for (len = 0; (ch = getchar()) != '\n' &&
- ch != ' ' && ch != '\t'; len++)
- *p++ = ch;
- *p++ = '\0';
- if (len != 0)
- cmd->argc++;
- }
- }
- cmd->argv[cmd->argc] = NULL;
+ for (p++; *(p = skipblnk(p)) != '\0'; *p++ = '\0') {
+ cmd->argv[cmd->argc++] = q = p;
+ for (; *p && *p != '\t' && *p != ' '; p++);
}
+ cmd->argv[cmd->argc] = NULL;
return cmd->rc;
}
-char
-skipblnk()
+static int
+readline(p, to)
+ register char *p;
+ int to;
{
- register char ch;
+ char *buf = p, ch;
+ int i;
+
+ for (i = to; i-- && !ischar(); )
+#ifndef _TEST
+ usleep(100000);
+#else
+ ;
+#endif
+ if (i < 0)
+ return 0;
+ while (1) {
+ switch (ch = getchar()) {
+ case '\n':
+ p[1] = *p = '\0';
+ break;
+ case '\b':
+ if (p > buf) {
+ putchar('\b');
+ putchar(' ');
+ putchar('\b');
+ p--;
+ }
+ continue;
+ default:
+ *p++ = ch;
+ continue;
+ }
+ break;
+ }
+ return p - buf;
+}
+
+char *
+skipblnk(p)
+ register char *p;
+{
/* skip blanks */
- while ((ch = getchar()) != '\n' &&
- (ch == ' ' || ch == '\t'));
+ while (*p == '\t' || *p == ' ')
+ p++;
- return ch;
+ return p;
}
int
execmd(cmd)
- register struct cmd_state *cmd;
+ struct cmd_state *cmd;
{
struct stat sb;
int fd;
register char *p, *q;
- register struct cmd_table *ct;
+ register const struct cmd_table *ct;
cmd->rc = 0;
-
switch (cmd->cmd) {
+#ifdef DEBUG
+ case CMD_DEBUG:
+ debug = !debug;
+ printf("debug is %s\n", debug? "on": "off");
+ break;
+#endif
+
case CMD_HELP:
printf("commands: ");
for (ct = cmd_table; ct->cmd_name != NULL; ct++)
case CMD_LS:
{
- q = cmd->argv[1] == NULL? "." : cmd->argv[1];
- sprintf(cmd->path, "%s%s%s",
- cmd->bootdev, cmd->cwd, q);
+ if (cmd->argv[1] != NULL)
+ strncpy (cmd->path, cmd->argv[1],
+ sizeof(cmd->path));
+ else
+ sprintf(cmd->path, "%s%s/.",
+ cmd->bootdev, cmd->cwd);
if (stat(cmd->path, &sb) < 0) {
printf("stat(%s): %d\n", cmd->path, errno);
}
if ((sb.st_mode & S_IFMT) != S_IFDIR)
- ls(q, &sb);
+ ls(cmd->path, &sb);
else {
if ((fd = opendir(cmd->path)) < 0) {
printf ("opendir(%s): %d\n",
break;
}
- p = cmd->path + strlen(cmd->path);
+ /* no strlen in lib !!! */
+ for (p = cmd->path; *p; p++);
*p++ = '/';
*p = '\0';
- while(readdir(fd, p) >= 0 && *p != '\0') {
+ while(readdir(fd, p) >= 0) {
- if (stat(cmd->path, &sb) < 0) {
+ if (stat(cmd->path, &sb) < 0)
printf("stat(%s): %d\n",
cmd->path, errno);
- break;
- }
- ls(p, &sb);
+ else
+ ls(p, &sb);
}
closedir (fd);
break;
case CMD_SET:
- printf("OpenBSD boot version %s\n"
+ printf("OpenBSD/i386 boot version %s(debug is %s)\n"
"device:\t%s\n"
"cwd:\t%s\n"
"image:\t%s\n"
"load at:\t%p\n"
"timeout:\t%d\n",
- version, cmd->bootdev, cmd->cwd, cmd->image,
+ version,
+#ifdef DEBUG
+ (debug? "on": "off"),
+#endif
+ cmd->bootdev, cmd->cwd, cmd->image,
cmd->addr, cmd->timeout);
break;
case CMD_REBOOT:
- exit(1);
+ cmd->rc = -1;
break;
case CMD_BOOT:
- return 1;
+ if (cmd->argc > 1)
+ strncpy(cmd->path, cmd->argv[1], sizeof(cmd->path));
+ else
+ sprintf(cmd->path, "%s%s%s", cmd->bootdev,
+ cmd->cwd, cmd->image);
+ cmd->rc = 1;
break;
case CMD_ERROR:
lsrwx(sb->st_mode >> 3, (sb->st_mode & S_ISUID? "sS" : "x-"));
lsrwx(sb->st_mode , (sb->st_mode & S_ISTXT? "tT" : "x-"));
- printf (" %s\tuid=%u\tgid=%u\t%lu\n", name, sb->st_uid, sb->st_gid,
- (u_long)sb->st_size);
+ printf (" %u,%u\t%lu\t%s\n", sb->st_uid, sb->st_gid,
+ (u_long)sb->st_size, name);
}
-/* $OpenBSD: cmd.h,v 1.1 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: cmd.h,v 1.2 1997/03/31 23:06:21 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
struct cmd_state {
char bootdev[16]; /* device */
char image[32]; /* image */
- char cwd[MAXPATHLEN - 32 - 32];
+ char cwd[MAXPATHLEN - 32 - 16];
void *addr; /* load here */
int timeout;
char path[MAXPATHLEN]; /* buffer for pathname compose */
- enum { CMD_ADDR, CMD_BOOT, CMD_CD, CMD_DEVICE, CMD_HELP,
+ enum { CMD_ADDR, CMD_BOOT, CMD_CD, CMD_DEVICE, CMD_DEBUG, CMD_HELP,
CMD_IMAGE, CMD_LS, CMD_NOPE, CMD_REBOOT, CMD_SET,
- CMD_ERROR /* last !!! */ };
- int cmd;
+ CMD_ERROR /* last !!! */
+ } cmd;
int argc;
char *argv[8]; /* XXX i hope this is enough */
int rc;
-/* $OpenBSD: conf.c,v 1.2 1997/03/31 03:12:04 weingart Exp $ */
+/* $OpenBSD: conf.c,v 1.3 1997/03/31 23:06:22 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include <ufs.h>
#include <nfs.h>
#include <cd9660.h>
+#ifdef notdef
+#include <fat.h>
+#include <tftp.h>
+#endif
#include <netif.h>
#include "biosdev.h"
#include "unixdev.h"
+const char version[] = "0.99a";
int debug = 1;
struct fs_ops file_system[] = {
#else
{ "BIOS", biosstrategy, biosopen, biosclose, biosioctl },
#endif
+#if 0
+ { "TFTP", tftpstrategy, tftpopen, tftpclose, tftpioctl },
+#endif
};
int ndevs = NENTS(devsw);
{ "unix",unix_probe,unix_putc,unix_getc,unix_ischar},
#else
{ "kbd", kbd_probe, kbd_putc, kbd_getc, kbd_ischar },
+#if 0
{ "com", com_probe, com_putc, com_getc, com_ischar },
#endif
+#endif
};
int ncons = NENTS(consw);
-/* $OpenBSD: crt0.c,v 1.1 1997/03/31 03:12:04 weingart Exp $ */
+/* $OpenBSD: crt0.c,v 1.2 1997/03/31 23:06:22 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
{
extern char end[];
register caddr_t p = (caddr_t)(((u_long)end + PGOFSET) & ~PGOFSET);
- register size_t sz = 0x10000 - (u_long)p - NBPG;
-
-#ifdef DEBUG
- /* we are low on memory w/ the DEBUG defined ); */
- sz = 40 * NBPG;
-#endif
/* map heap */
- if ( (p = ummap(p, sz, PROT_READ|PROT_WRITE,
+ if ( (p = ummap(p, 32*NBPG, PROT_READ|PROT_WRITE,
MAP_FIXED|MAP_ANON, -1, 0)) == (caddr_t)-1) {
printf("mmap failed: %d\n", errno);
uexit(1);
-/* $OpenBSD: srt0.S,v 1.1 1997/03/31 03:12:05 weingart Exp $ */
+/* $OpenBSD: srt0.S,v 1.2 1997/03/31 23:06:23 mickey Exp $ */
/* $NetBSD: srt0.c,v 1.3 1994/10/27 04:21:59 cgd Exp $ */
/*-
* @(#)srt0.c 5.3 (Berkeley) 4/28/91
*/
-/*
- * Startup code for standalone system
- * Non-relocating version -- for programs which are loaded by boot
- * Relocating version for boot
- * Small relocating version for "micro" boot
- */
-
#include <machine/psl.h>
#define _LOCORE
#include <machine/segments.h>
.globl _edata
.globl _boot
.globl __rtt
+ .globl _Gdtr
+#ifndef NO_IDTR
+ .globl _Idtr_prot
+#endif
+ .globl _codeseg
+
+ .text
+ .globl start_boot
+start_boot:
+#ifdef DEBUG
+ movl $0xb80a0, %ebx
+ movl $0x07420742, (%ebx)
+#endif
+
+ lgdt _Gdtr
+ ljmp $8, $1f
+1:
+ movw $0x10, %ax
+ movl %ax, %ds
+ movl %ax, %ss
+ movl %ax, %es
+ movl %ax, %fs
+ movl %ax, %gs
+
+#ifdef DEBUG
+ movl $0xb80a4, %ebx
+ movl $0x07520752, (%ebx)
+#endif
+
+ popl %eax
+ cmpl $BOOTMAGIC, %eax
+ je 1f
+#ifdef DEBUG
+ movl $0xb80a8, %ebx
+ movl $0x4741474d, (%ebx)
+#endif
+1:
+ /* zero .bss */
+ xorl %eax, %eax
+ movl $_end, %ecx
+ subl $_edata,%ecx
+ movl $_edata, %edi
+ cld
+ rep; stosb
+
+ call _boot
+
+__rtt:
+#ifdef DEBUG
+ movl $0xb8000, %ebx
+ movl $0x4f514f51, (%ebx)
+ hlt
+#endif
+ movl $-7, %eax
+ movw $0x1234, %ax
+ movw %ax, 0x472 # warm boot
+ movl $0, %esp # segment violation
+ ret
.data
- .globl _Gdtr
- .align 2
-_Gdtr: .word 4 * 8 - 1
- .long 2f
+
.align 3
-2: /* 0x00 : null */
+gdt: /* 0x00 : null */
.long 0, 0
/* 0x08 : flat code */
.word 0xFFFF # lolimit
.word 0xFFFF # lolimit
.word 0 # lobase
.byte 0 # midbase
- .byte SDT_MEMERC | 0 | 0x80 # RWXAC, dpl = 0, present
- .byte 0x0 | 0 | 0 | 0 # hilimit, xx, 16bit, byte granularity
+ .byte SDT_MEMERAC | 0 | 0x80 # RWXAC, dpl = 0, present
+ .byte 0xf | 0 | 0 | 0 # hilimit, xx, 16bit, byte granularity
.byte 0 # hibase
+_Gdtr: .word . - gdt
+ .long gdt
+ .word 0
- .globl _codeseg
- .globl _bootdev
- .globl _boothowto
- .globl _cyloffset
_codeseg: .long 0
-_bootdev: .long 0
-_boothowto: .long 0
-_cyloffset: .long 0
-_esym: .long 0
-
- .text
-text_start:
-
-#define NOP inb $0x84,%al ; inb $0x84,%al
-
- .globl start_boot
-
-start_boot:
- pushl %ebp
- movl %esp, %ebp
-
-#ifdef REL
- /* relocate code+data */
- call 1f
-1: popl %esi
- subl $1b, %esi
- addl $text_start, %esi /* %esi = %eip - (1b - text_start) */
- subl $0x20, %esi /* XXX - Fudge factor for header */
- movl $REL, %edi
- movl $_edata, %ecx
- subl $text_start, %ecx
- shrl $2, %ecx
- incl %ecx
- cld
- rep
- movsl
-#endif /* REL */
-
- lgdt _Gdtr
-
- /* The following should *not* be moved before the lgdt.
- * Trust me, bad things will happen!
- * Start executing from relocated code
- */
- movl $0x10, %eax
- movl %eax, %ds
- movl %eax, %es
- movl %eax, %fs
- movl %eax, %gs
- movl %eax, %ss
- ljmp $0x8,$docs
-docs:
- nop
-
- /* XXX - I don't know if the following is right */
- movl 8(%ebp), %eax
- movl %eax, _boothowto
- movl 12(%ebp),%eax
- movl %eax, _bootdev
- movl 16(%ebp),%eax
- movl %eax, _cyloffset
- movl 20(%ebp),%eax
- movl %eax, _esym
-
- /* save old stack state */
- movl %esp,savearea
- movl %ebp,savearea+4
-
- /* setup stack pointer */
-#ifdef REL
- movl $0xfffc, %esp
-#else
- movl $_end, %eax
- addl $10000, %eax
- movl %eax, %esp
-#endif
-
- /* clear memory as needed */
- movl %esp,%esi
- movl $_end, %eax
- subl $_edata,%eax
- pushl %eax
- pushl $0
- pushl $_edata
- call _memset
- #call _kbdreset /* resets keyboard and gatea20 brain damage */
- movl %esi,%esp
-
- pushl __rtt
- ljmp $0x8, $_boot /* Jmp to boot code */
-
- .data
-
-savearea: .long 0,0 # sp & bp to return to
-
- .text
-
-__rtt:
- movl $-7,%eax
-#ifdef REL
- movw $0x1234,%ax
- movw %ax,0x472 # warm boot
- movl $0,%esp # segment violation
- ret
-#else
- movl savearea,%esp
- movl savearea+4,%ebp
- ret
-#endif
-
- .globl _inb
-_inb: movl 4(%esp),%edx
- subl %eax,%eax # clr eax
- NOP
- inb %dx,%al
- ret
-
- .globl _outb
-_outb: movl 4(%esp),%edx
- NOP
- movl 8(%esp),%eax
- outb %al,%dx
- ret
-
- .globl ___udivsi3
-___udivsi3:
- movl 4(%esp),%eax
- xorl %edx,%edx
- divl 8(%esp)
- ret
-
- .globl ___divsi3
-___divsi3:
- movl 4(%esp),%eax
- xorl %edx,%edx
- cltd
- idivl 8(%esp)
- ret
-
- .globl _insw
-_insw:
- pushl %edi
- movw 8(%esp),%dx
- movl 12(%esp),%edi
- movl 16(%esp),%ecx
- NOP
- cld
- nop
- .byte 0x66,0xf2,0x6d # rep insw
- nop
- movl %edi,%eax
- popl %edi
- ret
-
- # outsw(port,addr,cnt)
- .globl _outsw
-_outsw:
- pushl %esi
- movw 8(%esp),%dx
- movl 12(%esp),%esi
- movl 16(%esp),%ecx
- NOP
- cld
- nop
- .byte 0x66,0xf2,0x6f # rep outsw
- nop
- movl %esi,%eax
- popl %esi
- ret
-
+++ /dev/null
-
-char version[] = "1.0";
-# $OpenBSD: Makefile,v 1.2 1997/03/31 03:12:06 weingart Exp $
+# $OpenBSD: Makefile,v 1.3 1997/03/31 23:06:24 mickey Exp $
PROG= installboot
-CFLAGS+=-DDEBUG -g -Wall
MAN= installboot.8
# Need this to work in the miniroot
-/* $OpenBSD: installboot.c,v 1.2 1997/03/31 03:12:07 weingart Exp $ */
+/* $OpenBSD: installboot.c,v 1.3 1997/03/31 23:06:24 mickey Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
if (protosize > SBSIZE - DEV_BSIZE)
errx(1, "proto bootblocks too big");
- if ((devfd = open(dev, O_RDWR, 0)) < 0)
+ if ((devfd = open(dev, (nowrite? O_RDONLY:O_RDWR), 0)) < 0)
err(1, "open: %s", dev);
/* Sync filesystems (to clean in-memory superblock?) */
-# $OpenBSD: Makefile,v 1.3 1997/03/31 05:52:24 weingart Exp $
+# $OpenBSD: Makefile,v 1.4 1997/03/31 23:06:25 mickey Exp $
-LIB= sa
+LIB= sa
-CFLAGS+=-Wall
-#CFLAGS+=-DBIOS_DEBUG
-#CFLAGS+=-DEXEC_DEBUG
-CFLAGS+=-DNO_IDTR
-CFLAGS+=-DHEAP_START="0x10000"
-CFLAGS+=-DHEAP_LIMIT="0xa0000"
-CFLAGS+=-D__INTERNAL_LIBSA_CREAD
+CFLAGS+=$(SACFLAGS) -D__INTERNAL_LIBSA_CREAD
+CFLAGS+=-DHEAP_START=$(HEAP_START) -DHEAP_LIMIT=$(HEAP_LIMIT)
CFLAGS+=${DEBUGFLAGS} -I${.CURDIR} -I${.CURDIR}/..
CFLAGS+=-I${.CURDIR}/../../../.. -I${.CURDIR}/../../../../lib/libsa
+AS+= -R
#AS+= -Wa,-a
S=${.CURDIR}/../../../..
-DIR_SA=$S/lib/libsa
+DIR_SA= $S/lib/libsa
DIR_KERN=$S/lib/libkern
# stand routines
-SRCS= alloc.c exit.c exec.c getfile.c gets.c globals.c strcmp.c \
- strncmp.c memcmp.c memcpy.c memset.c printf.c strerror.c strncpy.c
+SRCS= alloc.c exit.c exec.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
+
+# math for cd9660
+SRCS+= divdi3.c qdivrem.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
+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
# network routines
-SRCS+= arp.c ether.c in_cksum.c net.c netif.c rpc.c
+SRCS+= arp.c ether.c in_cksum.c net.c netif.c rpc.c
# network info services
-SRCS+= bootp.c bootparam.c rarp.c
+SRCS+= bootp.c bootparam.c rarp.c
# boot filesystems
-SRCS+= ufs.c nfs.c
+SRCS+= ufs.c nfs.c cd9660.c
# i386 stuff
-SRCS+= asm.S bioscom.S biosdev.c biosdisk.S bioskbd.S biostime.S startprog.S \
- dev_i386.c exec_i386.c gateA20.c memprobe.c memsize.S probe_keyboard.c \
- real_prot.S srt0.S unixsys.S
+SRCS+= asm.S bioscom.S biosdev.c biosdisk.S bioskbd.S biostime.S biosmem.S \
+ dev_i386.c gateA20.c memprobe.c real_prot.S unixsys.S exec_i386.S
NOPROFILE=noprofile
NOPIC=nopic
.PATH: ${DIR_SA} ${DIR_KERN}
-all: ${SALIB}
+all: machine-links ${SALIB}
-.include <bsd.lib.mk>
+machine-links:
+ @rm -f machine i386
+ @ln -s ${S}/arch/i386 i386
+ @ln -s ${S}/arch/i386/include machine
+install:
+
+.include <bsd.lib.mk>
-/* $OpenBSD: bioscom.S,v 1.2 1997/03/31 03:12:09 weingart Exp $ */
+/* $OpenBSD: bioscom.S,v 1.3 1997/03/31 23:06:26 mickey Exp $ */
/*
* Mach Operating System
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.2 92/04/04 11:34:26 rpd
- * $Id: bioscom.S,v 1.2 1997/03/31 03:12:09 weingart Exp $
+ * $Id: bioscom.S,v 1.3 1997/03/31 23:06:26 mickey Exp $
*/
/*
#include <machine/asm.h>
+ .data
port:
- .long 0x3f8
+ .long 0x2f8
.text
* probe com[0-3] ports and store first found in 'port' variable
*/
ENTRY(com_probe)
- push %ebp
- mov %esp, %ebp
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %edx
/*
* void init_serial(void)
addb $5, %dl
jmp 1b
2:
+ popl %edx
+ popl %ebp
xorl %eax, %eax # is present (:
incl %eax
- popl %ebp
ret
/*
ENTRY(com_putc)
pushl %ebp
movl %esp, %ebp
+ pushl %ebx
movl $port, %edx # line status reg
add 5, %edx
sub $5, %edx # TX output reg
outb %al, %dx # send this one
+ popl %edx
popl %ebp
ret
*/
ENTRY(com_getc)
- push %ebp
- movl %esp, %ebp
+ pushl %edx
movl $port, %edx # line status reg
addl 5, %edx
jne 2f
movb $0x08, %eax # look like BS
2:
- popl %ebp
+ popl %edx
ret
/*
* if there is a character pending, return true; otherwise return 0
*/
ENTRY(com_ischar)
- push %ebp
- mov %esp, %ebp
+ pushl %edx
xorl %eax, %eax
movl $port, %edx # line status reg
inb %dx, %al
andb $0x01, %al # RX char available?
- pop %ebp
+ pop %edx
ret
-/* $OpenBSD: biosdev.c,v 1.2 1997/03/31 03:12:09 weingart Exp $ */
+/* $OpenBSD: biosdev.c,v 1.3 1997/03/31 23:06:26 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
*/
#include <sys/param.h>
+#include <sys/reboot.h>
+#include <sys/disklabel.h>
+#include <string.h>
#include <libsa.h>
#include "biosdev.h"
-dev_t maj, unit, part;
+extern int debug;
-int
-biosstrategy(void *devdata, int rw,
- daddr_t blk, size_t size, void *buf, size_t *rsize)
-{
- int error = 0;
+struct biosdisk {
u_int dinfo;
- register size_t i, nsect;
- void *local_buf, *lb; /* 1MB real mode stuff */
-
- /* We need a buffer below 1MB
- *
- * Note: not really needed for the gzip stuff,
- * as it already allocates buffers below 1MB,
- * but just to make sure (in case using oread()
- */
- lb = local_buf = alloc(size);
-
-#ifdef BIOS_DEBUG
- printf("biosstrategy: %s %d bytes @ %d -> %p\n",
- (rw==F_READ?"reading":"writing"), size, blk, buf);
-#endif
-
- dinfo = biosdinfo(bootdev);
- nsect = (size + DEV_BSIZE-1) / DEV_BSIZE;
- for (i = 0; error == 0 && i < nsect; ) {
- register int cyl, hd, sect, n;
-
- btochs(blk, cyl, hd, sect,
- BIOSNHEADS(dinfo), BIOSNSECTS(dinfo));
- if ((sect + (nsect - i)) >= BIOSNSECTS(dinfo))
- n = BIOSNSECTS(dinfo) - sect;
- else
- n = nsect - i;
-#ifdef BIOS_DEBUG
- printf("biosread: dev=%x, cyl=%d, hd=%d, sc=%d, n=%d, buf=%lx",
- bootdev, cyl, hd, sect, n, (u_long)local_buf);
-#endif
- if (rw == F_READ)
- error = biosread (bootdev, cyl, hd, sect, n, local_buf);
- else
- error = bioswrite(bootdev, cyl, hd, sect, n, local_buf);
-#ifdef BIOS_DEBUG
- printf(", ret=%x\n", error);
-#endif
- local_buf += n * DEV_BSIZE;
- i += n;
- blk += n;
- }
-
- /* Copy to final location */
- memcpy(buf, lb, size);
- free(lb, size);
-
- /* Amount we read */
- *rsize = i * DEV_BSIZE;
-
- return error;
-}
+ struct {
+ u_int8_t mboot[DOSPARTOFF];
+ struct dos_partition dparts[NDOSPART];
+ u_int16_t signature;
+ } mbr;
+ struct disklabel disklabel;
+ dev_t bsddev;
+ u_int8_t biosdev;
+};
int
biosopen(struct open_file *f, ...)
{
va_list ap;
- register char *cp, *fname, **file;
- static const char *devs[] = {"wd", "hd", "fd", "wt", "sd", NULL};
+ register char *p, *cp, *fname, **file;
+ char devname[sizeof(bdevs[0])];
+ dev_t maj, unit, part;
+ register struct biosdisk *bd;
+ daddr_t off = LABELSECTOR;
+ u_int8_t *buf;
+ int i;
+ size_t rsize;
va_start(ap, f);
cp = fname = *(file = va_arg(ap, char **));
va_end(ap);
+#ifdef BIOS_DEBUG
+ if (debug)
+ printf("%s\n", cp);
+#endif
+
+ f->f_devdata = NULL;
/* search for device specification */
- while (*cp != 0 && *cp != '(')
- cp++;
+ for ( p = devname; *cp != 0 && *cp != '(';)
+ *p++ = *cp++;
+ *p = '\0';
if (*cp != 0) {
if (*cp++ == '(') {
- char **devp = (char **)devs;
-
- for (; *devp != NULL &&
- (fname[0] != (*devp)[0] ||
- fname[1] != (*devp)[1]); devp++)
- ;
- if (*devp == NULL) {
- printf("Unknown device");
- errno = ENXIO;
- return -1;
+ for (maj = 0; maj < NENTS(bdevs) &&
+ strncmp(devname, bdevs[maj], sizeof(devname));
+ maj++);
+ if (maj >= NENTS(bdevs)) {
+ printf("Unknown device: %s\n", devname);
+ return ENXIO;
}
- maj = devp - (char **)devs;
- }
- /* check syntax */
- if (cp[1] != ',' || cp[3] != ')') {
+ } else {
printf("Syntax error\n");
- errno = EINVAL;
- return -1;
+ return EINVAL;
}
/* get unit */
unit = *cp++ - '0';
else {
printf("Bad unit number\n");
- errno = ENXIO;
- return -1;
+ return ENXIO;
}
cp++; /* skip ',' */
/* get partition */
part = *cp++ - 'a';
else {
printf("Bad partition id\n");
- errno = ENXIO;
- return -1;
+ return ENXIO;
}
cp++; /* skip ')' */
if (*cp != 0)
*file = cp;
+ bd = alloc(sizeof(*bd));
+ bzero(bd, sizeof(bd));
+
switch (maj) {
- case 0:
- case 4:
- bootdev = unit | 0x80;
+ case 0: /* wd */
+ case 4: /* sd */
+ bd->biosdev = (u_int8_t)(unit | 0x80);
break;
- case 1:
- bootdev = unit | 0x80;
- unit = 0;
+ case 2: /* fd */
+ bd->biosdev = (u_int8_t)unit;
break;
- case 2:
- bootdev = unit;
- break;
- case 3:
+ case 3: /* wt */
#ifdef DEBUG
- printf("Wangtek is unsupported\n");
+ if (debug)
+ printf("Wangtek is unsupported\n");
#endif
- errno = ENXIO;
- return -1;
default:
- break;
+ free(bd, 0);
+ return ENXIO;
}
+ bd->bsddev = MAKEBOOTDEV(maj, 0, 0, unit, part);
+ bd->dinfo = biosdinfo((dev_t)bd->biosdev);
+
+ } else
+ return ENOENT;
+
+#ifdef BIOS_DEBUG
+ if (debug) {
+ printf("BIOS geometry: heads: %u, s/t: %u\n",
+ BIOSNHEADS(bd->dinfo), BIOSNSECTS(bd->dinfo));
}
+#endif
+
+ if (maj == 0 || maj == 4) { /* wd, sd */
+ if ((errno = biosstrategy(bd, F_READ, DOSBBSECTOR,
+ DEV_BSIZE, &bd->mbr, &rsize)) != 0) {
+#ifdef DEBUG
+ if (debug)
+ printf("cannot read MBR\n");
+#endif
+ free(bd, 0);
+ return errno;
+ }
+
+ /* check mbr signature */
+ if (bd->mbr.signature != 0xaa55) {
+#ifdef DEBUG
+ if (debug)
+ printf("bad MBR signature\n");
+#endif
+ free(bd, 0);
+ return EINVAL;
+ }
+
+ for (off = 0, i = 0; i < NDOSPART; i++)
+ if (bd->mbr.dparts[i].dp_typ == DOSPTYP_OPENBSD) {
+ off = bd->mbr.dparts[i].dp_start + LABELSECTOR;
+ break;
+ }
+
+ if (off == 0) {
+#ifdef DEBUG
+ if (debug)
+ printf("no BSD partition\n");
+#endif
+ free(bd, 0);
+ return EINVAL;
+ }
+ }
+
+ buf = alloc(DEV_BSIZE);
+#ifdef BIOS_DEBUG
+ if (debug)
+ printf("loading disklabel @ %u\n", off);
+#endif
+ /* read disklabel */
+ if ((errno = biosstrategy(bd, F_READ, off,
+ DEV_BSIZE, buf, &rsize)) != 0) {
+#ifdef DEBUG
+ if (debug)
+ printf("failed to read disklabel\n");
+#endif
+ free(buf, 0);
+ free(bd, 0);
+ return errno;
+ }
+
+ if ((p = getdisklabel(buf, &bd->disklabel)) != NULL) {
+#ifdef DEBUG
+ if (debug)
+ printf("%s\n", p);
+#endif
+ free(buf, 0);
+ free(bd, 0);
+ return EINVAL;
+ }
+
+ free(buf,0);
+ f->f_devdata = bd;
return 0;
}
+/* BIOS disk errors translation table */
+static const struct bd_error {
+ u_int8_t bd_id;
+ int unix_id;
+ char *msg;
+} bd_errors[] = {
+ { 0x00, 0 , "successful completion" },
+ { 0x01, EINVAL , "invalid function or parameter" },
+ { 0x02, EIO , "address mark not found" },
+ { 0x03, EROFS , "disk write-protected" },
+ { 0x04, EIO , "sector not found/read error" },
+ { 0x05, EIO , "reset failed" },
+ { 0x06, EIO , "disk changed" },
+ { 0x07, EIO , "drive parameter activity failed" },
+ { 0x08, EINVAL , "DMA overrun" },
+ { 0x09, EINVAL , "data boundary error" },
+ { 0x0A, EIO , "bad sector detected" },
+ { 0x0B, EIO , "bad track detected" },
+ { 0x0C, ENXIO , "unsupported track or invalid media" },
+ { 0x0D, EINVAL , "invalid number of sectors on format" },
+ { 0x0E, EIO , "control data address mark detected" },
+ { 0x0F, EIO , "DMA arbitration level out of range" },
+ { 0x10, EIO , "uncorrectable CRC or ECC error on read" },
+ { 0x11, 0 , "data ECC corrected" },
+ { 0x20, EIO , "controller failure" },
+ { 0x31, ENXIO , "no media in drive" },
+ { 0x32, ENXIO , "incorrect drive type stored in CMOS" },
+ { 0x40, EIO , "seek failed" },
+ { 0x80, EIO , "operation timed out" },
+ { 0xAA, EIO , "drive not ready" },
+ { 0xB0, EIO , "volume not locked in drive" },
+ { 0xB1, EIO , "volume locked in drive" },
+ { 0xB2, EIO , "volume not removable" },
+ { 0xB3, EDEADLK, "volume in use" },
+ { 0xB4, ENOLCK , "lock count exceeded" },
+ { 0xB5, EINVAL , "valid eject request failed" },
+ { 0xBB, EIO , "undefined error" },
+ { 0xCC, EROFS , "write fault" },
+ { 0xE0, EIO , "status register error" },
+ { 0xFF, EIO , "sense operation failed" }
+};
+int bd_nents = NENTS(bd_errors);
+
int
-biosclose(struct open_file *f)
+biosstrategy(void *devdata, int rw,
+ daddr_t blk, size_t size, void *buf, size_t *rsize)
{
+ u_int8_t error = 0;
+ register struct biosdisk *bd = (struct biosdisk *)devdata;
+ register size_t i, nsect, n;
+ register const struct bd_error *p = bd_errors;
+ nsect = (size + DEV_BSIZE-1) / DEV_BSIZE;
+ blk += bd->disklabel.d_partitions[B_PARTITION(bd->bsddev)].p_offset;
+
+#ifdef BIOS_DEBUG
+ if (debug)
+ printf("biosstrategy(%p,%s,%u,%u,%p,%p), dev=%x:%x\nbiosread:",
+ bd, (rw==F_READ?"reading":"writing"), blk, size,
+ buf, rsize, bd->biosdev, bd->bsddev);
+#endif
+
+ for (i = 0; error == 0 && i < nsect;
+ i += n, blk += n, buf += n * DEV_BSIZE) {
+ register int cyl, hd, sect;
+#if 0
+ /* fight seg boundary error XXX */
+ static u_int8_t bbuf[DEV_BSIZE];
+#endif
+
+ btochs(blk, cyl, hd, sect,
+ BIOSNHEADS(bd->dinfo), BIOSNSECTS(bd->dinfo));
+ if ((sect + (nsect - i)) >= BIOSNSECTS(bd->dinfo))
+ n = BIOSNSECTS(bd->dinfo) - sect;
+ else
+ n = nsect - i;
+#ifdef BIOS_DEBUG
+ if (debug)
+ printf(" (%d,%d,%d,%d)@%p", cyl, hd, sect, n, buf);
+#endif
+ if (rw == F_READ) {
+ error = biosread (bd->biosdev, cyl, hd, sect, n, buf);
+ /* bcopy(bbuf, buf, sizeof(bbuf)); */
+ } else {
+ /* bcopy(buf, bbuf, sizeof(bbuf)); */
+ error = bioswrite(bd->biosdev, cyl, hd, sect, n, buf);
+ }
+ if (error != 0) {
+ for (p = bd_errors; p < &bd_errors[bd_nents] &&
+ p->bd_id != error; p++);
+
+ if (error == 0x11) /* ECC corrected */
+ error = 0;
+ }
+ }
+
+#ifdef BIOS_DEBUG
+ if (debug) {
+ if (error != 0)
+ printf("=%x(%s)", p->bd_id, p->msg);
+ putchar('\n');
+ }
+#endif
+
+ *rsize = i * DEV_BSIZE;
+
+ return p->unix_id;
+}
+
+int
+biosclose(struct open_file *f)
+{
+ free(f->f_devdata, 0);
return 0;
}
-/* $OpenBSD: biosdev.h,v 1.2 1997/03/31 03:12:10 weingart Exp $ */
+/* $OpenBSD: biosdev.h,v 1.3 1997/03/31 23:06:27 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
int com_getc __P((void));
int com_ischar __P((void));
+/* biosmem.S */
+u_int biosmem __P((int));
+
/* biostime.S */
void usleep __P((u_long));
-/* $OpenBSD: biosdisk.S,v 1.2 1997/03/31 03:12:11 weingart Exp $ */
+/* $OpenBSD: biosdisk.S,v 1.3 1997/03/31 23:06:27 mickey Exp $ */
/*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
ENTRY(biosread)
pushl %ebp
movl %esp, %ebp
- pushl %ebx
- pushl %esi
- pushl %edi
- push %es
+ pushal
movb 8(%ebp), %dl # device
movw 12(%ebp), %cx
movb 24(%ebp), %al # number of sectors
movl %eax, %esi # save this against mode switch
movl 28(%ebp), %ebx # offset
-
-
- # prot_to_real will set %es to BOOTSEG
- # Which means %cs == %es.
- # XXX - This hoses things severly. Better
- # recoup %es to point to the base of the given
- # buffer, and let %bx be the index into it,
- # that way we can read a max of 64K give or
- # take 15 bytes anyways.
-
- # Save %es in %edi
- movl %ebx, %eax
- shrl $4, %eax
- movl %eax, %edi
- andl $0xF, %ebx
+ movl %ebx, %edi # spilt off for seg:off pair
+ shrl $4, %edi
+ andl $0xf, %ebx # atomic read for up to 64k
call _C_LABEL(prot_to_real) # enter real mode
- # Restore %es
movl %di, %es
-
- # Restore %ax
movl %si, %ax
-
int $0x13
- setc %bl
-
+ movb $0, %cl
+ jnc 1f
+ movb %ah, %cl
+1:
data32
call _C_LABEL(real_to_prot) # back to protected mode
- movzbl %bl, %eax # return value in %ax
+ movzbl %cl, %eax # return value in %ax
+ movl %eax, 1f
- pop %es
- popl %edi
- popl %esi
- popl %ebx
+ popal
+ movl 1f, %eax
popl %ebp
ret
+1: .long 0
ENTRY(bioswrite)
pushl %ebp
movl %esp, %ebp
pushl %ebx
- pushl %esi
- pushl %edi
+ pushl %ecx
+ pushl %edx
movb 8(%ebp), %dl # diskinfo(drive #)
andb $0x3f, %cl # mask of cylinder gunk
movb %cl, %al # max sector (and # sectors)
- popl %edi
- popl %esi
+ popl %edx
+ popl %ecx
popl %ebx
popl %ebp
ret
-/* $OpenBSD: bioskbd.S,v 1.2 1997/03/31 03:12:11 weingart Exp $ */
+/* $OpenBSD: bioskbd.S,v 1.3 1997/03/31 23:06:28 mickey Exp $ */
/*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
*
*/
ENTRY(kbd_probe)
-
+#if 0
+#include <machine/console.h>
+#include <machine/cpufunc.h>
+#include "boot.h"
+
+int
+probe_keyboard(void)
+{
+ int i, retries = 5;
+ unsigned char val;
+
+ /* flush any noise in the buffer */
+ while (inb(KB_STAT) & KB_BUF_FULL) {
+ delay1ms();
+ (void) inb(KB_DATA);
+ }
+
+ /* Try to reset keyboard hardware */
+ again:
+ while (--retries) {
+#ifdef DEBUG
+ printf("%d ", retries);
+#endif
+ while ((inb(KB_STAT) & KB_READY) == KB_READY) delay1ms();
+ outb(KB_DATA, KB_RESET);
+ for (i=0; i<1000; i++) {
+ delay1ms();
+ val = inb(KB_DATA);
+ if (val == KB_ACK || val == KB_ECHO)
+ goto gotack;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+gotres:
+#ifdef DEBUG
+ printf("gotres\n");
+#endif
+ if (!retries) {
+#ifdef DEBUG
+ printf("gave up\n");
+#endif
+ return(1);
+ }
+gotack:
+ delay1ms();
+ while ((inb(KB_STAT) & KB_BUF_FULL) == 0) delay1ms();
+ delay1ms();
+#ifdef DEBUG
+ printf("ACK ");
+#endif
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ goto gotack;
+ if (val == KB_RESEND)
+ goto again;
+ if (val != KB_RESET_DONE) {
+#ifdef DEBUG
+ printf("stray val %d\n", val);
+#endif
+ return(0);
+ }
+#ifdef DEBUG
+ printf("ok\n");
+#endif
+ return(0);
+}
+
+#endif
movl 1, %eax /* present (: */
ret
ENTRY(kbd_putc)
pushl %ebp
movl %esp, %ebp
- pushl %ebx
- pushl %esi
- pushl %edi
+ pushal
movb 8(%ebp), %cl
movb %cl, %al
movb $0x0e, %ah
- xorl %ebx, %ebx
- incl %ebx
+ xorl %bx, %bx
+ incl %bx
int $0x10 # display a byte
data32
call _C_LABEL(real_to_prot)
- popl %edi
- popl %esi
- popl %ebx
+ popal
popl %ebp
ret
# ZF = set
*/
ENTRY(kbd_ischar)
- pushl %ebp
- movl %esp, %ebp
- pushl %ebx
- pushl %esi
- pushl %edi
+ pushal
call _C_LABEL(prot_to_real)
call _C_LABEL(real_to_prot)
movzbl %bl, %eax
+ movl %eax, 1f
- popl %edi
- popl %esi
- popl %ebx
- popl %ebp
+ popal
+ movl 1f, %eax
ret
+1: .long 0
+
-/* $OpenBSD: dev_i386.c,v 1.2 1997/03/31 03:12:12 weingart Exp $ */
+/* $OpenBSD: dev_i386.c,v 1.3 1997/03/31 23:06:28 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include <libsa.h>
#include "biosdev.h"
+const char bdevs[19][4] = {
+ "wd", "", "fd", "wt", "sd", "st", "cd", "mcd",
+ "", "", "", "", "", "", "", "scd", "", "", "acd"
+};
+
/* pass dev_t to the open routines */
int
devopen(struct open_file *f, const char *fname, char **file)
{
struct devsw *dp = devsw;
- register int i, rc = 0;
+ register int i, rc = 1;
*file = (char *)fname;
- for (i = 0; i < ndevs ; dp++, i++)
- if ((rc = (*dp->dv_open)(f, file))== 0) {
+ for (i = 0; i < ndevs && rc != 0; dp++, i++)
+ if ((rc = (*dp->dv_open)(f, file)) == 0) {
f->f_dev = dp;
return 0;
- }
+ }
if ((f->f_flags & F_NODEV) == 0)
f->f_dev = dp;
putchar(c)
int c;
{
- putc(c);
- if (c == '\n')
+ static int pos = 0;
+
+ switch(c) {
+ case '\t':
+ while(++pos % 8)
+ putc(' ');
+ break;
+ case '\n':
putc('\r');
+ case '\r':
+ putc(c);
+ pos=0;
+ break;
+ default:
+ putc(c);
+ pos++;
+ break;
+ }
}
int
return(c);
}
+
+++ /dev/null
-
-/* $OpenBSD: exec_i386.c,v 1.2 1997/03/31 05:52:25 weingart Exp $ */
-
-#include <sys/param.h>
-#include <sys/exec.h>
-#include <sys/reboot.h>
-#include <libsa.h>
-
-
-void
-machdep_start(startaddr, howto, loadaddr, ssym, esym)
- char *startaddr, *loadaddr, *ssym, *esym;
- int howto;
-{
- static int argv[9];
- struct exec *x;
-
-
-#ifdef DEBUG
- x = (void *)loadaddr;
- printf("exec {\n");
- printf(" a_midmag = %lx\n", x->a_midmag);
- printf(" a_text = %lx\n", x->a_text);
- printf(" a_data = %lx\n", x->a_data);
- printf(" a_bss = %lx\n", x->a_bss);
- printf(" a_syms = %lx\n", x->a_syms);
- printf(" a_entry = %lx\n", x->a_entry);
- printf(" a_trsize = %lx\n", x->a_trsize);
- printf(" a_drsize = %lx\n", x->a_drsize);
- printf("}\n");
-
- getchar();
-#endif
-
- (int)startaddr &= 0xffffff;
-
- /*
- * We now pass the various bootstrap parameters to the loaded
- * image via the argument list
- *
- * arg0 = 8 (magic)
- * arg1 = boot flags
- * arg2 = boot device
- * arg3 = Cylinder offset (XXX - used to be ssym)
- * arg4 = end of symbol table (0 if not loaded)
- * arg5 = transfer address from image
- * arg6 = transfer address for next image pointer
- * arg7 = conventional memory size (640)
- * arg8 = extended memory size (8196)
- */
- argv[0] = 8;
- argv[1] = howto;
- argv[2] = bootdev; /* Boot device */
- argv[3] = 0; /* Cyl offset */
- argv[4] = 0;
- argv[5] = (int)startaddr;
- argv[6] = 0;
- argv[7] = memsize(0);
- argv[8] = memsize(1);
-
-#ifdef DEBUG
- { int i;
- for(i = 0; i <= argv[0]; i++)
- printf("argv[%d] = %x\n", i, argv[i]);
-
- getchar();
- }
-#endif
-
- /****************************************************************/
- /* copy that first page and overwrite any BIOS variables */
- /****************************************************************/
- printf("entry point at 0x%x\n", (int)startaddr);
- startprog(startaddr, argv);
-}
-
-/* $OpenBSD: libsa.h,v 1.2 1997/03/31 03:12:14 weingart Exp $ */
+/* $OpenBSD: libsa.h,v 1.3 1997/03/31 23:06:29 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include <stand.h>
-void startprog __P((char *addr, int argv[]));
-void gateA20 __P((int on));
-int memsize __P((int which));
-int memprobe __P((void));
+void gateA20 __P((int));
+void memprobe __P((void));
-extern dev_t bootdev, maj, unit, part;
-extern u_long cyloffset;
-extern u_long ourseg, esym;
+extern u_long codeseg;
extern int boothowto;
+extern u_int cnvmem, extmem;
+extern const char bdevs[19][4];
-/* $OpenBSD: memprobe.c,v 1.1 1997/03/31 03:12:14 weingart Exp $ */
+/* $OpenBSD: memprobe.c,v 1.2 1997/03/31 23:06:30 mickey Exp $ */
#include <sys/param.h>
-#include <libsa.h>
+#include "libsa.h"
+#include "biosdev.h"
+static int addrprobe __P((int));
+
+void
+memprobe()
+{
+ int ram;
+
+ cnvmem = biosmem(0);
+ extmem = biosmem(1);
+
+ /* probe extended memory
+ *
+ * There is no need to do this in assembly language. This are
+ * much easier to debug in C anyways.
+ */
+ for(ram = 1024; ram < 512*1024; ram += 4){
+
+ printf("Probing memory: %d KB\r", ram-1024);
+ if(addrprobe(ram)) break;
+ }
+
+ printf("\n");
+ extmem = ram - 1024;
+}
/* addrprobe(kloc): Probe memory at address kloc * 1024.
*
}
-/* memprobe(): return probed memory size in KB for extended memory
- *
- * There is no need to do this in assembly language. This are
- * much easier to debug in C anyways.
- */
-int memprobe(void){
- int ram;
-
- for(ram = 1024; ram < 512*1024; ram += 4){
-
- printf("Probing memory: %d KB\r", ram-1024);
- if(addrprobe(ram)) break;
- }
-
- printf("\n");
- return(ram-1024);
-}
-
+++ /dev/null
-/* $OpenBSD: memsize.S,v 1.2 1997/03/31 03:12:15 weingart Exp $ */
-
-/*
- * 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.
- */
-
-/*
- 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 <machine/asm.h>
-#define addr32 .byte 0x67
-#define data32 .byte 0x66
-
-/*
-#
-# 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)
- pushl %ebp
- movl %esp, %ebp
- pushl %esi
- pushl %edi
-
- movl 8(%ebp), %edx
-
- call _C_LABEL(prot_to_real) # enter real mode
-
- testb %dl, %dl
- jnz 1f
-
- int $0x12
- jmp 2f
-
-1:
- movb $0x88, %ah
- int $0x15
-
-2:
- movl %eax, %edx
-
- data32
- call _C_LABEL(real_to_prot)
-
- movl %edx, %eax
- popl %edi
- popl %esi
- popl %ebp
- ret
+++ /dev/null
-/*-
- * Copyright (c) 1992-1995 Søren Schmidt
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz and Don Ahn.
- *
- * 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
- * in this position and unchanged.
- * 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.
- *
- * This is a modified version of the keyboard reset code used in syscons.
- * If the keyboard reset fails, we assume that the keyboard has been
- * unplugged and we use a serial port (COM1) as the console instead.
- * Returns 1 on failure (no keyboard), 0 on success (keyboard attached).
- *
- * This grody hack brought to you by Bill Paul (wpaul@ctr.columbia.edu)
- *
- * $Id: probe_keyboard.c,v 1.2 1997/03/31 03:12:15 weingart Exp $
- */
-
-#ifdef PROBE_KEYBOARD
-
-#include <machine/console.h>
-#include <machine/cpufunc.h>
-#include "boot.h"
-
-int
-probe_keyboard(void)
-{
- int i, retries = 5;
- unsigned char val;
-
- /* flush any noise in the buffer */
- while (inb(KB_STAT) & KB_BUF_FULL) {
- delay1ms();
- (void) inb(KB_DATA);
- }
-
- /* Try to reset keyboard hardware */
- again:
- while (--retries) {
-#ifdef DEBUG
- printf("%d ", retries);
-#endif
- while ((inb(KB_STAT) & KB_READY) == KB_READY) delay1ms();
- outb(KB_DATA, KB_RESET);
- for (i=0; i<1000; i++) {
- delay1ms();
- val = inb(KB_DATA);
- if (val == KB_ACK || val == KB_ECHO)
- goto gotack;
- if (val == KB_RESEND)
- break;
- }
- }
-gotres:
-#ifdef DEBUG
- printf("gotres\n");
-#endif
- if (!retries) {
-#ifdef DEBUG
- printf("gave up\n");
-#endif
- return(1);
- }
-gotack:
- delay1ms();
- while ((inb(KB_STAT) & KB_BUF_FULL) == 0) delay1ms();
- delay1ms();
-#ifdef DEBUG
- printf("ACK ");
-#endif
- val = inb(KB_DATA);
- if (val == KB_ACK)
- goto gotack;
- if (val == KB_RESEND)
- goto again;
- if (val != KB_RESET_DONE) {
-#ifdef DEBUG
- printf("stray val %d\n", val);
-#endif
- return(0);
- }
-#ifdef DEBUG
- printf("ok\n");
-#endif
- return(0);
-}
-
-#endif /* PROBE_KEYBOARD */
-/* $OpenBSD: real_prot.S,v 1.2 1997/03/31 03:12:16 weingart Exp $ */
+/* $OpenBSD: real_prot.S,v 1.3 1997/03/31 23:06:31 mickey Exp $ */
/*
* Mach Operating System
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.2 92/04/04 11:34:13 rpd
- * $Id: real_prot.S,v 1.2 1997/03/31 03:12:16 weingart Exp $
*/
* transfer from real mode to protected mode.
*/
-.align 4,0x90
ENTRY(real_to_prot)
- /* guarantee that interrupt is disabled when in prot mode */
+ /* guarantee that interrupts are disabled when in prot mode */
cli
/* load the gdtr */
movl %ax, %ds
movl %ax, %ss
movl %ax, %es
+ movl %ax, %fs
+ movl %ax, %gs
#ifndef NO_IDTR
/* load idtr so we can debug */
*
*/
-.align 4,0x90
ENTRY(prot_to_real)
- /*
- * This is self-modifying code, but we need a writable
- * code segment, and an intersegment return does not give us that.
- */
- movw _codeseg, %ax
- pushw %ax
- movw $2f, %ax
- pushw %ax
+ movl _codeseg, %eax
+ # movw %ax, 2f
/* Change to use16 mode. */
ljmp $0x18, $1f
-
-1: /* clear the PE bit of CR0 */
+1:
+ /* clear the PE bit of CR0 */
movl %cr0, %eax
data32
andl $~CR0_PE, %eax
movl %eax, %cr0
- /*
- * make intersegment jmp to flush the processor pipeline
- * using the fake stack frame set up earlier
- * and reload CS register
- */
-#if 0
- hlt
-#endif
- lret
-2: /*
- * we are in real mode now
- * set up the real mode segment registers : DS, SS, ES
- */
+ data32
+ # ljmp _codeseg, $2f
+ .byte 0xea
+ .long 3f
+2: .word 0
+3:
+ /* setup: %ds, %es, %ss */
movl %cs, %ax
movl %ax, %ds
movl %ax, %ss
movl %ax, %es
+ movl %ax, %fs
+ movl %ax, %gs
#ifndef NO_IDTR
/* load idtr so we can debug */
addr32
+++ /dev/null
-/* $OpenBSD: srt0.S,v 1.2 1997/03/31 03:12:16 weingart Exp $ */
-/* $NetBSD: srt0.c,v 1.3 1994/10/27 04:21:59 cgd Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software 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.
- *
- * @(#)srt0.c 5.3 (Berkeley) 4/28/91
- */
-
-/*
- * Startup code for standalone system
- * Non-relocating version -- for programs which are loaded by boot
- * Relocating version for boot
- * Small relocating version for "micro" boot
- */
-
-#include <machine/psl.h>
-
- .globl _end
- .globl _edata
- .globl _boot
- .globl __rtt
- .globl _bootdev
- .globl _boothowto
- .globl _cyloffset
-
- .data
- .globl _Gdtr
-_Gdtr:
- .long 0
- .word 0
-_bootdev: .long 0
-_boothowto: .long 0
-_cyloffset: .long 0
-_esym: .long 0
-
- .text
-
-#define NOP inb $0x84,%al ; inb $0x84,%al
-
- .globl start_boot
-
-start_boot:
- pushl %ebp
- movl %esp, %ebp
-
- /* First, reset the PSL. */
- pushl $PSL_MBO
- popfl
-
- movl 8(%ebp), %eax
- movl %eax, _boothowto
- movl 12(%ebp),%eax
- movl %eax, _bootdev
- movl 16(%ebp),%eax
- movl %eax, _cyloffset
- movl 20(%ebp),%eax
- movl %eax, _esym
-
- /* save old stack state */
- movl %esp,savearea
- movl %ebp,savearea+4
-
-#if 0
- /* setup stack pointer */
- movl _end, %eax
- addl $10000, %eax
- movl %eax, %esp
-
- /* clear memory as needed */
- movl %esp,%esi
- movl $_edata,%edx
-
- movl %esp,%eax
- subl %edx,%eax
- pushl %edx
- pushl 0
- pushl %esp
- call _memset
-
- #call _kbdreset /* resets keyboard and gatea20 brain damage */
- movl %esi,%esp
-#endif
- call _boot
- jmp __rtt
-
- .data
-
-savearea: .long 0,0 # sp & bp to return to
-
- .text
-
-__rtt:
- movl $-7,%eax
-#ifdef REL
-#ifndef SMALL
- call _reset_cpu
-#endif
- movw $0x1234,%ax
- movw %ax,0x472 # warm boot
- movl $0,%esp # segment violation
- ret
-#else
- movl savearea,%esp
- movl savearea+4,%ebp
- ret
-#endif
+++ /dev/null
-/* $OpenBSD: startprog.S,v 1.2 1997/03/31 05:52:25 weingart Exp $ */
-
-#include <machine/asm.h>
-
-
-/*
- * startprog(phyaddr, argv)
- * start the program on protected mode where phyaddr is the entry point
- */
-ENTRY(startprog)
- pushl %ebp
- movl %esp, %ebp
-
- # get things we need into registers
- movl 8(%ebp), %ecx # entry offset
- movl 12(%ebp), %eax # &argv
-
- # make a new stack at 0:0x90000 (big segs)
- movl $0x10, %ebx
- movw %bx, %ss
- movl $0x90000, %ebx
- movl %ebx, %esp
-
- # push some number of args onto the stack
- pushl 28(%eax) # argv[7] = cnvmem
- pushl 32(%eax) # argv[8] = extmem
- pushl 16(%eax) # argv[4] = esym
- pushl 12(%eax) # argv[3] = cyl offset
- pushl 8(%eax) # argv[2] = bootdev
- pushl 4(%eax) # argv[1] = howto
- pushl $0 # dummy 'return' address
-
- # push on our entry address
- movl $0x8, %ebx # segment
- pushl %bx
- pushl %ecx
-
- # convert over the other data segs
- movl $0x10, %ebx
- movl %bx, %ds
- movl %bx, %es
-
- # convert the PC (and code seg)
- lret
-
-# $OpenBSD: Makefile,v 1.1 1997/03/31 03:12:18 weingart Exp $
+# $OpenBSD: Makefile,v 1.2 1997/03/31 23:06:33 mickey Exp $
+CFLAGS +=$(SACFLAGS)
.include "../Makefile.inc"
-CFLAGS+=-Wall
-
S = ${.CURDIR}/../../../..
ZDST=${.OBJDIR}
.include "${S}/lib/libz/Makefile.inc"
all: ${ZLIB}
.include <bsd.obj.mk>
-.include <bsd.dep.mk>
.include <bsd.subdir.mk>
.include <bsd.sys.mk>
-/* $OpenBSD: boot.c,v 1.2 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: boot.c,v 1.3 1997/03/31 23:06:20 mickey Exp $ */
+
/*
* Copyright (c) 1997 Michael Shalayeff
* All rights reserved.
#include <sys/param.h>
#include <sys/reboot.h>
#include <sys/stat.h>
-#include <a.out.h>
-#include <sys/disklabel.h>
#include <libsa.h>
#include "cmd.h"
-/*
- * Boot program, loaded by boot block from remaing 7.5K of boot area.
- * Sifts through disklabel and attempts to load an program image of
- * a standalone program off the disk. If keyboard is hit during load,
- * or if an error is encounter, try alternate files.
- */
-
-char *kernels[] = {
- "bsd", "bsd.gz",
- "obsd", "obsd.gz",
- "bsd.old", "bsd.old.gz",
- NULL
-};
+char *kernels[] = { "bsd", "bsd.gz",
+ "obsd", "obsd.gz",
+ "bsd.old", "bsd.old.gz",
+ NULL };
-int retry = 0;
-extern char version[];
-extern dev_t bootdev;
-extern int boothowto;
-int cnvmem, extmem, probemem;
+extern const char version[];
+int boothowto;
+u_int cnvmem, extmem;
-void boot ();
-struct cmd_state cmd;
+void devboot __P((dev_t, char *));
-/*
- * Boot program... loads /boot out of filesystem indicated by arguements.
- * We assume an autoboot unless we detect a misconfiguration.
- */
void
-boot()
+boot(bootdev)
+ dev_t bootdev;
{
register char *bootfile = kernels[0];
+ register struct cmd_state *cmd;
register int i;
-
- /* Get memory size */
- cnvmem = memsize(0);
- extmem = memsize(1);
+#ifdef DEBUG
+ *(u_int16_t*)0xb8148 = 0x4730;
+#endif
gateA20(1);
- probemem = memprobe();
+#ifndef _TEST
+ memprobe();
+#endif
+#ifdef DEBUG
+ *(u_int16_t*)0xb8148 = 0x4f31;
+#endif
+ cons_probe();
+ printf("\n>> OpenBSD BOOT: %u/%u k [%s]\n", cnvmem, extmem, version);
/* XXX init cmd here to cut on .data !!! */
- strncpy(cmd.bootdev,
-#ifdef _TEST
- "/dev/rfd0a",
-#else
- "fd(0,a)",
-#endif
- sizeof(cmd.bootdev));
- cmd.image[0] = '\0';
- cmd.cwd[0] = '/';
- cmd.cwd[1] = '\0';
- cmd.addr = (void *)0x100000;
- cmd.timeout = 50000;
-
- printf("\n>> OpenBSD BOOT: %d/%d (%d) k [%s]\n",
- cnvmem, extmem, probemem, version);
+ cmd = (struct cmd_state *)alloc(sizeof(*cmd));
+ devboot(bootdev, cmd->bootdev);
+ cmd->image[0] = '\0';
+ cmd->cwd[0] = '/';
+ cmd->cwd[1] = '\0';
+ cmd->addr = (void *)0x100000;
+ cmd->timeout = 50;
for (i = 0;;) {
- strncpy(cmd.image, bootfile, sizeof(cmd.image));
+ strncpy(cmd->image, bootfile, sizeof(cmd->image));
do {
printf("boot> ");
- } while(!getcmd(&cmd) && !execmd(&cmd));
+ } while(!getcmd(cmd) && !execmd(cmd));
+
+ if (cmd->rc < 0)
+ break;
- sprintf(cmd.path, "%s%s%s", cmd.bootdev, cmd.cwd, bootfile);
- printf("\nbooting %s: ", cmd.path);
- exec (cmd.path, cmd.addr, boothowto);
+ printf("\nbooting %s: ", cmd->path);
+ exec (cmd->path, cmd->addr, boothowto);
if(kernels[++i] == NULL)
bootfile = kernels[i=0];
else
bootfile = kernels[i];
- cmd.timeout += 20;
+ cmd->timeout += 20;
printf(" failed(%d)\nwill try %s\n", errno, bootfile);
}
}
+void
+devboot(bootdev, p)
+ dev_t bootdev;
+ char *p;
+{
+#ifdef _TEST
+ *p++ = '/';
+ *p++ = 'd';
+ *p++ = 'e';
+ *p++ = 'v';
+ *p++ = '/';
+ *p++ = 'r';
+#endif
+ if (bootdev & 0x80)
+ *p++ = 'h';
+ else
+ *p++ = 'f';
+ *p++ = 'd';
+#ifndef _TEST
+ *p++ = '(';
+#endif
+ *p++ = '0' + (bootdev & 0x7f);
+#ifndef _TEST
+ *p++ = ',';
+#endif
+ *p++ = 'a';
+#ifndef _TEST
+ *p++ = ')';
+#endif
+ *p = '\0';
+}
+
#ifdef _TEST
int
main()
-/* $OpenBSD: cmd.c,v 1.1 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: cmd.c,v 1.2 1997/03/31 23:06:21 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
#include <string.h>
#include <libsa.h>
#include "cmd.h"
+#ifndef _TEST
+#include <biosdev.h>
+#endif
-static struct cmd_table {
+extern int debug;
+
+const struct cmd_table {
char *cmd_name;
int cmd_id;
} cmd_table[] = {
{"boot", CMD_BOOT},
{"cd", CMD_CD},
{"device", CMD_DEVICE},
+#ifdef DEBUG
+ {"debug", CMD_DEBUG},
+#endif
{"help", CMD_HELP},
{"image", CMD_IMAGE},
{"ls", CMD_LS},
{NULL, 0},
};
-extern char version[];
-void ls __P((char *, register struct stat *));
-char skipblnk __P((void));
+extern const char version[];
+static void ls __P((char *, register struct stat *));
+static char *skipblnk __P((register char *));
+static int readline __P((register char *, int));
-char cmd_buf[133];
+char *cmd_buf = NULL;
int
getcmd(cmd)
- register struct cmd_state *cmd;
+ struct cmd_state *cmd;
{
- register struct cmd_table *ct = cmd_table;
- register char *p = cmd_buf; /* input */
- register char ch;
- int len;
+ register const struct cmd_table *ct = cmd_table;
+ register char *p = cmd_buf, *q; /* input */
+
+ if (cmd_buf == NULL)
+ p = cmd_buf = alloc(133);
cmd->rc = 0;
cmd->argc = 1;
- for (len = cmd->timeout; len-- && !ischar(); );
-
- if (len < 0) {
+ if (!readline(cmd_buf, cmd->timeout)) {
cmd->cmd = CMD_BOOT;
cmd->argv[0] = cmd_table[CMD_BOOT].cmd_name;
cmd->argv[1] = NULL;
return 0;
}
- ch = skipblnk();
+ p = skipblnk(cmd_buf);
- for (len = 0; ch != '\n' &&
- ch != ' ' && ch != '\t'; len++, ch = getchar())
- *p++ = ch;
+ /* command */
+ for ( q = p; *p != '\0' && *p != ' ' && *p != '\t'; p++);
*p = '\0';
- if (len == 0 && ch == '\n') {
- cmd->cmd = CMD_NOPE;
- return 0;
- }
-
- while (ct->cmd_name != NULL &&
- strncmp(cmd_buf, ct->cmd_name, len))
+ while (ct->cmd_name != NULL && strncmp(q, ct->cmd_name, (p - q)))
ct++;
if (ct->cmd_name == NULL) {
- cmd->cmd = CMD_ERROR;
- cmd->argv[0] = ct->cmd_name;
+ cmd->cmd = CMD_BOOT;
+ cmd->argv[0] = cmd_table[CMD_BOOT].cmd_name;
+ cmd->argv[1] = skipblnk(cmd_buf);
+ cmd->argv[2] = NULL;
+ cmd->argc++;
return 0;
}
cmd->cmd = ct->cmd_id;
cmd->argv[0] = ct->cmd_name;
- if (ct->cmd_name != NULL) {
- while (ch != '\n') {
-
- ch = skipblnk();
-
- if (ch != '\n') {
- cmd->argv[cmd->argc] = p;
- *p++ = ch;
- for (len = 0; (ch = getchar()) != '\n' &&
- ch != ' ' && ch != '\t'; len++)
- *p++ = ch;
- *p++ = '\0';
- if (len != 0)
- cmd->argc++;
- }
- }
- cmd->argv[cmd->argc] = NULL;
+ for (p++; *(p = skipblnk(p)) != '\0'; *p++ = '\0') {
+ cmd->argv[cmd->argc++] = q = p;
+ for (; *p && *p != '\t' && *p != ' '; p++);
}
+ cmd->argv[cmd->argc] = NULL;
return cmd->rc;
}
-char
-skipblnk()
+static int
+readline(p, to)
+ register char *p;
+ int to;
{
- register char ch;
+ char *buf = p, ch;
+ int i;
+
+ for (i = to; i-- && !ischar(); )
+#ifndef _TEST
+ usleep(100000);
+#else
+ ;
+#endif
+ if (i < 0)
+ return 0;
+ while (1) {
+ switch (ch = getchar()) {
+ case '\n':
+ p[1] = *p = '\0';
+ break;
+ case '\b':
+ if (p > buf) {
+ putchar('\b');
+ putchar(' ');
+ putchar('\b');
+ p--;
+ }
+ continue;
+ default:
+ *p++ = ch;
+ continue;
+ }
+ break;
+ }
+ return p - buf;
+}
+
+char *
+skipblnk(p)
+ register char *p;
+{
/* skip blanks */
- while ((ch = getchar()) != '\n' &&
- (ch == ' ' || ch == '\t'));
+ while (*p == '\t' || *p == ' ')
+ p++;
- return ch;
+ return p;
}
int
execmd(cmd)
- register struct cmd_state *cmd;
+ struct cmd_state *cmd;
{
struct stat sb;
int fd;
register char *p, *q;
- register struct cmd_table *ct;
+ register const struct cmd_table *ct;
cmd->rc = 0;
-
switch (cmd->cmd) {
+#ifdef DEBUG
+ case CMD_DEBUG:
+ debug = !debug;
+ printf("debug is %s\n", debug? "on": "off");
+ break;
+#endif
+
case CMD_HELP:
printf("commands: ");
for (ct = cmd_table; ct->cmd_name != NULL; ct++)
case CMD_LS:
{
- q = cmd->argv[1] == NULL? "." : cmd->argv[1];
- sprintf(cmd->path, "%s%s%s",
- cmd->bootdev, cmd->cwd, q);
+ if (cmd->argv[1] != NULL)
+ strncpy (cmd->path, cmd->argv[1],
+ sizeof(cmd->path));
+ else
+ sprintf(cmd->path, "%s%s/.",
+ cmd->bootdev, cmd->cwd);
if (stat(cmd->path, &sb) < 0) {
printf("stat(%s): %d\n", cmd->path, errno);
}
if ((sb.st_mode & S_IFMT) != S_IFDIR)
- ls(q, &sb);
+ ls(cmd->path, &sb);
else {
if ((fd = opendir(cmd->path)) < 0) {
printf ("opendir(%s): %d\n",
break;
}
- p = cmd->path + strlen(cmd->path);
+ /* no strlen in lib !!! */
+ for (p = cmd->path; *p; p++);
*p++ = '/';
*p = '\0';
- while(readdir(fd, p) >= 0 && *p != '\0') {
+ while(readdir(fd, p) >= 0) {
- if (stat(cmd->path, &sb) < 0) {
+ if (stat(cmd->path, &sb) < 0)
printf("stat(%s): %d\n",
cmd->path, errno);
- break;
- }
- ls(p, &sb);
+ else
+ ls(p, &sb);
}
closedir (fd);
break;
case CMD_SET:
- printf("OpenBSD boot version %s\n"
+ printf("OpenBSD/i386 boot version %s(debug is %s)\n"
"device:\t%s\n"
"cwd:\t%s\n"
"image:\t%s\n"
"load at:\t%p\n"
"timeout:\t%d\n",
- version, cmd->bootdev, cmd->cwd, cmd->image,
+ version,
+#ifdef DEBUG
+ (debug? "on": "off"),
+#endif
+ cmd->bootdev, cmd->cwd, cmd->image,
cmd->addr, cmd->timeout);
break;
case CMD_REBOOT:
- exit(1);
+ cmd->rc = -1;
break;
case CMD_BOOT:
- return 1;
+ if (cmd->argc > 1)
+ strncpy(cmd->path, cmd->argv[1], sizeof(cmd->path));
+ else
+ sprintf(cmd->path, "%s%s%s", cmd->bootdev,
+ cmd->cwd, cmd->image);
+ cmd->rc = 1;
break;
case CMD_ERROR:
lsrwx(sb->st_mode >> 3, (sb->st_mode & S_ISUID? "sS" : "x-"));
lsrwx(sb->st_mode , (sb->st_mode & S_ISTXT? "tT" : "x-"));
- printf (" %s\tuid=%u\tgid=%u\t%lu\n", name, sb->st_uid, sb->st_gid,
- (u_long)sb->st_size);
+ printf (" %u,%u\t%lu\t%s\n", sb->st_uid, sb->st_gid,
+ (u_long)sb->st_size, name);
}
-/* $OpenBSD: cmd.h,v 1.1 1997/03/31 03:12:03 weingart Exp $ */
+/* $OpenBSD: cmd.h,v 1.2 1997/03/31 23:06:21 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
struct cmd_state {
char bootdev[16]; /* device */
char image[32]; /* image */
- char cwd[MAXPATHLEN - 32 - 32];
+ char cwd[MAXPATHLEN - 32 - 16];
void *addr; /* load here */
int timeout;
char path[MAXPATHLEN]; /* buffer for pathname compose */
- enum { CMD_ADDR, CMD_BOOT, CMD_CD, CMD_DEVICE, CMD_HELP,
+ enum { CMD_ADDR, CMD_BOOT, CMD_CD, CMD_DEVICE, CMD_DEBUG, CMD_HELP,
CMD_IMAGE, CMD_LS, CMD_NOPE, CMD_REBOOT, CMD_SET,
- CMD_ERROR /* last !!! */ };
- int cmd;
+ CMD_ERROR /* last !!! */
+ } cmd;
int argc;
char *argv[8]; /* XXX i hope this is enough */
int rc;