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*33522Sbostic * @(#)boot.c 7.9 (Berkeley) 02/22/88 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 2430547Skarels #define UNIX "/vmunix" 2525626Skarels char line[100]; 2624217Sbloom 2730547Skarels extern unsigned opendev; 283347Swnj 29315Sbill main() 30315Sbill { 3126828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */ 32*33522Sbostic int io, retry, type; 33315Sbill 343274Swnj #ifdef lint 353274Swnj howto = 0; devtype = 0; 363274Swnj #endif 3725626Skarels printf("\nBoot\n"); 381575Sbill #ifdef JUSTASK 391593Sbill howto = RB_ASKNAME|RB_SINGLE; 401575Sbill #else 4126828Skarels if ((howto & RB_ASKNAME) == 0) { 4230547Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 4333408Skarels if ((unsigned)type < ndevs && devsw[type].dv_name) 4430547Skarels strcpy(line, UNIX); 4530547Skarels else 4630769Skarels howto |= RB_SINGLE|RB_ASKNAME; 471466Sbill } 481575Sbill #endif 49*33522Sbostic for (retry = 0;;) { 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 8333433Sbostic i = read(io, (char *)&x, sizeof(x)); 8433433Sbostic if (i != sizeof(x) || (x.a_magic != OMAGIC && x.a_magic != ZMAGIC 8533433Sbostic && x.a_magic != NMAGIC)) { 8630769Skarels printf("Bad format\n"); 8730769Skarels return; 8830769Skarels } 89315Sbill printf("%d", x.a_text); 9033433Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1) 916069Smckusic goto shread; 92315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 93315Sbill goto shread; 94315Sbill addr = (char *)x.a_text; 9533433Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 966069Smckusic while ((int)addr & CLOFSET) 976069Smckusic *addr++ = 0; 98315Sbill printf("+%d", x.a_data); 99315Sbill if (read(io, addr, x.a_data) != x.a_data) 100315Sbill goto shread; 101315Sbill addr += x.a_data; 102315Sbill printf("+%d", x.a_bss); 103315Sbill for (i = 0; i < x.a_bss; i++) 104315Sbill *addr++ = 0; 10530769Skarels if (howto & RB_KDB && x.a_syms) { 10630769Skarels *(int *)addr = x.a_syms; /* symbol table size */ 10730769Skarels addr += sizeof (int); 10830769Skarels printf("[+%d", x.a_syms); 10930769Skarels if (read(io, addr, x.a_syms) != x.a_syms) 11030769Skarels goto shread; 11130769Skarels addr += x.a_syms; 11230769Skarels if (read(io, addr, sizeof (int)) != sizeof (int)) 11330769Skarels goto shread; 11430769Skarels i = *(int *)addr - sizeof (int); /* string table size */ 11530769Skarels addr += sizeof (int); 11630769Skarels printf("+%d]", i); 11730769Skarels if (read(io, addr, i) != i) 11830769Skarels goto shread; 11930769Skarels addr += i; 12030769Skarels esym = roundup((int)addr, sizeof (int)); 12130769Skarels x.a_bss = 0; 12230769Skarels } else 12330769Skarels howto &= ~RB_KDB; 12430769Skarels for (i = 0; i < 128*512; i++) /* slop */ 12530769Skarels *addr++ = 0; 126315Sbill x.a_entry &= 0x7fffffff; 127315Sbill printf(" start 0x%x\n", x.a_entry); 128315Sbill (*((int (*)()) x.a_entry))(); 12925438Skarels return; 130315Sbill shread: 13130769Skarels printf("Short read\n"); 13230769Skarels return; 133315Sbill } 13417198Stef 13533408Skarels #ifdef VAX750 13617198Stef /* 750 Patchable Control Store magic */ 13717198Stef 13817198Stef #include "../vax/mtpr.h" 13917198Stef #include "../vax/cpu.h" 14017198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 14117198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 14217198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 14317198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 14417198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 14517198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 14617198Stef 14717198Stef loadpcs() 14817198Stef { 14917198Stef register int *ip; /* known to be r11 below */ 15017198Stef register int i; /* known to be r10 below */ 15117198Stef register int *jp; /* known to be r9 below */ 15217198Stef register int j; 15326503Skarels static int pcsdone = 0; 15417198Stef union cpusid sid; 15517198Stef char pcs[100]; 15632198Skarels char *cp; 15717198Stef 15817198Stef sid.cpusid = mfpr(SID); 15926503Skarels if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone) 16017198Stef return; 16117198Stef printf("Updating 11/750 microcode: "); 16232198Skarels for (cp = line; *cp; cp++) 16332198Skarels if (*cp == ')' || *cp == ':') 16432198Skarels break; 16532198Skarels if (*cp) { 16632198Skarels strncpy(pcs, line, 99); 16732198Skarels pcs[99] = 0; 16832198Skarels i = cp - line + 1; 16932198Skarels } else 17032198Skarels i = 0; 17132198Skarels strcpy(pcs + i, "pcs750.bin"); 17217198Stef i = open(pcs, 0); 17317198Stef if (i < 0) 17417198Stef return; 17517198Stef /* 17617198Stef * We ask for more than we need to be sure we get only what we expect. 17717198Stef * After read: 17817198Stef * locs 0 - 1023 packed patchbits 17917198Stef * 1024 - 11264 packed microcode 18017198Stef */ 18117198Stef if (read(i, (char *)0, 23*512) != 22*512) { 18217198Stef printf("Error reading %s\n", pcs); 18317198Stef close(i); 18417198Stef return; 18517198Stef } 18617198Stef close(i); 18717198Stef 18817198Stef /* 18917198Stef * Enable patchbit loading and load the bits one at a time. 19017198Stef */ 19117198Stef *((int *)PCS_PATCHBIT) = 1; 19217198Stef ip = (int *)PCS_PATCHADDR; 19317198Stef jp = (int *)0; 19417198Stef for (i=0; i < PCS_BITCNT; i++) { 19517198Stef asm(" extzv r10,$1,(r9),(r11)+"); 19617198Stef } 19717198Stef *((int *)PCS_PATCHBIT) = 0; 19817198Stef 19917198Stef /* 20017198Stef * Load PCS microcode 20 bits at a time. 20117198Stef */ 20217198Stef ip = (int *)PCS_PCSADDR; 20317198Stef jp = (int *)1024; 20417198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 20517198Stef asm(" extzv r10,$20,(r9),(r11)+"); 20617198Stef } 20717198Stef 20817198Stef /* 20917198Stef * Enable PCS. 21017198Stef */ 21117198Stef i = *jp; /* get 1st 20 bits of microcode again */ 21217198Stef i &= 0xfffff; 21317198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 21417198Stef *((int *)PCS_PCSADDR) = i; 21517198Stef 21617198Stef sid.cpusid = mfpr(SID); 21717198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 21826503Skarels pcsdone = 1; 21917198Stef } 22033408Skarels #endif 221