diff options
35 files changed, 3 insertions, 6207 deletions
diff --git a/appl/cmd/fone.b b/appl/cmd/fone.b deleted file mode 100644 index 51bbede6..00000000 --- a/appl/cmd/fone.b +++ /dev/null @@ -1,560 +0,0 @@ -implement fone; - -include "sys.m"; - sys: Sys; - stderr: ref Sys->FD; - stdout: ref Sys->FD; - logfd: ref Sys->FD; - -include "draw.m"; - draw: Draw; - -include "bufio.m"; - bufio: Bufio; - Iobuf: import bufio; - -include "string.m"; - str: String; - -include "sh.m"; - smtp: Command; - -#include "keyring.m"; - -include "daytime.m"; - daytime: Daytime; - -TIMEGRAN: con 60000; -debug := 0; -logflag := 0; -logfile := ""; # name of log file -Nphones := 0; # number of telephone sets configured -voicefile := ""; # name of serial port to DECTalk -voice: ref sys->FD; -mailhost := ""; - -person: adt { - mailaddr: string; - name: string; # name pronounced by the voice - lineno: string; # 4 digit extension - time: string; - orignum: string; # originating number - origname: string; # originating name - state: int; - flags: int; -}; - -# states -ONHOOK: con 0; -RING: con 1; -DISPLAY: con 2; -OFFHOOK: con 3; - -# flags -LOG: con 1; -MAIL: con 2; -ANNOUNCE: con 4; - -telset: adt { - devfile: string; # file name of interface to phone set - apprfile: string; - apprtime: int; # time appearance file is read - phonefd: ref sys->FD; # open FD for this set - numappr: int; # number of appearances on this set - people: array of person; # appearance data for this set - version: string; # telephone set version -}; - -phone:= array[4] of telset; - -months:= array[13] of { 0 => "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug","Sep", "Oct", "Nov", "Dec"}; - -fone: module { - init: fn(ctxt: ref Draw->Context, argv: list of string); -}; - -init(nil: ref Draw->Context, argv: list of string) { - - sys = load Sys Sys->PATH; - bufio = load Bufio Bufio->PATH; - str = load String String->PATH; - daytime = load Daytime Daytime->PATH; - smtp = load Command "smtp.dis"; -# keyring := load Keyring Keyring->PATH; - - stdout = sys->fildes(1); - logfd = stdout; - stderr = sys->fildes(2); - voicechan := chan of string; - timechan := chan of string; - -# -# set up name space. According to tradition this is done -# outside of the program. Needs to be here so debugging -# is not so tedious. -# - if (sys->pctl(sys->FORKNS, nil) < 0) { - sys->fprint(stderr, "pctl(FORKNS) failed: %r\n"); - exit; - } - if (sys->bind("#t", "/dev", sys->MAFTER) < 0) { - sys->fprint(stderr, "bind #t failed: %r\n"); - exit; - } - if (sys->bind("#p", "/prog", sys->MAFTER) < 0) { - sys->fprint(stderr, "bind #p failed: %r\n"); - exit; - } - - if (sys->bind("#C", "/", sys->MAFTER) < 0) { - sys->fprint(stderr, "bind #C failed: %r\n"); - exit; - } - - argv = tl argv; - while(argv != nil && len hd argv && (arg := hd argv)[0] == '-' && len arg > 1){ - case arg[1] { - 'd' => - debug = 1; - logflag = 1; - } - argv = tl argv; - } - configfile("fone.cfg"); -# -# Sound Blaster using sbtalker and read -# -# voice = SBsetup(); -# -# DECtalk using second serial port - voice = DTsetup(voicefile); - - sys->fprint(voice, "hello.\r"); - - - spawn timekeeper(timechan); - for (phoneid := 0; phoneid < Nphones; phoneid++) - spawn watchphone(phoneid, voicechan); - for (;;) alt { - mesg := <- voicechan => - sys->fprint(voice, "%s", mesg); - tmesg := <- timechan => - case tmesg { - "filecheck" => - for (i:=0; i<Nphones; i++) { - (r, f) := sys->stat(phone[i].apprfile); - if (r < 0) { - sys->fprint(stderr, "cannot stat %s: %r\n", phone[i].apprfile); - continue; - } - if (f.mtime > phone[i].apprtime) - getcallapprinfo(i); - } - } - } -} - -# -# read in the configuration file which tells the program which -# files and devices to use. -# -configfile(cfgname: string): int { - line, errstr: string; - - cfgfd := sys->open(cfgname, sys->OREAD); - if (cfgfd == nil) { - sys->fprint(stderr, "open %s failed, %r\n", cfgname); - bye(); - } - do { - (line, errstr) = getline(cfgfd); - if (errstr != nil) { - sys->fprint(stderr, "error reading config file: %r\n"); - return -1; - } - if (line != nil) { - (i, t) := sys->tokenize(line, ": \t\r\n"); - if ((hd t)[0] == '#') continue; - case hd t { - "logfile" => - if (i < 2) { - sys->fprint(stderr, "no log file name found. %d\n", i); - sys->fprint(stderr, "logfile: log_file_name\n"); - return -1; - } - t = tl t; - logfile = hd t; - if (logfile != nil) { - if ((logfd = sys->open(logfile, sys->OWRITE)) == nil) { - sys->fprint(stderr, "open log file %s failed\n", logfile); - continue; - } - logflag = 1; - } - "mailhost" => - if (i < 2) { - sys->fprint(stderr, "no mailhost found."); - sys->fprint(stderr, "mailhost: host_name\n"); - return -1; - } - t = tl t; - mailhost = hd t; - "voice" => - if (i < 2) { - sys->fprint(stderr, "no log file name found."); - sys->fprint(stderr, "voice: serial_port\n"); - return -1; - } - t = tl t; - voicefile = hd t; - "phone" => - if (i < 3) { - sys->fprint(stderr, "not enough fields for phone attendance line\n"); - sys->fprint(stderr, "attend: serial_port phone_appearance_file_name\n"); - return -1; - } - t = tl t; - phonefile := hd t; - t = tl t; - apprfile := hd t; - phone[Nphones].devfile = phonefile; - phone[Nphones].apprfile = apprfile; - phone[Nphones].phonefd = sys->open(phonefile, sys->ORDWR); - if (phone[Nphones].phonefd == nil) { - sys->fprint(stderr, "open %s failed, %r\n", phonefile); - return -1; - } - (numappr, version) := phoneinit(Nphones); - if (numappr == 0) continue; - phone[Nphones].numappr = numappr; - phone[Nphones].people = array[numappr + 1] of person; - phone[Nphones].version = version; - if (debug) sys->fprint(stderr, "phone %d initialized\n", Nphones); - getcallapprinfo(Nphones); - ++Nphones; - * => - sys->fprint(stderr, "bad keyword <%s> in configuration file\n", hd t); - return -1; - } - } - } while (line != nil); - return 0; -} - -# -# -# -timekeeper(tchan: chan of string) { - for(;;) { - sys->sleep(TIMEGRAN); - tchan <- = sys->sprint("filecheck"); - } -} - -# -# monitor the status messages of the phone(s). -# look for ring indications and subsequent display data to send -# to users if they do not answer their phones. -# If display data is received and the phone is not answered, -# a mail message is sent. -# -watchphone(pindex: int, voicechan: chan of string) { - buf, errbuf: string; - - do { - (buf, errbuf) = getline(phone[pindex].phonefd); - if (errbuf != nil) { - sys->fprint(stderr, "%s\n", errbuf); - return; - } - if (debug) sys->fprint(stderr, "phone %d: %s\n", pindex, buf); - (resultcode, info) := str->splitl(buf, ":"); - if (resultcode == nil) continue; - - # get rid of colon - info = info[1:]; - - (i, t) := sys->tokenize(info, ","); - appr := int hd t; - t = tl t; - --i; - case resultcode { - "RING" or "02" => - if ((phone[pindex].people[appr].flags & ANNOUNCE)) - voicechan <- = sys->sprint("phone call for, %s.\r", phone[pindex].people[appr].name); - phone[pindex].people[appr].state = RING; - phone[pindex].people[appr].time = ""; - phone[pindex].people[appr].orignum = ""; - phone[pindex].people[appr].origname = ""; - "DISPLAY" or "06" => - if (i <= 0) { - sys->fprint(stderr, "not enough args for DISPLAY result code\n"); - continue; - } - displaydata := hd t; - (displaytype, s) := str->toint(displaydata[0:2], 16); - case displaytype { - 16r03 => - # originating number - phone[pindex].people[appr].orignum = displaydata[2:]; - 16r05 => - # originating name - phone[pindex].people[appr].origname = displaydata[2:]; - 16r0a => - correct24hr: int; - - # date and time - if (displaydata[13:15] == "pm") - correct24hr = 12; - else - correct24hr = 0; -# hour := int displaydata[8:10] + correct24hr; - phone[pindex].people[appr].time = sys->sprint("%s %2d %2d:%.2d", months[int displaydata[2:4]], int displaydata[5:7], int displaydata[8:10] % 12 + correct24hr, int displaydata[11:13]); - phone[pindex].people[appr].state = DISPLAY; - if (logflag && (phone[pindex].people[appr].flags & LOG)) - sys->fprint(logfd, "%s: x%s %s (%s)\n", phone[pindex].people[appr].time, phone[pindex].people[appr].lineno, phone[pindex].people[appr].orignum, phone[pindex].people[appr].origname); - } - "SIGNAL" or "13" => - signalcode := hd t; - t = tl t; - --i; - case signalcode { - "4F" => - if (i <= 0) { - if (phone[pindex].people[appr].state == DISPLAY) { - phone[pindex].people[appr].state = OFFHOOK; - } - continue; - } - causecode := hd t; - case causecode { - "10" => - case phone[pindex].people[appr].state { - DISPLAY => - if ((phone[pindex].people[appr].flags & MAIL) && phone[pindex].people[appr].mailaddr != "-") { - mailmesg := sys->sprint("From: phoneca\nTo: %s\nSubject: Phone call from %s\n\n from: %s\n phone: %s\n time: %s\n", phone[pindex].people[appr].mailaddr, phone[pindex].people[appr].orignum, phone[pindex].people[appr].origname, phone[pindex].people[appr].orignum, phone[pindex].people[appr].time); - - spawn smtp->init(nil, "smtp" :: mailhost :: "phoneca" :: phone[pindex].people[appr].mailaddr :: mailmesg :: nil); - } - } - phone[pindex].people[appr].state = ONHOOK; - } - } - } - } while(errbuf == nil); -} - -usage() { - sys->fprint(stderr, "usage: fone -d phone_dev\n"); - bye(); -} - -# -# wait for an OK from a particular phone, part of Hayes protocol -OK(phonefd: ref sys->FD): int { - buf, err: string; - - do { - (buf, err) = getline(phonefd); - if (err != nil) { - sys->fprint(stderr, "%s\n", err); - return(0); - } - if (debug) sys->fprint(stderr, "%s\n", buf); - } while (buf != "OK" && buf != "0"); - return(1); -} - -bye() { - exit; -} - -phoneinit(pindex: int): (int, string) { - buf, err: string; - i: int; - t: list of string; - - phonefd := phone[pindex].phonefd; -# E0=echo OFF, V0=verbal return codes ON/OFF, &D0=ignore DTR transition - if (debug) sys->fprint(stderr, "initialize phone %d serial port...", pindex); - sys->fprint(phonefd, "ATE0V1&D0\r"); - if (!OK(phonefd)) return (0, "cannot initialize phone"); - -# &&I=init phone, I3=report phone type - if (debug) sys->fprint(stderr, "get phone version..."); - sys->fprint(phonefd, "AT&&II3\r"); - do { - (buf, err) = getline(phonefd); - if (err != nil) { - sys->fprint(stderr, "%s\n", err); - return (0, "cannot get phone version"); - } - (i, t) = sys->tokenize(buf, " \n\r"); - } while (i != 4 || hd t != "03-"); - t = tl t; - if (!OK(phonefd)) return (0, "cannot get phone version"); - version := hd t; - if (debug) sys->fprint(stderr, "version <%s>\n", version); - numappr := int version[2:4]; - -# %A0=3 channel assigned to control voice - if (debug) sys->fprint(stderr, "control phone's voice channel..."); - sys->fprint(phonefd, "AT%%A0=3\r"); - if (!OK(phonefd)) return (0, "cannot control voice channel"); - return (numappr, version); -} - -# -# get a line of text (up to a newline or carriage return) -# throw away initial newlines or carriage returns -# -getline(fd: ref sys->FD): (string, string) { - c := array[1] of byte; - s := ""; - i := 0; - - loop: while(i < 4096) { - r := sys->read(fd, c, 1); - if(r < 0) - return (s, sys->sprint("%r")); - if(r == 0) - return (nil, nil); - case int c[0] { - '\r' or - '\n' => - if(i != 0) - break loop; - * => - s[i++] = int c[0]; - } - - } - return (s, nil); -} -# -# read in names and mail addresses for appearances on each phone -# -getcallapprinfo(pindex: int) { - name : string; - filename := phone[pindex].apprfile; - - if (debug) sys->fprint(stderr, "getting call appearance data from %s\n", filename); - who := bufio->open(filename, sys->OREAD); - if (who == nil) { - sys->fprint(stderr, "open %s failed, %r\n", filename); - bye(); - } - phone[pindex].apprtime = daytime->now(); - while ((s := who.gets('\n')) != nil) { - if ((array of byte(s))[0] == byte '#') continue; - (i, t) := sys->tokenize(s, " \t\n\r"); - if(i < 5) { - sys->fprint(stderr, "Error in %s. The line was:\n%s\n", filename, s); - continue; - } - appr := int hd t; - t = tl t; - phone[pindex].people[appr].lineno = hd t; - t = tl t; - flags := hd t; - phone[pindex].people[appr].flags = 0; - for (n:=0; n<len flags; n++) { - case int (array of byte flags)[n] { - 'l' => - phone[pindex].people[appr].flags |= LOG; - 'm' => - phone[pindex].people[appr].flags |= MAIL; - 'a' => - phone[pindex].people[appr].flags |= ANNOUNCE; - * => - sys->fprint(stderr, "unknown flag %c\n", int (array of byte flags)[n]); - } - } - t = tl t; - phone[pindex].people[appr].mailaddr = hd t; - t = tl t; - name = ""; - while(t != nil) { - name += " " + hd t; - t = tl t; - } - phone[pindex].people[appr].name = name; -# if (debug) sys->fprint(stderr, "added user %s at %d\n", phone[pindex].people[appr].name, appr); - } -} - -# -# Setup connection to use READ.EXE command in SounBlaster software -# -SBsetup(): ref sys->FD { - cmd := sys->open("/cmd/clone", sys->ORDWR); - if (cmd == nil) { - sys->fprint(stderr, "open %s failed, %r\n", "/cmd/clone"); - bye(); - } - cmdno := array[32] of byte; - if ((n:=sys->read(cmd, cmdno, 32)) <= 0) { - sys->fprint(stderr, "read error: %r\n"); - bye(); - } - cmddirname := "/cmd/" + string cmdno[0:n]; - - if (debug) sys->fprint(stderr, "exec'ing command\n"); - if ((n=sys->fprint(cmd, "exec command")) < 0) { - sys->fprint(stderr, "fprint of cmd failed:%r\n"); - bye(); - } - - cmddata := sys->open(cmddirname + "/data", sys->ORDWR); - if (cmddata == nil) { - sys->fprint(stderr, "open %s:%r\n", cmddirname + "/data"); - bye(); - } - - buf := array[128] of byte; -# sys->fprint(stderr, "sending sbtalker\n"); - if ((n=sys->fprint(cmddata, "sbtalker /dBLASTER\r")) < 0) { - sys->fprint(stderr, "fprint of cmddata failed:%r\n"); - bye(); - } - n = sys->read(cmddata, buf, 128); - if (n < 0) { - sys->fprint(stderr, "read /cmd/n/data failed:%r\n"); - bye(); - } - sys->fprint(stderr, "%*s\n", n, string buf[0:n]); - -# sys->fprint(stderr, "sending read\n"); - if ((n=sys->fprint(cmddata, "read\r")) < 0) { - sys->fprint(stderr, "fprint of cmddata failed:%r\n"); - bye(); - } - n = sys->read(cmddata, buf, 128); - if (n < 0) { - sys->fprint(stderr, "read /cmd/n/data failed:%r\n"); - bye(); - } - sys->fprint(stderr, "%*s\n", n, string buf[0:n]); - return cmddata; -} - -# -# setup connection to DECTalk -# -DTsetup(voicedev: string): ref sys->FD { - voicel := sys->open(voicedev, sys->ORDWR); - if (voicel == nil) { - sys->fprint(stderr, "open %s failed, %r\n", voicedev); - bye(); - } - voicectl := sys->open(voicedev+"ctl", sys->OWRITE); - if (voicectl == nil) { - sys->fprint(stderr, "open %s failed, %r\n", voicedev+"ctl"); - bye(); - } - if (sys->fprint(voicectl, "B1200") != 5) { - sys->fprint(stderr, "write %s failed, %r\n", voicedev+"ctl"); - bye(); - } - return voicel; -} diff --git a/appl/cmd/mkfile b/appl/cmd/mkfile index 892f65cb..a158edaa 100644 --- a/appl/cmd/mkfile +++ b/appl/cmd/mkfile @@ -67,7 +67,6 @@ TARG=\ fc.dis\ fcp.dis\ fmt.dis\ - fone.dis\ fortune.dis\ freq.dis\ fs.dis\ diff --git a/appl/lib/mkfile b/appl/lib/mkfile index 206e4240..4f975883 100644 --- a/appl/lib/mkfile +++ b/appl/lib/mkfile @@ -100,7 +100,6 @@ TARG=\ readpng.dis\ readxbitmap.dis\ regex.dis\ - regexutils.dis\ registries.dis\ rfc822.dis\ riff.dis\ diff --git a/appl/lib/regexutils.b b/appl/lib/regexutils.b deleted file mode 100644 index 4040f0bf..00000000 --- a/appl/lib/regexutils.b +++ /dev/null @@ -1,65 +0,0 @@ -implement RegexUtils; - -# matching and substitution functions -# evb@lucent.com - -include "sys.m"; - sys: Sys; - -include "regexutils.m"; - -init() -{ - if (sys == nil) - sys = load Sys Sys->PATH; - - regex = load Regex Regex->PATH; - if (regex == nil) - raise "fail: Regex not loaded"; -} - -match(pattern: Regex->Re, s: string): string -{ - pos := regex->execute(pattern, s); - if (pos == nil) - return ""; - (beg, end) := pos[0]; - - return s[beg:end]; -} - -match_mult(pattern: Regex->Re, s: string): array of (int, int) -{ - return regex->execute(pattern, s); -} - -sub(text, pattern, new: string): string -{ - return sub_re(text, regex->compile(pattern, 0).t0, new); -} - -sub_re(text: string, pattern: Regex->Re, new: string): string -{ - pos := regex->execute(pattern, text); - if (pos == nil) - return text; - - (beg, end) := pos[0]; - newline := text[:beg] + new + text[end:]; - return newline; -} - -subg(text, pattern, new: string): string -{ - return subg_re(text, regex->compile(pattern, 0).t0, new); -} - -subg_re(text: string, pattern: Regex->Re, new: string): string -{ - oldtext := text; - while ( (text = sub_re(text, pattern, new)) != oldtext) { - oldtext = text; - } - - return text; -} diff --git a/dis/fone.dis b/dis/fone.dis Binary files differdeleted file mode 100644 index f55ee89d..00000000 --- a/dis/fone.dis +++ /dev/null diff --git a/emu/Hp/NOTE b/emu/Hp/NOTE deleted file mode 100644 index 3f1041ea..00000000 --- a/emu/Hp/NOTE +++ /dev/null @@ -1 +0,0 @@ -this, like Irix, lacks deveia diff --git a/emu/Hp/asm-s800.s b/emu/Hp/asm-s800.s deleted file mode 100644 index 865c0b2b..00000000 --- a/emu/Hp/asm-s800.s +++ /dev/null @@ -1,113 +0,0 @@ -; -; /* -; * To get lock routine, compile this into a .s, then SUBSTITUTE -; * a LOAD AND CLEAR WORD instruction for the load and store of -; * l->key. -; * -; */ -; typedef struct Lock { -; int key; -; int pid; -; } Lock; -; -; int -; mutexlock(Lock *l) -; { -; int key; -; -; key = l->key; -; l->key = 0; -; return key != 0; -; } - - .LEVEL 1.1 - - .SPACE $TEXT$,SORT=8 - .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY,SORT=24 -mutexlock - .PROC - .CALLINFO FRAME=0,ARGS_SAVED - .ENTRY -; SUBSTITUTED LDW 0(%r26),%r31 -; SUBSTITUTED STWS %r0,0(%r26) - LDCWS 0(%r26),%r31 ; SUBSTITUTED - COMICLR,= 0,%r31,%r28 - LDI 1,%r28 - .EXIT - BV,N %r0(%r2) - .PROCEND - -; -; JIT help -; - .SPACE $TEXT$,SORT=8 - .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY,SORT=24 -calldata - .PROC - .CALLINFO CALLER,FRAME=16,SAVE_RP - .ENTRY - STW %r2,-20(%r30) - LDO 64(%r30),%r30 - ADDIL LR'dataptr-$global$,%r27 - LDW RR'dataptr-$global$(%r1),%r31 - BLE 0(%sr5,%r31) - COPY %r31,%r2 - LDW -84(%r30),%r2 - BV %r0(%r2) - .EXIT - LDO -64(%r30),%r30 - .PROCEND - - .SPACE $PRIVATE$ - .SUBSPA $SHORTBSS$ -dataptr .COMM 4 - .SUBSPA $SHORTDATA$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=24 -dyncall - .WORD $$dyncall - .EXPORT calldata - .EXPORT dyncall - .IMPORT $$dyncall,MILLICODE - - .SPACE $TEXT$ - .SUBSPA $CODE$ - .SPACE $PRIVATE$,SORT=16 - .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=0x1f,SORT=16 - .SPACE $TEXT$ - .SUBSPA $CODE$ - .EXPORT mutexlock,ENTRY,PRIV_LEV=3,ARGW0=GR,RTNVAL=GR - - .code -; segflush(addr,len) - .proc - .callinfo - .export segflush,entry -segflush - .enter - ldsid (0,%arg0),%r1 - mtsp %r1,%sr0 - ldo -1(%arg1),%arg1 - copy %arg0,%arg2 - copy %arg1,%arg3 - fdc %arg1(0,%arg0) - -loop1 - addib,>,n -16,%arg1,loop1 - fdc %arg1(0,%arg0) - fdc 0(0,%arg0) - sync - fic %arg3(%sr0,%arg2) -loop2 - addib,>,n -16,%arg3,loop2 - fic %arg3(%sr0,%arg2) - fic 0(%sr0,%arg2) - sync - nop - nop - nop - nop - nop - nop - nop - .leave - .procend - .end diff --git a/emu/Hp/cmd.c b/emu/Hp/cmd.c deleted file mode 100644 index bff1f03b..00000000 --- a/emu/Hp/cmd.c +++ /dev/null @@ -1,213 +0,0 @@ -#include <sys/types.h> -#include <signal.h> -#include <pwd.h> -#include <sys/resource.h> -#include <sys/wait.h> -#include <fcntl.h> - -#include "dat.h" -#include "fns.h" -#include "error.h" - -enum -{ - Debug = 0 -}; - -/* - * os-specific devcmd support. - * this version should be reasonably portable across Unix systems. - */ -typedef struct Targ Targ; -struct Targ -{ - int fd[3]; /* fd[0] is standard input, fd[1] is standard output, fd[2] is standard error */ - char** args; - char* dir; - int pid; - int wfd; /* child writes errors that occur after the fork or on exec */ - int uid; - int gid; -}; - -extern int gidnobody; -extern int uidnobody; - -static int -childproc(Targ *t) -{ - int i, nfd; - - if(Debug) - print("devcmd: '%s'", t->args[0]); - - nfd = getdtablesize(); - for(i = 0; i < nfd; i++) - if(i != t->fd[0] && i != t->fd[1] && i != t->fd[2] && i != t->wfd) - close(i); - - dup2(t->fd[0], 0); - dup2(t->fd[1], 1); - dup2(t->fd[2], 2); - close(t->fd[0]); - close(t->fd[1]); - close(t->fd[2]); - - /* should have an auth file to do host-specific authorisation? */ - if(t->gid != -1){ - if(setgid(t->gid) < 0 && getegid() == 0){ - fprint(t->wfd, "can't set gid %d: %s", t->gid, strerror(errno)); - _exit(1); - } - } - - if(t->uid != -1){ - if(setuid(t->uid) < 0 && geteuid() == 0){ - fprint(t->wfd, "can't set uid %d: %s", t->uid, strerror(errno)); - _exit(1); - } - } - - if(t->dir != nil && chdir(t->dir) < 0){ - fprint(t->wfd, "can't chdir to %s: %s", t->dir, strerror(errno)); - _exit(1); - } - - signal(SIGPIPE, SIG_DFL); - - execvp(t->args[0], t->args); - if(Debug) - print("execvp: %s\n",strerror(errno)); - fprint(t->wfd, "exec failed: %s", strerror(errno)); - - _exit(1); -} - -void* -oscmd(char **args, int nice, char *dir, int *fd) -{ - Targ *t; - int r, fd0[2], fd1[2], fd2[2], wfd[2], n, pid; - - t = mallocz(sizeof(*t), 1); - if(t == nil) - return nil; - - fd0[0] = fd0[1] = -1; - fd1[0] = fd1[1] = -1; - fd2[0] = fd2[1] = -1; - wfd[0] = wfd[1] = -1; - if(pipe(fd0) < 0 || pipe(fd1) < 0 || pipe(fd2) < 0 || pipe(wfd) < 0) - goto Error; - if(fcntl(wfd[1], F_SETFD, FD_CLOEXEC) < 0) /* close on exec to give end of file on success */ - goto Error; - - t->fd[0] = fd0[0]; - t->fd[1] = fd1[1]; - t->fd[2] = fd2[1]; - t->wfd = wfd[1]; - t->args = args; - t->dir = dir; - t->gid = up->env->gid; - if(t->gid == -1) - t->gid = gidnobody; - t->uid = up->env->uid; - if(t->uid == -1) - t->uid = uidnobody; - - signal(SIGCHLD, SIG_DFL); - switch(pid = fork()) { - case -1: - goto Error; - case 0: - setpgrp(); - if(nice) - oslopri(); - childproc(t); - _exit(1); - default: - t->pid = pid; - if(Debug) - print("cmd pid %d\n", t->pid); - break; - } - - close(fd0[0]); - close(fd1[1]); - close(fd2[1]); - close(wfd[1]); - - n = read(wfd[0], up->genbuf, sizeof(up->genbuf)-1); - close(wfd[0]); - if(n > 0){ - close(fd0[1]); - close(fd1[0]); - close(fd2[0]); - free(t); - up->genbuf[n] = 0; - if(Debug) - print("oscmd: bad exec: %q\n", up->genbuf); - error(up->genbuf); - return nil; - } - - fd[0] = fd0[1]; - fd[1] = fd1[0]; - fd[2] = fd2[0]; - return t; - -Error: - r = errno; - if(Debug) - print("oscmd: %q\n",strerror(r)); - close(fd0[0]); - close(fd0[1]); - close(fd1[0]); - close(fd1[1]); - close(fd2[0]); - close(fd2[1]); - close(wfd[0]); - close(wfd[1]); - error(strerror(r)); - return nil; -} - -int -oscmdkill(void *a) -{ - Targ *t = a; - - if(Debug) - print("kill: %d\n", t->pid); - return kill(-t->pid, SIGTERM); -} - -int -oscmdwait(void *a, char *buf, int n) -{ - Targ *t = a; - int s; - - if(waitpid(t->pid, &s, 0) == -1){ - if(Debug) - print("wait error: %d [in %d] %q\n", t->pid, getpid(), strerror(errno)); - return -1; - } - if(WIFEXITED(s)){ - if(WEXITSTATUS(s) == 0) - return snprint(buf, n, "%d 0 0 0 ''", t->pid); - return snprint(buf, n, "%d 0 0 0 'exit: %d'", t->pid, WEXITSTATUS(s)); - } - if(WIFSIGNALED(s)){ - if(WTERMSIG(s) == SIGTERM || WTERMSIG(s) == SIGKILL) - return snprint(buf, n, "%d 0 0 0 killed", t->pid); - return snprint(buf, n, "%d 0 0 0 'signal: %d'", t->pid, WTERMSIG(s)); - } - return snprint(buf, n, "%d 0 0 0 'odd status: 0x%x'", t->pid, s); -} - -void -oscmdfree(void *a) -{ - free(a); -} diff --git a/emu/Hp/devaudio.c b/emu/Hp/devaudio.c deleted file mode 100644 index c26143e3..00000000 --- a/emu/Hp/devaudio.c +++ /dev/null @@ -1,506 +0,0 @@ -#include "dat.h" -#include "fns.h" -#include "error.h" - -#include <sys/audio.h> - - -enum{ - Qdir, - Qaudio, - Qaudioctl, /* deprecated */ - Qvolume, - - Fmono = 1, - Fin = 2, - Fout = 4, - Fhearn = 8, - - Vaudio = 0, - Vsynth, - Vcd, - Vline, - Vmic, - Vspeaker, - Vtreb, - Vbass, - Vspeed, - Vbits, - Vchans, - Venc, - Nvol, - - Epcm = 0, - Eulaw, - Ealaw, - Nenc, - - Speed = 44100, - Ncmd = 50, /* max volume command words */ -}; -Dirtab audiotab[]={ - "audio", {Qaudio, 0}, 0, 0666, - "audioctl", {Qaudioctl, 0}, 0, 0666, - "volume", {Qvolume, 0}, 0, 0666, -}; - -typedef struct Audiodev Audiodev; - -struct Audiodev { - int fd; - int swab; - int repl1; - int repl2; -}; - -static struct -{ - QLock; /* XXX maybe we should use this guy! */ - int rivol[Nvol]; /* right/left input/output volumes */ - int livol[Nvol]; - int rovol[Nvol]; - int lovol[Nvol]; -} audio; - -static struct -{ - char* name; - int flag; - int ilval; /* initial values */ - int irval; -} volumes[] = -{ -/*[Vaudio]*/ "audio", Fout, 50, 50, -/*[Vsynth]*/ "synth", Fin|Fout, 0, 0, -/*[Vcd]*/ "cd", Fin|Fout, 0, 0, -/*[Vline]*/ "line", Fin|Fout, 0, 0, -/*[Vmic]*/ "mic", Fin|Fout|Fmono, 0, 0, -/*[Vspeaker]*/ "speaker", Fout|Fmono, 0, 0, - -/*[Vtreb]*/ "treb", Fout, 50, 50, -/*[Vbass]*/ "bass", Fout, 50, 50, - -/*[Vspeed]*/ "speed", Fin|Fout|Fmono, Speed, Speed, -/*[Vbits]*/ "bits", Fin|Fout|Fmono|Fhearn, 16, 16, -/*[Vchans]*/ "chans", Fin|Fout|Fmono|Fhearn, 2, 2, -/*[Venc]*/ "enc", Fin|Fout|Fmono|Fhearn, Epcm, Epcm, - 0 -}; - -static char *encname[] = -{ -/*Epcm*/ "pcm", -/*Eulaw*/ "ulaw", -/*Ealaw*/ "alaw", -}; - -static char Evolume[] = "illegal volume specifier"; - -static void -resetlevel(void) -{ - int i; - - for(i=0; volumes[i].name; i++) { - audio.lovol[i] = volumes[i].ilval; - audio.rovol[i] = volumes[i].irval; - audio.livol[i] = volumes[i].ilval; - audio.rivol[i] = volumes[i].irval; - } -} - -/* Start OS-dependant code */ -static int -doioctl(int fd, int whim, void *data, char *what) -{ - char ebuf[ERRMAX]; - int r, n; - - osenter(); - r = ioctl(fd, whim, data); - osleave(); - if (r < 0) { - n = snprint(ebuf, ERRMAX, "ioctl %s: ", what); - oserrstr(ebuf+n, sizeof ebuf-n); - error(ebuf); - } - return r; -} - -static void -setlevels(Audiodev *a) -{ - struct audio_describe au; - struct audio_gain gain; - int i, x; - -/* XXX todo: simulate it with a data conversion routine (could also do swab...) */ - if (audio.lovol[Venc] == Epcm && audio.lovol[Vbits] != 16) { - audio.lovol[Vbits] = 16; - error("pcm must be 16 bits"); - } - if (audio.lovol[Vchans] != 1 && audio.lovol[Vchans] != 2) { - audio.lovol[Vchans] = 1; - error("bad number of channels"); - } - - doioctl(a->fd, AUDIO_DESCRIBE, &au, "describe"); - doioctl(a->fd, AUDIO_SET_SAMPLE_RATE, audio.lovol[Vspeed], "rate"); /* what if input != output??? */ - doioctl(a->fd, AUDIO_SET_CHANNELS, audio.lovol[Vchans], "channels"); - - switch (audio.lovol[Venc]) { - default: - case Epcm: - x = AUDIO_FORMAT_LINEAR16BIT; - break; - case Eulaw: - x = AUDIO_FORMAT_ULAW; - break; - case Ealaw: - x = AUDIO_FORMAT_ALAW; - break; - } - doioctl(a->fd, AUDIO_SET_DATA_FORMAT, x, "set format"); - - x = 0; - if (audio.lovol[Vspeaker] != 0 || audio.rovol[Vspeaker] != 0) - x |= AUDIO_OUT_SPEAKER; - if (audio.lovol[Vaudio] != 0 || audio.rovol[Vaudio] != 0) - x |= AUDIO_OUT_HEADPHONE; - if (audio.lovol[Vline] != 0 || audio.rovol[Vline] != 0) - x |= AUDIO_OUT_LINE; - doioctl(a->fd, AUDIO_SET_OUTPUT, x, "set output"); - - x = 0; - if (audio.livol[Vline] != 0 || audio.rivol[Vline] != 0) - x |= AUDIO_IN_LINE; - if (audio.livol[Vmic] != 0 || audio.rivol[Vmic] != 0 || x == 0) /* must set at least one */ - x |= AUDIO_IN_MIKE; - doioctl(a->fd, AUDIO_SET_INPUT, x, "set input"); - -/* XXX todo: get the gains right. should scale 0-100 into min-max (as in struct audio_describe au) */ -/* doioctl(a->fd, AUDIO_GET_GAINS, &gain, "get gains"); */ - gain.channel_mask = AUDIO_CHANNEL_LEFT|AUDIO_CHANNEL_RIGHT; - for (i = 0; i < 2; i++) { - gain.cgain[i].receive_gain = au.min_receive_gain; - gain.cgain[i].monitor_gain = au.min_monitor_gain; - gain.cgain[i].transmit_gain = au.max_transmit_gain; - } - doioctl(a->fd, AUDIO_SET_GAINS, &gain, "set gains"); -} - -static char * -audiofname(int isctl) -{ - if (isctl) - return "/dev/audioCtl"; - else - return "/dev/audio"; -} - -static void -audioswab(uchar *p, int n) -{ - int x; - - /* XXX slow; should check for 16bit mode; should be combined with format conversion; etc */ - while (n >= 2) { - x = p[0]; - p[0] = p[1]; - p[1] = x; - p +=2; - n -=2; - } -} -/* End OS-dependant code */ - -static void -audioinit(void) -{ - resetlevel(); -} - -static Chan* -audioattach(char* spec) -{ - return devattach('A', spec); -} - -static int -audiowalk(Chan* c, char* name) -{ - return devwalk(c, name, audiotab, nelem(audiotab), devgen); -} - -static void -audiostat(Chan* c, char* db) -{ - devstat(c, db, audiotab, nelem(audiotab), devgen); -} - -static Chan* -audioopen(Chan *c, int omode) -{ - Audiodev *a; - long path; - char ebuf[ERRMAX]; - - path = c->qid.path & ~CHDIR; - if (path != Qdir){ -/* XXX Irix portability? (multiple opens -- how to match ctl with data???) */ - a = malloc(sizeof(Audiodev)); - if(a == nil) - error(Enomem); - if (waserror()) { - free(a); - nexterror(); - } - a->fd = open(audiofname(path != Qaudio), omode&7); - if(a->fd < 0) - oserror(); - if (path == Qaudio) - setlevels(a); - c->aux = a; - poperror(); - } - return devopen(c, omode, audiotab, nelem(audiotab), devgen); -} - -static void -audioclose(Chan* c) -{ - Audiodev *a; - - a = c->aux; - if (a != nil) { - close(a->fd); - free(a); - } -} - -static long -audioread(Chan* c, void *ua, long n, vlong offset) -{ - Audiodev *a; - char buf[300], ebuf[ERRMAX]; - int liv, riv, lov, rov; - int j, m; - long path; - - a = c->aux; - path = (c->qid.path & ~CHDIR); - switch(path){ - case Qdir: - return devdirread(c, a, n, audiotab, nelem(audiotab), devgen); - case Qaudio: - osenter(); - n = read(a->fd, ua, n); - osleave(); - if (n < 0) - oserror(); - audioswab(ua, n); /* XXX what if n is odd? also, only if 16 bit... must fix portability */ - break; - case Qaudioctl: - case Qvolume: - j = 0; - buf[0] = 0; - for(m=0; volumes[m].name; m++){ - if ((volumes[m].flag & Fhearn) && path == Qvolume) - continue; - liv = audio.livol[m]; - riv = audio.rivol[m]; - lov = audio.lovol[m]; - rov = audio.rovol[m]; - j += snprint(buf+j, sizeof(buf)-j, "%s", volumes[m].name); - if(m == Venc) - j += snprint(buf+j, sizeof(buf)-j, " %s", encname[lov]); - else if((volumes[m].flag & Fmono) || liv==riv && lov==rov){ - if((volumes[m].flag&(Fin|Fout))==(Fin|Fout) && liv==lov) - j += snprint(buf+j, sizeof(buf)-j, " %d", liv); - else{ - if(volumes[m].flag & Fin) - j += snprint(buf+j, sizeof(buf)-j, " in %d", liv); - if(volumes[m].flag & Fout) - j += snprint(buf+j, sizeof(buf)-j, " out %d", lov); - } - }else{ - if((volumes[m].flag&(Fin|Fout))==(Fin|Fout) && liv==lov && riv==rov) - j += snprint(buf+j, sizeof(buf)-j, " left %d right %d", - liv, riv); - else{ - if(volumes[m].flag & Fin) - j += snprint(buf+j, sizeof(buf)-j, " in left %d right %d", - liv, riv); - if(volumes[m].flag & Fout) - j += snprint(buf+j, sizeof(buf)-j, " out left %d right %d", - lov, rov); - } - } - j += snprint(buf+j, sizeof(buf)-j, "\n"); - } - return readstr(offset, ua, n, buf); - default: - n=0; - break; - } - return n; -} - -static long -audiowrite(Chan* c, char *ua, long n, vlong offset) -{ - Audiodev *a; - long m, n0; - int i, nf, v, left, right, in, out; - char buf[255], *field[Ncmd], ebuf[ERRMAX], *p; - - a = c->aux; - switch(c->qid.path & ~CHDIR){ - case Qaudio: - n &= ~1; - audioswab(ua, n); /* XXX VERY BAD BUG; THIS CHANGES THE CALLER'S DATA */ - osenter(); - n = write(a->fd, ua, n); - osleave(); - if (n < 0) - oserror(); - break; - case Qaudioctl: - case Qvolume: - v = Vaudio; - left = 1; - right = 1; - in = 1; - out = 1; - if(n > sizeof(buf)-1) - n = sizeof(buf)-1; - memmove(buf, ua, n); - buf[n] = '\0'; - - nf = getfields(buf, field, Ncmd, 1, " \t\n"); - for(i = 0; i < nf; i++){ - /* - * a number is volume - */ - if(field[i][0] >= '0' && field[i][0] <= '9') { - m = strtoul(field[i], &p, 10); - if (p != nil && *p == 'k') - m *= 1000; - if(left && out) - audio.lovol[v] = m; - if(left && in) - audio.livol[v] = m; - if(right && out) - audio.rovol[v] = m; - if(right && in) - audio.rivol[v] = m; - setlevels(a); - goto cont0; - } - - for(m=0; volumes[m].name; m++) { - if(strcmp(field[i], volumes[m].name) == 0) { - v = m; - in = 1; - out = 1; - left = 1; - right = 1; - goto cont0; - } - } - - if(strcmp(field[i], "reset") == 0) { - resetlevel(); - setlevels(a); - goto cont0; - } - if(strcmp(field[i], "in") == 0) { - in = 1; - out = 0; - goto cont0; - } - if(strcmp(field[i], "out") == 0) { - in = 0; - out = 1; - goto cont0; - } - if(strcmp(field[i], "left") == 0) { - left = 1; - right = 0; - goto cont0; - } - if(strcmp(field[i], "right") == 0) { - left = 0; - right = 1; - goto cont0; - } - if(strcmp(field[i], "rate") == 0) { - v = Vspeed; - in = 1; - out = 1; - left = 1; - right = 1; - goto cont0; - } - if(strcmp(field[i], "chan") == 0) { /* XXX egregious backward compatibility hack */ - v = Vchans; - in = 1; - out = 1; - left = 1; - right = 1; - goto cont0; - } - if(v == Venc) { - if (strcmp(field[i], "pcm") == 0) { - audio.lovol[v] = Epcm; - goto cont0; - } - if (strcmp(field[i], "ulaw") == 0) { - audio.lovol[v] = Eulaw; - goto cont0; - } - if (strcmp(field[i], "alaw") == 0) { - audio.lovol[v] = Ealaw; - goto cont0; - } - } - if(v == Vchans) { - if (strcmp(field[i], "mono") == 0) { - audio.lovol[v] = 1; - goto cont0; - } - if (strcmp(field[i], "stereo") == 0) { - audio.lovol[v] = 2; - goto cont0; - } - } - error(Evolume); - break; - cont0:; - } - break; - default: - error(Ebadusefd); - } - return n; -} - -Dev audiodevtab = { - 'A', - "audio", - - audioinit, - audioattach, - devclone, - audiowalk, - audiostat, - audioopen, - devcreate, - audioclose, - audioread, - devbread, - audiowrite, - devbwrite, - devremove, - devwstat, -}; diff --git a/emu/Hp/devfs.c b/emu/Hp/devfs.c deleted file mode 100644 index 194c1090..00000000 --- a/emu/Hp/devfs.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "devfs-posix.c" - -static vlong -osdisksize(int fd) -{ - return 0; -} diff --git a/emu/Hp/emu b/emu/Hp/emu deleted file mode 100644 index be898d74..00000000 --- a/emu/Hp/emu +++ /dev/null @@ -1,112 +0,0 @@ -dev - root - cons - env - mnt - pipe - prog - prof - srv - dup - ssl - cap - fs - cmd cmd - indir - - draw win-x11a - pointer - snarf - - ip ipif-posix ipaux -# eia -# audio audio - audio - mem - -lib - interp - tk - freetype - math - draw - - memlayer - memdraw - keyring - sec - mp - - 9 - -link - -mod - sys - draw - - tk - math - srv srv - keyring - crypt - ipints - loader - freetype - -port - alloc - cache - chan - dev - devtab - - dial - dis - discall - env - error - errstr - exception - exportfs - inferno - latin1 - main - parse - pgrp - print - proc - qio - random - sysfile - uqid - -code - -init - emuinit - -root - /dev / - /fd / - /prog / - /prof / - /net / - /net.alt / - /chan / - /nvfs / - /env / -# /chan -# /dev -# /dis -# /env -# /n -# /net -# /nvfs / -# /prog -# /icons -# /osinit.dis -# /dis/emuinit.dis -# /dis/lib/auth.dis -# /dis/lib/ssl.dis -# /n/local / diff --git a/emu/Hp/mkfile b/emu/Hp/mkfile deleted file mode 100644 index f332db7a..00000000 --- a/emu/Hp/mkfile +++ /dev/null @@ -1,49 +0,0 @@ -SYSTARG=Hp -OBJTYPE=s800 -<../../mkconfig -SYSTARG=Hp -OBJTYPE=s800 - -#Configurable parameters - -CONF=emu #default configuration -CONFLIST=emu -CLEANCONFLIST= - -INSTALLDIR=$ROOT/$SYSTARG/$OBJTYPE/bin #path of directory where kernel is installed - -#end configurable parameters - -<$ROOT/mkfiles/mkfile-$SYSTARG-$OBJTYPE #set vars based on target system - -<| $SHELLNAME ../port/mkdevlist $CONF #sets $IP, $DEVS, $PORT, $LIBS - -OBJ=\ - asm-$OBJTYPE.$O\ - os.$O\ - $CONF.root.$O\ - lock.$O\ - $DEVS\ - $PORT\ - -HFILES=\ - -CFLAGS='-DROOT="'$ROOT'"' -DEMU -I. -I../port -I$ROOT/$SYSTARG/$OBJTYPE/include -I$ROOT/include -I$ROOT/libinterp $CTHREADFLAGS $CFLAGS $EMUOPTIONS -SYSLIBS= -lm -lX11 -lcma -KERNDATE=`{$NDATE} - -default:V: $O.$CONF - -<../port/portmkfile - -$O.$CONF: $OBJ $CONF.c $CONF.root.h $LIBFILES - $CC $CFLAGS '-DKERNDATE='$KERNDATE $CONF.c - $LD $LDFLAGS -o $target $OBJ $CONF.$O $LIBFILES $SYSLIBS - -install:V: $O.$CONF - cp $O.$CONF $INSTALLDIR/$CONF - -devaudio.$O: devaudio.c - $CC $CFLAGS devaudio.c - -devfs.$O: ../port/devfs-posix.c diff --git a/emu/Hp/mkfile-Hp b/emu/Hp/mkfile-Hp deleted file mode 100644 index 37c625db..00000000 --- a/emu/Hp/mkfile-Hp +++ /dev/null @@ -1,13 +0,0 @@ -# -# architecture-dependent files for Hp -# - -TARGFILES=asm-Hp-s800.$O\ - devfs-posix.$O\ - devip.$O\ - ipif-posix.$O\ - os-Hp.$O\ - win-x11.$O\ - devaudio-Hp.$O\ - srv.$O\ - lock.$O\ diff --git a/emu/Hp/os.c b/emu/Hp/os.c deleted file mode 100644 index b51b4a8c..00000000 --- a/emu/Hp/os.c +++ /dev/null @@ -1,585 +0,0 @@ -#include <pthread.h> -#include <signal.h> -#include "dat.h" -#include "fns.h" -#include "error.h" -#include <sys/socket.h> -#include <time.h> -#include <sys/time.h> -#include <termios.h> -#include <pwd.h> -#include <errno.h> - -enum -{ - BUNCHES = 5000, - DELETE = 0x7F -}; -char *hosttype = "Hp"; - - -static pthread_key_t prdakey; - -extern int dflag; - -Lock mulock = {1, 0}; - -ulong -_tas(ulong *l) -{ - ulong v; - - while(!(mutexlock(&mulock))) - pthread_yield(); - - v = *l; - if(v == 0) - *l = 1; - mulock.key = 1; - return v; -} - -static ulong erendezvous(void*, ulong); - - -void -osblock(void) -{ - erendezvous(up, 0); -} - -void -osready(Proc *p) -{ - erendezvous(p, 0); -} - - -void -pexit(char *msg, int t) -{ - Osenv *e; - - lock(&procs.l); - if(up->prev) - up->prev->next = up->next; - else - procs.head = up->next; - - if(up->next) - up->next->prev = up->prev; - else - procs.tail = up->prev; - unlock(&procs.l); - - e = up->env; - if(e != nil) { - closefgrp(e->fgrp); - closepgrp(e->pgrp); - closeegrp(e->egrp); - closesigs(e->sigs); - } - free(up->prog); - free(up); - pthread_exit(0); -} - -void -trapBUS(int signo, siginfo_t *info, void *context) -{ - if(info) - print("trapBUS: signo: %d code: %d addr: %lx\n", - info->si_signo, info->si_code, info->si_addr); - else - print("trapBUS: no info\n"); - disfault(nil, "Bus error"); -} - -void -trapUSR1(void) -{ - int intwait; - - intwait = up->intwait; - up->intwait = 0; /* clear it to let proc continue in osleave */ - - if(up->type != Interp) /* Used to unblock pending I/O */ - return; - - if(intwait == 0) /* Not posted so it's a sync error */ - disfault(nil, Eintr); /* Should never happen */ -} - -void -trapILL(void) -{ - disfault(nil, "Illegal instruction"); -} - -void -trapSEGV(void) -{ - disfault(nil, "Segmentation violation"); -} - -sigset_t set; -setsigs() -{ - struct sigaction act; - - memset(&act, 0 , sizeof(act)); - sigemptyset(&set); - - act.sa_handler=SIG_IGN; - if(sigaction(SIGPIPE, &act, nil)) - panic("can't ignore sig pipe"); - - if(sigaddset(&set,SIGUSR1)== -1) - panic("sigaddset SIGUSR1"); - - if(sigaddset(&set,SIGUSR2)== -1) - panic("sigaddset SIGUSR2"); - - /* For the correct functioning of devcmd in the - * face of exiting slaves - */ - if(sflag == 0) { - act.sa_handler=trapBUS; - act.sa_flags|=SA_SIGINFO; - if(sigaction(SIGBUS, &act, nil)) - panic("sigaction SIGBUS"); - act.sa_handler=trapILL; - if(sigaction(SIGILL, &act, nil)) - panic("sigaction SIGILL"); - act.sa_handler=trapSEGV; - if(sigaction(SIGSEGV, &act, nil)) - panic("sigaction SIGSEGV"); - if(sigaddset(&set,SIGINT)== -1) - panic("sigaddset"); - } - if(sigprocmask(SIG_BLOCK,&set,nil)!= 0) - panic("sigprocmask"); -} - -static void * -tramp(void *v) -{ - struct Proc *Up; - pthread_t thread; - struct sigaction oldact; - - setsigs(); - if(sigaction(SIGBUS, nil, &oldact)) - panic("sigaction failed"); - if(oldact.sa_handler!=trapBUS && sflag==0) - panic("3rd old act sa_handler"); - - if(pthread_setspecific(prdakey,v)) { - print("set specific data failed in tramp\n"); - pthread_exit(0); - } - Up = v; - thread = pthread_self(); - Up->sigid = cma_thread_get_unique(&thread); - /* attempt to catch signals again */ - setsigs(); - Up->func(Up->arg); - pexit("", 0); -} - -pthread_t active_threads[BUNCHES]; /* this should be more than enuf */ - -void -kproc(char *name, void (*func)(void*), void *arg, int flags) -{ - pthread_t thread; - pthread_attr_t attr; - int id; - Proc *p; - Pgrp *pg; - Fgrp *fg; - Egrp *eg; - struct sigaction oldact; - - p = newproc(); - - if(flags & KPDUPPG) { - pg = up->env->pgrp; - incref(&pg->r); - p->env->pgrp = pg; - } - if(flags & KPDUPFDG) { - fg = up->env->fgrp; - incref(&fg->r); - p->env->fgrp = fg; - } - if(flags & KPDUPENVG) { - eg = up->env->egrp; - incref(&eg->r); - p->env->egrp = eg; - } - - p->env->uid = up->env->uid; - p->env->gid = up->env->gid; - kstrdup(&p->env->user, up->env->user); - - strcpy(p->text, name); - - p->func = func; - p->arg = arg; - - lock(&procs.l); - if(procs.tail != nil) { - p->prev = procs.tail; - procs.tail->next = p; - } - else { - procs.head = p; - p->prev = nil; - } - procs.tail = p; - unlock(&procs.l); - if((pthread_attr_create(&attr))== -1) - panic("pthread_attr_create failed"); - - pthread_attr_setsched(&attr,SCHED_OTHER); - if(pthread_create(&thread, &attr, tramp, p)) - panic("thr_create failed\n"); - if(sigaction(SIGBUS, nil, &oldact)) - panic("sigaction failed"); - if(oldact.sa_handler!=trapBUS && sflag == 0) - panic("2nd old act sa_handler"); - - if((id=cma_thread_get_unique(&thread))>=BUNCHES) - panic("id too big"); - active_threads[id]=thread; -} - -void -oshostintr(Proc *p) -{ - pthread_cancel(active_threads[p->sigid]); -} - -void -oslongjmp(void *regs, osjmpbuf env, int val) -{ - USED(regs); - siglongjmp(env, val); -} - -struct termios tinit; - -static void -termset(void) -{ - struct termios t; - - tcgetattr(0, &t); - tinit = t; - t.c_lflag &= ~(ICANON|ECHO|ISIG); - t.c_cc[VMIN] = 1; - t.c_cc[VTIME] = 0; - tcsetattr(0, TCSANOW, &t); -} - -static void -termrestore(void) -{ - tcsetattr(0, TCSANOW, &tinit); -} - -void -cleanexit(int x) -{ - USED(x); - - if(up->intwait) { - up->intwait = 0; - return; - } - - if(dflag == 0) - termrestore(); - - kill(0, SIGKILL); - exit(0); -} - -void -osreboot(char *file, char **argv) -{ - if(dflag == 0) - termrestore(); - execvp(file, argv); - panic("reboot failure"); -} - -int gidnobody= -1, uidnobody= -1; - -void -getnobody() -{ - struct passwd *pwd; - - if(pwd = getpwnam("nobody")) { - uidnobody = pwd->pw_uid; - gidnobody = pwd->pw_gid; - } -} - -static pthread_mutex_t rendezvouslock; - -void -libinit(char *imod) -{ - struct passwd *pw; - struct Proc *Up; - struct sigaction oldact; - int ii; - int retval; - int *pidptr; - char sys[64]; - - cma_init(); - setsid(); - /* mulock.key = 1; */ /* initialize to unlock */ - if(pthread_mutex_init(&rendezvouslock,pthread_mutexattr_default)) - panic("pthread_mutex_init"); - - gethostname(sys, sizeof(sys)); - kstrdup(&ossysname, sys); - getnobody(); - - if(dflag == 0) - termset(); - - setsigs(); - if(sigaction(SIGBUS, nil, &oldact)) { - panic("sigaction failed"); - } - if(oldact.sa_handler!=trapBUS && sflag == 0) - panic("1st old act sa_handler"); - - if(pthread_keycreate(&prdakey,NULL)) - print("keycreate failed\n"); - - Up = newproc(); - if(pthread_setspecific(prdakey,Up)) - panic("set specific thread data failed\n"); - - pw = getpwuid(getuid()); - if(pw != nil) - kstrdup(&eve, pw->pw_name); - else - print("cannot getpwuid\n"); - - up->env->uid = getuid(); - up->env->gid = getgid(); - emuinit(imod); -} - -int -readkbd(void) -{ - int n; - char buf[1]; - - n = read(0, buf, sizeof(buf)); - if(n != 1) { - print("keyboard close (n=%d, %s)\n", n, strerror(errno)); - pexit("keyboard thread", 0); - } - - switch(buf[0]) { - case '\r': - buf[0] = '\n'; - break; - case DELETE: - cleanexit(0); - break; - } - return buf[0]; -} - -enum -{ - NHLOG = 7, - NHASH = (1<<NHLOG) -}; - -typedef struct Tag Tag; -struct Tag -{ - void* tag; - ulong val; - int pid; - Tag* hash; - Tag* free; - pthread_cond_t cv; -}; - -static Tag* ht[NHASH]; -static Tag* ft; - -static ulong -erendezvous(void *tag, ulong value) -{ - int h; - ulong rval; - Tag *t, *f, **l; - int ii=0; - - h = (ulong)tag & (NHASH-1); - - if(pthread_mutex_lock(&rendezvouslock)) - panic("pthread_mutex_lock"); - - l = &ht[h]; - for(t = *l; t; t = t->hash) { - if(t->tag == tag) { - rval = t->val; - t->val = value; - t->tag = 0; - if(pthread_mutex_unlock(&rendezvouslock)) - panic("pthread_mutex_unlock"); - if(pthread_cond_signal(&(t->cv))) - panic("pthread_cond_signal"); - return rval; - } - } - - t = ft; - if(t == 0) { - t = malloc(sizeof(Tag)); - if(t == 0) - panic("rendezvous: no memory"); - if(pthread_cond_init(&(t->cv),pthread_condattr_default)) { - print("pthread_cond_init (errno: %s) \n", strerror(errno)); - panic("pthread_cond_init"); - } - } else - ft = t->free; - - t->tag = tag; - t->val = value; - t->hash = *l; - *l = t; - - while(t->tag) - pthread_cond_wait(&(t->cv),&rendezvouslock); - - rval = t->val; - for(f = *l; f; f = f->hash){ - if(f == t) { - *l = f->hash; - break; - } - l = &f->hash; - } - t->free = ft; - ft = t; - if(pthread_mutex_unlock(&rendezvouslock)) - panic("pthread_mutex_unlock"); - - return rval; -} - - -/* - * Return an abitrary millisecond clock time - */ -long -osmillisec(void) -{ - static long sec0 = 0, usec0; - struct timeval t; - - if(gettimeofday(&t,(struct timezone*)0)<0) - return(0); - if(sec0==0) { - sec0 = t.tv_sec; - usec0 = t.tv_usec; - } - return((t.tv_sec-sec0)*1000+(t.tv_usec-usec0+500)/1000); -} - -/* - * Return the time since the epoch in nanoseconds and microseconds - * The epoch is defined at 1 Jan 1970 - */ -vlong -osnsec(void) -{ - struct timeval t; - - gettimeofday(&t, nil); - return (vlong)t.tv_sec*1000000000L + t.tv_usec*1000; -} - -vlong -osusectime(void) -{ - struct timeval t; - - gettimeofday(&t, nil); - return (vlong)t.tv_sec * 1000000 + t.tv_usec; -} - - -int -osmillisleep(ulong milsec) -{ - struct timespec time; - time.tv_sec = milsec/1000; - time.tv_nsec= (milsec%1000)*1000000; - if(pthread_delay_np(&time)== -1) - ; /* might be interrupted */ - return 0; -} - -Proc * -getup(void) -{ - void *vp; - - vp=nil; - pthread_getspecific(prdakey,&vp); - return(vp); -} - -ulong -getcallerpc(void *arg) -{ - return 0 ; -} - -void -osyield(void) -{ - pthread_yield(); -} - -void -ospause(void) -{ - int s; - - for(;;) { - switch(s=sigwait(&set)) { - case SIGUSR1: - trapUSR1(); - case SIGINT: - cleanexit(0); - default: - print("signal: %d %s\n",s, strerror(errno)); - panic("sigwait"); - } - } -} - -void -oslopri(void) -{ - /* TO DO */ -} diff --git a/emu/Nt/r16.h b/emu/Nt/r16.h index 4dbfa43f..de09eacc 100644 --- a/emu/Nt/r16.h +++ b/emu/Nt/r16.h @@ -7,4 +7,4 @@ typedef unsigned short Rune16; Rune16* runes16dup(Rune16*); Rune16* utftorunes16(Rune16*, char*, int); char* runes16toutf(char*, Rune16*, int); - int runescmp(Rune16*, Rune16*); + int runes16cmp(Rune16*, Rune16*); diff --git a/emu/Nt/win.c b/emu/Nt/win.c index 4eb56f45..b6330b16 100644 --- a/emu/Nt/win.c +++ b/emu/Nt/win.c @@ -752,7 +752,7 @@ int clipwrite(char *buf) { HANDLE h; - char *p, *e; + char *p; Rune *rp; int n; @@ -771,11 +771,7 @@ clipwrite(char *buf) if(h == NULL) error(Enovmem); rp = GlobalLock(h); - p = buf; - e = p+n; - while(p<e) - p += chartorune(rp++, p); - *rp = 0; + utftorunes16(rp, buf, n+1); GlobalUnlock(h); SetClipboardData(CF_UNICODETEXT, h); diff --git a/lib9/getcallerpc-Hp-s800.s b/lib9/getcallerpc-Hp-s800.s deleted file mode 100644 index 2a1f4080..00000000 --- a/lib9/getcallerpc-Hp-s800.s +++ /dev/null @@ -1,12 +0,0 @@ - .LEVEL 1.1 - - .SPACE $TEXT$,SORT=8 - .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY,SORT=24 -getcallerpc - .PROC - .CALLINFO FRAME=0,ARGS_SAVED - .ENTRY - LDI 0,%r28 - .EXIT - BV,N %r0(%r2) - .PROCEND diff --git a/lib9/lock-Hp-s800.s b/lib9/lock-Hp-s800.s deleted file mode 100644 index 26b6ca47..00000000 --- a/lib9/lock-Hp-s800.s +++ /dev/null @@ -1,38 +0,0 @@ -; -; /* -; * To get lock routine, compile this into a .s, then SUBSTITUTE -; * a LOAD AND CLEAR WORD instruction for the load and store of -; * l->key. -; * -; */ -; typedef struct Lock { -; int key; -; } Lock; -; -; int -; mutexlock(Lock *l) -; { -; int key; -; -; key = l->key; -; l->key = 0; -; return key != 0; -; } - - .LEVEL 1.1 - - .SPACE $TEXT$,SORT=8 - .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY,SORT=24 -mutexlock - .PROC - .CALLINFO FRAME=0,ARGS_SAVED - .ENTRY -; SUBSTITUTED LDW 0(%r26),%r31 -; SUBSTITUTED STWS %r0,0(%r26) - LDCWS 0(%r26),%r31 ; SUBSTITUTED - COMICLR,= 0,%r31,%r28 - LDI 1,%r28 - .EXIT - BV,N %r0(%r2) - .PROCEND - .end diff --git a/libdynld/dynld-68000.c b/libdynld/dynld-68000.c deleted file mode 100644 index db907983..00000000 --- a/libdynld/dynld-68000.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "lib9.h" -#include <a.out.h> -#include <dynld.h> - -#define CHK(i,ntab) if((unsigned)(i)>=(ntab))return "bad relocation index" - -long -dynmagic(void) -{ - return DYN_MAGIC | A_MAGIC; -} - -char* -dynreloc(uchar *b, ulong p, int m, Dynsym **tab, int ntab) -{ - USED(b); - USED(p); - USED(m); - USED(tab); - USED(ntab); - return "68000 unimplemented"; -} diff --git a/libinterp/comp-s800.c b/libinterp/comp-s800.c deleted file mode 100644 index 90d8afc3..00000000 --- a/libinterp/comp-s800.c +++ /dev/null @@ -1,2024 +0,0 @@ -#include "lib9.h" -#include "isa.h" -#include "interp.h" -#include "raise.h" - -#define P4(o) ((o) < (1 << 4)) -#define N4(o) (~(o) < (1 << 4)) -#define P13(o) ((o) < (1 << 13)) -#define N13(o) (~(o) < (1 << 13)) -#define B4(o) ((o) & M4) -#define B11(o) ((o) & M11) -#define B13(o) ((o) & M13) -#define B21(o) ((o) & M21) - -#define DOT ((ulong)code) -#define RELPC(pc) ((ulong)(base+pc)) - -#define nop() arith(Aor, RZ, RZ, RZ) -#define bra(o) BL(RZ, (o)) -#define add(r, c) LDSTpos(Oldo, c, r, r) -#define displ(ix) ((ulong)(base+patch[ix]-code-2)) -#define mdispl(ix) ((ulong)(base+macro[ix]-code-2)) -#define mbra(ix) bra(mdispl(ix)) - -enum -{ - R0 = 0, - R1 = 1, - R2 = 2, - - R19 = 19, - R20 = 20, - R21 = 21, - R22 = 22, - R23 = 23, - R24 = 24, - R25 = 25, - R26 = 26, - R27 = 27, - R28 = 28, - R29 = 29, - R30 = 30, - R31 = 31, - - RLINK = R2, /* Function linkage */ - - RZ = R0, /* Always 0 */ - RFP = R26, /* Frame Pointer */ - RMP = R25, /* Module Pointer */ - RREG = R24, /* Pointer to REG */ - RTA = R29, /* Intermediate address for double indirect */ - RCON = R23, /* Constant builder */ - RCALL = R31, /* Call temp and link dest */ - - RA3 = R22, /* gpr 3 */ - RA2 = R21, /* gpr 2 2+3 = big */ - RA1 = R20, /* gpr 1 */ - RA0 = R19, /* gpr 0 0+1 = big */ - - RCSP = R30, /* C stack pointer */ - RARG0 = R26, /* C arg0 */ - RMILLI0 = R22, /* Millicode arg0 */ - - /* Floating */ - FRZ = 0, /* Zero */ - FR0 = 4, - FR1 = 5, - - /* opcodes */ - Osys = 0x00, - Oarith = 0x02, - Oldwx = 0x03, - Oldil = 0x08, - Oldo = 0x0D, - Oldb = 0x10, - Oldh = 0x11, - Oldw = 0x12, - Ostb = 0x18, - Osth = 0x19, - Ostw = 0x1A, - Ocombt = 0x20, - Ocomibt = 0x21, - Ocombf = 0x22, - Ocomibf = 0x23, - Oaddibt = 0x29, - Oaddibf = 0x2B, - Oextrs = 0x34, - Obe = 0x38, - Oble = 0x39, - Obr = 0x3A, - - Oflldst = 0x0B, - Ofltc = 0x0C, - - Ftst = 0x2420, - Fload = 0, - Fstore = 1, - - /* psuedo opcodes */ - Pld = 0x10, /* base of loads */ - Pst = 0x18, /* base of stores */ - - /* sub opcodes */ - Aand = 0x10, - Aor = 0x12, - Axor = 0x14, - Asub = 0x20, - Aadd = 0x30, - Ash1add = 0x32, - Ash2add = 0x34, - - /* FP sub codes */ - Fadd = 0, - Fsub = 1, - Fmul = 2, - Fdiv = 3, - - Sldsid = 0x85, - Smtsp = 0xC1, - - /* conditions */ - Cnever = 0, - Cequal = 1, - Cless = 2, - Cleq = 3, - Clessu = 4, - Clequ = 5, - Csv = 6, - Codd = 7, - - /* FP conditions */ - Fnever = 0, - Fequal = 1, - Fless = 2, - Fleq = 3, - Fgrt = 4, - Fgeq = 5, - Fneq = 6, - Falways = 7, - - /* masks */ - M4 = 0xF, - M5 = 0x1F, - M10 = 0x3FF, - M11 = 0x7FF, - M13 = 0x1FFF, - M21 = 0x1FFFFF, - - /* spaces */ - STemp = 0, - SCode = 4, - SData = 5, - - PRESZ = 20, - - /* punt ops */ - SRCOP = (1<<0), - DSTOP = (1<<1), - WRTPC = (1<<2), - TCHECK = (1<<3), - NEWPC = (1<<4), - DBRAN = (1<<5), - THREOP = (1<<6), - - ANDAND = 1, - OROR = 2, - EQAND = 3, - - MacFRP = 0, - MacRET = 1, - MacCASE = 2, - MacCOLR = 3, - MacMCAL = 4, - MacFRAM = 5, - MacMFRA = 6, - NMACRO -}; - -static ulong* code; -static ulong* base; -static ulong* patch; -static int pass; -static Module* mod; -static uchar* tinit; -static ulong* litpool; -static int nlit; -static void macfrp(void); -static void macret(void); -static void maccase(void); -static void maccolr(void); -static void macmcal(void); -static void macfram(void); -static void macmfra(void); -static ulong macro[NMACRO]; - void (*comvec)(void); -extern void das(uchar*, int); -extern ulong *dataptr; -extern void calldata(); -extern void calltext(); -extern long dyncall; - -#define T(r) *((void**)(R.r)) - -static void -prlast() -{ - print("%x\t%x\n", code - 1, code[-1]); -} - -struct -{ - int idx; - void (*gen)(void); - char* name; -} mactab[] = -{ - MacFRP, macfrp, "FRP", /* decrement and free pointer */ - MacRET, macret, "RET", /* return instruction */ - MacCASE, maccase, "CASE", /* case instruction */ - MacCOLR, maccolr, "COLR", /* increment and color pointer */ - MacMCAL, macmcal, "MCAL", /* mcall bottom half */ - MacFRAM, macfram, "FRAM", /* frame instruction */ - MacMFRA, macmfra, "MFRA", /* punt mframe because t->initialize==0 */ -}; - -static void -rdestroy(void) -{ - destroy(R.s); -} - -static void -rmcall(void) -{ - Prog *p; - Frame *f; - - f = (Frame*)R.FP; - if(f == H) - error(exModule); - - f->mr = nil; - ((void(*)(Frame*))R.dt)(f); - R.SP = (uchar*)f; - R.FP = f->fp; - if(f->t == nil) - unextend(f); - else - freeptrs(f, f->t); - p = currun(); - if(p->kill) - error(p->kill); -} - -static void -rmfram(void) -{ - Type *t; - Frame *f; - uchar *nsp; - - t = (Type*)R.s; - nsp = R.SP + t->size; - if(nsp >= R.TS) { - R.s = t; - extend(); - T(d) = R.s; - return; - } - f = (Frame*)R.SP; - R.SP = nsp; - f->t = t; - f->mr = nil; - initmem(t, f); - T(d) = f; -} - -static void -urk(void) -{ - error("compile failed"); -} - -static int -mkspace(int s) -{ - return ((s & 4) << 11) | ((s & 3) << 14); -} - -static ulong -posdisp(int disp) -{ - return (((disp & M10) << 1) | ((disp >> 10) & 1)) << 2; -} - -static ulong -disp11(int disp) -{ - return posdisp(disp) | (disp < 0 ? 1 : 0); -} - -static void -opatch(ulong *b) -{ - *b |= posdisp(code - b - 2); -} - -static ulong -frig17(ulong v) -{ - return ((v & M10) << 3) | - ((v & (1 << 10)) >> 8) | - ((v & (M5 << 11)) << 5) | - ((v >> 16) & 1); -} - -static ulong -frig21(ulong v) -{ - return ((v >> 20) & 1) | - ((v >> 8) & (M11 << 1)) | - ((v & 3) << 12) | - ((v & (3 << 7)) << 7) | - ((v & (M5 << 2)) << 14); -} - -static void -BLE(int r, int off, int s) -{ - *code++ = (Oble << 26) | (r << 21) | mkspace(s) | frig17(off >> 2); -} - -static void -BE(int r, int off, int s) -{ - *code++ = (Obe << 26) | (r << 21) | mkspace(s) | frig17(off); -} - -static void -BL(int r, int off) -{ - *code++ = (Obr << 26) | (r << 21) | frig17(off); -} - -static void -BV(int r) -{ - *code++ = (Obr << 26) | (r << 21) | (6 << 13); -} - -static void -LDIL(int r, ulong imm) -{ - *code++ = (Oldil << 26) | (r << 21) | frig21(imm); -} - -static void -LDWX(int i, int b, int r, int t) -{ - *code++ = (Oldwx << 26) | (b << 21) | (r << 16) | ((i - Pld) << 6) | t; -} - -static void -LDSTneg(int i, ulong off, int b, int r) -{ - *code++ = (i << 26) | (b << 21) | (r << 16) | (B13(off) << 1) | 1; -} - -static void -LDSTpos(int i, ulong off, int b, int r) -{ - *code++ = (i << 26) | (b << 21) | (r << 16) | (off << 1); -} - -static void -FLDSTneg(int inst, ulong disp, int rm, int r) -{ - *code++ = (Oflldst << 26) | (rm << 21) | (B4(disp) << 17) | (1 << 16) | (1 << 12) | (inst << 9) | r; -} - -static void -FLDSTpos(int inst, ulong disp, int rm, int r) -{ - *code++ = (Oflldst << 26) | (rm << 21) | (disp << 17) | (1 << 12) | (inst << 9) | r; -} - -static void -FLDSTX(int inst, int b, int x, int r) -{ - *code++ = (Oflldst << 26) | (b << 21) | (x << 17) | (inst << 9) | r; -} - -static void -FCMP(int r, int c, int b) -{ - *code++ = (Ofltc << 26) | (r << 21) | (b << 16) | (6 << 9) | (c << 2); -} - -static void -FTEST() -{ - *code++ = (Ofltc << 26) | Ftst; -} - -static void -farith(int o, int r1, int r2, int t) -{ - *code++ = (Ofltc << 26) | (r1 << 21) | (r2 << 16) | (o << 13) | (7 << 9) | t; -} - -static void -arith(int o, int s, int m, int d) -{ - *code++ = (Oarith << 26) | (m << 21) | (s << 16) | (o << 5) | d; -} - -static void -mov(int s, int d) -{ - LDSTpos(Oldo, 0, s, d); -} - -static void -shrs(int r, int s, int t) -{ - *code++ = (Oextrs << 26) | (r << 21) | (t << 16) | (7 << 10) | ((31 - s) << 5) | s; -} - -static void -comb(int op, int r1, int c, int r2, int off) -{ - *code++ = (op << 26) | (r2 << 21) | (r1 << 16) | (c << 13) | disp11(off); -} - -static int -es5(int v) -{ - return (B4(v) << 1) | (v < 0 ? 1 : 0); -} - -static void -combt(int r1, int c, int r2, int off) -{ - comb(Ocombt, r1, c, r2, off); -} - -static void -comibt(int r1, int c, int v, int off) -{ - comb(Ocomibt, es5(v), c, r1, off); -} - -static void -combf(int r1, int c, int r2, int off) -{ - comb(Ocombf, r1, c, r2, off); -} - -static void -comibf(int r1, int c, int v, int off) -{ - comb(Ocomibf, es5(v), c, r1, off); -} - -static void -combdis(int r1, int c, int r2, int f, int ix) -{ - comb(f ? Ocombf : Ocombt, r1, c, r2, displ(ix)); -} - -static void -addibt(int r1, int c, int v, int off) -{ - comb(Oaddibt, es5(v), c, r1, off); -} - -static void -addibf(int r1, int c, int v, int off) -{ - comb(Oaddibf, es5(v), c, r1, off); -} - -static void -con(ulong o, int r, int opt) -{ - if(opt) { - if(P13(o)) { - LDSTpos(Oldo, o, RZ, r); - return; - } - if(N13(o)) { - LDSTneg(Oldo, o, RZ, r); - return; - } - LDIL(r, B21(o >> 11)); - if(B11(o) != 0) - LDSTpos(Oldo, B11(o), r, r); - } - else { - LDIL(r, B21(o >> 11)); - LDSTpos(Oldo, B11(o), r, r); - } -} - -static void -call(ulong a, int s) -{ - if (s == SCode) { - con(a, RMILLI0, 1); - a = dyncall; - } - LDIL(RCALL, a >> 11); - BLE(RCALL, B11(a), s); - mov(RCALL, RLINK); -} - -static void -callindir(int r) -{ - BLE(r, 0, SData); - mov(RCALL, RLINK); -} - -static void -leafret() -{ - BV(RLINK); - nop(); -} - -static void -linkage() -{ - LDSTneg(Ostw, -20, RCSP, RLINK); - LDSTpos(Oldo, 64, RCSP, RCSP); -} - -static void -ret() -{ - LDSTneg(Oldw, -84, RCSP, RLINK); - BV(RLINK); - LDSTneg(Oldo, -64, RCSP, RCSP); -} - -static void -mem(int inst, ulong disp, int rm, int r) -{ - if(P13(disp)) { - LDSTpos(inst, disp, rm, r); - return; - } - if(N13(disp)) { - LDSTneg(inst, disp, rm, r); - return; - } - con(disp, RCON, 1); - if(inst >= Pst) { - arith(Aadd, rm, RCON, RCON); - LDSTpos(inst, 0, RCON, r); - } - else - LDWX(inst, RCON, rm, r); -} - -static void -fmem(int inst, ulong disp, int rm, int r) -{ - if(P4(disp)) { - FLDSTpos(inst, disp, rm, r); - return; - } - if(N4(disp)) { - FLDSTneg(inst, disp, rm, r); - return; - } - con(disp, RCON, 1); - FLDSTX(inst, RCON, rm, r); -} - -static void -opwld(Inst *i, int mi, int r) -{ - int ir, rta; - - switch(UXSRC(i->add)) { - default: - print("%D\n", i); - urk(); - case SRC(AFP): - mem(mi, i->s.ind, RFP, r); - return; - case SRC(AMP): - mem(mi, i->s.ind, RMP, r); - return; - case SRC(AIMM): - con(i->s.imm, r, 1); - return; - case SRC(AIND|AFP): - ir = RFP; - break; - case SRC(AIND|AMP): - ir = RMP; - break; - } - rta = RTA; - if(mi == Oldo) - rta = r; - mem(Oldw, i->s.i.f, ir, rta); - mem(mi, i->s.i.s, rta, r); -} - -static void -opwst(Inst *i, int mi, int r) -{ - int ir, rta; - - switch(UXDST(i->add)) { - default: - print("%D\n", i); - urk(); - case DST(AIMM): - con(i->d.imm, r, 1); - return; - case DST(AFP): - mem(mi, i->d.ind, RFP, r); - return; - case DST(AMP): - mem(mi, i->d.ind, RMP, r); - return; - case DST(AIND|AFP): - ir = RFP; - break; - case DST(AIND|AMP): - ir = RMP; - break; - } - rta = RTA; - if(mi == Oldo) - rta = r; - mem(Oldw, i->d.i.f, ir, rta); - mem(mi, i->d.i.s, rta, r); -} - -static void -opbig(Adr *a, int am, int mi, int r) -{ - int ir; - - switch(am) { - default: - urk(); - case AFP: - mem(mi, a->ind, RFP, r); - mem(mi, a->ind+4, RFP, r+1); - return; - case AMP: - mem(mi, a->ind, RMP, r); - mem(mi, a->ind+4, RMP, r+1); - return; - case AIND|AFP: - ir = RFP; - break; - case AIND|AMP: - ir = RMP; - break; - } - mem(Oldw, a->i.f, ir, RTA); - mem(mi, a->i.s, RTA, r); - mem(mi, a->i.s+4, RTA, r+1); -} - -static void -opbigld(Inst *i, int r) -{ - opbig(&i->s, USRC(i->add), Oldw, r); -} - -static void -opbigst(Inst *i, int r) -{ - opbig(&i->d, UDST(i->add), Ostw, r); -} - -static void -opfloat(Adr *a, int am, int mi, int r) -{ - int ir; - - switch(am) { - default: - urk(); - case AFP: - fmem(mi, a->ind, RFP, r); - return; - case AMP: - fmem(mi, a->ind, RMP, r); - return; - case AIND|AFP: - ir = RFP; - break; - case AIND|AMP: - ir = RMP; - break; - } - mem(Oldw, a->i.f, ir, RTA); - fmem(mi, a->i.s, RTA, r); -} - -static void -opflld(Inst *i, int r) -{ - opfloat(&i->s, USRC(i->add), Fload, r); -} - -static void -opflst(Inst *i, int r) -{ - opfloat(&i->d, UDST(i->add), Fstore, r); -} - -static void -midfl(Inst *i, int r) -{ - int ir; - - switch(i->add&ARM) { - default: - opfloat(&i->d, UDST(i->add), Fload, r); - return; - case AXINF: - ir = RFP; - break; - case AXINM: - ir = RMP; - break; - } - fmem(Fload, i->reg, ir, r); -} - -static void -literal(ulong imm, int roff) -{ - nlit++; - - con((ulong)litpool, RTA, 0); - LDSTpos(Ostw, roff, RREG, RTA); - - if(pass == 0) - return; - - *litpool = imm; - litpool++; -} - -static -void -compdbg(void) -{ - print("%s:%d@%.8lux\n", R.M->m->name, *(ulong *)R.m, *(ulong *)R.s); -} - -static void -punt(Inst *i, int m, void (*fn)(void)) -{ - ulong pc; - - if(m & SRCOP) { - if(UXSRC(i->add) == SRC(AIMM)) - literal(i->s.imm, O(REG, s)); - else { - opwld(i, Oldo, RA0); - mem(Ostw, O(REG, s), RREG, RA0); - } - } - - if(m & DSTOP) { - opwst(i, Oldo, RA0); - mem(Ostw, O(REG, d), RREG, RA0); - } - - if(m & WRTPC) { - con(RELPC(patch[i-mod->prog+1]), RA0, 0); - mem(Ostw, O(REG, PC), RREG, RA0); - } - - if(m & DBRAN) { - pc = patch[(Inst*)i->d.imm-mod->prog]; - literal(RELPC(pc), O(REG, d)); - } - - switch(i->add&ARM) { - case AXNON: - if(m & THREOP) { - mem(Oldw, O(REG, d), RREG, RA0); - mem(Ostw, O(REG, m), RREG, RA0); - } - break; - case AXIMM: - literal((short)i->reg, O(REG, m)); - break; - case AXINF: - mem(Oldo, i->reg, RFP, RA0); - mem(Ostw, O(REG, m), RREG, RA0); - break; - case AXINM: - mem(Oldo, i->reg, RMP, RA0); - mem(Ostw, O(REG, m), RREG, RA0); - break; - } - - mem(Ostw, O(REG, FP), RREG, RFP); - call((ulong)fn, SCode); - - con((ulong)&R, RREG, 1); - if(m & TCHECK) { - mem(Oldw, O(REG, t), RREG, RA0); - combt(RA0, Cequal, RZ, 3); - nop(); - mem(Oldw, O(REG, xpc), RREG, RLINK); - leafret(); - } - - mem(Oldw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, MP), RREG, RMP); - - if(m & NEWPC) { - mem(Oldw, O(REG, PC), RREG, RA0); - BV(RA0); - nop(); - } -} - -static void -mid(Inst *i, int mi, int r) -{ - int ir; - - switch(i->add&ARM) { - default: - opwst(i, mi, r); - return; - case AXIMM: - con((short)i->reg, r, 1); - return; - case AXINF: - ir = RFP; - break; - case AXINM: - ir = RMP; - break; - } - mem(mi, i->reg, ir, r); -} - -static void -cbral(Inst *i, int jmsw, int fm, int jlsw, int fl, int mode) -{ - ulong dst, *label; - - opwld(i, Oldo, RA1); - mid(i, Oldo, RA3); - mem(Oldw, 0, RA1, RA2); - mem(Oldw, 0, RA3, RA0); - label = nil; - dst = i->d.ins-mod->prog; - switch(mode) { - case ANDAND: - label = code; - comb(RA0, jmsw, RA2, fm, 0); - break; - case OROR: - combdis(RA0, jmsw, RA2, fm, dst); - break; - case EQAND: - combdis(RA0, jmsw, RA2, fm, dst); - nop(); - label = code; - combf(RA0, Cequal, RA2, 0); - break; - } - nop(); - mem(Oldw, 4, RA3, RA0); - mem(Oldw, 4, RA1, RA2); - combdis(RA0, jlsw, RA2, fl, dst); - if(label != nil) - opatch(label); -} - -static void -commcall(Inst *i) -{ - int o; - - opwld(i, Oldw, RA2); - con(RELPC(patch[i-mod->prog+1]), RA0, 0); - mem(Ostw, O(Frame, lr), RA2, RA0); - mem(Ostw, O(Frame, fp), RA2, RFP); - mem(Oldw, O(REG, M), RREG, RA3); - mem(Ostw, O(Frame, mr), RA2, RA3); - opwst(i, Oldw, RA3); - o = OA(Modlink, links)+i->reg*sizeof(Modl)+O(Modl, u.pc); - mem(Oldw, o, RA3, RA0); - call(base+macro[MacMCAL], SData); -} - -static void -comcase(Inst *i, int w) -{ - int l; - WORD *t, *e; - - if(w != 0) { - opwld(i, Oldw, RA0); // v - opwst(i, Oldo, RCON); // table - mbra(MacCASE); - nop(); - } - - t = (WORD*)(mod->origmp+i->d.ind+4); - l = t[-1]; - - /* have to take care not to relocate the same table twice - - * the limbo compiler can duplicate a case instruction - * during its folding phase - */ - - if(pass == 0) { - if(l >= 0) - t[-1] = -l-1; /* Mark it not done */ - return; - } - if(l >= 0) /* Check pass 2 done */ - return; - t[-1] = -l-1; /* Set real count */ - e = t + t[-1]*3; - while(t < e) { - t[2] = RELPC(patch[t[2]]); - t += 3; - } - t[0] = RELPC(patch[t[0]]); -} - -static void -comcasel(Inst *i) -{ - int l; - WORD *t, *e; - - t = (WORD*)(mod->origmp+i->d.ind+8); - l = t[-2]; - if(pass == 0) { - if(l >= 0) - t[-2] = -l-1; /* Mark it not done */ - return; - } - if(l >= 0) /* Check pass 2 done */ - return; - t[-2] = -l-1; /* Set real count */ - e = t + t[-2]*6; - while(t < e) { - t[4] = RELPC(patch[t[4]]); - t += 6; - } - t[0] = RELPC(patch[t[0]]); -} - -static void -commframe(Inst *i) -{ - int o; - ulong *punt, *mlnil; - - opwld(i, Oldw, RA0); - mlnil = code; - comibt(RA0, Cequal, -1, 0); - nop(); - - o = OA(Modlink, links)+i->reg*sizeof(Modl)+O(Modl, frame); - mem(Oldw, o, RA0, RA3); - mem(Oldw, O(Type, initialize), RA3, RA1); - punt = code; - combf(RA1, Cequal, RZ, 0); - nop(); - - opwst(i, Oldo, RA0); - - /* Type in RA3, destination in RA0 */ - opatch(mlnil); - con(RELPC(patch[i-mod->prog+1]), RLINK, 0); - mbra(MacMFRA); - nop(); - - /* Type in RA3 */ - opatch(punt); - call(base+macro[MacFRAM], SData); - opwst(i, Ostw, RA2); -} - -static void -movloop(Inst *i, int ld, int st) -{ - int s; - - if(ld == Oldw) - s = 4; - else - s = 1; - opwld(i, Oldo, RA1); - opwst(i, Oldo, RA2); - mem(ld, 0, RA1, RA0); - mem(st, 0, RA2, RA0); - add(RA2, s); - addibf(RA3, Cequal, -1, -5); - add(RA1, s); -} - -static void -comp(Inst *i) -{ - int r, f; - WORD *t, *e; - char buf[64]; - - if(0) { - Inst xx; - xx.add = AXIMM|SRC(AIMM); - xx.s.imm = (ulong)code; - xx.reg = i-mod->prog; - punt(&xx, SRCOP, compdbg); - } - - switch(i->op) { - default: - snprint(buf, sizeof buf, "%s compile, no '%D'", mod->name, i); - error(buf); - break; - case IMCALL: - if((i->add&ARM) == AXIMM) - commcall(i); - else - punt(i, SRCOP|DSTOP|THREOP|WRTPC|NEWPC, optab[i->op]); - break; - case ISEND: - case IRECV: - case IALT: - punt(i, SRCOP|DSTOP|TCHECK|WRTPC, optab[i->op]); - break; - case ISPAWN: - punt(i, SRCOP|DBRAN, optab[i->op]); - break; - case IBNEC: - case IBEQC: - case IBLTC: - case IBLEC: - case IBGTC: - case IBGEC: - punt(i, SRCOP|DBRAN|NEWPC|WRTPC, optab[i->op]); - break; - case ICASEC: - comcase(i, 0); - punt(i, SRCOP|DSTOP|NEWPC, optab[i->op]); - break; - case ICASEL: - comcasel(i); - punt(i, SRCOP|DSTOP|NEWPC, optab[i->op]); - break; - case IADDC: - case IMULL: - case IDIVL: - case IMODL: - case IMULW: - case IDIVW: - case IMODW: - case IMULB: - case IDIVB: - case IMODB: - case ISHRW: - case ISHLW: - case ISHRB: - case ISHLB: - case IADDL: - case ISUBL: - case IORL: - case IANDL: - case IXORL: - case ICVTWL: - case ISHLL: - case ISHRL: - case IINDX: - punt(i, SRCOP|DSTOP|THREOP, optab[i->op]); - break; - case ILOAD: - case INEWA: - case INEW: - case ISLICEA: - case ISLICELA: - case ICONSB: - case ICONSW: - case ICONSL: - case ICONSF: - case ICONSM: - case ICONSMP: - case ICONSP: - case IMOVMP: - case IHEADMP: - case IHEADM: - case IHEADB: - case IHEADW: - case IHEADL: - case IHEADF: - case IINDC: - case ILENC: - case IINSC: - case ICVTAC: - case ICVTCW: - case ICVTWC: - case ICVTLC: - case ICVTCL: - case ICVTFC: - case ICVTCF: - case ICVTFL: - case ICVTLF: - case ICVTWF: - case ICVTFW: - case IMSPAWN: - case ICVTCA: - case ISLICEC: - case INBALT: - punt(i, SRCOP|DSTOP, optab[i->op]); - break; - case INEWCM: - case INEWCMP: - punt(i, SRCOP|DSTOP|THREOP, optab[i->op]); - break; - case IMFRAME: - if((i->add&ARM) == AXIMM) - commframe(i); - else - punt(i, SRCOP|DSTOP|THREOP, optab[i->op]); - break; - case ICASE: - comcase(i, 1); - // comcase(i, 0); - // punt(i, SRCOP|DSTOP|NEWPC, optab[i->op]); - break; - case IGOTO: - opwld(i, Oldw, RA1); - opwst(i, Oldo, RA0); - arith(Ash2add, RA1, RZ, RA1); - LDWX(Oldw, RA0, RA1, RA0); - BV(RA0); - nop(); - - if(pass == 0) - break; - - t = (WORD*)(mod->origmp+i->d.ind); - e = t + t[-1]; - t[-1] = 0; - while(t < e) { - t[0] = RELPC(patch[t[0]]); - t++; - } - break; - case IMOVL: - movl: - opbigld(i, RA0); - opbigst(i, RA0); - break; - case IMOVM: - if((i->add&ARM) == AXIMM) { - if(i->reg == 8) - goto movl; - if((i->reg&3) == 0) { - con(i->reg>>2, RA3, 1); - movloop(i, Oldw, Ostw); - break; - } - } - mid(i, Oldw, RA3); - movloop(i, Oldb, Ostb); - break; - case IFRAME: - if(UXSRC(i->add) != SRC(AIMM)) { - punt(i, SRCOP|DSTOP, optab[i->op]); - break; - } - tinit[i->s.imm] = 1; - con((ulong)mod->type[i->s.imm], RA3, 1); - call(base+macro[MacFRAM], SData); - opwst(i, Ostw, RA2); - break; - case INEWCB: - case INEWCW: - case INEWCF: - case INEWCP: - case INEWCL: - punt(i, DSTOP|THREOP, optab[i->op]); - break; - case IEXIT: - punt(i, 0, optab[i->op]); - break; - case ICVTBW: - opwld(i, Oldb, RA0); - opwst(i, Ostw, RA0); - break; - case ICVTWB: - opwld(i, Oldw, RA0); - opwst(i, Ostb, RA0); - break; - case ILEA: - opwld(i, Oldo, RA0); - opwst(i, Ostw, RA0); - break; - case IMOVW: - opwld(i, Oldw, RA0); - opwst(i, Ostw, RA0); - break; - case IMOVB: - opwld(i, Oldb, RA0); - opwst(i, Ostb, RA0); - break; - case ITAIL: - opwld(i, Oldw, RA0); - mem(Oldw, O(List, tail), RA0, RA1); - goto movp; - case IMOVP: - case IHEADP: - opwld(i, Oldw, RA1); - if(i->op == IHEADP) - mem(Oldw, OA(List, data), RA1, RA1); - movp: - comibt(RA1, Cequal, (ulong)H, 3); // H is small (-1) - nop(); - call(base+macro[MacCOLR], SData); // 3 instrs - opwst(i, Oldw, RA0); - opwst(i, Ostw, RA1); - call(base+macro[MacFRP], SData); - break; - case ILENA: - opwld(i, Oldw, RA1); - comibt(RA1, Cequal, (ulong)H, 0); - mov(RZ, RA0); - mem(Oldw, O(Array, len), RA1, RA0); - opwst(i, Ostw, RA0); - break; - case ILENL: - mov(RZ, RA0); - opwld(i, Oldw, RA1); - comibt(RA1, Cequal, (ulong)H, 3); - nop(); - mem(Oldw, O(List, tail), RA1, RA1); - bra(-5); - add(RA0, 1); - opwst(i, Ostw, RA0); - break; - case ICALL: - opwld(i, Oldw, RA0); - con(RELPC(patch[i-mod->prog+1]), RA1, 0); - mem(Ostw, O(Frame, lr), RA0, RA1); - mem(Ostw, O(Frame, fp), RA0, RFP); - bra(displ(i->d.ins-mod->prog)); - mov(RA0, RFP); - break; - case IJMP: - bra(displ(i->d.ins-mod->prog)); - nop(); - break; - case IBEQW: - r = Cequal; - f = 0; - braw: - opwld(i, Oldw, RA0); - mid(i, Oldw, RA1); - combdis(RA0, r, RA1, f, i->d.ins-mod->prog); - nop(); - break; - case IBNEW: - r = Cequal; - f = 1; - goto braw; - case IBLTW: - r = Cless; - f = 0; - goto braw; - case IBLEW: - r = Cleq; - f = 0; - goto braw; - case IBGTW: - r = Cleq; - f = 1; - goto braw; - case IBGEW: - r = Cless; - f = 1; - goto braw; - case IBEQB: - r = Cequal; - f = 0; - brab: - opwld(i, Oldb, RA0); - mid(i, Oldb, RA1); - combdis(RA0, r, RA1, f, i->d.ins-mod->prog); - nop(); - break; - case IBNEB: - r = Cequal; - f = 1; - goto brab; - case IBLTB: - r = Cless; - f = 0; - goto brab; - case IBLEB: - r = Cleq; - f = 0; - goto brab; - case IBGTB: - r = Cleq; - f = 1; - goto brab; - case IBGEB: - r = Cless; - f = 1; - goto brab; - case IBEQF: - r = Fneq; - braf: - opflld(i, FR1); - midfl(i, FR0); - FCMP(FR1, r, FR0); - bra(displ(i->d.ins-mod->prog)); - nop(); - break; - case IBNEF: - r = Fequal; - goto braf; - case IBLTF: - r = Fgeq; - goto braf; - case IBLEF: - r = Fgrt; - goto braf; - case IBGTF: - r = Fleq; - goto braf; - case IBGEF: - r = Fless; - goto braf; - case IRET: - // punt(i, NEWPC, optab[i->op]); - mbra(MacRET); - mem(Oldw, O(Frame, t), RFP, RA1); - break; - case IORW: - r = Aor; - goto arithw; - case IANDW: - r = Aand; - goto arithw; - case IXORW: - r = Axor; - goto arithw; - case ISUBW: - r = Asub; - goto arithw; - case IADDW: - r = Aadd; - arithw: - mid(i, Oldw, RA1); - opwld(i, Oldw, RA0); - arith(r, RA1, RA0, RA1); - opwst(i, Ostw, RA1); - break; - case IORB: - r = Aor; - goto arithb; - case IANDB: - r = Aand; - goto arithb; - case IXORB: - r = Axor; - goto arithb; - case ISUBB: - r = Asub; - goto arithb; - case IADDB: - r = Aadd; - arithb: - mid(i, Oldb, RA1); - opwld(i, Oldb, RA0); - arith(r, RA1, RA0, RA1); - opwst(i, Ostb, RA1); - break; - case IINDL: - case IINDF: - case IINDW: - case IINDB: - opwld(i, Oldw, RA0); /* a */ - r = 0; - switch(i->op) { - case IINDL: - case IINDF: - r = 3; - break; - case IINDW: - r = 2; - break; - } - opwst(i, Oldw, RA1); - mem(Oldw, O(Array, data), RA0, RA0); - switch(r) { - default: - urk(); - case 0: - arith(Aadd, RA0, RA1, RA0); - break; - case 2: - arith(Ash2add, RA1, RA0, RA0); - break; - case 3: - arith(Ash2add, RA1, RZ, RA1); - arith(Ash1add, RA1, RA0, RA0); - break; - } - r = RMP; - if((i->add&ARM) == AXINF) - r = RFP; - mem(Ostw, i->reg, r, RA0); - break; - case ICVTLW: - opwld(i, Oldo, RA0); - mem(Oldw, 4, RA0, RA0); - opwst(i, Ostw, RA0); - break; - case IBEQL: - cbral(i, Cequal, 1, Cequal, 0, ANDAND); - break; - case IBNEL: - cbral(i, Cequal, 1, Cequal, 1, OROR); - break; - case IBLEL: - cbral(i, Cless, 0, Clequ, 0, EQAND); - break; - case IBGTL: - cbral(i, Cleq, 1, Clequ, 1, EQAND); - break; - case IBLTL: - cbral(i, Cless, 0, Clessu, 0, EQAND); - break; - case IBGEL: - cbral(i, Cleq, 1, Clessu, 1, EQAND); - break; - case IMOVF: - opflld(i, FR0); - opflst(i, FR0); - break; - case IDIVF: - r = Fdiv; - goto arithf; - case IMULF: - r = Fmul; - goto arithf; - case ISUBF: - r = Fsub; - goto arithf; - case IADDF: - r = Fadd; - arithf: - midfl(i, FR1); - opflld(i, FR0); - farith(r, FR1, FR0, FR1); - opflst(i, FR1); - break; - case INEGF: - opflld(i, FR0); - farith(Fsub, FRZ, FR0, FR0); - opflst(i, FR0); - break; - case IRAISE: - punt(i, SRCOP|WRTPC|NEWPC, optab[i->op]); - break; - case IMULX: - case IDIVX: - case ICVTXX: - case IMULX0: - case IDIVX0: - case ICVTXX0: - case IMULX1: - case IDIVX1: - case ICVTXX1: - case ICVTFX: - case ICVTXF: - case IEXPW: - case IEXPL: - case IEXPF: - punt(i, SRCOP|DSTOP|THREOP, optab[i->op]); - break; - case ISELF: - punt(i, DSTOP, optab[i->op]); - break; - } -} - -/* - * Preamble. This is complicated by the space registers. - * We point comvec at calldata which does a dataspace call - * to dataptr. The code at dataptr calls the real preamble - * code at start which saves the link register and branches - * to the new pc. When the compiled code finally returns - * by branching indirect through the saved link it will - * return into the dataptr code which will return to text - * space (calldata) which will return to the outside. - */ -static void -preamble(void) -{ - ulong *start; - - if (comvec) - return; - - code = (ulong*)malloc(PRESZ * sizeof(*code)); - - if (code == nil) - urk(); - - start = code; - con((ulong)&R, RREG, 1); // load R - mem(Ostw, O(REG, xpc), RREG, RLINK); // save link - mem(Oldw, O(REG, PC), RREG, RA0); // load new PC - mem(Oldw, O(REG, FP), RREG, RFP); // load FP - BV(RA0); // jump to new PC - mem(Oldw, O(REG, MP), RREG, RMP); // load MP (delay) - - dataptr = code; - LDSTneg(Ostw, -20, RCSP, RLINK); // save return link - LDSTpos(Oldo, 64, RCSP, RCSP); // stack frame - con((ulong)start, RA0, 1); // load start - BLE(RA0, 0, SData); // call real preamble - mov(RCALL, RLINK); // linkage (delay) - LDSTneg(Oldw, -84, RCSP, RLINK); // fetch return link - BE(RLINK, 0, SCode); // return to text space - LDSTneg(Oldo, -64, RCSP, RCSP); // stack frame (delay) - - if (code > start + PRESZ) - error("preamble overrun"); - - segflush(start, PRESZ * sizeof(*code)); - - if(cflag > 4) { - print("preamble:\n"); - das(start, code-start); - } - - comvec = calldata; -} - -static void -maccase(void) -{ - ulong *loop, *def, *lab1; - - mem(Oldw, 0, RCON, RA3); // n = t[0] - mem(Oldo, 4, RCON, RCON); // t = &t[1] - arith(Ash1add, RA3, RA3, RA1); // n1 = 3*n - arith(Ash2add, RA1, RZ, RA1); // n1 = 12*n - LDWX(Oldw, RCON, RA1, RLINK); // rlink = default - - loop = code; // loop: - def = code; - combt(RA3, Cleq, RZ, 0); // if (n <= 0) goto out - // nop(); - - shrs(RA3, 1, RA2); // n' = n>>1 - arith(Ash1add, RA2, RA2, RTA); // n2 = 3*n' - arith(Ash2add, RTA, RCON, RA1); // l = &t[n2] - - mem(Oldw, 0, RA1, RTA); // l[0] - lab1 = code; - combt(RTA, Cleq, RA0, 0); // if (l[0] <= v) goto 1f - nop(); - bra(loop-code-2); // goto loop - mov(RA2, RA3); // n = n2 (delay) - - opatch(lab1); // 1f: - mem(Oldw, 4, RA1, RTA); // l[1] - lab1 = code; - combt(RA0, Cless, RTA, 0); // if (v < l[1]) goto 1f - nop(); - - mem(Oldo, 12, RA1, RCON); // t = &l[3] - arith(Asub, RA3, RA2, RA3); // n -= n' - bra(loop-code-2); // goto loop - mem(Oldo, -1, RA3, RA3); // n -= 1 (delay) - - opatch(lab1); // 1f: - mem(Oldw, 8, RA1, RLINK); // rlink = l[2] - - opatch(def); // out: - BV(RLINK); // jmp rlink - nop(); -} - -static void -macfrp(void) -{ - ulong *lab1, *lab2; - - /* destroy the pointer in RA0 */ - lab1 = code; - comibt(RA0, Cequal, -1, 0); // if (p == h) goto out - nop(); - - mem(Oldw, O(Heap, ref)-sizeof(Heap), RA0, RA2); // r = D2H(v)->ref - lab2 = code; - addibf(RA2, Cequal, -1, 0); // if (--r != 0) goto store - nop(); - - mem(Ostw, O(REG, FP), RREG, RFP); // call destroy - mem(Ostw, O(REG, st), RREG, RLINK); - mem(Ostw, O(REG, s), RREG, RA0); - call((ulong)rdestroy, SCode); - - con((ulong)&R, RREG, 1); - mem(Oldw, O(REG, st), RREG, RLINK); - mem(Oldw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, MP), RREG, RMP); - leafret(); - - opatch(lab2); // store - mem(Ostw, O(Heap, ref)-sizeof(Heap), RA0, RA2); - opatch(lab1); // out - leafret(); -} - -static void -macret(void) -{ - Inst i; - ulong *cp1, *cp2, *cp3, *cp4, *cp5, *cp6; - - cp1 = code; - combt(RA1, Cequal, RZ, 0); // if (t(Rfp) == 0) goto punt - nop(); - - mem(Oldw, O(Type, destroy), RA1, RA0); - cp2 = code; - combt(RA0, Cequal, RZ, 0); // if (destroy(t(fp)) == 0) goto punt - nop(); - - mem(Oldw, O(Frame, fp), RFP, RA2); - cp3 = code; - combt(RA2, Cequal, RZ, 0); // if (fp(Rfp) == 0) goto punt - nop(); - - mem(Oldw, O(Frame, mr), RFP, RA3); - cp4 = code; - combt(RA3, Cequal, RZ, 0); // if (mr(Rfp) == 0) goto call - nop(); - - mem(Oldw, O(REG, M), RREG, RA2); - mem(Oldw, O(Heap, ref)-sizeof(Heap), RA2, RA3); - cp5 = code; - addibt(RA3, Cequal, -1, 0); // if (--ref(arg) == 0) goto punt - nop(); - mem(Ostw, O(Heap, ref)-sizeof(Heap), RA2, RA3); - - mem(Oldw, O(Frame, mr), RFP, RA1); - mem(Ostw, O(REG, M), RREG, RA1); - mem(Oldw, O(Modlink, compiled), RA1, RA2); // check for uncompiled code - mem(Oldw, O(Modlink, MP), RA1, RMP); - cp6 = code; - combt(RA2, Cequal, RZ, 0); - nop(); - mem(Ostw, O(REG, MP), RREG, RMP); - - opatch(cp4); - callindir(RA0); // call destroy(t(fp)) - - mem(Ostw, O(REG, SP), RREG, RFP); - mem(Oldw, O(Frame, lr), RFP, RA1); - mem(Oldw, O(Frame, fp), RFP, RFP); - mem(Ostw, O(REG, FP), RREG, RFP); - BV(RA1); // goto lr(Rfp) - mem(Oldw, O(Frame, fp), RFP, RFP); // (delay) - - opatch(cp6); - callindir(RA0); // call destroy(t(fp)) - - mem(Ostw, O(REG, SP), RREG, RFP); - mem(Oldw, O(Frame, lr), RFP, RA1); - mem(Oldw, O(Frame, fp), RFP, RFP); - mem(Ostw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, xpc), RREG, RA2); - BV(RA2); // return to uncompiled code - mem(Oldw, O(REG, PC), RREG, RA1); - - opatch(cp1); - opatch(cp2); - opatch(cp3); - opatch(cp5); - i.add = AXNON; - punt(&i, TCHECK|NEWPC, optab[IRET]); -} - -static void -maccolr(void) -{ - ulong *br; - - /* color the pointer in RA1 */ - mem(Oldw, O(Heap, ref)-sizeof(Heap), RA1, RA0); // inc ref - add(RA0, 1); - mem(Ostw, O(Heap, ref)-sizeof(Heap), RA1, RA0); - con((ulong)&mutator, RA2, 1); - mem(Oldw, O(Heap, color)-sizeof(Heap), RA1, RA0); - mem(Oldw, 0, RA2, RA2); - br = code; - combt(RA0, Cequal, RA2, 0); // if (color == mutator) goto out - con(propagator, RA2, 1); - mem(Ostw, O(Heap, color)-sizeof(Heap), RA1, RA2); // color = propagator - con((ulong)&nprop, RA2, 1); - mem(Ostw, 0, RA2, RA1); // nprop = !0 - opatch(br); - leafret(); -} - -static void -macmcal(void) -{ - ulong *lab1, *lab2; - - mem(Oldw, O(Modlink, prog), RA3, RA1); - lab1 = code; - combf(RA1, Cequal, RZ, 0); // if (m->prog != nil) goto 1f - nop(); - - mem(Ostw, O(REG, st), RREG, RLINK); - mem(Ostw, O(REG, FP), RREG, RA2); - mem(Ostw, O(REG, dt), RREG, RA0); - call((ulong)rmcall, SCode); // CALL rmcall - - con((ulong)&R, RREG, 1); - mem(Oldw, O(REG, st), RREG, RLINK); - mem(Oldw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, MP), RREG, RMP); - leafret(); - - opatch(lab1); // 1f - mov(RA2, RFP); - mem(Ostw, O(REG, M), RREG, RA3); - mem(Oldw, O(Heap, ref)-sizeof(Heap), RA3, RA1); - add(RA1, 1); - mem(Ostw, O(Heap, ref)-sizeof(Heap), RA3, RA1); - mem(Oldw, O(Modlink, compiled), RA3, RA1); - mem(Oldw, O(Modlink, MP), RA3, RMP); - lab2 = code; - combt(RA1, Cequal, RZ, 0); - mem(Ostw, O(REG, MP), RREG, RMP); - - BV(RA0); - nop(); - - opatch(lab2); - mem(Ostw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, xpc), RREG, RA1); - BV(RA1); // call to uncompiled code - mem(Ostw, O(REG, PC), RREG, RA0); -} - -static void -macfram(void) -{ - ulong *lab1; - - mem(Oldw, O(REG, SP), RREG, RA0); - mem(Oldw, O(Type, size), RA3, RA1); - arith(Aadd, RA0, RA1, RA0); // new frame - mem(Oldw, O(REG, TS), RREG, RA1); // top of stack - lab1 = code; - combt(RA0, Cless, RA1, 0); - nop(); - - mem(Ostw, O(REG, s), RREG, RA3); - mem(Ostw, O(REG, st), RREG, RLINK); - mem(Ostw, O(REG, FP), RREG, RFP); - call((ulong)extend, SCode); // CALL extend - - con((ulong)&R, RREG, 1); - mem(Oldw, O(REG, st), RREG, RLINK); - mem(Oldw, O(REG, FP), RREG, RFP); - mem(Oldw, O(REG, s), RREG, RA2); - mem(Oldw, O(REG, MP), RREG, RMP); - leafret(); - - opatch(lab1); - mem(Oldw, O(REG, SP), RREG, RA2); // old frame - mem(Ostw, O(REG, SP), RREG, RA0); // new frame - - mem(Ostw, O(Frame, t), RA2, RA3); // f->t = t - mem(Oldw, O(Type, initialize), RA3, RA3); - BV(RA3); // initialize - mem(Ostw, O(Frame, mr), RA2, RZ); // f->mr = nil -} - -static void -macmfra(void) -{ - mem(Ostw, O(REG, st), RREG, RLINK); - mem(Ostw, O(REG, s), RREG, RA3); // save type - mem(Ostw, O(REG, d), RREG, RA0); // save destination - mem(Ostw, O(REG, FP), RREG, RFP); - call((ulong)rmfram, SCode); // call rmfram - - con((ulong)&R, RREG, 1); // reload - mem(Oldw, O(REG, st), RREG, RLINK); - mem(Oldw, O(REG, FP), RREG, RFP); - BV(RLINK); - mem(Oldw, O(REG, MP), RREG, RMP); -} - -void -comd(Type *t) -{ - int i, j, m, c; - ulong frp; - - frp = (ulong)(base+macro[MacFRP]); - mem(Ostw, O(REG, dt), RREG, RLINK); - for(i = 0; i < t->np; i++) { - c = t->map[i]; - j = i<<5; - for(m = 0x80; m != 0; m >>= 1) { - if(c & m) { - mem(Oldw, j, RFP, RA0); - call(frp, SData); - } - j += sizeof(WORD*); - } - } - mem(Oldw, O(REG, dt), RREG, RLINK); - leafret(); -} - -void -comi(Type *t) -{ - int i, j, m, c; - - con((ulong)H, RA0, 1); - for(i = 0; i < t->np; i++) { - c = t->map[i]; - j = i<<5; - for(m = 0x80; m != 0; m >>= 1) { - if(c & m) - mem(Ostw, j, RA2, RA0); - j += sizeof(WORD*); - } - } - leafret(); -} - -void -typecom(Type *t) -{ - int n; - ulong tmp[4096], *start; - - if(t == nil || t->initialize != 0) - return; - - code = tmp; - comi(t); - n = code - tmp; - code = tmp; - comd(t); - n += code - tmp; - - n *= sizeof(*code); - code = mallocz(n, 0); - if(code == nil) - return; - - start = code; - t->initialize = code; - comi(t); - t->destroy = code; - comd(t); - - if (code - start != n / sizeof(*code)) - error("typecom mismatch"); - - segflush(start, n); - - if(cflag > 1) - print("typ= %.8lux %4d i %.8lux d %.8lux asm=%d\n", - t, t->size, t->initialize, t->destroy, n); -} - -static void -patchex(Module *m, ulong *p) -{ - Handler *h; - Except *e; - - if((h = m->htab) == nil) - return; - for( ; h->etab != nil; h++){ - h->pc1 = p[h->pc1]; - h->pc2 = p[h->pc2]; - for(e = h->etab; e->s != nil; e++) - e->pc = p[e->pc]; - if(e->pc != -1) - e->pc = p[e->pc]; - } -} - -int -compile(Module *m, int size, Modlink *ml) -{ - ulong v; - Link *l; - Modl *e; - int i, n; - ulong *s, tmp[4096]; - - base = nil; - patch = mallocz(size*sizeof(*patch), 0); - tinit = malloc(m->ntype*sizeof(*tinit)); - if(tinit == nil || patch == nil) - goto bad; - - preamble(); - - mod = m; - n = 0; - pass = 0; - nlit = 0; - - for(i = 0; i < size; i++) { - code = tmp; - comp(&m->prog[i]); - patch[i] = n; - n += code - tmp; - } - - for(i = 0; i < nelem(mactab); i++) { - code = tmp; - mactab[i].gen(); - macro[mactab[i].idx] = n; - n += code - tmp; - } - - base = mallocz((n + nlit) * sizeof(ulong), 0); - if(base == nil) - goto bad; - - if(cflag > 1) - print("dis=%5d %5d s800=%5d asm=%.8lux lit=%d: %s\n", - size, size*sizeof(Inst), n, base, nlit, m->name); - - pass++; - nlit = 0; - litpool = (ulong*)base + n; - code = base; - - for(i = 0; i < size; i++) { - s = code; - comp(&m->prog[i]); - if(cflag > 2) { - print("%D\n", &m->prog[i]); - das(s, code-s); - } - } - - for(i = 0; i < nelem(mactab); i++) { - s = code; - mactab[i].gen(); - if(cflag > 2) { - print("%s:\n", mactab[i].name); - das(s, code-s); - } - } - - if (code - base != n) - error("typecom mismatch"); - - segflush(base, n * sizeof(*base)); - - for(l = m->ext; l->name; l++) { - l->u.pc = (Inst*)RELPC(patch[l->u.pc-m->prog]); - typecom(l->frame); - } - if(ml != nil) { - e = &ml->links[0]; - for(i = 0; i < ml->nlinks; i++) { - e->u.pc = (Inst*)RELPC(patch[e->u.pc-m->prog]); - typecom(e->frame); - e++; - } - } - for(i = 0; i < m->ntype; i++) { - if(tinit[i] != 0) - typecom(m->type[i]); - } - patchex(m, patch); - m->entry = (Inst*)RELPC(patch[mod->entry-mod->prog]); - if(cflag > 2) - print("entry %lx\n", m->entry); - free(patch); - free(tinit); - free(m->prog); - m->prog = (Inst*)base; - m->compiled = 1; - return 1; -bad: - free(patch); - free(tinit); - free(base); - return 0; -} diff --git a/libinterp/das-s800.c b/libinterp/das-s800.c deleted file mode 100644 index a96cc23a..00000000 --- a/libinterp/das-s800.c +++ /dev/null @@ -1,457 +0,0 @@ -#include "lib9.h" -#include "isa.h" -#include "interp.h" - -/* s800 disassembler. */ -/* does not handle stuff that won't be generated */ - -typedef struct instr Instr; - -struct instr -{ - ulong value; /* bits 31-00 */ - uchar op; /* bits 31-26 */ - uchar subop; /* bits 11-05 */ - uchar sysop; /* bits 12-05 */ - uchar reg0; /* bits 25-21 */ - uchar reg1; /* bits 20-16 */ - uchar reg2; /* bits 4-0 */ - uchar space; /* bits 15-14 */ - uchar indexed; /* bit 13 */ - uchar cond; /* bits 15-13 */ - uchar sr; /* bits 13,15,14 */ - uchar ftype; /* bits 12-9 */ - uchar simm; /* bit 12 */ - uchar store; /* bit 9 */ - uchar size; /* bits 8-6 */ - uchar mod; /* bit 5 */ - uchar shz; /* bit 9-5 */ - long imm21; /* bits 20-00 */ - short simm14; /* bits 13-01, sign 00 */ - short simm11; /* bits 10-01, sign 00 */ - short simm5; /* bits 4-1, sign 0 */ - short off; /* bits 13-02, sign 00 */ - char csimm5; /* bits 20-17, sign 16 */ - char *curr; /* current fill level in output buffer */ - char *end; /* end of buffer */ -}; - -typedef struct opdec Opdec; - -struct opdec -{ - char *mnem; - void (*func)(Instr *, char *); -}; - -static char ill[] = "ILL"; -static char sizes[] = "BHWXXXXX"; - -static char *conds[8] = -{ - "never", - "equal", - "less", - "leq", - "lessu", - "lequ", - "sv", - "odd", -}; - -static char *fconds[8] = -{ - "F", - "==", - "<", - "<=", - ">", - ">=", - "!=", - "T", -}; - -static void das_nil(Instr *, char *); -static void das_sys(Instr *, char *); -static void das_arith(Instr *, char *); -static void das_ldwx(Instr *, char *); -static void das_ld(Instr *, char *); -static void das_ldil(Instr *, char *); -static void das_ldo(Instr *, char *); -static void das_st(Instr *, char *); -static void das_fldst(Instr *, char *); -static void das_fltc(Instr *, char *); -static void das_combt(Instr *, char *); -static void das_ibt(Instr *, char *); -static void das_combf(Instr *, char *); -static void das_ibf(Instr *, char *); -static void das_extrs(Instr *, char *); -static void das_be(Instr *, char *); -static void das_bx(Instr *, char *); - -Opdec dastab[1 << 6] = -{ - {ill, das_sys}, /* 0x00 */ - {ill, das_nil}, /* 0x01 */ - {ill, das_arith}, /* 0x02 */ - {ill, das_ldwx}, /* 0x03 */ - {ill, das_nil}, /* 0x04 */ - {ill, das_nil}, /* 0x05 */ - {ill, das_nil}, /* 0x06 */ - {ill, das_nil}, /* 0x07 */ - {ill, das_ldil}, /* 0x08 */ - {ill, das_nil}, /* 0x09 */ - {ill, das_nil}, /* 0x0A */ - {ill, das_fldst}, /* 0x0B */ - {ill, das_fltc}, /* 0x0C */ - {ill, das_ldo}, /* 0x0D */ - {ill, das_nil}, /* 0x0E */ - {ill, das_nil}, /* 0x0F */ - - {"LDB", das_ld}, /* 0x10 */ - {"LDH", das_ld}, /* 0x11 */ - {"LDW", das_ld}, /* 0x12 */ - {ill, das_nil}, /* 0x13 */ - {ill, das_nil}, /* 0x14 */ - {ill, das_nil}, /* 0x15 */ - {ill, das_nil}, /* 0x16 */ - {ill, das_nil}, /* 0x17 */ - {"STB", das_st}, /* 0x18 */ - {"STH", das_st}, /* 0x19 */ - {"STW", das_st}, /* 0x1A */ - {ill, das_nil}, /* 0x1B */ - {ill, das_nil}, /* 0x1C */ - {ill, das_nil}, /* 0x1D */ - {ill, das_nil}, /* 0x1E */ - {ill, das_nil}, /* 0x1F */ - - {ill, das_combt}, /* 0x20 */ - {"COM", das_ibt}, /* 0x21 */ - {ill, das_combf}, /* 0x22 */ - {"COM", das_ibf}, /* 0x23 */ - {ill, das_nil}, /* 0x24 */ - {ill, das_nil}, /* 0x25 */ - {ill, das_nil}, /* 0x26 */ - {ill, das_nil}, /* 0x27 */ - {ill, das_nil}, /* 0x28 */ - {"ADD", das_ibt}, /* 0x29 */ - {ill, das_nil}, /* 0x2A */ - {"ADD", das_ibf}, /* 0x2B */ - {ill, das_nil}, /* 0x2C */ - {ill, das_nil}, /* 0x2D */ - {ill, das_nil}, /* 0x2E */ - {ill, das_nil}, /* 0x2F */ - - {ill, das_nil}, /* 0x30 */ - {ill, das_nil}, /* 0x31 */ - {ill, das_nil}, /* 0x32 */ - {ill, das_nil}, /* 0x33 */ - {ill, das_extrs}, /* 0x34 */ - {ill, das_nil}, /* 0x35 */ - {ill, das_nil}, /* 0x36 */ - {ill, das_nil}, /* 0x37 */ - {"BE", das_be}, /* 0x38 */ - {"BLE", das_be}, /* 0x39 */ - {ill, das_bx}, /* 0x3A */ - {ill, das_nil}, /* 0x3B */ - {ill, das_nil}, /* 0x3C */ - {ill, das_nil}, /* 0x3D */ - {ill, das_nil}, /* 0x3E */ - {ill, das_nil}, /* 0x3F */ -}; - -static void -bprint(Instr *i, char *fmt, ...) -{ - va_list arg; - - va_start(arg, fmt); - i->curr = vseprint(i->curr, i->end, fmt, arg); - va_end(arg); -} - -static void -decode(ulong *pc, Instr *i) -{ - ulong w; - int t; - - w = *pc; - - i->value = w; - i->op = (w >> 26) & 0x3F; - i->subop = (w >> 5) & 0x7F; - i->sysop = (w >> 5) & 0xFF; - i->reg0 = (w >> 21) & 0x1F; - i->reg1 = (w >> 16) & 0x1F; - i->reg2 = w & 0x1F; - i->space = (w >> 14) & 0x03; - i->indexed = (w >> 13) & 0x01; - i->cond = (w >> 13) & 0x07; - i->sr = (i->cond >> 1) | ((i->cond & 1) << 2); - i->ftype = (w >> 9) & 0xF; - i->simm = (w >> 12) & 0x01; - i->store = (w >> 9) & 0x01; - i->size = (w >> 6) & 0x07; - i->mod = (w >> 5) & 0x01; - i->shz = (w >> 5) & 0x1F; - i->imm21 = w & 0x01FFFFF; - i->simm14 = (w >> 1) & 0x1FFF; - i->simm11 = (w >> 1) & 0x03FF; - i->simm5 = (w >> 1) & 0x0F; - i->off = ((w >> 3) & 0x3FF) | ((w & (1 << 2)) << 8); - i->csimm5 = (w >> 17) & 0x0F; - if(w & 1) { - i->simm14 |= ~((1 << 13) - 1); - i->simm11 |= ~((1 << 10) - 1); - i->simm5 |= ~((1 << 4) - 1); - i->off |= ~((1 << 10) - 1); - } - if(w & (1 << 16)) - i->csimm5 |= ~((1 << 4) - 1); -} - -static void -das_ill(Instr *i) -{ - das_nil(i, ill); -} - -static void -das_nil(Instr *i, char *m) -{ - bprint(i, "%s\t%lx", m, i->value); -} - -static void -das_sys(Instr *i, char *m) -{ - switch(i->sysop) { - case 0x85: - bprint(i, "LDSID\t(sr%d,r%d),r%d", i->sr, i->reg0, i->reg2); - break; - case 0xC1: - bprint(i, "MTSP\tr%d,sr%d", i->reg1, i->sr); - break; - default: - das_ill(i); - } -} - -static void -das_arith(Instr *i, char *m) -{ - switch(i->subop) { - case 0x10: - m = "AND"; - break; - case 0x12: - if (i->reg1 + i->reg0 + i->reg2 == 0) { - bprint(i, "NOP"); - return; - } - m = "OR"; - break; - case 0x14: - m = "XOR"; - break; - case 0x20: - m = "SUB"; - break; - case 0x30: - m = "ADD"; - break; - case 0x32: - m = "SH1ADD"; - break; - case 0x34: - m = "SH2ADD"; - break; - default: - das_ill(i); - return; - } - - bprint(i, "%s\tr%d,r%d,r%d", m, i->reg1, i->reg0, i->reg2); -} - -static void -das_ldwx(Instr *i, char *m) -{ - bprint(i, "LD%cX\tr%d(r%d),r%d", sizes[i->size], i->reg0, i->reg1, i->reg2); -} - -static void -das_ld(Instr *i, char *m) -{ - bprint(i, "%s\t%d(r%d),r%d", m, i->simm14, i->reg0, i->reg1); -} - -static ulong -unfrig17(ulong v) -{ - ulong r; - - r = ((v >> 3) & 0x3FF) | - ((v & (1 << 2)) << 8) | - ((v & (0x1F << 16)) >> 5); - if (v & 1) - r |= ~((1 << 16) - 1); - return r << 2; -} - -static ulong -unfrig21(ulong v) -{ - return (((v & 1) << 20) | - ((v & (0x7FF << 1)) << 8) | - ((v >> 12) & 3) | - ((v & (3 << 14)) >> 7) | - ((v & (0x1F << 16)) >> 14)) << 11; -} - -static void -das_ldil(Instr *i, char *m) -{ - bprint(i, "LDIL\tL%%0x%lx,r%d", unfrig21(i->imm21), i->reg0); -} - -static void -das_ldo(Instr *i, char *m) -{ - bprint(i, "LDO\t%d(r%d),r%d", i->simm14, i->reg0, i->reg1); -} - -static void -das_st(Instr *i, char *m) -{ - bprint(i, "%s\tr%d,%d(r%d)", m, i->reg1, i->simm14, i->reg0); -} - -static void -das_fldst(Instr *i, char *m) -{ - if (i->simm) { - if (i->store) - bprint(i, "FSTDS\tfr%d,%d(r%d)", i->reg2, i->csimm5, i->reg0); - else - bprint(i, "FLDDS\t%d(r%d),fr%d", i->reg0, i->csimm5, i->reg2); - } - else { - if (i->store) - bprint(i, "FSTDX\tfr%d,r%d(r%d)", i->reg2, i->reg1, i->reg0); - else - bprint(i, "FLDDX\tr%d(r%d),fr%d", i->reg0, i->reg1, i->reg2); - } -} - -static void -das_fltc(Instr *i, char *m) -{ - char *o; - - switch (i->ftype) { - case 2: - bprint(i, "FTEST"); - break; - case 6: - bprint(i, "FCMP\tfr%d,%s,fr%d", i->reg0, fconds[i->reg2 >> 2], i->reg1); - break; - case 7: - switch (i->cond) { - case 0: - o = "ADD"; - break; - case 1: - o = "SUB"; - break; - case 2: - o = "MUL"; - break; - case 3: - o = "DIV"; - break; - default: - das_ill(i); - return; - } - bprint(i, "F%s\tfr%d,fr%d,fr%d", o, i->reg0, i->reg1, i->reg2); - break; - default: - das_ill(i); - } -} - -static void -das_combt(Instr *i, char *m) -{ - bprint(i, "COMBT,%s\tr%d,r%d,%d", conds[i->cond], i->reg1, i->reg0, i->off); -} - -static void -das_ibt(Instr *i, char *m) -{ - bprint(i, "%sIBT,%s\t%d,r%d,%d", m, conds[i->cond], i->csimm5, i->reg0, i->off); -} - -static void -das_combf(Instr *i, char *m) -{ - bprint(i, "COMBF,%s\tr%d,r%d,%d", conds[i->cond], i->reg1, i->reg0, i->off); -} - -static void -das_ibf(Instr *i, char *m) -{ - bprint(i, "%sIBF,%s\t%d,r%d,%d", m, conds[i->cond], i->csimm5, i->reg0, i->off); -} - -static void -das_extrs(Instr *i, char *m) -{ - bprint(i, "EXTRS\tr%d,%d,%d,r%d", i->reg0, i->shz, 32 - i->reg2, i->reg1); -} - -static void -das_be(Instr *i, char *m) -{ - bprint(i, "%s\t%d(sr%d,r%d)", m, unfrig17(i->value), i->sr, i->reg0); -} - -static void -das_bx(Instr *i, char *m) -{ - switch(i->cond) { - case 0: - bprint(i, "BL\t%d,r%d", unfrig17(i->value), i->reg0); - break; - case 6: - bprint(i, "BV\tr%d(r%d)", i->reg1, i->reg0); - break; - default: - das_ill(i); - } -} - -static int -inst(ulong *pc) -{ - Instr instr; - static char buf[128]; - - decode(pc, &instr); - instr.curr = buf; - instr.end = buf + sizeof(buf) - 1; - (*dastab[instr.op].func)(&instr, dastab[instr.op].mnem); - if (cflag > 5) - print("\t%.8lux %.8lux %s\n", pc, *pc, buf); - else - print("\t%.8lux %s\n", pc, buf); -} - -void -das(ulong *x, int n) -{ - while (--n >= 0) - inst(x++); -} diff --git a/libkern/frexp-68000.c b/libkern/frexp-68000.c deleted file mode 100644 index ac22e037..00000000 --- a/libkern/frexp-68000.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <u.h> -#include <libc.h> - -#define MASK 0x7ffL -#define SHIFT 20 -#define BIAS 1022L - -typedef union -{ - double d; - struct - { - long ms; - long ls; - }; -} Cheat; - -double -frexp(double d, int *ep) -{ - Cheat x; - - if(d == 0) { - *ep = 0; - return 0; - } - x.d = d; - *ep = ((x.ms >> SHIFT) & MASK) - BIAS; - x.ms &= ~(MASK << SHIFT); - x.ms |= BIAS << SHIFT; - return x.d; -} - -double -ldexp(double d, int e) -{ - Cheat x; - - if(d == 0) - return 0; - x.d = d; - e += (x.ms >> SHIFT) & MASK; - if(e <= 0) - return 0; /* underflow */ - if(e >= MASK){ /* overflow */ - if(d < 0) - return Inf(-1); - return Inf(1); - } - x.ms &= ~(MASK << SHIFT); - x.ms |= (long)e << SHIFT; - return x.d; -} - -double -modf(double d, double *ip) -{ - Cheat x; - int e; - - if(d < 1) { - if(d < 0) { - x.d = modf(-d, ip); - *ip = -*ip; - return -x.d; - } - *ip = 0; - return d; - } - x.d = d; - e = ((x.ms >> SHIFT) & MASK) - BIAS; - if(e <= SHIFT+1) { - x.ms &= ~(0x1fffffL >> e); - x.ls = 0; - } else - if(e <= SHIFT+33) - x.ls &= ~(0x7fffffffL >> (e-SHIFT-2)); - *ip = x.d; - return d - x.d; -} diff --git a/libkern/getfcr-68000.s b/libkern/getfcr-68000.s deleted file mode 100644 index 7f67d038..00000000 --- a/libkern/getfcr-68000.s +++ /dev/null @@ -1,19 +0,0 @@ -TEXT getfsr(SB), $0 - MOVL $0, R0 - MOVL FPSR, R0 - RTS - -TEXT setfsr(SB), $0 - MOVL new+0(FP), R1 - MOVL R1, FPSR - RTS - -TEXT getfcr(SB), $0 - MOVL $0, R0 - MOVL FPCR, R0 - RTS - -TEXT setfcr(SB), $0 - MOVL new+0(FP), R1 - MOVL R1, FPCR - RTS diff --git a/libkern/memmove-68000.s b/libkern/memmove-68000.s deleted file mode 100644 index efb0853e..00000000 --- a/libkern/memmove-68000.s +++ /dev/null @@ -1,124 +0,0 @@ - TEXT memmove(SB), $0 - BRA move - - TEXT memcpy(SB), $0 -move: - - MOVL n+8(FP), R0 /* count */ - BEQ return - BGT ok - MOVL 0, R0 -ok: - MOVL s1+0(FP), A2 /* dest pointer */ - MOVL s2+4(FP), A1 /* source pointer */ - - CMPL A2,A1 - BHI back - -/* - * byte-at-a-time foreward copy to - * get source (A1) alligned. - */ -f1: - MOVL A1, R1 - ANDL $3, R1 - BEQ f2 - SUBL $1, R0 - BLT return - MOVB (A1)+, (A2)+ - BRA f1 - -/* - * check that dest is alligned - * if not, just go byte-at-a-time - */ -f2: - MOVL A2, R1 - ANDL $3, R1 - BEQ f3 - SUBL $1, R0 - BLT return - BRA f5 -/* - * quad-long-at-a-time forward copy - */ -f3: - SUBL $16, R0 - BLT f4 - MOVL (A1)+, (A2)+ - MOVL (A1)+, (A2)+ - MOVL (A1)+, (A2)+ - MOVL (A1)+, (A2)+ - BRA f3 - -/* - * cleanup byte-at-a-time - */ -f4: - ADDL $15, R0 - BLT return -f5: - MOVB (A1)+, (A2)+ - SUBL $1, R0 - BGE f5 - BRA return - -return: - MOVL s1+0(FP),R0 - RTS - -/* - * everything the same, but - * copy backwards - */ -back: - ADDL R0, A1 - ADDL R0, A2 - -/* - * byte-at-a-time backward copy to - * get source (A1) alligned. - */ -b1: - MOVL A1, R1 - ANDL $3, R1 - BEQ b2 - SUBL $1, R0 - BLT return - MOVB -(A1), -(A2) - BRA b1 - -/* - * check that dest is alligned - * if not, just go byte-at-a-time - */ -b2: - MOVL A2, R1 - ANDL $3, R1 - BEQ b3 - SUBL $1, R0 - BLT return - BRA b5 -/* - * quad-long-at-a-time backward copy - */ -b3: - SUBL $16, R0 - BLT b4 - MOVL -(A1), -(A2) - MOVL -(A1), -(A2) - MOVL -(A1), -(A2) - MOVL -(A1), -(A2) - BRA b3 - -/* - * cleanup byte-at-a-time backward - */ -b4: - ADDL $15, R0 - BLT return -b5: - MOVB -(A1), -(A2) - SUBL $1, R0 - BGE b5 - BRA return diff --git a/libkern/memset-68000.s b/libkern/memset-68000.s deleted file mode 100644 index 318f61a7..00000000 --- a/libkern/memset-68000.s +++ /dev/null @@ -1,57 +0,0 @@ - TEXT memset(SB), $0 - MOVL n+8(FP), R0 - BLE return - MOVL s1+0(FP), A1 - CLRL R1 - MOVB c+7(FP), R1 - BEQ l1 - -/* - * create 4 replicated copies - * of the byte in R1 - */ - MOVL R1, R2 - ASLL $8, R2 - ORL R2, R1 - MOVL R1, R2 - SWAP R2 - ORL R2, R1 - -/* - * byte-at-a-time until alligned - */ -l1: - MOVL A1, R1 - ANDL $3, R1 - BEQ l2 - SUBL $1, R0 - BLT return - MOVB R1, (A1)+ - BRA l1 - -/* - * quad-long-at-a-time set - */ -l2: - SUBL $16, R0 - BLT l3 - MOVL R1, (A1)+ - MOVL R1, (A1)+ - MOVL R1, (A1)+ - MOVL R1, (A1)+ - BRA l2 - -/* - * cleanup byte-at-a-time - */ -l3: - ADDL $15, R0 - BLT return -l4: - MOVB R1, (A1)+ - SUBL $1, R0 - BGE l4 - -return: - MOVL s1+0(FP),R0 - RTS diff --git a/libkern/mkfile-68000 b/libkern/mkfile-68000 deleted file mode 100644 index dd5da424..00000000 --- a/libkern/mkfile-68000 +++ /dev/null @@ -1,12 +0,0 @@ -# -# 68000-specific files -# -TARGFILES=\ - frexp-68000.$O\ - getfcr-68000.$O\ - memmove-68000.$O\ - memset-68000.$O\ - nan-68000.$O\ - strchr-68000.$O\ - muldiv-68000.$O\ - vlrt-68000.$O\ diff --git a/libkern/muldiv-68000.s b/libkern/muldiv-68000.s deleted file mode 100644 index 10ef6f46..00000000 --- a/libkern/muldiv-68000.s +++ /dev/null @@ -1,172 +0,0 @@ -/* - * calls _divul with - * absolute value arguments - */ -TEXT _divsl(SB), $0 - MOVL R0, TOS - - MOVL b+4(FP), R0 - BPL y1 - NEGL R0 - MOVL R0, TOS - - MOVL a+0(FP), R0 - BPL y3 - NEGL R0 - MOVL R0, TOS - - /* neg/neg */ - JSR _divul(SB) - MOVL TOS, R0 - MOVL R0, a+0(FP) - MOVL TOS, R0 - NEGL R0 - MOVL R0, b+4(FP) - MOVL TOS, R0 - RTS - -y1: MOVL R0, TOS - - MOVL a+0(FP), R0 - BPL y2 - NEGL R0 - MOVL R0, TOS - - /* neg/pos */ - JSR _divul(SB) - MOVL TOS, R0 - NEGL R0 - MOVL R0, a+0(FP) - MOVL TOS, R0 - NEGL R0 - MOVL R0, b+4(FP) - MOVL TOS, R0 - RTS - -y2: MOVL R0, TOS - - /* pos/pos */ - JSR _divul(SB) - MOVL TOS, R0 - MOVL R0, a+0(FP) - MOVL TOS, R0 - MOVL R0, b+4(FP) - MOVL TOS, R0 - RTS - -y3: MOVL R0, TOS - - /* pos/neg */ - JSR _divul(SB) - MOVL TOS, R0 - NEGL R0 - MOVL R0, a+0(FP) - MOVL TOS, R0 - MOVL R0, b+4(FP) - MOVL TOS, R0 - RTS - -/* - * for(i=1;; i++) { - * if(den & (1<<31)) - * break; - * den <<= 1; - * } - * - * for(; i; i--) { - * quo <<= 1; - * if(num >= den) { - * num -= den; - * quo |= 1; - * } - * den >>= 1; - * } - */ -TEXT _divul(SB), $0 - MOVL R0, TOS /* i */ - MOVL R1, TOS /* num */ - MOVL R2, TOS /* den */ - MOVL R3, TOS /* quo */ - - MOVL $0, R0 - MOVL $0, R3 - MOVL a+0(FP), R1 - MOVL b+4(FP), R2 - BEQ xout - BMI x1 - - ADDL $1, R0 - LSLL $1, R2 - BPL -2(PC) - -x1: LSLL $1, R3 - CMPL R1, R2 - BCS 3(PC) - SUBL R2, R1 - ORL $1, R3 - LSRL $1, R2 - DBMI R0, x1 - - MOVL R3, a+0(FP) - MOVL R1, b+4(FP) - -xout: - MOVL TOS, R3 - MOVL TOS, R2 - MOVL TOS, R1 - MOVL TOS, R0 - RTS - -/* - * x = 0; - * for(i=0; i<32; i++) { - * if(a & 1) - * x += b; - * a >>= 1; - * b <<= 1; - * } - * a = x; - */ -TEXT _mull(SB), $0 - MOVL R0, TOS /* i */ - MOVL R1, TOS /* a */ - MOVL R2, TOS /* b */ - MOVL R3, TOS /* x */ - - MOVL a+0(FP), R1 - MOVL b+4(FP), R2 - MOVL $32, R0 - CLRL R3 - -z1: ROTRL $1, R1 - BCC 2(PC) - ADDL R2, R3 - LSLL $1, R2 - DBEQ R0, z1 - - MOVL R3, b+4(FP) - MOVL TOS, R3 - MOVL TOS, R2 - MOVL TOS, R1 - MOVL TOS, R0 - RTS - -TEXT _ccr(SB), $0 - PEA (A0) - SUBL A0, A0 - - BCC 2(PC) - LEA 1(A0), A0 - - BVC 2(PC) - LEA 2(A0), A0 - - BNE 2(PC) - LEA 4(A0), A0 - - BPL 2(PC) - LEA 8(A0), A0 - - MOVW A0, a+0(FP) - MOVL TOS, A0 - RTS diff --git a/libkern/nan-68000.c b/libkern/nan-68000.c deleted file mode 100644 index e1b3db36..00000000 --- a/libkern/nan-68000.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <u.h> -#include <libc.h> - -#define NANEXP (2047<<20) -#define NANMASK (2047<<20) -#define NANSIGN (1<<31) - -double -NaN(void) -{ - union - { - double d; - long x[2]; - } a; - - a.x[0] = NANEXP; - a.x[1] = 1; - return a.d; -} - -int -isNaN(double d) -{ - union - { - double d; - long x[2]; - } a; - - a.d = d; - if((a.x[0] & NANMASK) != NANEXP) - return 0; - return !isInf(d, 0); -} - -double -Inf(int sign) -{ - union - { - double d; - long x[2]; - } a; - - a.x[0] = NANEXP; - a.x[1] = 0; - if(sign < 0) - a.x[0] |= NANSIGN; - return a.d; -} - -int -isInf(double d, int sign) -{ - union - { - double d; - long x[2]; - } a; - - a.d = d; - if(a.x[1] != 0) - return 0; - if(a.x[0] == NANEXP) - return sign >= 0; - if(a.x[0] == (NANEXP|NANSIGN)) - return sign <= 0; - return 0; -} diff --git a/libkern/strchr-68000.s b/libkern/strchr-68000.s deleted file mode 100644 index a5d4be2c..00000000 --- a/libkern/strchr-68000.s +++ /dev/null @@ -1,27 +0,0 @@ - TEXT strchr(SB), $0 - - MOVL s+0(FP), A0 - MOVB c+7(FP), R2 - BEQ null - -l: - MOVB (A0)+, R1 - BEQ out - CMPB R1, R2 - BNE l - - MOVL A0, R0 - ADDL $-1, R0 - RTS - -out: - CLRL R0 - RTS - -null: - TSTB (A0)+ - BNE null - - MOVL A0, R0 - ADDL $-1, R0 - RTS diff --git a/libkern/vlrt-68000.c b/libkern/vlrt-68000.c deleted file mode 100644 index 071aa180..00000000 --- a/libkern/vlrt-68000.c +++ /dev/null @@ -1,771 +0,0 @@ -typedef unsigned long ulong; -typedef unsigned int uint; -typedef unsigned short ushort; -typedef unsigned char uchar; -typedef signed char schar; - -#define SIGN(n) (1UL<<(n-1)) - -typedef struct Vlong Vlong; -struct Vlong -{ - union - { - struct - { - ulong hi; - ulong lo; - }; - struct - { - ushort hims; - ushort hils; - ushort loms; - ushort lols; - }; - }; -}; - -void abort(void); - -void -_addv(Vlong *r, Vlong a, Vlong b) -{ - ulong lo, hi; - - lo = a.lo + b.lo; - hi = a.hi + b.hi; - if(lo < a.lo) - hi++; - r->lo = lo; - r->hi = hi; -} - -void -_subv(Vlong *r, Vlong a, Vlong b) -{ - ulong lo, hi; - - lo = a.lo - b.lo; - hi = a.hi - b.hi; - if(lo > a.lo) - hi--; - r->lo = lo; - r->hi = hi; -} - -void -_d2v(Vlong *y, double d) -{ - union { double d; struct Vlong; } x; - ulong xhi, xlo, ylo, yhi; - int sh; - - x.d = d; - - xhi = (x.hi & 0xfffff) | 0x100000; - xlo = x.lo; - sh = 1075 - ((x.hi >> 20) & 0x7ff); - - ylo = 0; - yhi = 0; - if(sh >= 0) { - /* v = (hi||lo) >> sh */ - if(sh < 32) { - if(sh == 0) { - ylo = xlo; - yhi = xhi; - } else { - ylo = (xlo >> sh) | (xhi << (32-sh)); - yhi = xhi >> sh; - } - } else { - if(sh == 32) { - ylo = xhi; - } else - if(sh < 64) { - ylo = xhi >> (sh-32); - } - } - } else { - /* v = (hi||lo) << -sh */ - sh = -sh; - if(sh <= 10) { - ylo = xlo << sh; - yhi = (xhi << sh) | (xlo >> (32-sh)); - } else { - /* overflow */ - yhi = d; /* causes something awful */ - } - } - if(x.hi & SIGN(32)) { - if(ylo != 0) { - ylo = -ylo; - yhi = ~yhi; - } else - yhi = -yhi; - } - - y->hi = yhi; - y->lo = ylo; -} - -void -_f2v(Vlong *y, float f) -{ - - _d2v(y, f); -} - -double -_v2d(Vlong x) -{ - if(x.hi & SIGN(32)) { - if(x.lo) { - x.lo = -x.lo; - x.hi = ~x.hi; - } else - x.hi = -x.hi; - return -((long)x.hi*4294967296. + x.lo); - } - return (long)x.hi*4294967296. + x.lo; -} - -float -_v2f(Vlong x) -{ - return _v2d(x); -} - -static void -dodiv(Vlong num, Vlong den, Vlong *q, Vlong *r) -{ - ulong numlo, numhi, denhi, denlo, quohi, quolo, t; - int i; - - numhi = num.hi; - numlo = num.lo; - denhi = den.hi; - denlo = den.lo; - - /* - * get a divide by zero - */ - if(denlo==0 && denhi==0) { - numlo = numlo / denlo; - } - - /* - * set up the divisor and find the number of iterations needed - */ - if(numhi >= SIGN(32)) { - quohi = SIGN(32); - quolo = 0; - } else { - quohi = numhi; - quolo = numlo; - } - i = 0; - while(denhi < quohi || (denhi == quohi && denlo < quolo)) { - denhi = (denhi<<1) | (denlo>>31); - denlo <<= 1; - i++; - } - - quohi = 0; - quolo = 0; - for(; i >= 0; i--) { - quohi = (quohi<<1) | (quolo>>31); - quolo <<= 1; - if(numhi > denhi || (numhi == denhi && numlo >= denlo)) { - t = numlo; - numlo -= denlo; - if(numlo > t) - numhi--; - numhi -= denhi; - quolo |= 1; - } - denlo = (denlo>>1) | (denhi<<31); - denhi >>= 1; - } - - if(q) { - q->lo = quolo; - q->hi = quohi; - } - if(r) { - r->lo = numlo; - r->hi = numhi; - } -} - -void -_divvu(Vlong *q, Vlong n, Vlong d) -{ - - if(n.hi == 0 && d.hi == 0) { - q->hi = 0; - q->lo = n.lo / d.lo; - return; - } - dodiv(n, d, q, 0); -} - -void -_modvu(Vlong *r, Vlong n, Vlong d) -{ - - if(n.hi == 0 && d.hi == 0) { - r->hi = 0; - r->lo = n.lo % d.lo; - return; - } - dodiv(n, d, 0, r); -} - -static void -vneg(Vlong *v) -{ - - if(v->lo == 0) { - v->hi = -v->hi; - return; - } - v->lo = -v->lo; - v->hi = ~v->hi; -} - -void -_divv(Vlong *q, Vlong n, Vlong d) -{ - long nneg, dneg; - - if(n.hi == (((long)n.lo)>>31) && d.hi == (((long)d.lo)>>31)) { - q->lo = (long)n.lo / (long)d.lo; - q->hi = ((long)q->lo) >> 31; - return; - } - nneg = n.hi >> 31; - if(nneg) - vneg(&n); - dneg = d.hi >> 31; - if(dneg) - vneg(&d); - dodiv(n, d, q, 0); - if(nneg != dneg) - vneg(q); -} - -void -_modv(Vlong *r, Vlong n, Vlong d) -{ - long nneg, dneg; - - if(n.hi == (((long)n.lo)>>31) && d.hi == (((long)d.lo)>>31)) { - r->lo = (long)n.lo % (long)d.lo; - r->hi = ((long)r->lo) >> 31; - return; - } - nneg = n.hi >> 31; - if(nneg) - vneg(&n); - dneg = d.hi >> 31; - if(dneg) - vneg(&d); - dodiv(n, d, 0, r); - if(nneg) - vneg(r); -} - -void -_rshav(Vlong *r, Vlong a, int b) -{ - long t; - - t = a.hi; - if(b >= 32) { - r->hi = t>>31; - if(b >= 64) { - /* this is illegal re C standard */ - r->lo = t>>31; - return; - } - r->lo = t >> (b-32); - return; - } - if(b <= 0) { - r->hi = t; - r->lo = a.lo; - return; - } - r->hi = t >> b; - r->lo = (t << (32-b)) | (a.lo >> b); -} - -void -_rshlv(Vlong *r, Vlong a, int b) -{ - ulong t; - - t = a.hi; - if(b >= 32) { - r->hi = 0; - if(b >= 64) { - /* this is illegal re C standard */ - r->lo = 0; - return; - } - r->lo = t >> (b-32); - return; - } - if(b <= 0) { - r->hi = t; - r->lo = a.lo; - return; - } - r->hi = t >> b; - r->lo = (t << (32-b)) | (a.lo >> b); -} - -void -_lshv(Vlong *r, Vlong a, int b) -{ - ulong t; - - t = a.lo; - if(b >= 32) { - r->lo = 0; - if(b >= 64) { - /* this is illegal re C standard */ - r->hi = 0; - return; - } - r->hi = t << (b-32); - return; - } - if(b <= 0) { - r->lo = t; - r->hi = a.hi; - return; - } - r->lo = t << b; - r->hi = (t >> (32-b)) | (a.hi << b); -} - -void -_andv(Vlong *r, Vlong a, Vlong b) -{ - r->hi = a.hi & b.hi; - r->lo = a.lo & b.lo; -} - -void -_orv(Vlong *r, Vlong a, Vlong b) -{ - r->hi = a.hi | b.hi; - r->lo = a.lo | b.lo; -} - -void -_xorv(Vlong *r, Vlong a, Vlong b) -{ - r->hi = a.hi ^ b.hi; - r->lo = a.lo ^ b.lo; -} - -void -_negv(Vlong *r, Vlong a) -{ - if(a.lo == 0) { - r->hi = -a.hi; - r->lo = 0; - return; - } - r->hi = ~a.hi; - r->lo = -a.lo; -} - -void -_vpp(Vlong *l, Vlong *r) -{ - - l->hi = r->hi; - l->lo = r->lo; - r->lo++; - if(r->lo == 0) - r->hi++; -} - -void -_vmm(Vlong *l, Vlong *r) -{ - - l->hi = r->hi; - l->lo = r->lo; - if(r->lo == 0) - r->hi--; - r->lo--; -} - -void -_ppv(Vlong *l, Vlong *r) -{ - - r->lo++; - if(r->lo == 0) - r->hi++; - l->hi = r->hi; - l->lo = r->lo; -} - -void -_mmv(Vlong *l, Vlong *r) -{ - - if(r->lo == 0) - r->hi--; - r->lo--; - l->hi = r->hi; - l->lo = r->lo; -} - -void -_vasop(Vlong *ret, void *lv, void fn(Vlong*, Vlong, Vlong), int type, Vlong rv) -{ - Vlong t, u; - - u = *ret; - switch(type) { - default: - abort(); - break; - - case 1: /* schar */ - t.lo = *(schar*)lv; - t.hi = t.lo >> 31; - fn(&u, t, rv); - *(schar*)lv = u.lo; - break; - - case 2: /* uchar */ - t.lo = *(uchar*)lv; - t.hi = 0; - fn(&u, t, rv); - *(uchar*)lv = u.lo; - break; - - case 3: /* short */ - t.lo = *(short*)lv; - t.hi = t.lo >> 31; - fn(&u, t, rv); - *(short*)lv = u.lo; - break; - - case 4: /* ushort */ - t.lo = *(ushort*)lv; - t.hi = 0; - fn(&u, t, rv); - *(ushort*)lv = u.lo; - break; - - case 9: /* int */ - t.lo = *(int*)lv; - t.hi = t.lo >> 31; - fn(&u, t, rv); - *(int*)lv = u.lo; - break; - - case 10: /* uint */ - t.lo = *(uint*)lv; - t.hi = 0; - fn(&u, t, rv); - *(uint*)lv = u.lo; - break; - - case 5: /* long */ - t.lo = *(long*)lv; - t.hi = t.lo >> 31; - fn(&u, t, rv); - *(long*)lv = u.lo; - break; - - case 6: /* ulong */ - t.lo = *(ulong*)lv; - t.hi = 0; - fn(&u, t, rv); - *(ulong*)lv = u.lo; - break; - - case 7: /* vlong */ - case 8: /* uvlong */ - fn(&u, *(Vlong*)lv, rv); - *(Vlong*)lv = u; - break; - } - *ret = u; -} - -void -_p2v(Vlong *ret, void *p) -{ - long t; - - t = (ulong)p; - ret->lo = t; - ret->hi = 0; -} - -void -_sl2v(Vlong *ret, long sl) -{ - long t; - - t = sl; - ret->lo = t; - ret->hi = t >> 31; -} - -void -_ul2v(Vlong *ret, ulong ul) -{ - long t; - - t = ul; - ret->lo = t; - ret->hi = 0; -} - -void -_si2v(Vlong *ret, int si) -{ - long t; - - t = si; - ret->lo = t; - ret->hi = t >> 31; -} - -void -_ui2v(Vlong *ret, uint ui) -{ - long t; - - t = ui; - ret->lo = t; - ret->hi = 0; -} - -void -_sh2v(Vlong *ret, long sh) -{ - long t; - - t = (sh << 16) >> 16; - ret->lo = t; - ret->hi = t >> 31; -} - -void -_uh2v(Vlong *ret, ulong ul) -{ - long t; - - t = ul & 0xffff; - ret->lo = t; - ret->hi = 0; -} - -void -_sc2v(Vlong *ret, long uc) -{ - long t; - - t = (uc << 24) >> 24; - ret->lo = t; - ret->hi = t >> 31; -} - -void -_uc2v(Vlong *ret, ulong ul) -{ - long t; - - t = ul & 0xff; - ret->lo = t; - ret->hi = 0; -} - -long -_v2sc(Vlong rv) -{ - long t; - - t = rv.lo & 0xff; - return (t << 24) >> 24; -} - -long -_v2uc(Vlong rv) -{ - - return rv.lo & 0xff; -} - -long -_v2sh(Vlong rv) -{ - long t; - - t = rv.lo & 0xffff; - return (t << 16) >> 16; -} - -long -_v2uh(Vlong rv) -{ - - return rv.lo & 0xffff; -} - -long -_v2sl(Vlong rv) -{ - - return rv.lo; -} - -long -_v2ul(Vlong rv) -{ - - return rv.lo; -} - -long -_v2si(Vlong rv) -{ - - return rv.lo; -} - -long -_v2ui(Vlong rv) -{ - - return rv.lo; -} - -int -_testv(Vlong rv) -{ - return rv.lo || rv.hi; -} - -int -_eqv(Vlong lv, Vlong rv) -{ - return lv.lo == rv.lo && lv.hi == rv.hi; -} - -int -_nev(Vlong lv, Vlong rv) -{ - return lv.lo != rv.lo || lv.hi != rv.hi; -} - -int -_ltv(Vlong lv, Vlong rv) -{ - return (long)lv.hi < (long)rv.hi || - (lv.hi == rv.hi && lv.lo < rv.lo); -} - -int -_lev(Vlong lv, Vlong rv) -{ - return (long)lv.hi < (long)rv.hi || - (lv.hi == rv.hi && lv.lo <= rv.lo); -} - -int -_gtv(Vlong lv, Vlong rv) -{ - return (long)lv.hi > (long)rv.hi || - (lv.hi == rv.hi && lv.lo > rv.lo); -} - -int -_gev(Vlong lv, Vlong rv) -{ - return (long)lv.hi > (long)rv.hi || - (lv.hi == rv.hi && lv.lo >= rv.lo); -} - -int -_lov(Vlong lv, Vlong rv) -{ - return lv.hi < rv.hi || - (lv.hi == rv.hi && lv.lo < rv.lo); -} - -int -_lsv(Vlong lv, Vlong rv) -{ - return lv.hi < rv.hi || - (lv.hi == rv.hi && lv.lo <= rv.lo); -} - -int -_hiv(Vlong lv, Vlong rv) -{ - return lv.hi > rv.hi || - (lv.hi == rv.hi && lv.lo > rv.lo); -} - -int -_hsv(Vlong lv, Vlong rv) -{ - return lv.hi > rv.hi || - (lv.hi == rv.hi && lv.lo >= rv.lo); -} - -void -_mulv(Vlong *r, Vlong a, Vlong b) -{ - ulong ahi, alo, chi, clo, x; - int i; - - ahi = a.hi; - alo = a.lo; - chi = 0; - clo = 0; - - x = b.lo; - for(i=0; i<32; i++) { - if(x & 1) { - chi += ahi; - clo += alo; - if(clo < alo) - chi++; - } - ahi <<= 1; - if(alo & SIGN(32)) - ahi += 1; - alo <<= 1; - x >>= 1; - } - - /* - * same, but - * alo is known to be 0 - * can stop when x == 0 - */ - for(x=b.hi; x; x>>=1) { - if(x & 1) - chi += ahi; - ahi <<= 1; - } - - r->hi = chi; - r->lo = clo; -} @@ -145,9 +145,6 @@ kernel/&-Plan9:QV: # Convenience targets -Hp-% hp-%:V: - mk 'SYSHOST=Hp' 'OBJTYPE=s800' $stem - Inferno-% inferno-% Inferno-386-% inferno-386-%:V: mk 'SYSHOST=Inferno' 'OBJTYPE=386' $stem diff --git a/mkfiles/mkfile-Hp-s800 b/mkfiles/mkfile-Hp-s800 deleted file mode 100644 index e8a1f35b..00000000 --- a/mkfiles/mkfile-Hp-s800 +++ /dev/null @@ -1,33 +0,0 @@ -TARGMODEL= Posix -TARGSHTYPE= sh -CPUS= s800 - -O= o -OS= o - -AR= ar -ARFLAGS= cvru - -AS= c89 -c -ASFLAGS= - -CC= c89 -c -CFLAGS= -D_HPUX_SOURCE \ - -D_REENTRANT \ - +u4 \ - +e \ - -w\ - +DA1.0\ - -xCC \ - -Xa\ - -I$ROOT/Hp/s800/include\ - -I$ROOT/include\ - -ANSICPP= -LD= c89 -LDFLAGS= -s -L/usr/openwin/lib - -SYSLIBS= -lm -lX11 -lcma - -YACC= iyacc -YFLAGS= -d diff --git a/mkfiles/mkfile-Inferno-68000 b/mkfiles/mkfile-Inferno-68000 deleted file mode 100644 index 0bddea56..00000000 --- a/mkfiles/mkfile-Inferno-68000 +++ /dev/null @@ -1,24 +0,0 @@ -TARGMODEL= Inferno -TARGSHTYPE= rc -CPUS= 68000 - -O= 1 -OS= v851ok0q2t6 - -AR= ar -ARFLAGS= vu - -AS= 1a -ASFLAGS= - -CC= 1c -CFLAGS= -N -wFV -I$ROOT/Inferno/$OBJTYPE/include -I$ROOT/Inferno/include -I$ROOT/include -ANSICPP= -p - -LD= 1l -LDFLAGS= -H2 - -LDSYSLIBS= -lc - -YACC= yacc -YFLAGS= -d diff --git a/mkfiles/mkhost-Hp b/mkfiles/mkhost-Hp deleted file mode 100644 index 432337c7..00000000 --- a/mkfiles/mkhost-Hp +++ /dev/null @@ -1,12 +0,0 @@ - -# Variables for host system type = Hp - -SHELLTYPE= sh -SHELLNAME= /bin/sh -HOSTMODEL= Posix -OSTARG= os - -DATA2S= data2s -NDATE= ndate -KSIZE= ksize -AWK= awk diff --git a/module/regexutils.m b/module/regexutils.m deleted file mode 100644 index 50935d84..00000000 --- a/module/regexutils.m +++ /dev/null @@ -1,17 +0,0 @@ - -include "regex.m"; - regex: Regex; - -RegexUtils: module -{ - PATH: con "/dis/lib/regexutils.dis"; - init: fn(); - - match: fn(pattern: Regex->Re, s: string): string; - match_mult: fn(pattern: Regex->Re, s: string): array of (int, int); - sub: fn(text, pattern, new: string): string; - sub_re: fn(text: string, pattern: Regex->Re, new: string): string; - subg: fn(text, pattern, new: string): string; - subg_re: fn(text: string, pattern: Regex->Re, new: string): string; -}; - |
