handle var len names, sync with vax
[unix-history] / usr / src / sys / vax / stand / boot.c
index f7d0de6..c796425 100644 (file)
@@ -1,18 +1,19 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
+ * Copyright (c) 1982, 1986 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)boot.c      6.5 (Berkeley) %G%
+ *     @(#)boot.c      7.11 (Berkeley) %G%
  */
 
  */
 
-#include "../h/param.h"
-#include "../h/inode.h"
-#include "../h/fs.h"
-#include "../h/vm.h"
+#include "param.h"
+#include "inode.h"
+#include "fs.h"
+#include "vm.h"
+#include "reboot.h"
+
 #include <a.out.h>
 #include "saio.h"
 #include <a.out.h>
 #include "saio.h"
-#include "../h/reboot.h"
 
 /*
  * Boot program... arguments passed in r10 and r11 determine
 
 /*
  * Boot program... arguments passed in r10 and r11 determine
  * boot comes from.
  */
 
  * boot comes from.
  */
 
-/* Types in r10 specifying major device */
-char   devname[][2] = {
-       'h','p',        /* 0 = hp */
-       0,0,            /* 1 = ht */
-       'u','p',        /* 2 = up */
-       'h','k',        /* 3 = hk */
-       0,0,            /* 4 = sw */
-       0,0,            /* 5 = tm */
-       0,0,            /* 6 = ts */
-       0,0,            /* 7 = mt */
-       0,0,            /* 8 = tu */
-       'r','a',        /* 9 = ra */
-       'u','t',        /* 10 = ut */
-       'r','b',        /* 11 = rb */
-       0,0,            /* 12 = uu */
-       0,0,            /* 13 = rx */
-       'r','l',        /* 14 = rl */
-};
-
-/*
- * constants for converting a "minor" device numbers to unit number
- * and partition number
- */
-#define UNITSHIFT      16
-#define UNITMASK       0x1ff
-#define PARTITIONMASK  0x7
-#define PARTITIONSHIFT 3
-
-char line[100] = "xx(00,0)vmunix";
+char line[100];
 
 
-int    retry = 0;
+extern unsigned opendev;
 
 main()
 {
 
 main()
 {
-       register howto, devtype;        /* howto=r11, devtype=r10 */
-       int io;
-       register type, part, unit;
+       register unsigned howto, devtype;       /* howto=r11, devtype=r10 */
+       int io, retry, type;
 
 #ifdef lint
        howto = 0; devtype = 0;
 #endif
 
 #ifdef lint
        howto = 0; devtype = 0;
 #endif
-       printf("Boot\n");
-       loadpcs();
+       printf("\nBoot\n");
 #ifdef JUSTASK
        howto = RB_ASKNAME|RB_SINGLE;
 #else
 #ifdef JUSTASK
        howto = RB_ASKNAME|RB_SINGLE;
 #else
-       type = devtype & 0xff;
-       unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK;
-       part = unit & PARTITIONMASK;
-       unit = unit >> PARTITIONSHIFT;
-       if ((howto&RB_ASKNAME)==0) {
-               if (type >= 0 && type < sizeof(devname) / 2
-                   && devname[type][0]) {
-                       line[0] = devname[type][0];
-                       line[1] = devname[type][1];
-                       line[3] = unit / 10 + '0';
-                       line[4] = unit % 10 + '0';
-                       line[6] = part + '0';
-               } else
-                       howto = RB_SINGLE|RB_ASKNAME;
+       if ((howto & RB_ASKNAME) == 0) {
+               type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
+               if ((unsigned)type < ndevs && devsw[type].dv_name)
+                       strcpy(line, UNIX);
+               else
+                       howto |= RB_SINGLE|RB_ASKNAME;
        }
 #endif
        }
 #endif
-       for (;;) {
+       for (retry = 0;;) {
                if (howto & RB_ASKNAME) {
                        printf(": ");
                        gets(line);
                if (howto & RB_ASKNAME) {
                        printf(": ");
                        gets(line);
+                       if (line[0] == 0) {
+                               strcpy(line, UNIX);
+                               printf(": %s\n", line);
+                       }
                } else
                        printf(": %s\n", line);
                io = open(line, 0);
                if (io >= 0) {
                } else
                        printf(": %s\n", line);
                io = open(line, 0);
                if (io >= 0) {
-                       copyunix(howto, io);
+#ifdef VAX750
+                       loadpcs();
+#endif
+                       copyunix(howto, opendev, io);
                        close(io);
                        close(io);
-                       howto = RB_SINGLE|RB_ASKNAME;
+                       howto |= RB_SINGLE|RB_ASKNAME;
                }
                if (++retry > 2)
                }
                if (++retry > 2)
-                       howto = RB_SINGLE|RB_ASKNAME;
+                       howto |= RB_SINGLE|RB_ASKNAME;
        }
 }
 
 /*ARGSUSED*/
        }
 }
 
 /*ARGSUSED*/
-copyunix(howto, io)
-       register howto, io;
+copyunix(howto, devtype, aio)
+       register howto, devtype;        /* howto=r11, devtype=r10 */
+       int aio;
 {
 {
+       register int esym;              /* must be r9 */
        struct exec x;
        struct exec x;
-       register int i;
+       register int io = aio, i;
        char *addr;
 
        char *addr;
 
-       i = read(io, (char *)&x, sizeof x);
-       if (i != sizeof x ||
-           (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
-               _stop("Bad format\n");
+       if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
+               printf("bad magic #\n");
+               return;
+       }
        printf("%d", x.a_text);
        printf("%d", x.a_text);
-       if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
+       if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1)
                goto shread;
        if (read(io, (char *)0, x.a_text) != x.a_text)
                goto shread;
        addr = (char *)x.a_text;
                goto shread;
        if (read(io, (char *)0, x.a_text) != x.a_text)
                goto shread;
        addr = (char *)x.a_text;
-       if (x.a_magic == 0413 || x.a_magic == 0410)
+       if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
                while ((int)addr & CLOFSET)
                        *addr++ = 0;
        printf("+%d", x.a_data);
                while ((int)addr & CLOFSET)
                        *addr++ = 0;
        printf("+%d", x.a_data);
@@ -125,17 +97,39 @@ copyunix(howto, io)
                goto shread;
        addr += x.a_data;
        printf("+%d", x.a_bss);
                goto shread;
        addr += x.a_data;
        printf("+%d", x.a_bss);
-       x.a_bss += 128*512;     /* slop */
        for (i = 0; i < x.a_bss; i++)
                *addr++ = 0;
        for (i = 0; i < x.a_bss; i++)
                *addr++ = 0;
+       if (howto & RB_KDB && x.a_syms) {
+               *(int *)addr = x.a_syms;                /* symbol table size */
+               addr += sizeof (int);
+               printf("[+%d", x.a_syms);
+               if (read(io, addr, x.a_syms) != x.a_syms)
+                       goto shread;
+               addr += x.a_syms;
+               if (read(io, addr, sizeof (int)) != sizeof (int))
+                       goto shread;
+               i = *(int *)addr - sizeof (int);        /* string table size */
+               addr += sizeof (int);
+               printf("+%d]", i);
+               if (read(io, addr, i) != i)
+                       goto shread;
+               addr += i;
+               esym = roundup((int)addr, sizeof (int));
+               x.a_bss = 0;
+       } else
+               howto &= ~RB_KDB;
+       for (i = 0; i < 128*512; i++)   /* slop */
+               *addr++ = 0;
        x.a_entry &= 0x7fffffff;
        printf(" start 0x%x\n", x.a_entry);
        (*((int (*)()) x.a_entry))();
        return;
 shread:
        x.a_entry &= 0x7fffffff;
        printf(" start 0x%x\n", x.a_entry);
        (*((int (*)()) x.a_entry))();
        return;
 shread:
-       _stop("Short read\n");
+       printf("Short read\n");
+       return;
 }
 
 }
 
+#ifdef VAX750
 /* 750 Patchable Control Store magic */
 
 #include "../vax/mtpr.h"
 /* 750 Patchable Control Store magic */
 
 #include "../vax/mtpr.h"
@@ -153,23 +147,25 @@ loadpcs()
        register int i;         /* known to be r10 below */
        register int *jp;       /* known to be r9 below */
        register int j;
        register int i;         /* known to be r10 below */
        register int *jp;       /* known to be r9 below */
        register int j;
+       static int pcsdone = 0;
        union cpusid sid;
        char pcs[100];
        union cpusid sid;
        char pcs[100];
-       char *closeparen;
-       char *index();
+       char *cp;
 
        sid.cpusid = mfpr(SID);
 
        sid.cpusid = mfpr(SID);
-       if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95)
+       if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
                return;
        printf("Updating 11/750 microcode: ");
                return;
        printf("Updating 11/750 microcode: ");
-       strncpy(pcs, line, 99);
-       pcs[99] = 0;
-       closeparen = index(pcs, ')');
-       if (closeparen)
-               *(++closeparen) = 0;
-       else
-               return;
-       strcat(pcs, "pcs750.bin");
+       for (cp = line; *cp; cp++)
+               if (*cp == ')' || *cp == ':')
+                       break;
+       if (*cp) {
+               strncpy(pcs, line, 99);
+               pcs[99] = 0;
+               i = cp - line + 1;
+       } else
+               i = 0;
+       strcpy(pcs + i, "pcs750.bin");
        i = open(pcs, 0);
        if (i < 0)
                return;
        i = open(pcs, 0);
        if (i < 0)
                return;
@@ -216,4 +212,6 @@ loadpcs()
 
        sid.cpusid = mfpr(SID);
        printf("new rev level=%d\n", sid.cpu750.cp_urev);
 
        sid.cpusid = mfpr(SID);
        printf("new rev level=%d\n", sid.cpu750.cp_urev);
+       pcsdone = 1;
 }
 }
+#endif