1*6069Smckusic /* boot.c 4.7 82/03/07 */ 2315Sbill 3315Sbill #include "../h/param.h" 4315Sbill #include "../h/inode.h" 5*6069Smckusic #include "../h/fs.h" 6315Sbill #include "../h/vm.h" 7315Sbill #include <a.out.h> 8315Sbill #include "saio.h" 9*6069Smckusic #include "../h/reboot.h" 10315Sbill 111466Sbill /* 121466Sbill * Boot program... arguments passed in r10 and r11 determine 131466Sbill * whether boot stops to ask for system name and which device 141466Sbill * boot comes from. 151466Sbill */ 16315Sbill 171466Sbill /* Types in r10 specifying major device */ 181466Sbill char devname[][2] = { 191466Sbill 'h','p', /* 0 = hp */ 201466Sbill 0,0, /* 1 = ht */ 211466Sbill 'u','p', /* 2 = up */ 223261Swnj 'h','k', /* 3 = hk */ 234868Sroot 0,0, /* 4 = sw */ 244868Sroot 0,0, /* 5 = tm */ 254868Sroot 0,0, /* 6 = ts */ 264868Sroot 0,0, /* 7 = mt */ 274868Sroot 0,0, /* 8 = tu */ 284868Sroot 'r','a', /* 9 = ra */ 295154Ssam 'u', 't', /* 10 = ut */ 301466Sbill }; 311466Sbill 321466Sbill char line[100] = "xx(0,0)vmunix"; 331466Sbill 343347Swnj int retry = 0; 353347Swnj 36315Sbill main() 37315Sbill { 381466Sbill register howto, devtype; /* howto=r11, devtype=r10 */ 393347Swnj int io; 40315Sbill 413274Swnj #ifdef lint 423274Swnj howto = 0; devtype = 0; 433274Swnj #endif 44315Sbill printf("\nBoot\n"); 451575Sbill #ifdef JUSTASK 461593Sbill howto = RB_ASKNAME|RB_SINGLE; 471575Sbill #else 481466Sbill if ((howto&RB_ASKNAME)==0) { 491466Sbill if (devtype>=0 && devtype<sizeof(devname)/2 501466Sbill && devname[devtype][0]) { 511466Sbill line[0] = devname[devtype][0]; 521466Sbill line[1] = devname[devtype][1]; 533261Swnj } else 541466Sbill howto = RB_SINGLE|RB_ASKNAME; 551466Sbill } 561575Sbill #endif 571466Sbill for (;;) { 581466Sbill if (howto & RB_ASKNAME) { 591466Sbill printf(": "); 601466Sbill gets(line); 611466Sbill } else 621466Sbill printf(": %s\n", line); 631466Sbill io = open(line, 0); 641466Sbill if (io >= 0) 653347Swnj copyunix(howto, io); 661466Sbill if (++retry > 2) 671466Sbill howto = RB_SINGLE|RB_ASKNAME; 681466Sbill } 69315Sbill } 70315Sbill 713347Swnj /*ARGSUSED*/ 723347Swnj copyunix(howto, io) 733347Swnj register howto, io; 74315Sbill { 75315Sbill struct exec x; 76315Sbill register int i; 77315Sbill char *addr; 78315Sbill 79315Sbill i = read(io, (char *)&x, sizeof x); 80*6069Smckusic if (i != sizeof x || 81*6069Smckusic (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 82315Sbill _stop("Bad format\n"); 83315Sbill printf("%d", x.a_text); 84*6069Smckusic if ((x.a_magic == 0413 || x.a_magic == 0410) && 85*6069Smckusic lseek(io, 0x400, 0) == -1) 86*6069Smckusic goto shread; 87315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 88315Sbill goto shread; 89315Sbill addr = (char *)x.a_text; 90*6069Smckusic if (x.a_magic == 0413 || x.a_magic == 0410) 91*6069Smckusic while ((int)addr & CLOFSET) 92*6069Smckusic *addr++ = 0; 93315Sbill printf("+%d", x.a_data); 94315Sbill if (read(io, addr, x.a_data) != x.a_data) 95315Sbill goto shread; 96315Sbill addr += x.a_data; 97315Sbill printf("+%d", x.a_bss); 98315Sbill x.a_bss += 128*512; /* slop */ 99315Sbill for (i = 0; i < x.a_bss; i++) 100315Sbill *addr++ = 0; 101315Sbill x.a_entry &= 0x7fffffff; 102315Sbill printf(" start 0x%x\n", x.a_entry); 103315Sbill (*((int (*)()) x.a_entry))(); 104315Sbill _exit(); 105315Sbill shread: 106315Sbill _stop("Short read\n"); 107315Sbill } 108