1*49114Sbostic /*-
2*49114Sbostic * Copyright (c) 1982, 1986 The Regents of the University of California.
3*49114Sbostic * All rights reserved.
423220Smckusick *
5*49114Sbostic * %sccs.include.redist.c%
6*49114Sbostic *
7*49114Sbostic * @(#)bootxx.c 7.7 (Berkeley) 05/04/91
823220Smckusick */
97464Skre
1045803Sbostic #include "sys/param.h"
1145803Sbostic #include "sys/vm.h"
1245803Sbostic #include "sys/reboot.h"
137464Skre #include <a.out.h>
1445803Sbostic #include "stand/saio.h"
157464Skre
1632199Skarels char bootprog[] = "boot";
1732199Skarels extern unsigned opendev;
187464Skre
197464Skre /*
207464Skre * Boot program... arguments passed in r10 and r11
217464Skre * are passed through to the full boot program.
227464Skre */
237464Skre
main()247464Skre main()
257464Skre {
2626828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */
2726828Skarels int io, unit, partition;
2826828Skarels register char *cp;
297464Skre
307464Skre #ifdef lint
3132199Skarels howto = 0; devtype = 0; devtype = devtype;
327464Skre #endif
3325438Skarels printf("loading %s\n", bootprog);
347464Skre io = open(bootprog, 0);
357464Skre if (io >= 0)
3632199Skarels copyunix(howto, opendev, io);
3725438Skarels _stop("boot failed\n");
387464Skre }
397464Skre
407464Skre /*ARGSUSED*/
copyunix(howto,devtype,io)417464Skre copyunix(howto, devtype, io)
427464Skre register howto, devtype, io; /* howto=r11, devtype=r10 */
437464Skre {
447464Skre struct exec x;
457464Skre register int i;
467464Skre char *addr;
477464Skre
487464Skre i = read(io, (char *)&x, sizeof x);
4933430Sbostic if (i != sizeof x || N_BADMAG(x))
507464Skre _stop("Bad format\n");
5133430Sbostic if ((x.a_magic == ZMAGIC || x.a_magic == NMAGIC) &&
5233430Sbostic lseek(io, 0x400, L_SET) == -1)
537464Skre goto shread;
547464Skre if (read(io, (char *)0, x.a_text) != x.a_text)
557464Skre goto shread;
567464Skre addr = (char *)x.a_text;
5733430Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
587464Skre while ((int)addr & CLOFSET)
597464Skre *addr++ = 0;
607464Skre if (read(io, addr, x.a_data) != x.a_data)
617464Skre goto shread;
627464Skre addr += x.a_data;
637464Skre x.a_bss += 128*512; /* slop */
647464Skre for (i = 0; i < x.a_bss; i++)
657464Skre *addr++ = 0;
667464Skre x.a_entry &= 0x7fffffff;
677464Skre (*((int (*)()) x.a_entry))();
6825438Skarels return;
697464Skre shread:
707464Skre _stop("Short read\n");
717464Skre }
72