123219Smckusick /* 229292Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323219Smckusick * All rights reserved. The Berkeley software License Agreement 423219Smckusick * specifies the terms and conditions for redistribution. 523219Smckusick * 6*37220Skarels * @(#)boot.c 7.12 (Berkeley) 03/21/89 723219Smckusick */ 8315Sbill 930769Skarels #include "param.h" 1030769Skarels #include "inode.h" 1130769Skarels #include "fs.h" 1230769Skarels #include "vm.h" 1333408Skarels #include "reboot.h" 1433408Skarels 15315Sbill #include <a.out.h> 16315Sbill #include "saio.h" 17315Sbill 181466Sbill /* 191466Sbill * Boot program... arguments passed in r10 and r11 determine 201466Sbill * whether boot stops to ask for system name and which device 211466Sbill * boot comes from. 221466Sbill */ 23315Sbill 2425626Skarels char line[100]; 2524217Sbloom 2630547Skarels extern unsigned opendev; 273347Swnj 28315Sbill main() 29315Sbill { 3026828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */ 31*37220Skarels int io = 0, retry, type; 32315Sbill 333274Swnj #ifdef lint 343274Swnj howto = 0; devtype = 0; 353274Swnj #endif 361575Sbill #ifdef JUSTASK 371593Sbill howto = RB_ASKNAME|RB_SINGLE; 381575Sbill #else 3926828Skarels if ((howto & RB_ASKNAME) == 0) { 4030547Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 4133408Skarels if ((unsigned)type < ndevs && devsw[type].dv_name) 4230547Skarels strcpy(line, UNIX); 4330547Skarels else 4430769Skarels howto |= RB_SINGLE|RB_ASKNAME; 451466Sbill } 461575Sbill #endif 4733522Sbostic for (retry = 0;;) { 48*37220Skarels if (io >= 0) 49*37220Skarels printf("\nBoot\n"); 501466Sbill if (howto & RB_ASKNAME) { 511466Sbill printf(": "); 521466Sbill gets(line); 5330547Skarels if (line[0] == 0) { 5430547Skarels strcpy(line, UNIX); 5530547Skarels printf(": %s\n", line); 5630547Skarels } 571466Sbill } else 581466Sbill printf(": %s\n", line); 591466Sbill io = open(line, 0); 6017198Stef if (io >= 0) { 6133408Skarels #ifdef VAX750 6226503Skarels loadpcs(); 6333408Skarels #endif 6430547Skarels copyunix(howto, opendev, io); 6525438Skarels close(io); 6630769Skarels howto |= RB_SINGLE|RB_ASKNAME; 6717198Stef } 681466Sbill if (++retry > 2) 6930769Skarels howto |= RB_SINGLE|RB_ASKNAME; 701466Sbill } 71315Sbill } 72315Sbill 733347Swnj /*ARGSUSED*/ 7430922Skarels copyunix(howto, devtype, aio) 7530922Skarels register howto, devtype; /* howto=r11, devtype=r10 */ 7630922Skarels int aio; 77315Sbill { 7830922Skarels register int esym; /* must be r9 */ 79315Sbill struct exec x; 8030922Skarels register int io = aio, i; 81315Sbill char *addr; 82315Sbill 8335479Sbostic if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) { 84*37220Skarels printf("Bad format\n"); 8530769Skarels return; 8630769Skarels } 87315Sbill printf("%d", x.a_text); 8833433Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1) 896069Smckusic goto shread; 90315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 91315Sbill goto shread; 92315Sbill addr = (char *)x.a_text; 9333433Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 946069Smckusic while ((int)addr & CLOFSET) 956069Smckusic *addr++ = 0; 96315Sbill printf("+%d", x.a_data); 97315Sbill if (read(io, addr, x.a_data) != x.a_data) 98315Sbill goto shread; 99315Sbill addr += x.a_data; 100315Sbill printf("+%d", x.a_bss); 101315Sbill for (i = 0; i < x.a_bss; i++) 102315Sbill *addr++ = 0; 10330769Skarels if (howto & RB_KDB && x.a_syms) { 10430769Skarels *(int *)addr = x.a_syms; /* symbol table size */ 10530769Skarels addr += sizeof (int); 10630769Skarels printf("[+%d", x.a_syms); 10730769Skarels if (read(io, addr, x.a_syms) != x.a_syms) 10830769Skarels goto shread; 10930769Skarels addr += x.a_syms; 11030769Skarels if (read(io, addr, sizeof (int)) != sizeof (int)) 11130769Skarels goto shread; 11230769Skarels i = *(int *)addr - sizeof (int); /* string table size */ 11330769Skarels addr += sizeof (int); 11430769Skarels printf("+%d]", i); 11530769Skarels if (read(io, addr, i) != i) 11630769Skarels goto shread; 11730769Skarels addr += i; 11830769Skarels esym = roundup((int)addr, sizeof (int)); 11930769Skarels x.a_bss = 0; 12030769Skarels } else 12130769Skarels howto &= ~RB_KDB; 12230769Skarels for (i = 0; i < 128*512; i++) /* slop */ 12330769Skarels *addr++ = 0; 124315Sbill x.a_entry &= 0x7fffffff; 125315Sbill printf(" start 0x%x\n", x.a_entry); 126315Sbill (*((int (*)()) x.a_entry))(); 12725438Skarels return; 128315Sbill shread: 12930769Skarels printf("Short read\n"); 13030769Skarels return; 131315Sbill } 13217198Stef 13333408Skarels #ifdef VAX750 13417198Stef /* 750 Patchable Control Store magic */ 13517198Stef 13617198Stef #include "../vax/mtpr.h" 13717198Stef #include "../vax/cpu.h" 13817198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 13917198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 14017198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 14117198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 14217198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 14317198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 14417198Stef 14517198Stef loadpcs() 14617198Stef { 14717198Stef register int *ip; /* known to be r11 below */ 14817198Stef register int i; /* known to be r10 below */ 14917198Stef register int *jp; /* known to be r9 below */ 15017198Stef register int j; 15126503Skarels static int pcsdone = 0; 15217198Stef union cpusid sid; 15317198Stef char pcs[100]; 15432198Skarels char *cp; 15517198Stef 15617198Stef sid.cpusid = mfpr(SID); 15726503Skarels if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone) 15817198Stef return; 15917198Stef printf("Updating 11/750 microcode: "); 16032198Skarels for (cp = line; *cp; cp++) 16132198Skarels if (*cp == ')' || *cp == ':') 16232198Skarels break; 16332198Skarels if (*cp) { 16432198Skarels strncpy(pcs, line, 99); 16532198Skarels pcs[99] = 0; 16632198Skarels i = cp - line + 1; 16732198Skarels } else 16832198Skarels i = 0; 16932198Skarels strcpy(pcs + i, "pcs750.bin"); 17017198Stef i = open(pcs, 0); 17117198Stef if (i < 0) 17217198Stef return; 17317198Stef /* 17417198Stef * We ask for more than we need to be sure we get only what we expect. 17517198Stef * After read: 17617198Stef * locs 0 - 1023 packed patchbits 17717198Stef * 1024 - 11264 packed microcode 17817198Stef */ 17917198Stef if (read(i, (char *)0, 23*512) != 22*512) { 18017198Stef printf("Error reading %s\n", pcs); 18117198Stef close(i); 18217198Stef return; 18317198Stef } 18417198Stef close(i); 18517198Stef 18617198Stef /* 18717198Stef * Enable patchbit loading and load the bits one at a time. 18817198Stef */ 18917198Stef *((int *)PCS_PATCHBIT) = 1; 19017198Stef ip = (int *)PCS_PATCHADDR; 19117198Stef jp = (int *)0; 19217198Stef for (i=0; i < PCS_BITCNT; i++) { 19317198Stef asm(" extzv r10,$1,(r9),(r11)+"); 19417198Stef } 19517198Stef *((int *)PCS_PATCHBIT) = 0; 19617198Stef 19717198Stef /* 19817198Stef * Load PCS microcode 20 bits at a time. 19917198Stef */ 20017198Stef ip = (int *)PCS_PCSADDR; 20117198Stef jp = (int *)1024; 20217198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 20317198Stef asm(" extzv r10,$20,(r9),(r11)+"); 20417198Stef } 20517198Stef 20617198Stef /* 20717198Stef * Enable PCS. 20817198Stef */ 20917198Stef i = *jp; /* get 1st 20 bits of microcode again */ 21017198Stef i &= 0xfffff; 21117198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 21217198Stef *((int *)PCS_PCSADDR) = i; 21317198Stef 21417198Stef sid.cpusid = mfpr(SID); 21517198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 21626503Skarels pcsdone = 1; 21717198Stef } 21833408Skarels #endif 219