1*23220Smckusick /* 2*23220Smckusick * Copyright (c) 1982 Regents of the University of California. 3*23220Smckusick * All rights reserved. The Berkeley software License Agreement 4*23220Smckusick * specifies the terms and conditions for redistribution. 5*23220Smckusick * 6*23220Smckusick * @(#)bootxx.c 6.2 (Berkeley) 06/08/85 7*23220Smckusick */ 87464Skre 97464Skre #include "../h/param.h" 107464Skre #include "../h/inode.h" 117464Skre #include "../h/fs.h" 127464Skre #include "../h/vm.h" 137464Skre #include <a.out.h> 147464Skre #include "saio.h" 157464Skre #include "../h/reboot.h" 167464Skre 1711185Ssam char bootprog[] = "xx(0,0)boot"; 187464Skre 197464Skre /* 207464Skre * Boot program... arguments passed in r10 and r11 217464Skre * are passed through to the full boot program. 227464Skre */ 237464Skre 247464Skre main() 257464Skre { 267464Skre register howto, devtype; /* howto=r11, devtype=r10 */ 277464Skre int io; 287464Skre 297464Skre #ifdef lint 307464Skre howto = 0; devtype = 0; 317464Skre #endif 327464Skre printf("loading %s", bootprog); 337464Skre io = open(bootprog, 0); 347464Skre if (io >= 0) 357464Skre copyunix(howto, devtype, io); 367464Skre printf("boot failed"); 377464Skre _exit(); 387464Skre } 397464Skre 407464Skre /*ARGSUSED*/ 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); 497464Skre if (i != sizeof x || 507464Skre (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 517464Skre _stop("Bad format\n"); 527464Skre if ((x.a_magic == 0413 || x.a_magic == 0410) && 537464Skre lseek(io, 0x400, 0) == -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; 587464Skre if (x.a_magic == 0413 || x.a_magic == 0410) 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))(); 697464Skre _exit(); 707464Skre shread: 717464Skre _stop("Short read\n"); 727464Skre } 73