diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-03-31 23:06:34 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-03-31 23:06:34 +0000 |
commit | d56519762d6c1899f2baa3dbbc461af05cd168a6 (patch) | |
tree | 3d68308130e343610f48c1c66982d81dd56a226e /sys/stand/boot | |
parent | 10a04de1b4af9903e9146ad801619b45a42583c6 (diff) |
commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)
Diffstat (limited to 'sys/stand/boot')
-rw-r--r-- | sys/stand/boot/boot.c | 125 | ||||
-rw-r--r-- | sys/stand/boot/cmd.c | 185 | ||||
-rw-r--r-- | sys/stand/boot/cmd.h | 10 |
3 files changed, 192 insertions, 128 deletions
diff --git a/sys/stand/boot/boot.c b/sys/stand/boot/boot.c index 5770f608d53..91d43db5f87 100644 --- a/sys/stand/boot/boot.c +++ b/sys/stand/boot/boot.c @@ -1,4 +1,5 @@ -/* $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. @@ -34,92 +35,108 @@ #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() diff --git a/sys/stand/boot/cmd.c b/sys/stand/boot/cmd.c index f6d2aa39a9f..0b14120a626 100644 --- a/sys/stand/boot/cmd.c +++ b/sys/stand/boot/cmd.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,8 +36,13 @@ #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[] = { @@ -45,6 +50,9 @@ static struct 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}, @@ -54,104 +62,131 @@ static struct cmd_table { {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++) @@ -198,9 +233,12 @@ execmd(cmd) 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); @@ -208,7 +246,7 @@ execmd(cmd) } 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", @@ -216,18 +254,18 @@ execmd(cmd) 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); @@ -276,22 +314,31 @@ execmd(cmd) 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: @@ -319,7 +366,7 @@ ls(name, sb) 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); } diff --git a/sys/stand/boot/cmd.h b/sys/stand/boot/cmd.h index 35f3d58348a..25ac7d981fb 100644 --- a/sys/stand/boot/cmd.h +++ b/sys/stand/boot/cmd.h @@ -1,4 +1,4 @@ -/* $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 @@ -35,15 +35,15 @@ 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; |