diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-05-04 16:11:48 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-05-04 16:11:48 +0200 |
commit | 986886f2b8ab4a7e1b3d66e99934d8fdab537be9 (patch) | |
tree | c49e9711e7229a8d12f5b5b0ab38b5bd6c27b711 /sys/src/boot | |
parent | f7703d6971383c39f981f5676a4e28a6371c3997 (diff) |
retire the dec alpha port
Diffstat (limited to 'sys/src/boot')
-rw-r--r-- | sys/src/boot/alphapc/bootp.c | 556 | ||||
-rw-r--r-- | sys/src/boot/alphapc/conf.c | 75 | ||||
-rw-r--r-- | sys/src/boot/alphapc/conf.h | 20 | ||||
-rw-r--r-- | sys/src/boot/alphapc/cons.c | 243 | ||||
-rw-r--r-- | sys/src/boot/alphapc/dat.h | 169 | ||||
-rw-r--r-- | sys/src/boot/alphapc/exec.c | 40 | ||||
-rw-r--r-- | sys/src/boot/alphapc/fns.h | 37 | ||||
-rw-r--r-- | sys/src/boot/alphapc/ip.h | 98 | ||||
-rw-r--r-- | sys/src/boot/alphapc/l.s | 101 | ||||
-rw-r--r-- | sys/src/boot/alphapc/lib.h | 134 | ||||
-rw-r--r-- | sys/src/boot/alphapc/main.c | 25 | ||||
-rw-r--r-- | sys/src/boot/alphapc/mem.h | 15 | ||||
-rw-r--r-- | sys/src/boot/alphapc/memory.c | 108 | ||||
-rw-r--r-- | sys/src/boot/alphapc/mkfile | 42 | ||||
-rw-r--r-- | sys/src/boot/alphapc/mmu.c | 111 | ||||
-rw-r--r-- | sys/src/boot/alphapc/print.c | 575 | ||||
-rw-r--r-- | sys/src/boot/alphapc/u.h | 28 | ||||
-rw-r--r-- | sys/src/boot/alphapc/vmspal.h | 105 | ||||
-rw-r--r-- | sys/src/boot/mkfile | 3 |
19 files changed, 2 insertions, 2483 deletions
diff --git a/sys/src/boot/alphapc/bootp.c b/sys/src/boot/alphapc/bootp.c deleted file mode 100644 index 6a5bdabac..000000000 --- a/sys/src/boot/alphapc/bootp.c +++ /dev/null @@ -1,556 +0,0 @@ -#include "u.h" -#include "lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" - -#include "ip.h" - -uchar broadcast[Eaddrlen] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; - -static ushort tftpport = 5000; -static int Id = 1; -static Netaddr myaddr; -static Netaddr server; - -typedef struct { - uchar header[4]; - uchar data[Segsize]; -} Tftp; -static Tftp tftpb; - -int -etherrxpkt(int ctlrno, Etherpkt *pkt, int timo) -{ - int n; - - for (;;) { - n = devread(ctlrno, (uchar*)pkt, sizeof(*pkt), 0); - if (n >= 0) - return n; - if (timo-- < 0) - return -1; - } -} - -int -ethertxpkt(int ctlrno, Etherpkt *pkt, int len, int timo) -{ - USED(timo); - return devwrite(ctlrno, (uchar*)pkt, len, 0); -} - -static void -hnputs(uchar *ptr, ushort val) -{ - ptr[0] = val>>8; - ptr[1] = val; -} - -static void -hnputl(uchar *ptr, ulong val) -{ - ptr[0] = val>>24; - ptr[1] = val>>16; - ptr[2] = val>>8; - ptr[3] = val; -} - -static ulong -nhgetl(uchar *ptr) -{ - return ((ptr[0]<<24) | (ptr[1]<<16) | (ptr[2]<<8) | ptr[3]); -} - -static ushort -nhgets(uchar *ptr) -{ - return ((ptr[0]<<8) | ptr[1]); -} - -static short endian = 1; -static char* aendian = (char*)&endian; -#define LITTLE *aendian - -static ushort -ptcl_csum(void *a, int len) -{ - uchar *addr; - ulong t1, t2; - ulong losum, hisum, mdsum, x; - - addr = a; - losum = 0; - hisum = 0; - mdsum = 0; - - x = 0; - if((ulong)addr & 1) { - if(len) { - hisum += addr[0]; - len--; - addr++; - } - x = 1; - } - while(len >= 16) { - t1 = *(ushort*)(addr+0); - t2 = *(ushort*)(addr+2); mdsum += t1; - t1 = *(ushort*)(addr+4); mdsum += t2; - t2 = *(ushort*)(addr+6); mdsum += t1; - t1 = *(ushort*)(addr+8); mdsum += t2; - t2 = *(ushort*)(addr+10); mdsum += t1; - t1 = *(ushort*)(addr+12); mdsum += t2; - t2 = *(ushort*)(addr+14); mdsum += t1; - mdsum += t2; - len -= 16; - addr += 16; - } - while(len >= 2) { - mdsum += *(ushort*)addr; - len -= 2; - addr += 2; - } - if(x) { - if(len) - losum += addr[0]; - if(LITTLE) - losum += mdsum; - else - hisum += mdsum; - } else { - if(len) - hisum += addr[0]; - if(LITTLE) - hisum += mdsum; - else - losum += mdsum; - } - - losum += hisum >> 8; - losum += (hisum & 0xff) << 8; - while(hisum = losum>>16) - losum = hisum + (losum & 0xffff); - - return ~losum; -} - -static ushort -ip_csum(uchar *addr) -{ - int len; - ulong sum = 0; - - len = (addr[0]&0xf)<<2; - - while(len > 0) { - sum += addr[0]<<8 | addr[1] ; - len -= 2; - addr += 2; - } - - sum = (sum & 0xffff) + (sum >> 16); - sum = (sum & 0xffff) + (sum >> 16); - return (sum^0xffff); -} - -static void -udpsend(int ctlrno, Netaddr *a, void *data, int dlen) -{ - Udphdr *uh; - Etherhdr *ip; - Etherpkt pkt; - int len, ptcllen; - - - uh = (Udphdr*)&pkt; - - memset(uh, 0, sizeof(Etherpkt)); - memmove(uh->udpcksum+sizeof(uh->udpcksum), data, dlen); - - /* - * UDP portion - */ - ptcllen = dlen + (UDP_HDRSIZE-UDP_PHDRSIZE); - uh->ttl = 0; - uh->udpproto = IP_UDPPROTO; - uh->frag[0] = 0; - uh->frag[1] = 0; - hnputs(uh->udpplen, ptcllen); - hnputl(uh->udpsrc, myaddr.ip); - hnputs(uh->udpsport, myaddr.port); - hnputl(uh->udpdst, a->ip); - hnputs(uh->udpdport, a->port); - hnputs(uh->udplen, ptcllen); - uh->udpcksum[0] = 0; - uh->udpcksum[1] = 0; - dlen = (dlen+1)&~1; - hnputs(uh->udpcksum, ptcl_csum(&uh->ttl, dlen+UDP_HDRSIZE)); - - /* - * IP portion - */ - ip = (Etherhdr*)&pkt; - len = UDP_EHSIZE+UDP_HDRSIZE+dlen; /* non-descriptive names */ - ip->vihl = IP_VER|IP_HLEN; - ip->tos = 0; - ip->ttl = 255; - hnputs(ip->length, len-ETHER_HDR); - hnputs(ip->id, Id++); - ip->frag[0] = 0; - ip->frag[1] = 0; - ip->cksum[0] = 0; - ip->cksum[1] = 0; - hnputs(ip->cksum, ip_csum(&ip->vihl)); - - /* - * Ethernet MAC portion - */ - hnputs(ip->type, ET_IP); - memmove(ip->d, a->ea, sizeof(ip->d)); - - ethertxpkt(ctlrno, &pkt, len, Timeout); -} - -static void -nak(int ctlrno, Netaddr *a, int code, char *msg, int report) -{ - int n; - char buf[128]; - - buf[0] = 0; - buf[1] = Tftp_ERROR; - buf[2] = 0; - buf[3] = code; - strcpy(buf+4, msg); - n = strlen(msg) + 4 + 1; - udpsend(ctlrno, a, buf, n); - if(report) - print("\ntftp: error(%d): %s\n", code, msg); -} - -static int -udprecv(int ctlrno, Netaddr *a, void *data, int dlen) -{ - int n, len; - ushort csm; - Udphdr *h; - ulong addr, timo; - Etherpkt pkt; - static int rxactive; - - if(rxactive == 0) - timo = 1000; - else - timo = Timeout; - timo += msec(); - while(timo > msec()){ - n = etherrxpkt(ctlrno, &pkt, timo-msec()); - if(n <= 0) - continue; - - h = (Udphdr*)&pkt; - if(nhgets(h->type) != ET_IP) - continue; - - if(ip_csum(&h->vihl)) { - print("ip chksum error\n"); - continue; - } - if(h->vihl != (IP_VER|IP_HLEN)) { - print("ip bad vers/hlen\n"); - continue; - } - - if(h->udpproto != IP_UDPPROTO) - continue; - - h->ttl = 0; - len = nhgets(h->udplen); - hnputs(h->udpplen, len); - - if(nhgets(h->udpcksum)) { - csm = ptcl_csum(&h->ttl, len+UDP_PHDRSIZE); - if(csm != 0) { - print("udp chksum error csum #%4lux len %d\n", csm, n); - break; - } - } - - if(a->port != 0 && nhgets(h->udpsport) != a->port) - continue; - if(myaddr.port != 0 && nhgets(h->udpdport) != myaddr.port) - continue; - - addr = nhgetl(h->udpsrc); - if(a->ip != Bcastip && addr != a->ip) - continue; - - len -= UDP_HDRSIZE-UDP_PHDRSIZE; - if(len > dlen) { - print("udp: packet too big\n"); - continue; - } - - memmove(data, h->udpcksum+sizeof(h->udpcksum), len); - a->ip = addr; - a->port = nhgets(h->udpsport); - memmove(a->ea, pkt.s, sizeof(a->ea)); - - rxactive = 1; - return len; - } - - return 0; -} - -static int tftpblockno; - -static int -tftpopen(int ctlrno, Netaddr *a, char *name, Tftp *tftp) -{ - int i, len, rlen; - char buf[Segsize+2]; - - buf[0] = 0; - buf[1] = Tftp_READ; - len = sprint(buf+2, "%s", name) + 2; - len += sprint(buf+len+1, "octet") + 2; - - for(i = 0; i < 5; i++){ - udpsend(ctlrno, a, buf, len); - a->port = 0; - if((rlen = udprecv(ctlrno, a, tftp, sizeof(Tftp))) < sizeof(tftp->header)) - continue; - - switch((tftp->header[0]<<8)|tftp->header[1]){ - - case Tftp_ERROR: - print("tftpopen: error (%d): %s\n", - (tftp->header[2]<<8)|tftp->header[3], tftp->data); - return -1; - - case Tftp_DATA: - tftpblockno = 1; - len = (tftp->header[2]<<8)|tftp->header[3]; - if(len != tftpblockno){ - print("tftpopen: block error: %d\n", len); - nak(ctlrno, a, 1, "block error", 0); - return -1; - } - return rlen-sizeof(tftp->header); - } - } - - print("tftpopen: failed to connect to server\n"); - return -1; -} - -static int -tftpread(int ctlrno, Netaddr *a, Tftp *tftp, int dlen) -{ - int blockno, len; - uchar buf[4]; - - buf[0] = 0; - buf[1] = Tftp_ACK; - buf[2] = tftpblockno>>8; - buf[3] = tftpblockno; - tftpblockno++; - - dlen += sizeof(tftp->header); - -buggery: - udpsend(ctlrno, a, buf, sizeof(buf)); - - if((len = udprecv(ctlrno, a, tftp, dlen)) != dlen){ - print("tftpread: %d != %d\n", len, dlen); - nak(ctlrno, a, 2, "short read", 0); - } - - blockno = (tftp->header[2]<<8)|tftp->header[3]; - if(blockno != tftpblockno){ - print("tftpread: block error: %d, expected %d\n", blockno, tftpblockno); - - if(blockno == tftpblockno-1) - goto buggery; - nak(ctlrno, a, 1, "block error", 0); - - return -1; - } - - return len-sizeof(tftp->header); -} - -// #define BOOT_MAGIC L_MAGIC -#define BOOT_MAGIC 0x0700e0c3 - -void -getether(char *dev, uchar *ea) -{ - int i; - char *p; - - p = dev; - for (i = 0; i < 8; i++) { - p = strchr(p, ' '); - if (p == 0) - panic("no ether addr"); - p++; - } - for (i = 0; i < 6; i++) { - ea[i] = strtoul(p, &p, 16); - if (*p != (i == 5 ? ' ' : '-')) - panic("bad ether addr"); - p++; - } -} - -static char inibuf[BOOTARGSLEN]; - -int -bootp(char *dev) -{ - Bootp req, rep; - int i, fd, dlen, segsize, text, data, bss, total; - uchar *addr, *p, ea[6]; - char *cp; - ulong entry; - Exec *exec; - char *filename, confname[32]; - - getether(dev, ea); - fd = devopen(dev); - if (fd < 0) - panic("bootp devopen"); - - memset(&req, 0, sizeof(req)); - req.op = Bootrequest; - req.htype = 1; /* ethernet */ - req.hlen = Eaddrlen; /* ethernet */ - memmove(req.chaddr, ea, Eaddrlen); - - myaddr.ip = 0; - myaddr.port = BPportsrc; - memmove(myaddr.ea, ea, Eaddrlen); - - for(i = 0; i < 10; i++) { - server.ip = Bcastip; - server.port = BPportdst; - memmove(server.ea, broadcast, sizeof(server.ea)); - udpsend(fd, &server, &req, sizeof(req)); - if(udprecv(fd, &server, &rep, sizeof(rep)) <= 0) - continue; - if(memcmp(req.chaddr, rep.chaddr, Eaddrlen)) - continue; - if(rep.htype != 1 || rep.hlen != Eaddrlen) - continue; - break; - } - if(i >= 10) { - print("bootp timed out\n"); - return -1; - } - - sprint(confname, "/alpha/conf/%d.%d.%d.%d", - rep.yiaddr[0], - rep.yiaddr[1], - rep.yiaddr[2], - rep.yiaddr[3]); - - if(rep.sname[0] != '\0') - print("%s ", rep.sname); - print("(%d.%d.%d.%d!%d): %s...", - rep.siaddr[0], - rep.siaddr[1], - rep.siaddr[2], - rep.siaddr[3], - server.port, - confname); - - myaddr.ip = nhgetl(rep.yiaddr); - myaddr.port = tftpport++; - server.ip = nhgetl(rep.siaddr); - server.port = TFTPport; - - if((dlen = tftpopen(fd, &server, confname, &tftpb)) < 0) - return -1; - cp = inibuf; - while(dlen > 0) { - if(cp-inibuf+dlen > BOOTARGSLEN) - panic("conf too large"); - memmove(cp, tftpb.data, dlen); - cp += dlen; - if(dlen != Segsize) - break; - if((dlen = tftpread(fd, &server, &tftpb, sizeof(tftpb.data))) < 0) - return -1; - } - *cp = 0; - setconf(inibuf); - - filename = "/alpha/9apc"; - cp = getconf("bootfile"); - if(cp != nil) - filename = cp; - - print("%s\n", filename); - myaddr.port = tftpport++; - server.port = TFTPport; - if((dlen = tftpopen(fd, &server, filename, &tftpb)) < 0) - return -1; - - exec = (Exec*)(tftpb.data); - if(dlen < sizeof(Exec) || GLLONG(exec->magic) != BOOT_MAGIC){ - nak(fd, &server, 0, "bad magic number", 1); - return -1; - } - text = GLLONG(exec->text); - data = GLLONG(exec->data); - bss = GLLONG(exec->bss); - total = text+data+bss; - entry = GLLONG(exec->entry); - if (!validrgn(entry, entry+total)) - panic("memory range not available: %lux-%lux\n", entry, entry+total); - print("%d", text); - - addr = (uchar*)entry; - p = tftpb.data+sizeof(Exec); - dlen -= sizeof(Exec); - segsize = text; - for(;;){ - if(dlen == 0){ - if((dlen = tftpread(fd, &server, &tftpb, sizeof(tftpb.data))) < 0) - return -1; - p = tftpb.data; - } - if(segsize <= dlen) - i = segsize; - else - i = dlen; - memmove(addr, p, i); - - addr += i; - p += i; - segsize -= i; - dlen -= i; - - if(segsize <= 0){ - if(data == 0) - break; - print("+%d", data); - segsize = data; - data = 0; -// addr = (uchar*)pground((uvlong)addr); - } - } - nak(fd, &server, 3, "ok", 0); /* tftpclose */ - print("+%d=%d\n", bss, total); - print("entry: 0x%lux\n", entry); - - kexec(entry); - - return 0; -} diff --git a/sys/src/boot/alphapc/conf.c b/sys/src/boot/alphapc/conf.c deleted file mode 100644 index 8a4858d92..000000000 --- a/sys/src/boot/alphapc/conf.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -static char *confname[MAXCONF]; -static char *confval[MAXCONF]; -static int nconf; -static char bootargs[BOOTARGSLEN]; - -char* -getconf(char *name) -{ - int i; - - for(i = 0; i < nconf; i++) - if(strcmp(confname[i], name) == 0) - return confval[i]; - return 0; -} - -void -setconf(char *buf) -{ - char *cp, *line[MAXCONF]; - int i, n; - - /* - * Keep a pristine copy. - * Should change this to pass the parsed strings - * to the booted programme instead of the raw - * string, then it only gets done once. - */ - strcpy(bootargs, buf); - /* print("boot: stashing /alpha/conf boot args at 0x%lux\n", - bootargs); /* DEBUG */ - conf.bootargs = bootargs; - - n = getcfields(buf, line, MAXCONF, "\n"); - for(i = 0; i < n; i++){ - if(*line[i] == '#') - continue; - cp = strchr(line[i], '='); - if(cp == nil) - continue; - *cp++ = 0; - if(cp - line[i] >= NAMELEN+1) - *(line[i]+NAMELEN-1) = 0; - confname[nconf] = line[i]; - confval[nconf] = cp; - nconf++; - } -} - -int -getcfields(char* lp, char** fields, int n, char* sep) -{ - int i; - - for(i = 0; lp && *lp && i < n; i++){ - while(*lp && strchr(sep, *lp) != 0) - *lp++ = 0; - if(*lp == 0) - break; - fields[i] = lp; - while(*lp && strchr(sep, *lp) == 0){ - if(*lp == '\\' && *(lp+1) == '\n') - *lp++ = ' '; - lp++; - } - } - - return i; -} diff --git a/sys/src/boot/alphapc/conf.h b/sys/src/boot/alphapc/conf.h deleted file mode 100644 index 46c784ccf..000000000 --- a/sys/src/boot/alphapc/conf.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef struct Bank Bank; -typedef struct Bootconf Bootconf; - -struct Bootconf -{ - int nbank; - Bank *bank; - PCB *pcb; - uvlong maxphys; - char *bootargs; -}; - -struct Bank -{ - uvlong min; - uvlong max; -}; - -#define BOOTARGSLEN (4096) -#define MAXCONF 32 diff --git a/sys/src/boot/alphapc/cons.c b/sys/src/boot/alphapc/cons.c deleted file mode 100644 index d41cedc0f..000000000 --- a/sys/src/boot/alphapc/cons.c +++ /dev/null @@ -1,243 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -enum { - /* prom operations */ - Promop_getc = 1, - Promop_puts = 2, - Promop_open = 0x10, - Promop_close = 0x11, - Promop_read = 0x13, - Promop_write = 0x14, - Promop_getenv = 0x22, - - /* environment variable indices for getenv */ - /* auto_action might be 1; it looks that way. */ - Promenv_booted_dev = 4, - Promenv_booted_file = 6, - Promenv_booted_osflags = 8, - Promenv_tty_dev = 0xf, -}; - -Hwrpb *hwrpb; - -static uvlong dispatchf; -static ulong clk2ms; - -void -consinit(void) -{ - Procdesc *p; - Hwcrb *crb; - Hwdsr *dsr; - char *s; - - hwrpb = (Hwrpb*)0x10000000; - - crb = (Hwcrb*)((ulong)hwrpb + hwrpb->crboff); - p = (Procdesc*)(crb->dispatchva); - dispatchf = p->addr; - clk2ms = hwrpb->cfreq/1000; - - print("\nAlpha Plan 9 secondary boot\n"); - if (hwrpb->rev >= 6) { - dsr = (Hwdsr*)((ulong)hwrpb + hwrpb->dsroff); - s = (char*)dsr + dsr->sysnameoff + 8; - print("%s\n", s); - } -} - -uvlong -dispatch(uvlong r16, uvlong r17, uvlong r18, uvlong r19, uvlong r20) -{ - return gendispatch(dispatchf, r16, r17, r18, r19, r20); -}; - -int -devopen(char *s) -{ - vlong ret; - int n; - - n = strlen(s); - ret = dispatch(0x10, (uvlong)s, n, 0, 0); - if (ret < 0) - return -1; - return (int) ret; -} - -int -devclose(int fd) -{ - vlong ret; - - ret = dispatch(0x11, fd, 0, 0, 0); - if (ret < 0) - return -1; - return 0; -} - -int -devread(int fd, uchar *buf, int len, int blkno) -{ - vlong ret; - - ret = dispatch(0x13, fd, len, (uvlong)buf, blkno); - if (ret < 0) - return -1; - return (int) ret; -} - -int -devwrite(int fd, uchar *buf, int len, int blkno) -{ - vlong ret; - - ret = dispatch(0x14, fd, len, (uvlong)buf, blkno); - if (ret < 0) - return -1; - return (int) ret; -} - -void -dumpenv(void) -{ - int id, n; - static char buf[256]; - - /* old upper bound was 0x100, which blows up on my 164LX. 50 works. */ - for (id = 1; id < 50; id++) { - n = dispatch(Promop_getenv, id, (uvlong)buf, sizeof(buf)-1, 0); - if (n == 0) - continue; - if (n < 0) { - print("dispatch failed at id %d\n", id); - break; - } - buf[n] = 0; - print("env[0x%x]: %s\n", id, buf); - } -} - -char * -getenv(char *name) -{ - int id, n; - static char buf[256]; - - if (strcmp(name, "booted_dev") == 0) - id = Promenv_booted_dev; - else - return 0; - n = dispatch(Promop_getenv, id, (uvlong)buf, sizeof(buf), 0); - if (n < 0) - return 0; - buf[n] = 0; - return buf; -} - -void -putstrn0(char *s, int n) -{ - uvlong ret; - int cnt; - - for (;;) { - ret = dispatch(2, 0, (uvlong)s, n, 0); - cnt = (int) ret; - s += cnt; - n -= cnt; - if (n <= 0) - break; - } -} - -void -putstrn(char *s, int n) -{ - char *p; - - for (;;) { - if (n == 0) - return; - p = memchr(s, '\n', n); - if (p == 0) { - putstrn0(s, n); - return; - } - putstrn0(s, p-s); - putstrn0("\r\n", 2); - n -= p-s+1; - s = p+1; - } -} - -int -snprint(char *s, int n, char *fmt, ...) -{ - va_list arg; - - va_start(arg, fmt); - n = doprint(s, s+n, fmt, arg) - s; - va_end(arg); - return n; -} - -int -sprint(char *s, char *fmt, ...) -{ - int n; - va_list arg; - - va_start(arg, fmt); - n = doprint(s, s+PRINTSIZE, fmt, arg) - s; - va_end(arg); - return n; -} - -int -print(char *fmt, ...) -{ - int n; - va_list arg; - char buf[PRINTSIZE]; - - va_start(arg, fmt); - n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf; - va_end(arg); - putstrn(buf, n); - - return n; -} - -void -panic(char *fmt, ...) -{ - int n; - va_list arg; - char buf[PRINTSIZE]; - - strcpy(buf, "panic: "); - va_start(arg, fmt); - n = doprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf; - va_end(arg); - buf[n] = '\n'; - putstrn(buf, n+1); - firmware(); -} - -ulong -msec(void) -{ - static ulong last, wrap; - ulong cnt; - - cnt = pcc_cnt(); - if (cnt < last) - wrap++; - last = cnt; - return (((uvlong)wrap << 32) + cnt)/clk2ms; -} diff --git a/sys/src/boot/alphapc/dat.h b/sys/src/boot/alphapc/dat.h deleted file mode 100644 index d6d9f922e..000000000 --- a/sys/src/boot/alphapc/dat.h +++ /dev/null @@ -1,169 +0,0 @@ -typedef struct Hwrpb Hwrpb; -typedef struct Hwcpu Hwcpu; -typedef struct Hwcrb Hwcrb; -typedef struct Hwdsr Hwdsr; -typedef struct Procdesc Procdesc; -typedef struct Memdsc Memdsc; -typedef struct Memclust Memclust; -typedef struct PCB PCB; - -struct Hwrpb -{ - uvlong phys; - uvlong sign; - uvlong rev; - uvlong size; - uvlong cpu0; - uvlong by2pg; - uvlong pabits; - uvlong maxasn; - char ssn[16]; - uvlong systype; - uvlong sysvar; - uvlong sysrev; - uvlong ifreq; - uvlong cfreq; - uvlong vptb; - uvlong resv; - uvlong tbhint; - uvlong ncpu; - uvlong cpulen; - uvlong cpuoff; - uvlong nctb; - uvlong ctblen; - uvlong ctboff; - uvlong crboff; - uvlong memoff; - uvlong confoff; - uvlong fruoff; - uvlong termsaveva; - uvlong termsavex; - uvlong termrestva; - uvlong termrestx; - uvlong termresetva; - uvlong termresetx; - uvlong sysresv; - uvlong hardresv; - uvlong csum; - uvlong rxrdymsk; - uvlong txrdymsk; - uvlong dsroff; /* rev 6 or higher */ -}; - -extern Hwrpb* hwrpb; - -struct Hwcpu -{ - uvlong hwpcb[16]; - uvlong state; - uvlong palmainlen; - uvlong palscratchlen; - uvlong palmainpa; - uvlong palscratchpa; - uvlong palrev; - uvlong cputype; - uvlong cpuvar; - uvlong cpurev; - uvlong serial[2]; - /* more crap ... */ -}; - -struct Hwdsr -{ - vlong smm; - uvlong lurtoff; - uvlong sysnameoff; -}; - -struct Hwcrb -{ - uvlong dispatchva; - uvlong dispatchpa; - uvlong fixupva; - uvlong fixuppa; - /* more, uninteresting crud */ -}; - -struct Procdesc -{ - uvlong bollocks; - uvlong addr; -}; - -struct Memclust -{ - uvlong pfn; - uvlong npages; - uvlong ntest; - uvlong vabitm; - uvlong pabitm; - uvlong csumbitm; - uvlong usage; -}; - -struct Memdsc -{ - uvlong csum; - uvlong opt; - uvlong nclust; - Memclust clust[1]; -}; - -enum -{ - PRINTSIZE = 256, - MB = (1024*1024), -}; - -#define L_MAGIC ((((4*23)+0)*23)+7) - -typedef struct Exec Exec; -struct Exec -{ - uchar magic[4]; /* magic number */ - uchar text[4]; /* size of text segment */ - uchar data[4]; /* size of initialized data */ - uchar bss[4]; /* size of uninitialized data */ - uchar syms[4]; /* size of symbol table */ - uchar entry[4]; /* entry point */ - uchar spsz[4]; /* size of sp/pc offset table */ - uchar pcsz[4]; /* size of pc/line number table */ -}; - -enum { - Eaddrlen = 6, - ETHERMINTU = 60, /* minimum transmit size */ - ETHERMAXTU = 1514, /* maximum transmit size */ - ETHERHDRSIZE = 14, /* size of an ethernet header */ - - MaxEther = 2, -}; - -typedef struct { - uchar d[Eaddrlen]; - uchar s[Eaddrlen]; - uchar type[2]; - uchar data[1500]; - uchar crc[4]; -} Etherpkt; - -/* - * Process Control Block, used by OSF/1 PALcode when we switch to it - */ -struct PCB { - uvlong ksp; - uvlong usp; - uvlong ptbr; - ulong asn; - ulong pcc; - uvlong unique; - ulong fen; - ulong dummy; - uvlong rsrv1; - uvlong rsrv2; -}; - - -#include "conf.h" - -extern Bootconf conf; diff --git a/sys/src/boot/alphapc/exec.c b/sys/src/boot/alphapc/exec.c deleted file mode 100644 index 9bc626f8c..000000000 --- a/sys/src/boot/alphapc/exec.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -uchar pcbpage[64*1024+sizeof(PCB)]; -PCB *pcb; - -void (*kentry)(Bootconf*); - -void -gokernel(void) -{ - (*kentry)(&conf); -} - -void -kexec(ulong entry) -{ - uvlong pcbb, paltype; - - pcb = (PCB*)(((ulong)pcbpage+0xffff) & ~0xffff); /* page align, even on 64K page Alphas */ - memset(pcb, 0, sizeof(PCB)); - pcb->ksp = (uvlong)&entry; - pcb->ptbr = getptbr(); - pcb->fen = 1; - conf.pcb = pcb; - pcbb = paddr((uvlong)pcb); - kentry = (void(*)(Bootconf*))entry; - paltype = 2; /* OSF/1 please */ - switch (swppal(paltype, (uvlong)gokernel, pcbb, hwrpb->vptb, pcb->ksp)) { - case 1: - panic("unknown PALcode variant"); - case 2: - panic("PALcode variant not loaded"); - default: - panic("weird return status from swppal"); - } -} diff --git a/sys/src/boot/alphapc/fns.h b/sys/src/boot/alphapc/fns.h deleted file mode 100644 index 77a1204c1..000000000 --- a/sys/src/boot/alphapc/fns.h +++ /dev/null @@ -1,37 +0,0 @@ -uvlong allocate(int); -int bootp(char*); -void consinit(void); -int devopen(char*); -int devclose(int); -int devread(int, uchar*, int, int); -int devwrite(int, uchar*, int, int); -uvlong dispatch(uvlong, uvlong, uvlong, uvlong, uvlong); -void dumpenv(void); -void firmware(void); -uvlong gendispatch(uvlong, uvlong, uvlong, uvlong, uvlong, uvlong); -int getcfields(char*, char**, int, char*); -char* getconf(char*); -char* getenv(char*); -uvlong getptbr(void); -void kexec(ulong); -uvlong ldqp(uvlong); -void meminit(void); -void mmuinit(void); -ulong msec(void); -uvlong rdv(uvlong); -uvlong paddr(uvlong); -void panic(char *, ...); -ulong pcc_cnt(void); -uvlong pground(uvlong); -void putstrn(char *, int); -void setconf(char*); -void stqp(uvlong, uvlong); -int swppal(uvlong, uvlong, uvlong, uvlong, uvlong); -void tlbflush(void); -int validrgn(ulong, ulong); -void wrv(uvlong, uvlong); - -#define GSHORT(p) (((p)[1]<<8)|(p)[0]) -#define GLONG(p) ((GSHORT(p+2)<<16)|GSHORT(p)) -#define GLSHORT(p) (((p)[0]<<8)|(p)[1]) -#define GLLONG(p) ((GLSHORT(p)<<16)|GLSHORT(p+2)) diff --git a/sys/src/boot/alphapc/ip.h b/sys/src/boot/alphapc/ip.h deleted file mode 100644 index a39b5b4bd..000000000 --- a/sys/src/boot/alphapc/ip.h +++ /dev/null @@ -1,98 +0,0 @@ -typedef struct Udphdr Udphdr; -struct Udphdr -{ - uchar d[6]; /* Ethernet destination */ - uchar s[6]; /* Ethernet source */ - uchar type[2]; /* Ethernet packet type */ - - uchar vihl; /* Version and header length */ - uchar tos; /* Type of service */ - uchar length[2]; /* packet length */ - uchar id[2]; /* Identification */ - uchar frag[2]; /* Fragment information */ - - /* Udp pseudo ip really starts here */ - uchar ttl; - uchar udpproto; /* Protocol */ - uchar udpplen[2]; /* Header plus data length */ - uchar udpsrc[4]; /* Ip source */ - uchar udpdst[4]; /* Ip destination */ - uchar udpsport[2]; /* Source port */ - uchar udpdport[2]; /* Destination port */ - uchar udplen[2]; /* data length */ - uchar udpcksum[2]; /* Checksum */ -}; - -typedef struct Etherhdr Etherhdr; -struct Etherhdr -{ - uchar d[6]; - uchar s[6]; - uchar type[2]; - - /* Now we have the ip fields */ - uchar vihl; /* Version and header length */ - uchar tos; /* Type of service */ - uchar length[2]; /* packet length */ - uchar id[2]; /* Identification */ - uchar frag[2]; /* Fragment information */ - uchar ttl; /* Time to live */ - uchar proto; /* Protocol */ - uchar cksum[2]; /* Header checksum */ - uchar src[4]; /* Ip source */ - uchar dst[4]; /* Ip destination */ -}; - -enum -{ - IP_VER = 0x40, - IP_HLEN = 0x05, - UDP_EHSIZE = 22, - UDP_PHDRSIZE = 12, - UDP_HDRSIZE = 20, - ETHER_HDR = 14, - IP_UDPPROTO = 17, - ET_IP = 0x800, - Bcastip = 0xffffffff, - BPportsrc = 68, - BPportdst = 67, - TFTPport = 69, - Timeout = 5000, /* milliseconds */ - Bootrequest = 1, - Bootreply = 2, - Tftp_READ = 1, - Tftp_WRITE = 2, - Tftp_DATA = 3, - Tftp_ACK = 4, - Tftp_ERROR = 5, - Segsize = 512, - TFTPSZ = Segsize+10, -}; - -typedef struct Bootp Bootp; -struct Bootp -{ - uchar op; /* opcode */ - uchar htype; /* hardware type */ - uchar hlen; /* hardware address len */ - uchar hops; /* hops */ - uchar xid[4]; /* a random number */ - uchar secs[2]; /* elapsed snce client started booting */ - uchar pad[2]; - uchar ciaddr[4]; /* client IP address (client tells server) */ - uchar yiaddr[4]; /* client IP address (server tells client) */ - uchar siaddr[4]; /* server IP address */ - uchar giaddr[4]; /* gateway IP address */ - uchar chaddr[16]; /* client hardware address */ - char sname[64]; /* server host name (optional) */ - char file[128]; /* boot file name */ - char vend[128]; /* vendor-specific goo */ -}; - -typedef struct Netaddr Netaddr; -struct Netaddr -{ - ulong ip; - ushort port; - char ea[Eaddrlen]; -}; diff --git a/sys/src/boot/alphapc/l.s b/sys/src/boot/alphapc/l.s deleted file mode 100644 index 487be5891..000000000 --- a/sys/src/boot/alphapc/l.s +++ /dev/null @@ -1,101 +0,0 @@ -#include "mem.h" -#include "vmspal.h" - -#define SP R30 - -TEXT _main(SB), $-8 - MOVQ $setSB(SB), R29 - MOVQ $edata(SB), R1 - MOVQ $end(SB), R2 -loop2: - MOVQ R31, (R1) - ADDQ $8, R1 - CMPUGT R1, R2, R3 - BEQ R3, loop2 - - JSR main(SB) - -TEXT firmware(SB), $-8 - CALL_PAL $PALhalt - MOVQ $_divq(SB), R31 /* touch _divq etc.; doesn't need to execute */ - MOVQ $_divl(SB), R31 /* touch _divl etc.; doesn't need to execute */ - RET - -TEXT mb(SB), $-8 - MB - RET - -TEXT icflush(SB), $-8 - CALL_PAL $PALimb - RET - -TEXT tlbflush(SB), $-8 - CALL_PAL $PALmtpr_tbia - RET - -TEXT gendispatch(SB), $-8 - MOVQ 8(FP), R16 - MOVQ 16(FP), R17 - MOVQ 24(FP), R18 - MOVQ 32(FP), R19 - MOVQ 40(FP), R20 - MOVQ R26, R1 - JSR (R0) - MOVQ R1, R26 - RET /* 7a bug: should be RET (R1) */ - -TEXT rdv(SB), $-8 - MOVQ (R0), R0 - RET - -TEXT wrv(SB), $-8 - MOVQ 8(FP), R1 - MOVQ R1, (R0) - RET - -TEXT ipl(SB), $-8 - CALL_PAL $PALmfpr_ipl - RET - -TEXT mces(SB), $-8 - CALL_PAL $PALmfpr_mces - RET - -TEXT setipl(SB), $-8 - MOVQ R0, R16 - CALL_PAL $PALmtpr_ipl - RET - -TEXT setmces(SB), $-8 - MOVQ R0, R16 - CALL_PAL $PALmtpr_mces - RET - -TEXT ldqp(SB), $-8 - MOVQ R0, R16 - CALL_PAL $PALldqp - RET - -TEXT stqp(SB), $-8 - MOVQ R0, R16 - MOVQ 8(FP), R17 - CALL_PAL $PALstqp - RET - -TEXT getptbr(SB), $-8 - CALL_PAL $PALmfpr_ptbr - RET - -TEXT swppal(SB), $-8 - MOVQ R0, R16 /* which PALcode */ - MOVQ 8(FP), R17 /* new PC */ - MOVQ 16(FP), R18 /* PCBB (physical) */ - MOVQ 24(FP), R19 /* VPTB */ - MOVQ 32(FP), R20 /* new KSP */ - CALL_PAL $PALswppal - RET - -TEXT pcc_cnt(SB), $-8 - MOVQ PCC, R1 - MOVL R1, R0 - RET diff --git a/sys/src/boot/alphapc/lib.h b/sys/src/boot/alphapc/lib.h deleted file mode 100644 index 525ceff4b..000000000 --- a/sys/src/boot/alphapc/lib.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * functions (possibly) linked in, complete, from libc. - */ - -/* - * mem routines - */ -extern void *memccpy(void*, void*, int, long); -extern void *memset(void*, int, long); -extern int memcmp(void*, void*, long); -extern void *memmove(void*, void*, long); -extern void *memchr(void*, int, long); - -/* - * string routines - */ -extern char *strcat(char*, char*); -extern char *strchr(char*, char); -extern int strcmp(char*, char*); -extern char *strcpy(char*, char*); -extern char *strncat(char*, char*, long); -extern char *strncpy(char*, char*, long); -extern int strncmp(char*, char*, long); -extern long strlen(char*); -extern int atoi(char*); - -enum -{ - UTFmax = 3, /* maximum bytes per rune */ - Runesync = 0x80, /* cannot represent part of a UTF sequence */ - Runeself = 0x80, /* rune and UTF sequences are the same (<) */ - Runeerror = 0x80, /* decoding error in UTF */ -}; - -/* - * rune routines - */ -extern int runetochar(char*, Rune*); -extern int chartorune(Rune*, char*); -extern char* utfrune(char*, long); -extern int utflen(char*); - -extern int abs(int); - -/* - * print routines - */ -typedef -struct -{ - char* out; /* pointer to next output */ - char* eout; /* pointer to end */ - int f1; - int f2; - int f3; - int chr; -} Fconv; -extern void strconv(char*, Fconv*); -extern int numbconv(va_list*, Fconv*); -extern char *doprint(char*, char*, char*, va_list); -extern int fmtinstall(int, int (*)(va_list*, Fconv*)); -extern int sprint(char*, char*, ...); -extern int snprint(char*, int, char*, ...); -extern int print(char*, ...); - -/* - * one-of-a-kind - */ -extern long strtol(char*, char**, int); -extern ulong strtoul(char*, char**, int); -extern vlong strtovl(char*, char**, int); -extern char etext[]; -extern char edata[]; -extern char end[]; - -/* - * Syscall data structures - */ -#define MORDER 0x0003 /* mask for bits defining order of mounting */ -#define MREPL 0x0000 /* mount replaces object */ -#define MBEFORE 0x0001 /* mount goes before others in union directory */ -#define MAFTER 0x0002 /* mount goes after others in union directory */ -#define MCREATE 0x0004 /* permit creation in mounted directory */ -#define MRECOV 0x0008 /* perform recovery if mount channel is lost */ -#define MCACHE 0x0010 /* cache some data */ -#define MMASK 0x001F /* all bits on */ - -#define OREAD 0 /* open for read */ -#define OWRITE 1 /* write */ -#define ORDWR 2 /* read and write */ -#define OEXEC 3 /* execute, == read but check execute permission */ -#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ -#define OCEXEC 32 /* or'ed in, close on exec */ -#define ORCLOSE 64 /* or'ed in, remove on close */ - -#define NCONT 0 /* continue after note */ -#define NDFLT 1 /* terminate after note */ -#define NSAVE 2 /* clear note but hold state */ -#define NRSTR 3 /* restore saved state */ - -typedef struct Qid Qid; -typedef struct Dir Dir; -typedef struct Waitmsg Waitmsg; - -#define ERRLEN 64 -#define DIRLEN 116 -#define NAMELEN 28 - -struct Qid -{ - ulong path; - ulong vers; -}; - -struct Dir -{ - char name[NAMELEN]; - char uid[NAMELEN]; - char gid[NAMELEN]; - Qid qid; - ulong mode; - long atime; - long mtime; - Length; - short type; - short dev; -}; - -struct Waitmsg -{ - char pid[12]; /* of loved one */ - char time[3*12]; /* of loved one and descendants */ - char msg[ERRLEN]; -}; diff --git a/sys/src/boot/alphapc/main.c b/sys/src/boot/alphapc/main.c deleted file mode 100644 index 1d3d235dd..000000000 --- a/sys/src/boot/alphapc/main.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -Bootconf conf; - -void -main(void) -{ - char *dev; - - consinit(); - meminit(); - mmuinit(); - - dev = getenv("booted_dev"); - if (dev == 0) - panic("get dev name"); - if (strncmp(dev, "BOOTP", 5) == 0) - bootp(dev); - else - print("boot device %s not supported\n", dev); -} diff --git a/sys/src/boot/alphapc/mem.h b/sys/src/boot/alphapc/mem.h deleted file mode 100644 index 5ae7bb740..000000000 --- a/sys/src/boot/alphapc/mem.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Memory and machine-specific definitions. Used in C and assembler. - */ - -#define BI2BY 8 /* bits per byte */ -#define BI2WD 32 /* bits per word */ -#define BY2WD 4 /* bytes per word */ -#define BY2V 8 /* bytes per vlong */ - -#define KZERO 0x80000000 - -#define PTEVALID 0xff01 -#define PTEKVALID 0x1101 -#define PTEASM 0x0010 -#define PTEGH(s) ((s)<<5) diff --git a/sys/src/boot/alphapc/memory.c b/sys/src/boot/alphapc/memory.c deleted file mode 100644 index d4234bda5..000000000 --- a/sys/src/boot/alphapc/memory.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -static int debug; - -enum { - Maxbank = 2, -}; - -Bank bank[Maxbank]; -int nbank; - -void -meminit(void) -{ - Memdsc *mem; - Memclust *c; - int i; - uvlong npage, p0, p1; - extern ulong _main[], edata[]; - - mem = (Memdsc*)((ulong)hwrpb + hwrpb->memoff); - if (debug) - print("\nnumber of clusters: %lld\n", mem->nclust); - npage = 0; - conf.maxphys = 0; - for (i = 0; i < mem->nclust; i++) { - c = &mem->clust[i]; - p0 = c->pfn*hwrpb->by2pg; - p1 = (c->pfn+c->npages)*hwrpb->by2pg; - if (debug) { - print("clust%d: %llux-%llux, tested %llud/%llud vabitm %llux usage %llux\n", - i, p0, p1, c->ntest, c->npages, c->vabitm, c->usage); - if (c->vabitm) - print("\tfirst 64 pages: %llux\n", *(uvlong*)c->vabitm); - } - npage += c->npages; - if (p1 > conf.maxphys) - conf.maxphys = p1; - switch ((ulong)c->usage&3) { - case 0: - if (nbank >= Maxbank) { - print("increase Maxbank; lost %lldMB\n", c->npages*hwrpb->by2pg/MB); - break; - } - bank[nbank].min = p0; - bank[nbank].max = p1; - nbank++; - break; - case 2: - print("nvram skipped\n"); - break; - } - } - if (debug) - print("\n"); - - print("Memory size: %lludMB\n", npage*hwrpb->by2pg/MB); - print("\n"); - - /* kernel virtual space = 2G. leave room for kmapio */ - if (conf.maxphys > 1024*MB) { - print("meminit: too much physical memory; only first gigabyte mapped\n\n"); - conf.maxphys = 1024*MB; - } - - conf.nbank = nbank; - conf.bank = bank; -} - -int -validrgn(ulong min, ulong max) -{ - int i; - - min &= ~KZERO; - max &= ~KZERO; - for (i = 0; i < nbank; i++) - if (bank[i].min <= min && max <= bank[i].max) - return 1; - return 0; -} - -uvlong -allocate(int pages) -{ - uvlong top, len; - int from, i; - - top = 0; - len = pages*hwrpb->by2pg; - from = -1; - for (i = 0; i < nbank; i++) - if (bank[i].max - bank[i].min >= len && bank[i].max > top) { - top = bank[i].max; - from = i; - } - if (from < 0) - return 0; - bank[from].max -= len; - conf.bank[from].max = bank[from].max; - for (i = 0; i < len>>3; i++) - stqp(bank[from].max+8*i, 0); - return bank[from].max; -} diff --git a/sys/src/boot/alphapc/mkfile b/sys/src/boot/alphapc/mkfile deleted file mode 100644 index 8443876ce..000000000 --- a/sys/src/boot/alphapc/mkfile +++ /dev/null @@ -1,42 +0,0 @@ -objtype=alpha -</$objtype/mkfile - -TARGET=bootalphapc -OBJ=\ - l.$O\ - main.$O\ - conf.$O\ - cons.$O\ - exec.$O\ - bootp.$O\ - memory.$O\ - mmu.$O\ - print.$O\ - -HFILES=\ - u.h\ - mem.h\ - conf.h\ - dat.h\ - fns.h\ - lib.h\ - ip.h\ - -loadaddr = 0x20000020 - -$TARGET: $OBJ - $LD -o $target -l -R8 -H3 -T$loadaddr $prereq -lc - -install:V: $TARGET - cp $TARGET /$objtype - -clean nuke:V: - rm -f *.$O $TARGET - -%.$O: %.s - $AS $stem.s - -%.$O: %.c - $CC $CFLAGS $stem.c - -%.$O: $HFILES diff --git a/sys/src/boot/alphapc/mmu.c b/sys/src/boot/alphapc/mmu.c deleted file mode 100644 index 92c67aa17..000000000 --- a/sys/src/boot/alphapc/mmu.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "u.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "lib.h" - -static int debug; - -static uvlong by2pg; /* hwrpb->by2pg */ -static uvlong pte2pg; /* by2pg/8 */ -static uvlong pgmask; /* by2pg-1 */ -static uvlong ptemask; /* pte2pg-1 */ -static uvlong pgshift; /* log2(by2pg) */ -static uvlong pteshift; /* log2(pte2pg) = pgshift - 3 */ - -#define L1(va) (((uvlong)(va)>>3*pteshift+3) & (pte2pg-1)) -#define L2(va) (((uvlong)(va)>>2*pteshift+3) & (pte2pg-1)) -#define L3(va) (((uvlong)(va)>>pgshift) & (pte2pg-1)) -#define OFF(va) (((uvlong)(va)) & (by2pg-1)) - -#define V1(l1) (((vlong)l1<<(64-pteshift)) >> 64-(3*pteshift+3)) -#define V2(l2) (((uvlong)l2<<(64-pteshift)) >> 64-(2*pteshift+3)) -#define V3(l3) (((uvlong)l3<<(64-pteshift)) >> 64-pgshift) -#define VA(l1, l2, l3, off) (V1(l1) | V2(l2) | V3(l3) | (off)) - -static int -log2(uvlong x) -{ - int i; - - if ((x & (x-1)) == 0) - for (i = 0; i < 64; i++) - if (x & (1<<i)) - return i; - panic("log2: %llux", x); - return -1; -} - -void -mmuinit(void) -{ - int i; - uvlong npage, nlvl2, nlvl3; - uvlong l1p, l2p, lvl2, lvl3; - extern ulong _main[], edata[]; - - /* map entire physical memory at KZERO */ - by2pg = hwrpb->by2pg; - pte2pg = (by2pg >> 3); - pgmask = by2pg-1; - ptemask = pte2pg-1; - pgshift = log2(by2pg); - pteshift = pgshift-3; - - l1p = (1LL<<3*pteshift+3)|(1LL<<2*pteshift+3)|(1LL<<pgshift); - if (rdv(l1p+8*(pte2pg-1)) != 0 || rdv(l1p+8*(pte2pg-2)) != 0) - panic("KZERO lvl1 already mapped"); - - npage = (conf.maxphys+pgmask)>>pgshift; - nlvl3 = (npage+ptemask)>>pteshift; - nlvl2 = (nlvl3+ptemask)>>pteshift; - if (nlvl2 > 1) - panic("meminit: nlvl2"); /* cannot happen, due to virtual space limitation */ - if (debug) - print("nlvl1 %llud nlvl2 %llud nlvl3 %llud npage %llud\n", 1LL, nlvl2, nlvl3, npage); - - lvl2 = allocate(nlvl2+nlvl3); - lvl3 = lvl2 + nlvl2*by2pg; - - wrv(l1p+8*(pte2pg-2), rdv(l1p+8)|PTEASM); - wrv(l1p+8*(pte2pg-1), (lvl2<<(32-pgshift)) | PTEKVALID | PTEASM); - - l2p = (1LL<<3*pteshift+3)|(1LL<<2*pteshift+3)|((vlong)KZERO >> 2*pteshift)&((1LL<<2*pteshift+3)-1); - for (i = 0; i < nlvl3; i++) - stqp(lvl2+(l2p&(by2pg-1))+8*i, ((lvl3+i*by2pg)<<(32-pgshift)) | PTEKVALID | PTEASM); - - for (i = 0; i < npage; i++) - stqp(lvl3+8*i, ((uvlong)i<<32) | PTEKVALID | PTEASM); - - tlbflush(); - - if (debug) - print("\n"); -} - -uvlong -paddr(uvlong va) -{ - uvlong ptbr, x, pte; - - ptbr = getptbr(); - pte = ldqp((ptbr<<pgshift)+8*L1(va)); - if ((pte&PTEKVALID) != PTEKVALID) - return 0; - x = ((pte>>32)<<pgshift); - pte = ldqp(x+8*L2(va)); - if ((pte&PTEKVALID) != PTEKVALID) - return 0; - x = ((pte>>32)<<pgshift); - pte = ldqp(x+8*L3(va)); - if ((pte&PTEKVALID) != PTEKVALID) - return 0; - x = ((pte>>32)<<pgshift); - return x; -} - -uvlong -pground(uvlong x) -{ - return (x+pgmask) & ~pgmask; -} diff --git a/sys/src/boot/alphapc/print.c b/sys/src/boot/alphapc/print.c deleted file mode 100644 index 897624dd7..000000000 --- a/sys/src/boot/alphapc/print.c +++ /dev/null @@ -1,575 +0,0 @@ -#include "u.h" -#include "lib.h" - -enum -{ - SIZE = 1024, - IDIGIT = 30, - MAXCONV = 40, - FDIGIT = 30, - FDEFLT = 6, - NONE = -1000, - MAXFMT = 512, - - FPLUS = 1<<0, - FMINUS = 1<<1, - FSHARP = 1<<2, - FLONG = 1<<3, - FSHORT = 1<<4, - FUNSIGN = 1<<5, - FVLONG = 1<<6, -}; - -int printcol; - -static int convcount; -static char fmtindex[MAXFMT]; - -static int noconv(va_list*, Fconv*); -static int flags(va_list*, Fconv*); - -static int cconv(va_list*, Fconv*); -static int sconv(va_list*, Fconv*); -static int percent(va_list*, Fconv*); - -int numbconv(va_list*, Fconv*); - -static -int (*fmtconv[MAXCONV])(va_list*, Fconv*) = -{ - noconv -}; - -static -void -initfmt(void) -{ - int cc; - - cc = 0; - fmtconv[cc] = noconv; - cc++; - - fmtconv[cc] = flags; - fmtindex['+'] = cc; - fmtindex['-'] = cc; - fmtindex['#'] = cc; - fmtindex['h'] = cc; - fmtindex['l'] = cc; - fmtindex['u'] = cc; - cc++; - - fmtconv[cc] = numbconv; - fmtindex['d'] = cc; - fmtindex['o'] = cc; - fmtindex['x'] = cc; - fmtindex['X'] = cc; - cc++; - - fmtconv[cc] = cconv; - fmtindex['c'] = cc; - fmtindex['C'] = cc; - cc++; - - fmtconv[cc] = sconv; - fmtindex['s'] = cc; - fmtindex['S'] = cc; - cc++; - - fmtconv[cc] = percent; - fmtindex['%'] = cc; - cc++; - - convcount = cc; -} - -int -fmtinstall(int c, int (*f)(va_list*, Fconv*)) -{ - - if(convcount == 0) - initfmt(); - if(c < 0 || c >= MAXFMT) - return -1; - if(convcount >= MAXCONV) - return -1; - fmtconv[convcount] = f; - fmtindex[c] = convcount; - convcount++; - return 0; -} - -char* -doprint(char *s, char *es, char *fmt, va_list argp) -{ - int n, c; - Rune rune; - Fconv local; - - local.out = s; - local.eout = es-UTFmax-1; - -loop: - c = *fmt & 0xff; - if(c >= Runeself) { - n = chartorune(&rune, fmt); - fmt += n; - c = rune; - } else - fmt++; - switch(c) { - case 0: - *local.out = 0; - return local.out; - - default: - printcol++; - goto common; - - case '\n': - printcol = 0; - goto common; - - case '\t': - printcol = (printcol+8) & ~7; - goto common; - - common: - if(local.out < local.eout) - if(c >= Runeself) { - rune = c; - n = runetochar(local.out, &rune); - local.out += n; - } else - *local.out++ = c; - goto loop; - - case '%': - break; - } - local.f1 = NONE; - local.f2 = NONE; - local.f3 = 0; - - /* - * read one of the following - * 1. number, => f1, f2 in order. - * 2. '*' same as number (from args) - * 3. '.' ignored (separates numbers) - * 4. flag => f3 - * 5. verb and terminate - */ -l0: - c = *fmt & 0xff; - if(c >= Runeself) { - n = chartorune(&rune, fmt); - fmt += n; - c = rune; - } else - fmt++; - -l1: - if(c == 0) { - fmt--; - goto loop; - } - if(c == '.') { - if(local.f1 == NONE) - local.f1 = 0; - local.f2 = 0; - goto l0; - } - if((c >= '1' && c <= '9') || - (c == '0' && local.f1 != NONE)) { /* '0' is a digit for f2 */ - n = 0; - while(c >= '0' && c <= '9') { - n = n*10 + c-'0'; - c = *fmt++; - } - if(local.f1 == NONE) - local.f1 = n; - else - local.f2 = n; - goto l1; - } - if(c == '*') { - n = va_arg(argp, int); - if(local.f1 == NONE) - local.f1 = n; - else - local.f2 = n; - goto l0; - } - n = 0; - if(c >= 0 && c < MAXFMT) - n = fmtindex[c]; - local.chr = c; - n = (*fmtconv[n])(&argp, &local); - if(n < 0) { - local.f3 |= -n; - goto l0; - } - goto loop; -} - -int -numbconv(va_list *arg, Fconv *fp) -{ - char s[IDIGIT]; - int i, f, n, b, ucase; - short h; - long v; - vlong vl; - - SET(v); - SET(vl); - - ucase = 0; - b = fp->chr; - switch(fp->chr) { - case 'u': - fp->f3 |= FUNSIGN; - case 'd': - b = 10; - break; - - case 'o': - b = 8; - break; - - case 'X': - ucase = 1; - case 'x': - b = 16; - break; - } - - f = 0; - switch(fp->f3 & (FVLONG|FLONG|FSHORT|FUNSIGN)) { - case FVLONG|FLONG: - vl = va_arg(*arg, vlong); - break; - - case FUNSIGN|FVLONG|FLONG: - vl = va_arg(*arg, uvlong); - break; - - case FLONG: - v = va_arg(*arg, long); - break; - - case FUNSIGN|FLONG: - v = va_arg(*arg, ulong); - break; - - case FSHORT: - h = va_arg(*arg, int); - v = h; - break; - - case FUNSIGN|FSHORT: - h = va_arg(*arg, int); - v = (ushort)h; - break; - - default: - v = va_arg(*arg, int); - break; - - case FUNSIGN: - v = va_arg(*arg, unsigned); - break; - } - if(fp->f3 & FVLONG) { - if(!(fp->f3 & FUNSIGN) && vl < 0) { - vl = -vl; - f = 1; - } - } else { - if(!(fp->f3 & FUNSIGN) && v < 0) { - v = -v; - f = 1; - } - } - s[IDIGIT-1] = 0; - for(i = IDIGIT-2;; i--) { - if(fp->f3 & FVLONG) - n = (uvlong)vl % b; - else - n = (ulong)v % b; - n += '0'; - if(n > '9') { - n += 'a' - ('9'+1); - if(ucase) - n += 'A'-'a'; - } - s[i] = n; - if(i < 2) - break; - if(fp->f3 & FVLONG) - vl = (uvlong)vl / b; - else - v = (ulong)v / b; - if(fp->f2 != NONE && i >= IDIGIT-fp->f2) - continue; - if(fp->f3 & FVLONG) { - if(vl <= 0) - break; - continue; - } - if(v <= 0) - break; - } - - if(fp->f3 & FSHARP) { - if(b == 8 && s[i] != '0') - s[--i] = '0'; - if(b == 16) { - if(ucase) - s[--i] = 'X'; - else - s[--i] = 'x'; - s[--i] = '0'; - } - } - if(f) - s[--i] = '-'; - fp->f2 = NONE; - strconv(s+i, fp); - return 0; -} - -void -Strconv(Rune *s, Fconv *fp) -{ - int n, c, i; - Rune rune; - - if(fp->f3 & FMINUS) - fp->f1 = -fp->f1; - n = 0; - if(fp->f1 != NONE && fp->f1 >= 0) { - for(; s[n]; n++) - ; - while(n < fp->f1) { - if(fp->out < fp->eout) - *fp->out++ = ' '; - printcol++; - n++; - } - } - for(;;) { - c = *s++; - if(c == 0) - break; - n++; - if(fp->f2 == NONE || fp->f2 > 0) { - if(fp->out < fp->eout) - if(c >= Runeself) { - rune = c; - i = runetochar(fp->out, &rune); - fp->out += i; - } else - *fp->out++ = c; - if(fp->f2 != NONE) - fp->f2--; - switch(c) { - default: - printcol++; - break; - case '\n': - printcol = 0; - break; - case '\t': - printcol = (printcol+8) & ~7; - break; - } - } - } - if(fp->f1 != NONE && fp->f1 < 0) { - fp->f1 = -fp->f1; - while(n < fp->f1) { - if(fp->out < fp->eout) - *fp->out++ = ' '; - printcol++; - n++; - } - } -} - -void -strconv(char *s, Fconv *fp) -{ - int n, c, i; - Rune rune; - - if(fp->f3 & FMINUS) - fp->f1 = -fp->f1; - n = 0; - if(fp->f1 != NONE && fp->f1 >= 0) { - n = utflen(s); - while(n < fp->f1) { - if(fp->out < fp->eout) - *fp->out++ = ' '; - printcol++; - n++; - } - } - for(;;) { - c = *s & 0xff; - if(c >= Runeself) { - i = chartorune(&rune, s); - s += i; - c = rune; - } else - s++; - if(c == 0) - break; - n++; - if(fp->f2 == NONE || fp->f2 > 0) { - if(fp->out < fp->eout) - if(c >= Runeself) { - rune = c; - i = runetochar(fp->out, &rune); - fp->out += i; - } else - *fp->out++ = c; - if(fp->f2 != NONE) - fp->f2--; - switch(c) { - default: - printcol++; - break; - case '\n': - printcol = 0; - break; - case '\t': - printcol = (printcol+8) & ~7; - break; - } - } - } - if(fp->f1 != NONE && fp->f1 < 0) { - fp->f1 = -fp->f1; - while(n < fp->f1) { - if(fp->out < fp->eout) - *fp->out++ = ' '; - printcol++; - n++; - } - } -} - -static -int -noconv(va_list *arg, Fconv *fp) -{ - int n; - char s[10]; - - if(convcount == 0) { - initfmt(); - n = 0; - if(fp->chr >= 0 && fp->chr < MAXFMT) - n = fmtindex[fp->chr]; - return (*fmtconv[n])(arg, fp); - } - s[0] = '*'; - s[1] = fp->chr; - s[2] = '*'; - s[3] = 0; - fp->f1 = 0; - fp->f2 = NONE; - fp->f3 = 0; - strconv(s, fp); - return 0; -} - -static -int -cconv(va_list *arg, Fconv *fp) -{ - char s[10]; - Rune rune; - - rune = va_arg(*arg, int); - if(fp->chr == 'c') - rune &= 0xff; - s[runetochar(s, &rune)] = 0; - - fp->f2 = NONE; - strconv(s, fp); - return 0; -} - -static -int -sconv(va_list *arg, Fconv *fp) -{ - char *s; - Rune *r; - - if(fp->chr == 's') { - s = va_arg(*arg, char*); - if(s == 0) - s = "<null>"; - strconv(s, fp); - } else { - r = va_arg(*arg, Rune*); - if(r == 0) - r = L"<null>"; - Strconv(r, fp); - } - return 0; -} - -static -int -percent(va_list *arg, Fconv *fp) -{ - - USED(arg); - if(fp->out < fp->eout) - *fp->out++ = '%'; - printcol++; - return 0; -} - -static -int -flags(va_list *arg, Fconv *fp) -{ - int f; - - USED(arg); - - f = 0; - switch(fp->chr) { - case '+': - f = FPLUS; - break; - - case '-': - f = FMINUS; - break; - - case '#': - f = FSHARP; - break; - - case 'h': - f = FSHORT; - break; - - case 'l': - f = FLONG; - if(fp->f3 & FLONG) - f = FVLONG; - break; - - case 'u': - f = FUNSIGN; - break; - } - return -f; -} diff --git a/sys/src/boot/alphapc/u.h b/sys/src/boot/alphapc/u.h deleted file mode 100644 index fac9457af..000000000 --- a/sys/src/boot/alphapc/u.h +++ /dev/null @@ -1,28 +0,0 @@ -#define nil ((void*)0) -typedef unsigned short ushort; -typedef unsigned char uchar; -typedef signed char schar; -typedef unsigned long ulong; -typedef unsigned int uint; -typedef long long vlong; -typedef unsigned long long uvlong; -typedef union Length Length; -typedef ushort Rune; - -union Length -{ - vlong length; -}; - -/* stdarg */ -typedef char* va_list; -#define va_start(list, start) list = (char*)(&(start)+1) -#define va_end(list) -#define va_arg(list, mode)\ - (sizeof(mode)==1?\ - ((mode*)(list += 4))[-1]:\ - sizeof(mode)==2?\ - ((mode*)(list += 4))[-1]:\ - sizeof(mode)>4?\ - ((mode*)(list = (char*)((long)(list+7) & ~7) + sizeof(mode)))[-1]:\ - ((mode*)(list += sizeof(mode)))[-1]) diff --git a/sys/src/boot/alphapc/vmspal.h b/sys/src/boot/alphapc/vmspal.h deleted file mode 100644 index aaf26fccc..000000000 --- a/sys/src/boot/alphapc/vmspal.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * VMS PALcode instructions, in numerical order. - */ - -#define PALhalt 0x00 /* required per Alpha architecture */ -#define PALcflush 0x01 -#define PALdraina 0x02 /* required per Alpha architecture */ -#define PALldqp 0x03 - -#define PALstqp 0x04 -#define PALswpctx 0x05 -#define PALmfpr_asn 0x06 -#define PALmtpr_asten 0x07 -#define PALmtpr_astsr 0x08 -#define PALcserve 0x09 -#define PALswppal 0x0a -#define PALmfpr_fen 0x0b -#define PALmtpr_fen 0x0c -#define PALmtpr_ipir 0x0d -#define PALmfpr_ipl 0x0e -#define PALmtpr_ipl 0x0f -#define PALmfpr_mces 0x10 -#define PALmtpr_mces 0x11 -#define PALmfpr_pcbb 0x12 -#define PALmfpr_prbr 0x13 -#define PALmtpr_prbr 0x14 -#define PALmfpr_ptbr 0x15 -#define PALmfpr_scbb 0x16 -#define PALmtpr_scbb 0x17 -#define PALmtpr_sirr 0x18 -#define PALmfpr_sisr 0x19 -#define PALmfpr_tbchk 0x1a -#define PALmtpr_tbia 0x1b -#define PALmtpr_tbiap 0x1c -#define PALmtpr_tbis 0x1d -#define PALmfpr_esp 0x1e -#define PALmtpr_esp 0x1f -#define PALmfpr_ssp 0x20 -#define PALmtpr_ssp 0x21 -#define PALmfpr_usp 0x22 -#define PALmtpr_usp 0x23 -#define PALmtpr_tbisd 0x24 -#define PALmtpr_tbisi 0x25 -#define PALmfpr_asten 0x26 -#define PALmfpr_astsr 0x27 - /* where is instruction 0x28 ? */ -#define PALmfpr_vptb 0x29 -#define PALmtpr_vptb 0x2a -#define PALmtpr_perfmon 0x2b - /* where is instruction 0x2c ? */ - /* where is instruction 0x2d ? */ -#define PALmtpr_datfx 0x2e -/* - * ... 0x2f to 0x3e ?? - */ -#define PALmfpr_whami 0x3f -/* - * ... 0x40 to 0x7f ?? - */ -#define PALbpt 0x80 -#define PALbugchk 0x81 -#define PALchime 0x82 -#define PALchmk 0x83 -#define PALchms 0x84 -#define PALchmu 0x85 -#define PALimb 0x86 /* required per Alpha architecture */ -#define PALinsqhil 0x87 -#define PALinsqtil 0x88 -#define PALinsqhiq 0x89 -#define PALinsqtiq 0x8a -#define PALinsquel 0x8b -#define PALinsqueq 0x8c -#define PALinsqueld 0x8d /* INSQUEL/D */ -#define PALinsqueqd 0x8e /* INSQUEQ/D */ -#define PALprober 0x8f -#define PALprobew 0x90 -#define PALrd_ps 0x91 -#define PALrei 0x92 -#define PALremqhil 0x93 -#define PALremqtil 0x94 -#define PALremqhiq 0x95 -#define PALremqtiq 0x96 -#define PALremquel 0x97 -#define PALremqueq 0x98 -#define PALremqueld 0x99 /* REMQUEL/D */ -#define PALremqueqd 0x9a /* REMQUEQ/D */ -#define PALswasten 0x9b -#define PALwr_ps_sw 0x9c -#define PALrscc 0x9d -#define PALread_unq 0x9e -#define PALwrite_unq 0x9f -#define PALamovrr 0xa0 -#define PALamovrm 0xa1 -#define PALinsqhilr 0xa2 -#define PALinsqtilr 0xa3 - -#define PALinsqhiqr 0xa4 -#define PALinsqtiqr 0xa5 -#define PALremqhilr 0xa6 - -#define PALremqtilr 0xa7 -#define PALremqhiqr 0xa8 -#define PALremqtiqr 0xa9 -#define PALgentrap 0xaa - diff --git a/sys/src/boot/mkfile b/sys/src/boot/mkfile index 0118ae5a4..384bc9f28 100644 --- a/sys/src/boot/mkfile +++ b/sys/src/boot/mkfile @@ -1,7 +1,8 @@ ARCH=\ - alphapc\ bitsy\ + efi\ pc\ + zynq\ all:V: for(i in $ARCH)@{ |