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*30769Skarels * @(#)boot.c 7.3 (Berkeley) 04/02/87 723219Smckusick */ 8315Sbill 9*30769Skarels #include "param.h" 10*30769Skarels #include "inode.h" 11*30769Skarels #include "fs.h" 12*30769Skarels #include "vm.h" 13315Sbill #include <a.out.h> 14315Sbill #include "saio.h" 15*30769Skarels #include "reboot.h" 16315Sbill 171466Sbill /* 181466Sbill * Boot program... arguments passed in r10 and r11 determine 191466Sbill * whether boot stops to ask for system name and which device 201466Sbill * boot comes from. 211466Sbill */ 22315Sbill 2330547Skarels #define UNIX "/vmunix" 2425626Skarels char line[100]; 2524217Sbloom 263347Swnj int retry = 0; 2730547Skarels extern unsigned opendev; 283347Swnj 29315Sbill main() 30315Sbill { 3126828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */ 3230547Skarels int io, 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; 4330547Skarels if ((unsigned)type < ndevs && devsw[type].dv_name[0]) 4430547Skarels strcpy(line, UNIX); 4530547Skarels else 46*30769Skarels howto |= RB_SINGLE|RB_ASKNAME; 471466Sbill } 481575Sbill #endif 491466Sbill for (;;) { 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) { 6126503Skarels loadpcs(); 6230547Skarels copyunix(howto, opendev, io); 6325438Skarels close(io); 64*30769Skarels howto |= RB_SINGLE|RB_ASKNAME; 6517198Stef } 661466Sbill if (++retry > 2) 67*30769Skarels howto |= RB_SINGLE|RB_ASKNAME; 681466Sbill } 69315Sbill } 70315Sbill 713347Swnj /*ARGSUSED*/ 7226828Skarels copyunix(howto, devtype, io) 7326828Skarels register howto, devtype, io; /* howto=r11, devtype=r10 */ 74315Sbill { 75315Sbill struct exec x; 76315Sbill register int i; 77315Sbill char *addr; 78315Sbill 79315Sbill i = read(io, (char *)&x, sizeof x); 806069Smckusic if (i != sizeof x || 81*30769Skarels (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) { 82*30769Skarels printf("Bad format\n"); 83*30769Skarels return; 84*30769Skarels } 85315Sbill printf("%d", x.a_text); 867444Sroot if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -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; 916069Smckusic if (x.a_magic == 0413 || x.a_magic == 0410) 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; 101*30769Skarels if (howto & RB_KDB && x.a_syms) { 102*30769Skarels *(int *)addr = x.a_syms; /* symbol table size */ 103*30769Skarels addr += sizeof (int); 104*30769Skarels printf("[+%d", x.a_syms); 105*30769Skarels if (read(io, addr, x.a_syms) != x.a_syms) 106*30769Skarels goto shread; 107*30769Skarels addr += x.a_syms; 108*30769Skarels if (read(io, addr, sizeof (int)) != sizeof (int)) 109*30769Skarels goto shread; 110*30769Skarels i = *(int *)addr - sizeof (int); /* string table size */ 111*30769Skarels addr += sizeof (int); 112*30769Skarels printf("+%d]", i); 113*30769Skarels if (read(io, addr, i) != i) 114*30769Skarels goto shread; 115*30769Skarels addr += i; 116*30769Skarels esym = roundup((int)addr, sizeof (int)); 117*30769Skarels x.a_bss = 0; 118*30769Skarels } else 119*30769Skarels howto &= ~RB_KDB; 120*30769Skarels for (i = 0; i < 128*512; i++) /* slop */ 121*30769Skarels *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: 127*30769Skarels printf("Short read\n"); 128*30769Skarels return; 129315Sbill } 13017198Stef 13117198Stef /* 750 Patchable Control Store magic */ 13217198Stef 13317198Stef #include "../vax/mtpr.h" 13417198Stef #include "../vax/cpu.h" 13517198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 13617198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 13717198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 13817198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 13917198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 14017198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 14117198Stef 14217198Stef loadpcs() 14317198Stef { 14417198Stef register int *ip; /* known to be r11 below */ 14517198Stef register int i; /* known to be r10 below */ 14617198Stef register int *jp; /* known to be r9 below */ 14717198Stef register int j; 14826503Skarels static int pcsdone = 0; 14917198Stef union cpusid sid; 15017198Stef char pcs[100]; 15124217Sbloom char *closeparen; 15224217Sbloom char *index(); 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: "); 15824217Sbloom strncpy(pcs, line, 99); 15924217Sbloom pcs[99] = 0; 16024217Sbloom closeparen = index(pcs, ')'); 16124217Sbloom if (closeparen) 16224217Sbloom *(++closeparen) = 0; 16324217Sbloom else 16424217Sbloom return; 16517198Stef strcat(pcs, "pcs750.bin"); 16617198Stef i = open(pcs, 0); 16717198Stef if (i < 0) 16817198Stef return; 16917198Stef /* 17017198Stef * We ask for more than we need to be sure we get only what we expect. 17117198Stef * After read: 17217198Stef * locs 0 - 1023 packed patchbits 17317198Stef * 1024 - 11264 packed microcode 17417198Stef */ 17517198Stef if (read(i, (char *)0, 23*512) != 22*512) { 17617198Stef printf("Error reading %s\n", pcs); 17717198Stef close(i); 17817198Stef return; 17917198Stef } 18017198Stef close(i); 18117198Stef 18217198Stef /* 18317198Stef * Enable patchbit loading and load the bits one at a time. 18417198Stef */ 18517198Stef *((int *)PCS_PATCHBIT) = 1; 18617198Stef ip = (int *)PCS_PATCHADDR; 18717198Stef jp = (int *)0; 18817198Stef for (i=0; i < PCS_BITCNT; i++) { 18917198Stef asm(" extzv r10,$1,(r9),(r11)+"); 19017198Stef } 19117198Stef *((int *)PCS_PATCHBIT) = 0; 19217198Stef 19317198Stef /* 19417198Stef * Load PCS microcode 20 bits at a time. 19517198Stef */ 19617198Stef ip = (int *)PCS_PCSADDR; 19717198Stef jp = (int *)1024; 19817198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 19917198Stef asm(" extzv r10,$20,(r9),(r11)+"); 20017198Stef } 20117198Stef 20217198Stef /* 20317198Stef * Enable PCS. 20417198Stef */ 20517198Stef i = *jp; /* get 1st 20 bits of microcode again */ 20617198Stef i &= 0xfffff; 20717198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 20817198Stef *((int *)PCS_PCSADDR) = i; 20917198Stef 21017198Stef sid.cpusid = mfpr(SID); 21117198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 21226503Skarels pcsdone = 1; 21317198Stef } 214