1 /* 2 * Copyright (c) 1982 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)boot.c 6.3 (Berkeley) 06/08/85 7 */ 8 9 #include "../h/param.h" 10 #include "../h/inode.h" 11 #include "../h/fs.h" 12 #include "../h/vm.h" 13 #include <a.out.h> 14 #include "saio.h" 15 #include "../h/reboot.h" 16 17 /* 18 * Boot program... arguments passed in r10 and r11 determine 19 * whether boot stops to ask for system name and which device 20 * boot comes from. 21 */ 22 23 /* Types in r10 specifying major device */ 24 char devname[][2] = { 25 'h','p', /* 0 = hp */ 26 0,0, /* 1 = ht */ 27 'u','p', /* 2 = up */ 28 'h','k', /* 3 = hk */ 29 0,0, /* 4 = sw */ 30 0,0, /* 5 = tm */ 31 0,0, /* 6 = ts */ 32 0,0, /* 7 = mt */ 33 0,0, /* 8 = tu */ 34 'r','a', /* 9 = ra */ 35 'u','t', /* 10 = ut */ 36 'r','b', /* 11 = rb */ 37 0,0, /* 12 = uu */ 38 0,0, /* 13 = rx */ 39 'r','l', /* 14 = rl */ 40 }; 41 42 char line[100] = "xx(0,0)vmunix"; 43 44 int retry = 0; 45 46 main() 47 { 48 register howto, devtype; /* howto=r11, devtype=r10 */ 49 int io; 50 51 #ifdef lint 52 howto = 0; devtype = 0; 53 #endif 54 printf("\nBoot\n"); 55 #ifdef JUSTASK 56 howto = RB_ASKNAME|RB_SINGLE; 57 #else 58 if ((howto&RB_ASKNAME)==0) { 59 if (devtype>=0 && devtype<sizeof(devname)/2 60 && devname[devtype][0]) { 61 line[0] = devname[devtype][0]; 62 line[1] = devname[devtype][1]; 63 } else 64 howto = RB_SINGLE|RB_ASKNAME; 65 } 66 #endif 67 for (;;) { 68 if (howto & RB_ASKNAME) { 69 printf(": "); 70 gets(line); 71 } else 72 printf(": %s\n", line); 73 io = open(line, 0); 74 if (io >= 0) { 75 loadpcs(); 76 copyunix(howto, io); 77 } 78 if (++retry > 2) 79 howto = RB_SINGLE|RB_ASKNAME; 80 } 81 } 82 83 /*ARGSUSED*/ 84 copyunix(howto, io) 85 register howto, io; 86 { 87 struct exec x; 88 register int i; 89 char *addr; 90 91 i = read(io, (char *)&x, sizeof x); 92 if (i != sizeof x || 93 (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 94 _stop("Bad format\n"); 95 printf("%d", x.a_text); 96 if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) 97 goto shread; 98 if (read(io, (char *)0, x.a_text) != x.a_text) 99 goto shread; 100 addr = (char *)x.a_text; 101 if (x.a_magic == 0413 || x.a_magic == 0410) 102 while ((int)addr & CLOFSET) 103 *addr++ = 0; 104 printf("+%d", x.a_data); 105 if (read(io, addr, x.a_data) != x.a_data) 106 goto shread; 107 addr += x.a_data; 108 printf("+%d", x.a_bss); 109 x.a_bss += 128*512; /* slop */ 110 for (i = 0; i < x.a_bss; i++) 111 *addr++ = 0; 112 x.a_entry &= 0x7fffffff; 113 printf(" start 0x%x\n", x.a_entry); 114 (*((int (*)()) x.a_entry))(); 115 _exit(); 116 shread: 117 _stop("Short read\n"); 118 } 119 120 /* 750 Patchable Control Store magic */ 121 122 #include "../vax/mtpr.h" 123 #include "../vax/cpu.h" 124 #define PCS_BITCNT 0x2000 /* number of patchbits */ 125 #define PCS_MICRONUM 0x400 /* number of ucode locs */ 126 #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */ 127 #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */ 128 #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */ 129 #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */ 130 131 loadpcs() 132 { 133 register int *ip; /* known to be r11 below */ 134 register int i; /* known to be r10 below */ 135 register int *jp; /* known to be r9 below */ 136 register int j; 137 static int pcsdone = 0; 138 union cpusid sid; 139 char pcs[100]; 140 141 sid.cpusid = mfpr(SID); 142 if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone) 143 return; 144 printf("Updating 11/750 microcode: "); 145 strncpy(pcs, line, strlen("xx(0,0)")); 146 strcat(pcs, "pcs750.bin"); 147 i = open(pcs, 0); 148 if (i < 0) 149 return; 150 /* 151 * We ask for more than we need to be sure we get only what we expect. 152 * After read: 153 * locs 0 - 1023 packed patchbits 154 * 1024 - 11264 packed microcode 155 */ 156 if (read(i, (char *)0, 23*512) != 22*512) { 157 printf("Error reading %s\n", pcs); 158 close(i); 159 return; 160 } 161 close(i); 162 163 /* 164 * Enable patchbit loading and load the bits one at a time. 165 */ 166 *((int *)PCS_PATCHBIT) = 1; 167 ip = (int *)PCS_PATCHADDR; 168 jp = (int *)0; 169 for (i=0; i < PCS_BITCNT; i++) { 170 asm(" extzv r10,$1,(r9),(r11)+"); 171 } 172 *((int *)PCS_PATCHBIT) = 0; 173 174 /* 175 * Load PCS microcode 20 bits at a time. 176 */ 177 ip = (int *)PCS_PCSADDR; 178 jp = (int *)1024; 179 for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) { 180 asm(" extzv r10,$20,(r9),(r11)+"); 181 } 182 183 /* 184 * Enable PCS. 185 */ 186 i = *jp; /* get 1st 20 bits of microcode again */ 187 i &= 0xfffff; 188 i |= PCS_ENABLE; /* reload these bits with PCS enable set */ 189 *((int *)PCS_PCSADDR) = i; 190 191 sid.cpusid = mfpr(SID); 192 printf("new rev level=%d\n", sid.cpu750.cp_urev); 193 pcsdone = 1; 194 } 195