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*45803Sbostic * @(#)boot.c 7.14 (Berkeley) 12/16/90 723219Smckusick */ 8315Sbill 9*45803Sbostic #include "sys/param.h" 10*45803Sbostic #include "sys/vm.h" 11*45803Sbostic #include "sys/reboot.h" 1233408Skarels 13315Sbill #include <a.out.h> 14*45803Sbostic #include "stand/saio.h" 15315Sbill 161466Sbill /* 171466Sbill * Boot program... arguments passed in r10 and r11 determine 181466Sbill * whether boot stops to ask for system name and which device 191466Sbill * boot comes from. 201466Sbill */ 21315Sbill 2225626Skarels char line[100]; 2324217Sbloom 2430547Skarels extern unsigned opendev; 253347Swnj 26315Sbill main() 27315Sbill { 2826828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */ 2937220Skarels int io = 0, retry, type; 30315Sbill 313274Swnj #ifdef lint 323274Swnj howto = 0; devtype = 0; 333274Swnj #endif 341575Sbill #ifdef JUSTASK 351593Sbill howto = RB_ASKNAME|RB_SINGLE; 361575Sbill #else 3726828Skarels if ((howto & RB_ASKNAME) == 0) { 3830547Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 3933408Skarels if ((unsigned)type < ndevs && devsw[type].dv_name) 4030547Skarels strcpy(line, UNIX); 4130547Skarels else 4230769Skarels howto |= RB_SINGLE|RB_ASKNAME; 431466Sbill } 441575Sbill #endif 4533522Sbostic for (retry = 0;;) { 4637220Skarels if (io >= 0) 4737220Skarels printf("\nBoot\n"); 481466Sbill if (howto & RB_ASKNAME) { 491466Sbill printf(": "); 501466Sbill gets(line); 5130547Skarels if (line[0] == 0) { 5230547Skarels strcpy(line, UNIX); 5330547Skarels printf(": %s\n", line); 5430547Skarels } 551466Sbill } else 561466Sbill printf(": %s\n", line); 571466Sbill io = open(line, 0); 5817198Stef if (io >= 0) { 5933408Skarels #ifdef VAX750 6026503Skarels loadpcs(); 6133408Skarels #endif 6230547Skarels copyunix(howto, opendev, io); 6325438Skarels close(io); 6430769Skarels howto |= RB_SINGLE|RB_ASKNAME; 6517198Stef } 661466Sbill if (++retry > 2) 6730769Skarels howto |= RB_SINGLE|RB_ASKNAME; 681466Sbill } 69315Sbill } 70315Sbill 713347Swnj /*ARGSUSED*/ 7230922Skarels copyunix(howto, devtype, aio) 7330922Skarels register howto, devtype; /* howto=r11, devtype=r10 */ 7430922Skarels int aio; 75315Sbill { 7630922Skarels register int esym; /* must be r9 */ 77315Sbill struct exec x; 7830922Skarels register int io = aio, i; 79315Sbill char *addr; 80315Sbill 8135479Sbostic if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) { 8237220Skarels printf("Bad format\n"); 8330769Skarels return; 8430769Skarels } 85315Sbill printf("%d", x.a_text); 8633433Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1) 876069Smckusic goto shread; 88315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 89315Sbill goto shread; 90315Sbill addr = (char *)x.a_text; 9133433Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 926069Smckusic while ((int)addr & CLOFSET) 936069Smckusic *addr++ = 0; 94315Sbill printf("+%d", x.a_data); 95315Sbill if (read(io, addr, x.a_data) != x.a_data) 96315Sbill goto shread; 97315Sbill addr += x.a_data; 98315Sbill printf("+%d", x.a_bss); 99315Sbill for (i = 0; i < x.a_bss; i++) 100315Sbill *addr++ = 0; 10130769Skarels if (howto & RB_KDB && x.a_syms) { 10230769Skarels *(int *)addr = x.a_syms; /* symbol table size */ 10330769Skarels addr += sizeof (int); 10430769Skarels printf("[+%d", x.a_syms); 10530769Skarels if (read(io, addr, x.a_syms) != x.a_syms) 10630769Skarels goto shread; 10730769Skarels addr += x.a_syms; 10830769Skarels if (read(io, addr, sizeof (int)) != sizeof (int)) 10930769Skarels goto shread; 11030769Skarels i = *(int *)addr - sizeof (int); /* string table size */ 11130769Skarels addr += sizeof (int); 11230769Skarels printf("+%d]", i); 11330769Skarels if (read(io, addr, i) != i) 11430769Skarels goto shread; 11530769Skarels addr += i; 11630769Skarels esym = roundup((int)addr, sizeof (int)); 11730769Skarels x.a_bss = 0; 11830769Skarels } else 11930769Skarels howto &= ~RB_KDB; 12030769Skarels for (i = 0; i < 128*512; i++) /* slop */ 12130769Skarels *addr++ = 0; 122315Sbill x.a_entry &= 0x7fffffff; 123315Sbill printf(" start 0x%x\n", x.a_entry); 124315Sbill (*((int (*)()) x.a_entry))(); 12525438Skarels return; 126315Sbill shread: 12730769Skarels printf("Short read\n"); 12830769Skarels return; 129315Sbill } 13017198Stef 13133408Skarels #ifdef VAX750 13217198Stef /* 750 Patchable Control Store magic */ 13317198Stef 134*45803Sbostic #include "../include/mtpr.h" 135*45803Sbostic #include "../include/cpu.h" 13617198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 13717198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 13817198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 13917198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 14017198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 14117198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 14217198Stef 14317198Stef loadpcs() 14417198Stef { 14517198Stef register int *ip; /* known to be r11 below */ 14617198Stef register int i; /* known to be r10 below */ 14717198Stef register int *jp; /* known to be r9 below */ 14817198Stef register int j; 14926503Skarels static int pcsdone = 0; 15017198Stef union cpusid sid; 15117198Stef char pcs[100]; 15232198Skarels char *cp; 15317198Stef 15417198Stef sid.cpusid = mfpr(SID); 15526503Skarels if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone) 15617198Stef return; 15717198Stef printf("Updating 11/750 microcode: "); 15832198Skarels for (cp = line; *cp; cp++) 15932198Skarels if (*cp == ')' || *cp == ':') 16032198Skarels break; 16132198Skarels if (*cp) { 16232198Skarels strncpy(pcs, line, 99); 16332198Skarels pcs[99] = 0; 16432198Skarels i = cp - line + 1; 16532198Skarels } else 16632198Skarels i = 0; 16732198Skarels strcpy(pcs + i, "pcs750.bin"); 16817198Stef i = open(pcs, 0); 16917198Stef if (i < 0) 17017198Stef return; 17117198Stef /* 17217198Stef * We ask for more than we need to be sure we get only what we expect. 17317198Stef * After read: 17417198Stef * locs 0 - 1023 packed patchbits 17517198Stef * 1024 - 11264 packed microcode 17617198Stef */ 17717198Stef if (read(i, (char *)0, 23*512) != 22*512) { 17817198Stef printf("Error reading %s\n", pcs); 17917198Stef close(i); 18017198Stef return; 18117198Stef } 18217198Stef close(i); 18317198Stef 18417198Stef /* 18517198Stef * Enable patchbit loading and load the bits one at a time. 18617198Stef */ 18717198Stef *((int *)PCS_PATCHBIT) = 1; 18817198Stef ip = (int *)PCS_PATCHADDR; 18917198Stef jp = (int *)0; 19017198Stef for (i=0; i < PCS_BITCNT; i++) { 19117198Stef asm(" extzv r10,$1,(r9),(r11)+"); 19217198Stef } 19317198Stef *((int *)PCS_PATCHBIT) = 0; 19417198Stef 19517198Stef /* 19617198Stef * Load PCS microcode 20 bits at a time. 19717198Stef */ 19817198Stef ip = (int *)PCS_PCSADDR; 19917198Stef jp = (int *)1024; 20017198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 20117198Stef asm(" extzv r10,$20,(r9),(r11)+"); 20217198Stef } 20317198Stef 20417198Stef /* 20517198Stef * Enable PCS. 20617198Stef */ 20717198Stef i = *jp; /* get 1st 20 bits of microcode again */ 20817198Stef i &= 0xfffff; 20917198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 21017198Stef *((int *)PCS_PCSADDR) = i; 21117198Stef 21217198Stef sid.cpusid = mfpr(SID); 21317198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 21426503Skarels pcsdone = 1; 21517198Stef } 21633408Skarels #endif 217