1*23219Smckusick /* 2*23219Smckusick * Copyright (c) 1982 Regents of the University of California. 3*23219Smckusick * All rights reserved. The Berkeley software License Agreement 4*23219Smckusick * specifies the terms and conditions for redistribution. 5*23219Smckusick * 6*23219Smckusick * @(#)boot.c 6.3 (Berkeley) 06/08/85 7*23219Smckusick */ 8315Sbill 9315Sbill #include "../h/param.h" 10315Sbill #include "../h/inode.h" 116069Smckusic #include "../h/fs.h" 12315Sbill #include "../h/vm.h" 13315Sbill #include <a.out.h> 14315Sbill #include "saio.h" 156069Smckusic #include "../h/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 231466Sbill /* Types in r10 specifying major device */ 241466Sbill char devname[][2] = { 251466Sbill 'h','p', /* 0 = hp */ 261466Sbill 0,0, /* 1 = ht */ 271466Sbill 'u','p', /* 2 = up */ 283261Swnj 'h','k', /* 3 = hk */ 294868Sroot 0,0, /* 4 = sw */ 304868Sroot 0,0, /* 5 = tm */ 314868Sroot 0,0, /* 6 = ts */ 324868Sroot 0,0, /* 7 = mt */ 334868Sroot 0,0, /* 8 = tu */ 344868Sroot 'r','a', /* 9 = ra */ 3511886Sleres 'u','t', /* 10 = ut */ 3611886Sleres 'r','b', /* 11 = rb */ 3713163Ssam 0,0, /* 12 = uu */ 3813163Ssam 0,0, /* 13 = rx */ 3913163Ssam 'r','l', /* 14 = rl */ 401466Sbill }; 411466Sbill 421466Sbill char line[100] = "xx(0,0)vmunix"; 431466Sbill 443347Swnj int retry = 0; 453347Swnj 46315Sbill main() 47315Sbill { 481466Sbill register howto, devtype; /* howto=r11, devtype=r10 */ 493347Swnj int io; 50315Sbill 513274Swnj #ifdef lint 523274Swnj howto = 0; devtype = 0; 533274Swnj #endif 54315Sbill printf("\nBoot\n"); 551575Sbill #ifdef JUSTASK 561593Sbill howto = RB_ASKNAME|RB_SINGLE; 571575Sbill #else 581466Sbill if ((howto&RB_ASKNAME)==0) { 591466Sbill if (devtype>=0 && devtype<sizeof(devname)/2 601466Sbill && devname[devtype][0]) { 611466Sbill line[0] = devname[devtype][0]; 621466Sbill line[1] = devname[devtype][1]; 633261Swnj } else 641466Sbill howto = RB_SINGLE|RB_ASKNAME; 651466Sbill } 661575Sbill #endif 671466Sbill for (;;) { 681466Sbill if (howto & RB_ASKNAME) { 691466Sbill printf(": "); 701466Sbill gets(line); 711466Sbill } else 721466Sbill printf(": %s\n", line); 731466Sbill io = open(line, 0); 7417198Stef if (io >= 0) { 7517198Stef loadpcs(); 763347Swnj copyunix(howto, io); 7717198Stef } 781466Sbill if (++retry > 2) 791466Sbill howto = RB_SINGLE|RB_ASKNAME; 801466Sbill } 81315Sbill } 82315Sbill 833347Swnj /*ARGSUSED*/ 843347Swnj copyunix(howto, io) 853347Swnj register howto, io; 86315Sbill { 87315Sbill struct exec x; 88315Sbill register int i; 89315Sbill char *addr; 90315Sbill 91315Sbill i = read(io, (char *)&x, sizeof x); 926069Smckusic if (i != sizeof x || 936069Smckusic (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 94315Sbill _stop("Bad format\n"); 95315Sbill printf("%d", x.a_text); 967444Sroot if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) 976069Smckusic goto shread; 98315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 99315Sbill goto shread; 100315Sbill addr = (char *)x.a_text; 1016069Smckusic if (x.a_magic == 0413 || x.a_magic == 0410) 1026069Smckusic while ((int)addr & CLOFSET) 1036069Smckusic *addr++ = 0; 104315Sbill printf("+%d", x.a_data); 105315Sbill if (read(io, addr, x.a_data) != x.a_data) 106315Sbill goto shread; 107315Sbill addr += x.a_data; 108315Sbill printf("+%d", x.a_bss); 109315Sbill x.a_bss += 128*512; /* slop */ 110315Sbill for (i = 0; i < x.a_bss; i++) 111315Sbill *addr++ = 0; 112315Sbill x.a_entry &= 0x7fffffff; 113315Sbill printf(" start 0x%x\n", x.a_entry); 114315Sbill (*((int (*)()) x.a_entry))(); 115315Sbill _exit(); 116315Sbill shread: 117315Sbill _stop("Short read\n"); 118315Sbill } 11917198Stef 12017198Stef /* 750 Patchable Control Store magic */ 12117198Stef 12217198Stef #include "../vax/mtpr.h" 12317198Stef #include "../vax/cpu.h" 12417198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 12517198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 12617198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 12717198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 12817198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 12917198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 13017198Stef 13117198Stef loadpcs() 13217198Stef { 13317198Stef register int *ip; /* known to be r11 below */ 13417198Stef register int i; /* known to be r10 below */ 13517198Stef register int *jp; /* known to be r9 below */ 13617198Stef register int j; 13717198Stef static int pcsdone = 0; 13817198Stef union cpusid sid; 13917198Stef char pcs[100]; 14017198Stef 14117198Stef sid.cpusid = mfpr(SID); 14217198Stef if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone) 14317198Stef return; 14417198Stef printf("Updating 11/750 microcode: "); 14517198Stef strncpy(pcs, line, strlen("xx(0,0)")); 14617198Stef strcat(pcs, "pcs750.bin"); 14717198Stef i = open(pcs, 0); 14817198Stef if (i < 0) 14917198Stef return; 15017198Stef /* 15117198Stef * We ask for more than we need to be sure we get only what we expect. 15217198Stef * After read: 15317198Stef * locs 0 - 1023 packed patchbits 15417198Stef * 1024 - 11264 packed microcode 15517198Stef */ 15617198Stef if (read(i, (char *)0, 23*512) != 22*512) { 15717198Stef printf("Error reading %s\n", pcs); 15817198Stef close(i); 15917198Stef return; 16017198Stef } 16117198Stef close(i); 16217198Stef 16317198Stef /* 16417198Stef * Enable patchbit loading and load the bits one at a time. 16517198Stef */ 16617198Stef *((int *)PCS_PATCHBIT) = 1; 16717198Stef ip = (int *)PCS_PATCHADDR; 16817198Stef jp = (int *)0; 16917198Stef for (i=0; i < PCS_BITCNT; i++) { 17017198Stef asm(" extzv r10,$1,(r9),(r11)+"); 17117198Stef } 17217198Stef *((int *)PCS_PATCHBIT) = 0; 17317198Stef 17417198Stef /* 17517198Stef * Load PCS microcode 20 bits at a time. 17617198Stef */ 17717198Stef ip = (int *)PCS_PCSADDR; 17817198Stef jp = (int *)1024; 17917198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 18017198Stef asm(" extzv r10,$20,(r9),(r11)+"); 18117198Stef } 18217198Stef 18317198Stef /* 18417198Stef * Enable PCS. 18517198Stef */ 18617198Stef i = *jp; /* get 1st 20 bits of microcode again */ 18717198Stef i &= 0xfffff; 18817198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 18917198Stef *((int *)PCS_PCSADDR) = i; 19017198Stef 19117198Stef sid.cpusid = mfpr(SID); 19217198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 19317198Stef pcsdone = 1; 19417198Stef } 195