1*3347Swnj /* boot.c 4.4 81/03/22 */ 2315Sbill 3315Sbill #include "../h/param.h" 4315Sbill #include "../h/ino.h" 5315Sbill #include "../h/inode.h" 6315Sbill #include "../h/filsys.h" 7315Sbill #include "../h/dir.h" 8315Sbill #include "../h/vm.h" 9315Sbill #include <a.out.h> 10315Sbill #include "saio.h" 111466Sbill #include <sys/reboot.h> 12315Sbill 131466Sbill /* 141466Sbill * Boot program... arguments passed in r10 and r11 determine 151466Sbill * whether boot stops to ask for system name and which device 161466Sbill * boot comes from. 171466Sbill */ 18315Sbill 191466Sbill /* Types in r10 specifying major device */ 201466Sbill char devname[][2] = { 211466Sbill 'h','p', /* 0 = hp */ 221466Sbill 0,0, /* 1 = ht */ 231466Sbill 'u','p', /* 2 = up */ 243261Swnj 'h','k', /* 3 = hk */ 251466Sbill }; 261466Sbill 271466Sbill char line[100] = "xx(0,0)vmunix"; 281466Sbill 29*3347Swnj int retry = 0; 30*3347Swnj 31315Sbill main() 32315Sbill { 331466Sbill register howto, devtype; /* howto=r11, devtype=r10 */ 34*3347Swnj int io; 35315Sbill 363274Swnj #ifdef lint 373274Swnj howto = 0; devtype = 0; 383274Swnj #endif 39315Sbill printf("\nBoot\n"); 401575Sbill #ifdef JUSTASK 411593Sbill howto = RB_ASKNAME|RB_SINGLE; 421575Sbill #else 431466Sbill if ((howto&RB_ASKNAME)==0) { 441466Sbill if (devtype>=0 && devtype<sizeof(devname)/2 451466Sbill && devname[devtype][0]) { 461466Sbill line[0] = devname[devtype][0]; 471466Sbill line[1] = devname[devtype][1]; 483261Swnj } else 491466Sbill howto = RB_SINGLE|RB_ASKNAME; 501466Sbill } 511575Sbill #endif 521466Sbill for (;;) { 531466Sbill if (howto & RB_ASKNAME) { 541466Sbill printf(": "); 551466Sbill gets(line); 561466Sbill } else 571466Sbill printf(": %s\n", line); 581466Sbill io = open(line, 0); 591466Sbill if (io >= 0) 60*3347Swnj copyunix(howto, io); 611466Sbill if (++retry > 2) 621466Sbill howto = RB_SINGLE|RB_ASKNAME; 631466Sbill } 64315Sbill } 65315Sbill 66*3347Swnj /*ARGSUSED*/ 67*3347Swnj copyunix(howto, io) 68*3347Swnj register howto, io; 69315Sbill { 70315Sbill struct exec x; 71315Sbill register int i; 72315Sbill char *addr; 73315Sbill 74315Sbill i = read(io, (char *)&x, sizeof x); 75315Sbill if (i != sizeof x || x.a_magic != 0410) 76315Sbill _stop("Bad format\n"); 77315Sbill printf("%d", x.a_text); 78315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 79315Sbill goto shread; 80315Sbill addr = (char *)x.a_text; 81315Sbill while ((int)addr & CLOFSET) 82315Sbill *addr++ = 0; 83315Sbill printf("+%d", x.a_data); 84315Sbill if (read(io, addr, x.a_data) != x.a_data) 85315Sbill goto shread; 86315Sbill addr += x.a_data; 87315Sbill printf("+%d", x.a_bss); 88315Sbill x.a_bss += 128*512; /* slop */ 89315Sbill for (i = 0; i < x.a_bss; i++) 90315Sbill *addr++ = 0; 91315Sbill x.a_entry &= 0x7fffffff; 92315Sbill printf(" start 0x%x\n", x.a_entry); 93315Sbill (*((int (*)()) x.a_entry))(); 94315Sbill _exit(); 95315Sbill shread: 96315Sbill _stop("Short read\n"); 97315Sbill } 98