123220Smckusick /* 229293Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323220Smckusick * All rights reserved. The Berkeley software License Agreement 423220Smckusick * specifies the terms and conditions for redistribution. 523220Smckusick * 6*33430Sbostic * @(#)bootxx.c 7.4 (Berkeley) 02/04/88 723220Smckusick */ 87464Skre 933408Skarels #include "param.h" 1033408Skarels #include "inode.h" 1133408Skarels #include "fs.h" 1233408Skarels #include "vm.h" 1333408Skarels #include "reboot.h" 147464Skre #include <a.out.h> 157464Skre #include "saio.h" 167464Skre 1732199Skarels char bootprog[] = "boot"; 1832199Skarels extern unsigned opendev; 197464Skre 207464Skre /* 217464Skre * Boot program... arguments passed in r10 and r11 227464Skre * are passed through to the full boot program. 237464Skre */ 247464Skre 257464Skre main() 267464Skre { 2726828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */ 2826828Skarels int io, unit, partition; 2926828Skarels register char *cp; 307464Skre 317464Skre #ifdef lint 3232199Skarels howto = 0; devtype = 0; devtype = devtype; 337464Skre #endif 3425438Skarels printf("loading %s\n", bootprog); 357464Skre io = open(bootprog, 0); 367464Skre if (io >= 0) 3732199Skarels copyunix(howto, opendev, io); 3825438Skarels _stop("boot failed\n"); 397464Skre } 407464Skre 417464Skre /*ARGSUSED*/ 427464Skre copyunix(howto, devtype, io) 437464Skre register howto, devtype, io; /* howto=r11, devtype=r10 */ 447464Skre { 457464Skre struct exec x; 467464Skre register int i; 477464Skre char *addr; 487464Skre 497464Skre i = read(io, (char *)&x, sizeof x); 50*33430Sbostic if (i != sizeof x || N_BADMAG(x)) 517464Skre _stop("Bad format\n"); 52*33430Sbostic if ((x.a_magic == ZMAGIC || x.a_magic == NMAGIC) && 53*33430Sbostic lseek(io, 0x400, L_SET) == -1) 547464Skre goto shread; 557464Skre if (read(io, (char *)0, x.a_text) != x.a_text) 567464Skre goto shread; 577464Skre addr = (char *)x.a_text; 58*33430Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 597464Skre while ((int)addr & CLOFSET) 607464Skre *addr++ = 0; 617464Skre if (read(io, addr, x.a_data) != x.a_data) 627464Skre goto shread; 637464Skre addr += x.a_data; 647464Skre x.a_bss += 128*512; /* slop */ 657464Skre for (i = 0; i < x.a_bss; i++) 667464Skre *addr++ = 0; 677464Skre x.a_entry &= 0x7fffffff; 687464Skre (*((int (*)()) x.a_entry))(); 6925438Skarels return; 707464Skre shread: 717464Skre _stop("Short read\n"); 727464Skre } 73