BSD 4_1_snap development
[unix-history] / sys / stand / boot.c.ancient
CommitLineData
8de18358
C
1/* boot.c 4.4 81/03/22 */
2
3#include "../h/param.h"
4#include "../h/ino.h"
5#include "../h/inode.h"
6#include "../h/filsys.h"
7#include "../h/dir.h"
8#include "../h/vm.h"
9#include <a.out.h>
10#include "saio.h"
11#include <sys/reboot.h>
12
13/*
14 * Boot program... arguments passed in r10 and r11 determine
15 * whether boot stops to ask for system name and which device
16 * boot comes from.
17 */
18
19/* Types in r10 specifying major device */
20char devname[][2] = {
21 'h','p', /* 0 = hp */
22 0,0, /* 1 = ht */
23 'u','p', /* 2 = up */
24 'h','k', /* 3 = hk */
25};
26
27char line[100] = "xx(0,0)vmunix";
28
29int retry = 0;
30
31main()
32{
33 register howto, devtype; /* howto=r11, devtype=r10 */
34 int io;
35
36#ifdef lint
37 howto = 0; devtype = 0;
38#endif
39 printf("\nBoot\n");
40#ifdef JUSTASK
41 howto = RB_ASKNAME|RB_SINGLE;
42#else
43 if ((howto&RB_ASKNAME)==0) {
44 if (devtype>=0 && devtype<sizeof(devname)/2
45 && devname[devtype][0]) {
46 line[0] = devname[devtype][0];
47 line[1] = devname[devtype][1];
48 } else
49 howto = RB_SINGLE|RB_ASKNAME;
50 }
51#endif
52 for (;;) {
53 if (howto & RB_ASKNAME) {
54 printf(": ");
55 gets(line);
56 } else
57 printf(": %s\n", line);
58 io = open(line, 0);
59 if (io >= 0)
60 copyunix(howto, io);
61 if (++retry > 2)
62 howto = RB_SINGLE|RB_ASKNAME;
63 }
64}
65
66/*ARGSUSED*/
67copyunix(howto, io)
68 register howto, io;
69{
70 struct exec x;
71 register int i;
72 char *addr;
73
74 i = read(io, (char *)&x, sizeof x);
75 if (i != sizeof x || x.a_magic != 0410)
76 _stop("Bad format\n");
77 printf("%d", x.a_text);
78 if (read(io, (char *)0, x.a_text) != x.a_text)
79 goto shread;
80 addr = (char *)x.a_text;
81 while ((int)addr & CLOFSET)
82 *addr++ = 0;
83 printf("+%d", x.a_data);
84 if (read(io, addr, x.a_data) != x.a_data)
85 goto shread;
86 addr += x.a_data;
87 printf("+%d", x.a_bss);
88 x.a_bss += 128*512; /* slop */
89 for (i = 0; i < x.a_bss; i++)
90 *addr++ = 0;
91 x.a_entry &= 0x7fffffff;
92 printf(" start 0x%x\n", x.a_entry);
93 (*((int (*)()) x.a_entry))();
94 _exit();
95shread:
96 _stop("Short read\n");
97}