1 /*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 *
10 * @(#)boot.c 8.1 (Berkeley) 06/10/93
11 */
12
13 #include <sys/param.h>
14 #include <sys/exec.h>
15 #include <pmax/stand/dec_prom.h>
16
17 char line[1024];
18
19 /*
20 * This gets arguments from the PROM, calls other routines to open
21 * and load the program to boot, and then transfers execution to that
22 * new program.
23 * Argv[0] should be something like "rz(0,0,0)vmunix" on a DECstation 3100.
24 * Argv[0,1] should be something like "boot 5/rz0/vmunix" on a DECstation 5000.
25 * The argument "-a" means vmunix should do an automatic reboot.
26 */
27 void
main(argc,argv)28 main(argc, argv)
29 int argc;
30 char **argv;
31 {
32 register char *cp;
33 int ask, entry;
34
35 #ifdef JUSTASK
36 ask = 1;
37 #else
38 /* check for DS5000 boot */
39 if (strcmp(argv[0], "boot") == 0) {
40 argc--;
41 argv++;
42 }
43 cp = *argv;
44 ask = 0;
45 #endif /* JUSTASK */
46 for (;;) {
47 if (ask) {
48 printf("Boot: ");
49 gets(line);
50 if (line[0] == '\0')
51 continue;
52 cp = line;
53 argv[0] = cp;
54 argc = 1;
55 } else
56 printf("Boot: %s\n", cp);
57 entry = loadfile(cp);
58 if (entry != -1)
59 break;
60 ask = 1;
61 }
62 printf("Starting at 0x%x\n\n", entry);
63 if (callv == &callvec)
64 ((void (*)())entry)(argc, argv, 0, 0);
65 else
66 ((void (*)())entry)(argc, argv, DEC_PROM_MAGIC, callv);
67 }
68
69 /*
70 * Open 'filename', read in program and return the entry point or -1 if error.
71 */
loadfile(fname)72 loadfile(fname)
73 register char *fname;
74 {
75 register struct devices *dp;
76 register int fd, i, n;
77 struct exec aout;
78
79 if ((fd = open(fname, 0)) < 0) {
80 goto err;
81 }
82
83 /* read the exec header */
84 i = read(fd, (char *)&aout, sizeof(aout));
85 if (i != sizeof(aout)) {
86 goto cerr;
87 } else if (aout.a_magic != OMAGIC) {
88 goto cerr;
89 }
90
91 /* read the code and initialized data */
92 printf("Size: %d+%d", aout.a_text, aout.a_data);
93 if (lseek(fd, (off_t)N_TXTOFF(aout), 0) < 0) {
94 goto cerr;
95 }
96 i = aout.a_text + aout.a_data;
97 n = read(fd, (char *)aout.a_entry, i);
98 #ifndef SMALL
99 (void) close(fd);
100 #endif
101 if (n < 0) {
102 goto err;
103 } else if (n != i) {
104 goto err;
105 }
106
107 /* kernel will zero out its own bss */
108 n = aout.a_bss;
109 printf("+%d\n", n);
110
111 return ((int)aout.a_entry);
112
113 cerr:
114 #ifndef SMALL
115 (void) close(fd);
116 #endif
117 err:
118 printf("Can't boot '%s'\n", fname);
119 return (-1);
120 }
121