123219Smckusick /* 223219Smckusick * Copyright (c) 1982 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*25438Skarels * @(#)boot.c 6.5 (Berkeley) 11/08/85 723219Smckusick */ 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 4224217Sbloom /* 4324217Sbloom * constants for converting a "minor" device numbers to unit number 4424217Sbloom * and partition number 4524217Sbloom */ 4624217Sbloom #define UNITSHIFT 16 4724217Sbloom #define UNITMASK 0x1ff 4824217Sbloom #define PARTITIONMASK 0x7 4924217Sbloom #define PARTITIONSHIFT 3 501466Sbill 5124217Sbloom char line[100] = "xx(00,0)vmunix"; 5224217Sbloom 533347Swnj int retry = 0; 543347Swnj 55315Sbill main() 56315Sbill { 571466Sbill register howto, devtype; /* howto=r11, devtype=r10 */ 583347Swnj int io; 5924217Sbloom register type, part, unit; 60315Sbill 613274Swnj #ifdef lint 623274Swnj howto = 0; devtype = 0; 633274Swnj #endif 64*25438Skarels printf("Boot\n"); 65*25438Skarels loadpcs(); 661575Sbill #ifdef JUSTASK 671593Sbill howto = RB_ASKNAME|RB_SINGLE; 681575Sbill #else 6924217Sbloom type = devtype & 0xff; 7024217Sbloom unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK; 7124217Sbloom part = unit & PARTITIONMASK; 7224217Sbloom unit = unit >> PARTITIONSHIFT; 731466Sbill if ((howto&RB_ASKNAME)==0) { 7424217Sbloom if (type >= 0 && type < sizeof(devname) / 2 7524217Sbloom && devname[type][0]) { 7624217Sbloom line[0] = devname[type][0]; 7724217Sbloom line[1] = devname[type][1]; 7824217Sbloom line[3] = unit / 10 + '0'; 7924217Sbloom line[4] = unit % 10 + '0'; 8024217Sbloom line[6] = part + '0'; 813261Swnj } else 821466Sbill howto = RB_SINGLE|RB_ASKNAME; 831466Sbill } 841575Sbill #endif 851466Sbill for (;;) { 861466Sbill if (howto & RB_ASKNAME) { 871466Sbill printf(": "); 881466Sbill gets(line); 891466Sbill } else 901466Sbill printf(": %s\n", line); 911466Sbill io = open(line, 0); 9217198Stef if (io >= 0) { 933347Swnj copyunix(howto, io); 94*25438Skarels close(io); 95*25438Skarels howto = RB_SINGLE|RB_ASKNAME; 9617198Stef } 971466Sbill if (++retry > 2) 981466Sbill howto = RB_SINGLE|RB_ASKNAME; 991466Sbill } 100315Sbill } 101315Sbill 1023347Swnj /*ARGSUSED*/ 1033347Swnj copyunix(howto, io) 1043347Swnj register howto, io; 105315Sbill { 106315Sbill struct exec x; 107315Sbill register int i; 108315Sbill char *addr; 109315Sbill 110315Sbill i = read(io, (char *)&x, sizeof x); 1116069Smckusic if (i != sizeof x || 1126069Smckusic (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 113315Sbill _stop("Bad format\n"); 114315Sbill printf("%d", x.a_text); 1157444Sroot if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) 1166069Smckusic goto shread; 117315Sbill if (read(io, (char *)0, x.a_text) != x.a_text) 118315Sbill goto shread; 119315Sbill addr = (char *)x.a_text; 1206069Smckusic if (x.a_magic == 0413 || x.a_magic == 0410) 1216069Smckusic while ((int)addr & CLOFSET) 1226069Smckusic *addr++ = 0; 123315Sbill printf("+%d", x.a_data); 124315Sbill if (read(io, addr, x.a_data) != x.a_data) 125315Sbill goto shread; 126315Sbill addr += x.a_data; 127315Sbill printf("+%d", x.a_bss); 128315Sbill x.a_bss += 128*512; /* slop */ 129315Sbill for (i = 0; i < x.a_bss; i++) 130315Sbill *addr++ = 0; 131315Sbill x.a_entry &= 0x7fffffff; 132315Sbill printf(" start 0x%x\n", x.a_entry); 133315Sbill (*((int (*)()) x.a_entry))(); 134*25438Skarels return; 135315Sbill shread: 136315Sbill _stop("Short read\n"); 137315Sbill } 13817198Stef 13917198Stef /* 750 Patchable Control Store magic */ 14017198Stef 14117198Stef #include "../vax/mtpr.h" 14217198Stef #include "../vax/cpu.h" 14317198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */ 14417198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */ 14517198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 14617198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 14717198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 14817198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 14917198Stef 15017198Stef loadpcs() 15117198Stef { 15217198Stef register int *ip; /* known to be r11 below */ 15317198Stef register int i; /* known to be r10 below */ 15417198Stef register int *jp; /* known to be r9 below */ 15517198Stef register int j; 15617198Stef union cpusid sid; 15717198Stef char pcs[100]; 15824217Sbloom char *closeparen; 15924217Sbloom char *index(); 16017198Stef 16117198Stef sid.cpusid = mfpr(SID); 162*25438Skarels if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95) 16317198Stef return; 16417198Stef printf("Updating 11/750 microcode: "); 16524217Sbloom strncpy(pcs, line, 99); 16624217Sbloom pcs[99] = 0; 16724217Sbloom closeparen = index(pcs, ')'); 16824217Sbloom if (closeparen) 16924217Sbloom *(++closeparen) = 0; 17024217Sbloom else 17124217Sbloom return; 17217198Stef strcat(pcs, "pcs750.bin"); 17317198Stef i = open(pcs, 0); 17417198Stef if (i < 0) 17517198Stef return; 17617198Stef /* 17717198Stef * We ask for more than we need to be sure we get only what we expect. 17817198Stef * After read: 17917198Stef * locs 0 - 1023 packed patchbits 18017198Stef * 1024 - 11264 packed microcode 18117198Stef */ 18217198Stef if (read(i, (char *)0, 23*512) != 22*512) { 18317198Stef printf("Error reading %s\n", pcs); 18417198Stef close(i); 18517198Stef return; 18617198Stef } 18717198Stef close(i); 18817198Stef 18917198Stef /* 19017198Stef * Enable patchbit loading and load the bits one at a time. 19117198Stef */ 19217198Stef *((int *)PCS_PATCHBIT) = 1; 19317198Stef ip = (int *)PCS_PATCHADDR; 19417198Stef jp = (int *)0; 19517198Stef for (i=0; i < PCS_BITCNT; i++) { 19617198Stef asm(" extzv r10,$1,(r9),(r11)+"); 19717198Stef } 19817198Stef *((int *)PCS_PATCHBIT) = 0; 19917198Stef 20017198Stef /* 20117198Stef * Load PCS microcode 20 bits at a time. 20217198Stef */ 20317198Stef ip = (int *)PCS_PCSADDR; 20417198Stef jp = (int *)1024; 20517198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 20617198Stef asm(" extzv r10,$20,(r9),(r11)+"); 20717198Stef } 20817198Stef 20917198Stef /* 21017198Stef * Enable PCS. 21117198Stef */ 21217198Stef i = *jp; /* get 1st 20 bits of microcode again */ 21317198Stef i &= 0xfffff; 21417198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 21517198Stef *((int *)PCS_PCSADDR) = i; 21617198Stef 21717198Stef sid.cpusid = mfpr(SID); 21817198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev); 21917198Stef } 220