1*49112Sbostic /*-
2*49112Sbostic * Copyright (c) 1982, 1986 The Regents of the University of California.
3*49112Sbostic * All rights reserved.
423219Smckusick *
5*49112Sbostic * %sccs.include.redist.c%
6*49112Sbostic *
7*49112Sbostic * @(#)boot.c 7.15 (Berkeley) 05/04/91
823219Smckusick */
9315Sbill
1045803Sbostic #include "sys/param.h"
1145803Sbostic #include "sys/vm.h"
1245803Sbostic #include "sys/reboot.h"
1333408Skarels
14315Sbill #include <a.out.h>
1545803Sbostic #include "stand/saio.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
2325626Skarels char line[100];
2424217Sbloom
2530547Skarels extern unsigned opendev;
263347Swnj
main()27315Sbill main()
28315Sbill {
2926828Skarels register unsigned howto, devtype; /* howto=r11, devtype=r10 */
3037220Skarels int io = 0, retry, type;
31315Sbill
323274Swnj #ifdef lint
333274Swnj howto = 0; devtype = 0;
343274Swnj #endif
351575Sbill #ifdef JUSTASK
361593Sbill howto = RB_ASKNAME|RB_SINGLE;
371575Sbill #else
3826828Skarels if ((howto & RB_ASKNAME) == 0) {
3930547Skarels type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
4033408Skarels if ((unsigned)type < ndevs && devsw[type].dv_name)
4130547Skarels strcpy(line, UNIX);
4230547Skarels else
4330769Skarels howto |= RB_SINGLE|RB_ASKNAME;
441466Sbill }
451575Sbill #endif
4633522Sbostic for (retry = 0;;) {
4737220Skarels if (io >= 0)
4837220Skarels printf("\nBoot\n");
491466Sbill if (howto & RB_ASKNAME) {
501466Sbill printf(": ");
511466Sbill gets(line);
5230547Skarels if (line[0] == 0) {
5330547Skarels strcpy(line, UNIX);
5430547Skarels printf(": %s\n", line);
5530547Skarels }
561466Sbill } else
571466Sbill printf(": %s\n", line);
581466Sbill io = open(line, 0);
5917198Stef if (io >= 0) {
6033408Skarels #ifdef VAX750
6126503Skarels loadpcs();
6233408Skarels #endif
6330547Skarels copyunix(howto, opendev, io);
6425438Skarels close(io);
6530769Skarels howto |= RB_SINGLE|RB_ASKNAME;
6617198Stef }
671466Sbill if (++retry > 2)
6830769Skarels howto |= RB_SINGLE|RB_ASKNAME;
691466Sbill }
70315Sbill }
71315Sbill
723347Swnj /*ARGSUSED*/
copyunix(howto,devtype,aio)7330922Skarels copyunix(howto, devtype, aio)
7430922Skarels register howto, devtype; /* howto=r11, devtype=r10 */
7530922Skarels int aio;
76315Sbill {
7730922Skarels register int esym; /* must be r9 */
78315Sbill struct exec x;
7930922Skarels register int io = aio, i;
80315Sbill char *addr;
81315Sbill
8235479Sbostic if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
8337220Skarels printf("Bad format\n");
8430769Skarels return;
8530769Skarels }
86315Sbill printf("%d", x.a_text);
8733433Sbostic if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1)
886069Smckusic goto shread;
89315Sbill if (read(io, (char *)0, x.a_text) != x.a_text)
90315Sbill goto shread;
91315Sbill addr = (char *)x.a_text;
9233433Sbostic if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
936069Smckusic while ((int)addr & CLOFSET)
946069Smckusic *addr++ = 0;
95315Sbill printf("+%d", x.a_data);
96315Sbill if (read(io, addr, x.a_data) != x.a_data)
97315Sbill goto shread;
98315Sbill addr += x.a_data;
99315Sbill printf("+%d", x.a_bss);
100315Sbill for (i = 0; i < x.a_bss; i++)
101315Sbill *addr++ = 0;
10230769Skarels if (howto & RB_KDB && x.a_syms) {
10330769Skarels *(int *)addr = x.a_syms; /* symbol table size */
10430769Skarels addr += sizeof (int);
10530769Skarels printf("[+%d", x.a_syms);
10630769Skarels if (read(io, addr, x.a_syms) != x.a_syms)
10730769Skarels goto shread;
10830769Skarels addr += x.a_syms;
10930769Skarels if (read(io, addr, sizeof (int)) != sizeof (int))
11030769Skarels goto shread;
11130769Skarels i = *(int *)addr - sizeof (int); /* string table size */
11230769Skarels addr += sizeof (int);
11330769Skarels printf("+%d]", i);
11430769Skarels if (read(io, addr, i) != i)
11530769Skarels goto shread;
11630769Skarels addr += i;
11730769Skarels esym = roundup((int)addr, sizeof (int));
11830769Skarels x.a_bss = 0;
11930769Skarels } else
12030769Skarels howto &= ~RB_KDB;
12130769Skarels for (i = 0; i < 128*512; i++) /* slop */
12230769Skarels *addr++ = 0;
123315Sbill x.a_entry &= 0x7fffffff;
124315Sbill printf(" start 0x%x\n", x.a_entry);
125315Sbill (*((int (*)()) x.a_entry))();
12625438Skarels return;
127315Sbill shread:
12830769Skarels printf("Short read\n");
12930769Skarels return;
130315Sbill }
13117198Stef
13233408Skarels #ifdef VAX750
13317198Stef /* 750 Patchable Control Store magic */
13417198Stef
13545803Sbostic #include "../include/mtpr.h"
13645803Sbostic #include "../include/cpu.h"
13717198Stef #define PCS_BITCNT 0x2000 /* number of patchbits */
13817198Stef #define PCS_MICRONUM 0x400 /* number of ucode locs */
13917198Stef #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */
14017198Stef #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */
14117198Stef #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */
14217198Stef #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */
14317198Stef
loadpcs()14417198Stef loadpcs()
14517198Stef {
14617198Stef register int *ip; /* known to be r11 below */
14717198Stef register int i; /* known to be r10 below */
14817198Stef register int *jp; /* known to be r9 below */
14917198Stef register int j;
15026503Skarels static int pcsdone = 0;
15117198Stef union cpusid sid;
15217198Stef char pcs[100];
15332198Skarels char *cp;
15417198Stef
15517198Stef sid.cpusid = mfpr(SID);
15626503Skarels if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
15717198Stef return;
15817198Stef printf("Updating 11/750 microcode: ");
15932198Skarels for (cp = line; *cp; cp++)
16032198Skarels if (*cp == ')' || *cp == ':')
16132198Skarels break;
16232198Skarels if (*cp) {
16332198Skarels strncpy(pcs, line, 99);
16432198Skarels pcs[99] = 0;
16532198Skarels i = cp - line + 1;
16632198Skarels } else
16732198Skarels i = 0;
16832198Skarels strcpy(pcs + i, "pcs750.bin");
16917198Stef i = open(pcs, 0);
17017198Stef if (i < 0)
17117198Stef return;
17217198Stef /*
17317198Stef * We ask for more than we need to be sure we get only what we expect.
17417198Stef * After read:
17517198Stef * locs 0 - 1023 packed patchbits
17617198Stef * 1024 - 11264 packed microcode
17717198Stef */
17817198Stef if (read(i, (char *)0, 23*512) != 22*512) {
17917198Stef printf("Error reading %s\n", pcs);
18017198Stef close(i);
18117198Stef return;
18217198Stef }
18317198Stef close(i);
18417198Stef
18517198Stef /*
18617198Stef * Enable patchbit loading and load the bits one at a time.
18717198Stef */
18817198Stef *((int *)PCS_PATCHBIT) = 1;
18917198Stef ip = (int *)PCS_PATCHADDR;
19017198Stef jp = (int *)0;
19117198Stef for (i=0; i < PCS_BITCNT; i++) {
19217198Stef asm(" extzv r10,$1,(r9),(r11)+");
19317198Stef }
19417198Stef *((int *)PCS_PATCHBIT) = 0;
19517198Stef
19617198Stef /*
19717198Stef * Load PCS microcode 20 bits at a time.
19817198Stef */
19917198Stef ip = (int *)PCS_PCSADDR;
20017198Stef jp = (int *)1024;
20117198Stef for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
20217198Stef asm(" extzv r10,$20,(r9),(r11)+");
20317198Stef }
20417198Stef
20517198Stef /*
20617198Stef * Enable PCS.
20717198Stef */
20817198Stef i = *jp; /* get 1st 20 bits of microcode again */
20917198Stef i &= 0xfffff;
21017198Stef i |= PCS_ENABLE; /* reload these bits with PCS enable set */
21117198Stef *((int *)PCS_PCSADDR) = i;
21217198Stef
21317198Stef sid.cpusid = mfpr(SID);
21417198Stef printf("new rev level=%d\n", sid.cpu750.cp_urev);
21526503Skarels pcsdone = 1;
21617198Stef }
21733408Skarels #endif
218