1*45796Sbostic /* boot.c 7.5 90/12/16 */ 225865Ssam 3*45796Sbostic #include "../include/mtpr.h" 425865Ssam 543457Sroot #include "sys/param.h" 643457Sroot #include "sys/time.h" 743457Sroot #include "sys/vm.h" 843457Sroot #include "sys/reboot.h" 9*45796Sbostic #include "stand/saio.h" 1025865Ssam 1125865Ssam #include <a.out.h> 1225865Ssam 1325865Ssam /* 1425865Ssam * Boot program... arguments passed in r10 and r11 determine 1525865Ssam * whether boot stops to ask for system name and which device 1625865Ssam * boot comes from. 1725865Ssam */ 1825865Ssam 1930177Skarels #define DEV_DFLT 1 /* vd/dk */ 2038118Sbostic /*#define DEV_DFLT 2 /* hd */ 2125865Ssam 2225865Ssam char line[100]; 2325865Ssam 2430758Skarels extern unsigned opendev; 2530758Skarels extern unsigned bootdev; 2625865Ssam 2725865Ssam main() 2825865Ssam { 2930758Skarels register char *cp; /* skip r12 */ 3033652Sbostic register u_int howto, devtype; /* howto=r11, devtype=r10 */ 3137567Sbostic int io = 0, retry, type; 3225865Ssam 3325865Ssam #ifdef lint 3425865Ssam howto = 0; devtype = 0; 3525865Ssam #endif 3630758Skarels if ((devtype & B_MAGICMASK) != B_DEVMAGIC) 3730758Skarels devtype = DEV_DFLT << B_TYPESHIFT; /* unit, partition 0 */ 3830758Skarels bootdev = devtype; 3925865Ssam #ifdef JUSTASK 4025865Ssam howto = RB_ASKNAME|RB_SINGLE; 4129565Ssam #else 4229565Ssam if ((howto & RB_ASKNAME) == 0) { 4330758Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 4433652Sbostic if ((unsigned)type < ndevs && devsw[type].dv_name) 4530758Skarels strcpy(line, UNIX); 4630758Skarels else 4730758Skarels howto |= RB_SINGLE|RB_ASKNAME; 4829565Ssam } 4925865Ssam #endif 5033652Sbostic for (retry = 0;;) { 5137567Sbostic if (io >= 0) 5237567Sbostic printf("\nBoot"); 5325865Ssam if (howto & RB_ASKNAME) { 5425865Ssam printf(": "); 5525865Ssam gets(line); 5630758Skarels if (line[0] == 0) { 5730758Skarels strcpy(line, UNIX); 5830758Skarels printf(": %s\n", line); 5930758Skarels } 6025865Ssam } else 6125865Ssam printf(": %s\n", line); 6225865Ssam io = open(line, 0); 6329565Ssam if (io >= 0) { 6430758Skarels copyunix(howto, opendev, io); 6529565Ssam close(io); 6630758Skarels howto |= RB_SINGLE|RB_ASKNAME; 6729565Ssam } 6825865Ssam if (++retry > 2) 6925865Ssam howto |= RB_SINGLE|RB_ASKNAME; 7025865Ssam } 7125865Ssam } 7225865Ssam 7325865Ssam /*ARGSUSED*/ 7429565Ssam copyunix(howto, devtype, io) 7529565Ssam register io, howto, devtype; /* NOTE ORDER */ 7625865Ssam { 7730182Ssam register int esym; /* must be r9 */ 7825865Ssam register int i; 7929565Ssam register char *addr; 8030182Ssam struct exec x; 8125865Ssam 8237567Sbostic if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) { 8337567Sbostic printf("bad magic #\n"); 8430758Skarels return; 8530758Skarels } 8637567Sbostic printf("%ld", x.a_text); 8737567Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1) 8825865Ssam goto shread; 8930307Skarels if (read(io, (char *)RELOC, x.a_text) != x.a_text) 9025865Ssam goto shread; 9130307Skarels addr = (char *)(x.a_text + RELOC); 9237567Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 9325865Ssam while ((int)addr & CLOFSET) 9425865Ssam *addr++ = 0; 9537567Sbostic printf("+%ld", x.a_data); 9625865Ssam if (read(io, addr, x.a_data) != x.a_data) 9725865Ssam goto shread; 9825865Ssam addr += x.a_data; 9937567Sbostic printf("+%ld", x.a_bss); 10030182Ssam if (howto & RB_KDB && x.a_syms) { 10130182Ssam for (i = 0; i < x.a_bss; i++) 10230182Ssam *addr++ = 0; 10330182Ssam *(int *)addr = x.a_syms; /* symbol table size */ 10430182Ssam addr += sizeof (int); 10537567Sbostic printf("[+%ld", x.a_syms); 10630182Ssam if (read(io, addr, x.a_syms) != x.a_syms) 10730182Ssam goto shread; 10830182Ssam addr += x.a_syms; 10930182Ssam if (read(io, addr, sizeof (int)) != sizeof (int)) 11030182Ssam goto shread; 11130182Ssam i = *(int *)addr - sizeof (int); /* string table size */ 11230182Ssam addr += sizeof (int); 11330182Ssam printf("+%d]", i); 11430182Ssam if (read(io, addr, i) != i) 11530182Ssam goto shread; 11630182Ssam addr += i; 11730182Ssam esym = roundup((int)addr, sizeof (int)); 11830182Ssam x.a_bss = 0; 11930182Ssam } else 12030182Ssam howto &= ~RB_KDB; 12125865Ssam x.a_bss += 32*1024; /* slop */ 12225865Ssam for (i = 0; i < x.a_bss; i++) 12325865Ssam *addr++ = 0; 12425865Ssam x.a_entry &= 0x1fffffff; 12537567Sbostic printf(" start 0x%lx\n", x.a_entry); 12625865Ssam mtpr(PADC, 0); /* Purge data cache */ 12725865Ssam mtpr(PACC, 0); /* Purge code cache */ 12829565Ssam mtpr(DCR, 1); /* Enable data cache */ 12925865Ssam (*((int (*)()) x.a_entry))(); 13029565Ssam return; 13125865Ssam shread: 13237567Sbostic printf("short read\n"); 13330758Skarels return; 13425865Ssam } 135