date and time created 91/04/28 17:15:43 by william
[unix-history] / usr / src / sys / i386 / stand / boot.c
CommitLineData
3fd40431
WN
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz.
7 *
707550d2 8 * %sccs.include.redist.c%
3fd40431
WN
9 */
10
11#ifndef lint
12char copyright[] =
13"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
14 All rights reserved.\n";
15#endif /* not lint */
16
17#ifndef lint
707550d2 18static char sccsid[] = "@(#)boot.c 7.2 (Berkeley) %G%";
3fd40431
WN
19#endif /* not lint */
20
707550d2
WN
21#include "param.h"
22#include "reboot.h"
3fd40431 23#include <a.out.h>
707550d2 24#include <setjmp.h>
3fd40431
WN
25#include "saio.h"
26
27/*
707550d2 28 * Boot program... arguments from lower-level bootstrap determine
3fd40431
WN
29 * whether boot stops to ask for system name and which device
30 * boot comes from.
31 */
32
33#define UNIX "/vmunix"
34
35char line[100] = UNIX;
707550d2 36extern int opendev, bootdev, cyloffset;
3fd40431 37int retry = 0;
707550d2 38jmp_buf exception;
3fd40431 39
707550d2 40main(howto, dev, off)
3fd40431
WN
41{
42 int io;
43
707550d2
WN
44 if((dev&B_MAGICMASK) == B_DEVMAGIC) {
45 bootdev = dev;
46 cyloffset = off;
47 } else goto again;
48
49 if(_setjmp(exception)) {
50 close(io);
51 printf("- load aborted\n");
52again:
53 howto = RB_SINGLE|RB_ASKNAME;
54 cyloffset = 0;
55 }
56
3fd40431
WN
57 for (;;) {
58 if (howto & RB_ASKNAME) {
707550d2
WN
59 char *cp;
60
3fd40431
WN
61 printf("Boot: ");
62 gets(line);
707550d2
WN
63
64 /* process additional flags if any */
65 if(cp = (char *)index(line, ' ')) {
66 howto = strtol (cp, 0, 0);
67 *cp = '\0';
68 }
69 cyloffset = 0;
3fd40431
WN
70 } else
71 printf("Boot: %s\n", line);
707550d2 72
3fd40431
WN
73 if (line[0] == 0) {
74 strcpy(line, UNIX);
75 printf("Boot: %s\n", line);
76 }
77
78 io = open(line, 0);
3fd40431 79 if (io >= 0) {
707550d2
WN
80 copyunix(io, howto);
81 goto again;
82 } else if (++retry > 2)
83 goto again;
3fd40431
WN
84 }
85}
86
87/*ARGSUSED*/
707550d2 88copyunix(io, howto)
3fd40431
WN
89 register io;
90{
91 struct exec x;
92 int i;
707550d2 93 char *addr,c;
3fd40431
WN
94
95 i = read(io, (char *)&x, sizeof x);
96 if (i != sizeof x ||
707550d2
WN
97 (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) {
98 printf("Bad format\n");
99 return;
100 }
101
3fd40431
WN
102 printf("%d", x.a_text);
103 if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
104 goto shread;
105 if (read(io, (char *)0, x.a_text) != x.a_text)
106 goto shread;
707550d2 107
3fd40431
WN
108 addr = (char *)x.a_text;
109 if (x.a_magic == 0413 || x.a_magic == 0410)
110 while ((int)addr & CLOFSET)
111 *addr++ = 0;
112 printf("+%d", x.a_data);
113 if (read(io, addr, x.a_data) != x.a_data)
114 goto shread;
707550d2 115
3fd40431
WN
116 addr += x.a_data;
117 printf("+%d", x.a_bss);
118 x.a_bss += 128*512; /* slop */
119 for (i = 0; i < x.a_bss; i++)
120 *addr++ = 0;
707550d2
WN
121
122 /* mask high order bits corresponding to relocated system base */
123 x.a_entry &= 0xfff00000;
3fd40431 124 printf(" start 0x%x\n", x.a_entry);
707550d2
WN
125
126 if(c=scankbd())
127 _longjmp(&exception,1);
128
129 i = (*((int (*)()) x.a_entry))(howto, opendev, 0, cyloffset);
130
3fd40431
WN
131 if (i) printf("exit %d\n", i) ;
132 return;
133shread:
707550d2
WN
134 printf("Short read\n");
135 return;
3fd40431 136}