handle var len names, sync with vax
[unix-history] / usr / src / sys / vax / stand / boot.c
index 123e1b2..c796425 100644 (file)
@@ -3,16 +3,17 @@
  * 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      7.2 (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.
  */
 
-#define        UNIX    "/vmunix"
 char line[100];
 
 char line[100];
 
-int    retry = 0;
-unsigned bootdev;
 extern unsigned opendev;
 
 main()
 {
        register unsigned howto, devtype;       /* howto=r11, devtype=r10 */
 extern unsigned opendev;
 
 main()
 {
        register unsigned howto, devtype;       /* howto=r11, devtype=r10 */
-       int io, type;
+       int io, retry, type;
 
 #ifdef lint
        howto = 0; devtype = 0;
 #endif
 
 #ifdef lint
        howto = 0; devtype = 0;
 #endif
-       bootdev = devtype;
        printf("\nBoot\n");
 #ifdef JUSTASK
        howto = RB_ASKNAME|RB_SINGLE;
 #else
        if ((howto & RB_ASKNAME) == 0) {
                type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
        printf("\nBoot\n");
 #ifdef JUSTASK
        howto = RB_ASKNAME|RB_SINGLE;
 #else
        if ((howto & RB_ASKNAME) == 0) {
                type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
-               if ((unsigned)type < ndevs && devsw[type].dv_name[0])
+               if ((unsigned)type < ndevs && devsw[type].dv_name)
                        strcpy(line, UNIX);
                else
                        strcpy(line, UNIX);
                else
-                       howto = RB_SINGLE|RB_ASKNAME;
+                       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);
@@ -60,35 +57,39 @@ main()
                        printf(": %s\n", line);
                io = open(line, 0);
                if (io >= 0) {
                        printf(": %s\n", line);
                io = open(line, 0);
                if (io >= 0) {
+#ifdef VAX750
                        loadpcs();
                        loadpcs();
+#endif
                        copyunix(howto, opendev, io);
                        close(io);
                        copyunix(howto, opendev, 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, devtype, io)
-       register howto, devtype, io;    /* howto=r11, devtype=r10 */
+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);
@@ -96,17 +97,39 @@ copyunix(howto, devtype, 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"
@@ -127,21 +150,22 @@ loadpcs()
        static int pcsdone = 0;
        union cpusid sid;
        char pcs[100];
        static int pcsdone = 0;
        union cpusid sid;
        char pcs[100];
-       char *closeparen;
-       char *index();
+       char *cp;
 
        sid.cpusid = mfpr(SID);
        if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
                return;
        printf("Updating 11/750 microcode: ");
 
        sid.cpusid = mfpr(SID);
        if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
                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;
@@ -190,3 +214,4 @@ loadpcs()
        printf("new rev level=%d\n", sid.cpu750.cp_urev);
        pcsdone = 1;
 }
        printf("new rev level=%d\n", sid.cpu750.cp_urev);
        pcsdone = 1;
 }
+#endif