xref: /original-bsd/sys/i386/stand/bootxx.c (revision 188f7363)
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  *
8  * %sccs.include.noredist.c%
9  *
10  *	@(#)bootxx.c	7.1 (Berkeley) 04/24/90
11  */
12 
13 #include "../h/param.h"
14 #include "../h/inode.h"
15 #include "../h/fs.h"
16 #include <a.out.h>
17 #include "saio.h"
18 #include "../h/reboot.h"
19 #include "../h/dir.h"
20 #include "../h/disk.h"
21 #include "devvm.h"
22 
23 extern	int howto, bootdev, unit, cyloffset, boottype;
24 extern char bootprog[] ;
25 /*
26  * Boot program... arguments passed in r10 and r11
27  * are passed through to the full boot program.
28  */
29 
30 main()
31 {
32 	register int io, partition; register char *bp ;
33 
34 #ifdef lint
35 	howto = 0; devtype = 0;
36 #endif
37 	extern struct disklabel disklabel;
38 
39 	/* are we a disk, if so look at disklabel and do things */
40 	if (bootdev == 0 || bootdev == 3) {
41 	    /*
42 	     * Synthesize bootdev from unit, type and partition
43 	     * from the ROM monitor.
44 	     * It's dirty work, but someone's got to do it, and
45 	     * we always seem to get it.
46 	     */
47 	    for (io = 0; io < 8; io++)
48 		if (bootdev > 0) { /* XXX should check dk_type == DTYPE_SCSI */
49 			if (disklabel.dk_partition[io].cyloff
50 				== cyloffset * disklabel.dk_secpercyl)
51 				break;
52 		} else {
53 
54 			if (disklabel.dk_partition[io].cyloff == cyloffset)
55 			break;
56 		}
57 	    if (io == 8) io = 0; /* probably a bad or non-existant disklabel */
58 	    bootdev = makedev(bootdev, make_minor(unit, io));
59 	} else { io = 0 ; howto = (howto&0x7) | 3 ; }
60 	bp = bootprog ;
61 	while (*bp != '0') bp++ ;	/* n-char device names instead of 2 */
62 	*bp++ = unit % 10 + '0' ;
63 	*bp += io % 10 ;
64 /*	bootprog[3] = unit % 10 + '0';
65 	bootprog[4] = io % 10 + 'a';*/
66 	printf("loading %s\n", bootprog);
67 	io = open(bootprog, 0);
68 	if (io >= 0)
69 		copyunix(io);
70 	_stop("boot failed\n");
71 }
72 
73 /*ARGSUSED*/
74 copyunix(io)
75 	register io;
76 {
77 	struct exec x;
78 	register int i;
79 	char *addr;
80 
81 	i = read(io, (char *)&x, sizeof x);
82 	if (i != sizeof x ||
83 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
84 		_stop("Bad format\n");
85 	if ((x.a_magic == 0413 || x.a_magic == 0410) &&
86 	    lseek(io, 0x400, 0) == -1)
87 		goto shread;
88 	if (read(io, (char *)0, x.a_text) != x.a_text)
89 		goto shread;
90 	addr = (char *)x.a_text;
91 	if (x.a_magic == 0413 || x.a_magic == 0410)
92 		while ((int)addr & CLOFSET)
93 			*addr++ = 0;
94 	if (read(io, addr, x.a_data) != x.a_data)
95 		goto shread;
96 	addr += x.a_data;
97 	x.a_bss += 128*512;	/* slop */
98 	for (i = 0; i < x.a_bss; i++)
99 		*addr++ = 0;
100 	setregs();
101  	(*((int (*)()) x.a_entry))();
102 	return;
103 shread:
104 	_stop("Short read\n");
105 }
106