1*43457Sroot /* boot.c 7.3 90/06/22 */ 225865Ssam 337504Smckusick #include "machine/mtpr.h" 425865Ssam 5*43457Sroot #include "sys/param.h" 6*43457Sroot #include "sys/time.h" 7*43457Sroot #include "sys/vnode.h" 8*43457Sroot #include "ufs/inode.h" 9*43457Sroot #include "ufs/fs.h" 10*43457Sroot #include "sys/vm.h" 11*43457Sroot #include "sys/reboot.h" 1225865Ssam #include "saio.h" 1325865Ssam 1425865Ssam #include <a.out.h> 1525865Ssam 1625865Ssam /* 1725865Ssam * Boot program... arguments passed in r10 and r11 determine 1825865Ssam * whether boot stops to ask for system name and which device 1925865Ssam * boot comes from. 2025865Ssam */ 2125865Ssam 2230177Skarels #define DEV_DFLT 1 /* vd/dk */ 2338118Sbostic /*#define DEV_DFLT 2 /* hd */ 2425865Ssam 2525865Ssam char line[100]; 2625865Ssam 2730758Skarels extern unsigned opendev; 2830758Skarels extern unsigned bootdev; 2925865Ssam 3025865Ssam main() 3125865Ssam { 3230758Skarels register char *cp; /* skip r12 */ 3333652Sbostic register u_int howto, devtype; /* howto=r11, devtype=r10 */ 3437567Sbostic int io = 0, retry, type; 3525865Ssam 3625865Ssam #ifdef lint 3725865Ssam howto = 0; devtype = 0; 3825865Ssam #endif 3930758Skarels if ((devtype & B_MAGICMASK) != B_DEVMAGIC) 4030758Skarels devtype = DEV_DFLT << B_TYPESHIFT; /* unit, partition 0 */ 4130758Skarels bootdev = devtype; 4225865Ssam #ifdef JUSTASK 4325865Ssam howto = RB_ASKNAME|RB_SINGLE; 4429565Ssam #else 4529565Ssam if ((howto & RB_ASKNAME) == 0) { 4630758Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 4733652Sbostic if ((unsigned)type < ndevs && devsw[type].dv_name) 4830758Skarels strcpy(line, UNIX); 4930758Skarels else 5030758Skarels howto |= RB_SINGLE|RB_ASKNAME; 5129565Ssam } 5225865Ssam #endif 5333652Sbostic for (retry = 0;;) { 5437567Sbostic if (io >= 0) 5537567Sbostic printf("\nBoot"); 5625865Ssam if (howto & RB_ASKNAME) { 5725865Ssam printf(": "); 5825865Ssam gets(line); 5930758Skarels if (line[0] == 0) { 6030758Skarels strcpy(line, UNIX); 6130758Skarels printf(": %s\n", line); 6230758Skarels } 6325865Ssam } else 6425865Ssam printf(": %s\n", line); 6525865Ssam io = open(line, 0); 6629565Ssam if (io >= 0) { 6730758Skarels copyunix(howto, opendev, io); 6829565Ssam close(io); 6930758Skarels howto |= RB_SINGLE|RB_ASKNAME; 7029565Ssam } 7125865Ssam if (++retry > 2) 7225865Ssam howto |= RB_SINGLE|RB_ASKNAME; 7325865Ssam } 7425865Ssam } 7525865Ssam 7625865Ssam /*ARGSUSED*/ 7729565Ssam copyunix(howto, devtype, io) 7829565Ssam register io, howto, devtype; /* NOTE ORDER */ 7925865Ssam { 8030182Ssam register int esym; /* must be r9 */ 8125865Ssam register int i; 8229565Ssam register char *addr; 8330182Ssam struct exec x; 8425865Ssam 8537567Sbostic if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) { 8637567Sbostic printf("bad magic #\n"); 8730758Skarels return; 8830758Skarels } 8937567Sbostic printf("%ld", x.a_text); 9037567Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1) 9125865Ssam goto shread; 9230307Skarels if (read(io, (char *)RELOC, x.a_text) != x.a_text) 9325865Ssam goto shread; 9430307Skarels addr = (char *)(x.a_text + RELOC); 9537567Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 9625865Ssam while ((int)addr & CLOFSET) 9725865Ssam *addr++ = 0; 9837567Sbostic printf("+%ld", x.a_data); 9925865Ssam if (read(io, addr, x.a_data) != x.a_data) 10025865Ssam goto shread; 10125865Ssam addr += x.a_data; 10237567Sbostic printf("+%ld", x.a_bss); 10330182Ssam if (howto & RB_KDB && x.a_syms) { 10430182Ssam for (i = 0; i < x.a_bss; i++) 10530182Ssam *addr++ = 0; 10630182Ssam *(int *)addr = x.a_syms; /* symbol table size */ 10730182Ssam addr += sizeof (int); 10837567Sbostic printf("[+%ld", x.a_syms); 10930182Ssam if (read(io, addr, x.a_syms) != x.a_syms) 11030182Ssam goto shread; 11130182Ssam addr += x.a_syms; 11230182Ssam if (read(io, addr, sizeof (int)) != sizeof (int)) 11330182Ssam goto shread; 11430182Ssam i = *(int *)addr - sizeof (int); /* string table size */ 11530182Ssam addr += sizeof (int); 11630182Ssam printf("+%d]", i); 11730182Ssam if (read(io, addr, i) != i) 11830182Ssam goto shread; 11930182Ssam addr += i; 12030182Ssam esym = roundup((int)addr, sizeof (int)); 12130182Ssam x.a_bss = 0; 12230182Ssam } else 12330182Ssam howto &= ~RB_KDB; 12425865Ssam x.a_bss += 32*1024; /* slop */ 12525865Ssam for (i = 0; i < x.a_bss; i++) 12625865Ssam *addr++ = 0; 12725865Ssam x.a_entry &= 0x1fffffff; 12837567Sbostic printf(" start 0x%lx\n", x.a_entry); 12925865Ssam mtpr(PADC, 0); /* Purge data cache */ 13025865Ssam mtpr(PACC, 0); /* Purge code cache */ 13129565Ssam mtpr(DCR, 1); /* Enable data cache */ 13225865Ssam (*((int (*)()) x.a_entry))(); 13329565Ssam return; 13425865Ssam shread: 13537567Sbostic printf("short read\n"); 13630758Skarels return; 13725865Ssam } 138