commit b1f69d3efa85184384c2d2d02e03ed82b95b3007
parent ad2695b2628cb5ca89dabea6d94680593bdb9f30
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 30 Mar 2023 17:11:11 -0400
posix: consolidate
Diffstat:
M | posix/vm.c | | | 46 | ++++++++++++++++++++++------------------------ |
1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/posix/vm.c b/posix/vm.c
@@ -203,7 +203,7 @@ static void binopwr(byte binopidx, dword operand) {
if (operand&OPHASDISP) dwrite(hbankget(operand));
}
static void wfetchwr(dword op) { wopwr(0x10, op); }
-static void wstorewr(dword op) { wopwr(0x11, op); }
+static void wstorewr(dword op) { wopwr(0x10, op^OPINVERT); }
static void maddnwr(dword op, dword n) { wopwr(0x13, op); dwrite(n); }
static void wistorewr(dword op) { wopwr(0x16, op); }
static void dupwr() { psaddwr(0xfffffffc); wstorewr(OPPSP); }
@@ -237,16 +237,17 @@ static void entry(char *name) {
/* Operations */
static dword opaddr;
static dword *opdst;
+static dword opmask;
static dword (*mget)(dword a);
static void (*mset)(dword a, dword val);
static dword mget16(dword a) { return (dword)gw(a); }
static dword mget8(dword a) { return (dword)gb(a); }
static void mset16(dword a, dword val) { sw(a, (word)val); }
static void mset8(dword a, dword val) { sb(a, (byte)val); }
-#define M32B mget = gdr; mset = sdr
-#define M16B mget = mget16; mset = mset16
-#define M8B mget = mget8; mset = mset8
-static dword def_opdget() { return *opdst; }
+#define M32B mget = gdr; mset = sdr; opmask = 0xffffffff
+#define M16B mget = mget16; mset = mset16; opmask = 0xffff
+#define M8B mget = mget8; mset = mset8; opmask=0xff
+static dword def_opdget() { return *opdst & opmask; }
static void def_opdset(dword val) { *opdst = val; }
static dword def_opsget() { return mget(opaddr); }
static void def_opsset(dword val) { mset(opaddr, val); }
@@ -309,37 +310,34 @@ static void readop() {
if (op & OPADEST) opdst = &vm.A;
}
static void _wfetch() { readop(); opdset(opsget()); }
-static void _wstore() { readop(); opsset(opdget()); }
static void _wswap() { readop(); dword n; n = opsget(); opsset(opdget()); opdset(n); }
static void _maddn() { readop(); dword n=gpc(); n += opsget(); opsset(n); vm.Z = n == 0; }
+static void _wcmp() {
+ readop(); dword n = opsget(); dword ref = opdget();
+ vm.Z = n == ref; vm.C = ref < n;
+ vm.SC = (ref+0x80000000) < (n+0x80000000); }
static void _wifetch() { readop(); opdset(mget(gdr(opaddr))); }
static void _wistore() { readop(); mset(gdr(opaddr), opdget()); }
static void WFETCH() { M32B; _wfetch(); } // 0x10
-static void WSTORE() { M32B; _wstore(); }
static void WSWAP() { M32B; _wswap(); }
static void MADDN() { M32B; _maddn(); }
-static void WCMP() {
- readop(); dword n = gdr(opaddr); dword ref = opdget();
- vm.Z = n == ref; vm.C = ref < n;
- vm.SC = (ref+0x80000000) < (n+0x80000000); }
+static void WCMP() { M32B; _wcmp(); }
static void WIFETCH() { M32B; _wifetch(); }
static void WISTORE() { M32B; _wistore(); }
static void WLEA() { readop(); opdset(opaddr); }
static void WFETCH16() { M16B; _wfetch(); } // 0x18
-static void WSTORE16() { M16B; _wstore(); }
static void WSWAP16() { M16B; _wswap(); }
static void MADDN16() { M16B; _maddn(); }
-static void WCMP16() { readop(); vm.Z = opsget() == (opdget() & 0xffff); }
+static void WCMP16() { M16B; _wcmp(); }
static void WIFETCH16() { M16B; _wifetch(); }
static void WISTORE16() { M16B; _wistore(); }
static void WFETCH8() { M8B; _wfetch(); } // 0x20
-static void WSTORE8() { M8B; _wstore(); }
static void WSWAP8() { M8B; _wswap(); }
static void MADDN8() { M8B; _maddn(); }
-static void WCMP8() { readop(); vm.Z = opsget() == (opdget() & 0xff); }
+static void WCMP8() { M8B; _wcmp(); }
static void WIFETCH8() { M8B; _wifetch(); }
static void WISTORE8() { M8B; _wistore(); }
@@ -866,9 +864,9 @@ static void DRVWR() {
static void (*ops[OPCNT])() = {
BR, CALL, RET, BRWR, BRA, BRC, NULL, YIELD,
PSADD, RSADD, WLIT, ALIT, WADDN, AADDN, W2A, WSWAPA,
- WFETCH, WSTORE, WSWAP, MADDN, WCMP, WIFETCH, WISTORE, WLEA,
- WFETCH16, WSTORE16, WSWAP16, MADDN16, WCMP16, WIFETCH16, WISTORE16, WLEA,
- WFETCH8, WSTORE8, WSWAP8, MADDN8, WCMP8, WIFETCH8, WISTORE8, WLEA,
+ WFETCH, NULL, WSWAP, MADDN, WCMP, WIFETCH, WISTORE, WLEA,
+ WFETCH16, NULL, WSWAP16, MADDN16, WCMP16, WIFETCH16, WISTORE16, WLEA,
+ WFETCH8, NULL, WSWAP8, MADDN8, WCMP8, WIFETCH8, WISTORE8, WLEA,
NULL, BOOTRD, STDOUT, MAYBEKEY, NULL, MAKEMEM, ADDDISP, NULL,
MAYBEWORD, WORD, PARSE, FIND, WNF, FINDMOD, NULL, NULL,
STACKCHK, COMPWORD, RUNWORD, COMPILING, STARTCOMP, STOPCOMP, RSADDWR, COMPOP,
@@ -963,7 +961,6 @@ static void buildsysdict() {
entry("W>A,"); compileop(0x0e); retwr();
entry("W<>A,"); compileop(0x0f); retwr();
entry("@,"); compopwr(0x10); retwr();
- entry("!,"); compopwr(0x11); retwr();
entry("@!,"); compopwr(0x12); retwr();
// ( n ?disp operand -- )
entry("[+n],"); compopwr(0x13); writewr(); retwr();
@@ -993,10 +990,6 @@ static void buildsysdict() {
entry("branch!"); storewr(); retwr();
entry("yield"); compileop(0x07); retwr(); makeimm();
entry(";"); compileop(0x02); cwrite(0x3d); retwr(); makeimm();
- entry("dup,");
- litwr(0xfffffffc); callwr(find("ps+,"));
- callwr(find("PSP)")); callwr(find("!,")); retwr();
- entry("litn"); callwr(find("dup,")); callwr(find("LIT>W,")); retwr();
entry("i)"); callwr(find("m)")); cwrite(0x0c); /* W+n */ dwrite(1); retwr();
entry("*"); binopwr(0x02, OPPSP); nipwr(); retwr();
entry("and"); binopwr(0x08, OPPSP); nipwr(); retwr();
@@ -1009,7 +1002,12 @@ static void buildsysdict() {
entry("16b)"); litwr(OP16B); callwr(find("or")); retwr();
entry("8b)"); litwr(OP8B); callwr(find("or")); retwr();
entry("A>)"); litwr(OPADEST); callwr(find("or")); retwr();
- entry("<>)"); litwr(OPINVERT); callwr(find("or")); retwr();
+ entry("<>)"); litwr(OPINVERT); callwr(find("xor")); retwr();
+ entry("!,"); callwr(find("<>)")); callwr(find("@,")); retwr();
+ entry("dup,");
+ litwr(0xfffffffc); callwr(find("ps+,"));
+ callwr(find("PSP)")); callwr(find("!,")); retwr();
+ entry("litn"); callwr(find("dup,")); callwr(find("LIT>W,")); retwr();
sysalias("in<", "boot<");
sysalias("rtype", "byefail");
sysalias("abort", "byefail");