commit a6cda88e04d02897da4733b01d2ff06096285303
parent d0393d67ff1954ed1af81fdef842e0f1b61e6c10
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 19 Mar 2023 10:54:35 -0400
hal posix: consolidate
Diffstat:
3 files changed, 52 insertions(+), 44 deletions(-)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -55,7 +55,8 @@ code16b W>A, drop, A) 16b) [!], 2 A) [+n], drop, exit,
code8b W>A, drop, A) 8b) [!], 1 A) [+n], drop, exit,
code + PSP) +, nip, exit,
-: - swap -^ ;
+code - neg, PSP) +, nip, exit,
+: -^ swap - ;
: e>w 5 + ;
: w>e 5 - ;
: current sysdict @ e>w ;
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -347,10 +347,6 @@ xcode branch! ( tgt a -- )
ret,
\ Regular words
-xcode -^
- ax si 0 d) sub,
- xnip, ret,
-
xcode *
si 0 d) mul,
xnip, ret,
diff --git a/posix/vm.c b/posix/vm.c
@@ -5,10 +5,10 @@ enough, however, to generate native binary images for any supported target.
HAL argument structure:
b2:0 type 0=W 1=A 2=PSP 3=RSP 4=memory 5=immediate
-b3 has disp? (type "memory" and "immediate" always have disp)
+b3 has disp? (type "memory" and "immediate" always have disp)
b7:4 number bank id
-b8 16b?
-b9 8b?
+b8 16b?
+b9 8b?
Full HAL: Unlike regular kernels, this VM contains the full HAL because it has
no assembler to complete the HAL to "full" level later. It's all in there.
@@ -179,7 +179,6 @@ static void writewr() { alitwr(HERE); wistorewr(OPA); maddnwr(OPA, 4); dropwr();
static void cwritewr() { alitwr(HERE); wistorewr(OPA|OP8B); maddnwr(OPA, 1); dropwr(); }
static void compopwr(byte opcode) { litwr(opcode); cwrite(0x3f); }
static void storewr() { cwrite(0x0e); dropwr(); wstorewr(OPA); dropwr(); }
-static void ornwr(dword n) { cwrite(0x63); dwrite(n); }
static void callword(dword addr); // forward declaration
static void _entry(dword dict, byte *name, byte slen) {
@@ -278,8 +277,6 @@ static void HBANKGET() { vm.W = hbankget(vm.W); }
static void MAKEMEM() { vm.W = hbankset(OPHASDISP|OPMEM, vm.W); }
// operand n -- operand
static void ADDDISP() { dword by = ppop(); vm.W = hbankset(vm.W, by)|OPHASDISP; }
-static void WCMPI() {
- dword n = gpc(); vm.Z = n == vm.W; vm.C = vm.W < n; }
static void MAYBEWORD() { // 0x30
dword c, a;
@@ -453,19 +450,11 @@ static void addmeta(dword id) {
static void CODE16() { addmeta(EMETA_16B); }
static void CODE8() { addmeta(EMETA_8B); }
-static void SWAPSUB() { vm.W -= pnip(); } // 0x48
-static void MUL() { vm.W *= pnip(); }
-// ( a b -- r q )
+// 0x68
static void DIVMOD() { dword b = vm.W; dword a = pnip(); vm.W = a % b; ppush(a / b); }
-static void LSHIFT() { dword by = ppop(); vm.W <<= by; }
-static void RSHIFT() { dword by = ppop(); vm.W >>= by; }
static void LT() { vm.W = pnip() < vm.W; }
static void NEG() { vm.W = -vm.W; }
-static void AND() { vm.W &= pnip(); } // 0x50
-static void OR() { vm.W |= pnip(); }
-static void XOR() { vm.W ^= pnip(); }
-
static void BYE() { vm.PC = MEMSZ; } // 0x58
static void BYEFAIL() { vmabort(); }
static void QUIT() {
@@ -491,11 +480,7 @@ static void DBG() {
static void USLEEP() { usleep(ppop()); }
-static void SHLN() { vm.W <<= gpcb(); } // 0x60
-static void SHRN() { vm.W >>= gpcb(); }
-static void ANDN() { vm.W &= gpc(); }
-static void ORN() { vm.W |= gpc(); }
-static void XORN() { vm.W ^= gpc(); }
+// 0x60
static void WCHECKZ() { vm.Z = !vm.W; }
static void STOREZ() { vm.W = vm.Z; }
static void ACHECKZ() { vm.Z = !vm.A; }
@@ -521,6 +506,17 @@ static void WMOD8() { vm.W &= gb(readop()); }
static void WSHL8() { vm.W <<= gb(readop()); }
static void WSHR8() { vm.W >>= gb(readop()); }
+static void WAND() { vm.W &= gd(readop()); } // 0x80
+static void WOR() { vm.W |= gd(readop()); }
+static void WXOR() { vm.W ^= gd(readop()); }
+
+static void WAND16() { vm.W &= gw(readop()); } // 0x88
+static void WOR16() { vm.W |= gw(readop()); }
+static void WXOR16() { vm.W ^= gw(readop()); }
+
+static void WAND8() { vm.W &= gb(readop()); } // 0x90
+static void WOR8() { vm.W |= gb(readop()); }
+static void WXOR8() { vm.W ^= gb(readop()); }
/* Filesystem
At POSIX level, we don't have access to the underlying FS structure such as
@@ -774,7 +770,7 @@ static void MOUNTDRV() {
// ( -- )
static void UNMOUNTDRV() {
- if (fp) {
+ if (fp) {
fclose(fp);
fp = NULL;
}
@@ -799,24 +795,27 @@ static void DRVWR() {
fwrite(&vm.mem[src], SECSZ, 1, fp);
}
-#define OPCNT 0x90
+#define OPCNT 0xa8
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, WADD,
WFETCH16, WSTORE16, WSWAP16, MADDN16, WCMP16, WIFETCH16, WISTORE16, WADD16,
WFETCH8, WSTORE8, WSWAP8, MADDN8, WCMP8, WIFETCH8, WISTORE8, WADD8,
- WLEA, BOOTRD, STDOUT, MAYBEKEY, HBANKGET, MAKEMEM, ADDDISP, WCMPI,
+ WLEA, BOOTRD, STDOUT, MAYBEKEY, HBANKGET, MAKEMEM, ADDDISP, NULL,
MAYBEWORD, WORD, PARSE, FIND, WNF, FINDMOD, NULL, NULL,
STACKCHK, COMPWORD, RUNWORD, COMPILING, STARTCOMP, STOPCOMP, RSADDWR, COMPOP,
ALIGN4, ENTRY, CODE, CODE16, CODE8, NULL, NULL, NULL,
- SWAPSUB, MUL, DIVMOD, LSHIFT, RSHIFT, LT, NEG, NULL,
- AND, OR, XOR, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, DIVMOD, NULL, LT, NEG, NULL,
BYE, BYEFAIL, QUIT, ABORT_, DBG, USLEEP, NULL, NULL,
- SHLN, SHRN, ANDN, ORN, XORN, WCHECKZ, STOREZ, ACHECKZ,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, WCHECKZ, STOREZ, ACHECKZ,
WSUB, WMUL, WDIV, WMOD, WSHL, WSHR, NULL, NULL,
WSUB16, WMUL16, WDIV16, WMOD16, WSHL16, WSHR16, NULL, NULL,
WSUB8, WMUL8, WDIV8, WMOD8, WSHL8, WSHR8, NULL, NULL,
+ WAND, WOR, WXOR, NULL, NULL, NULL, NULL, NULL,
+ WAND16, WOR16, WXOR16, NULL, NULL, NULL, NULL, NULL,
+ WAND8, WOR8, WXOR8, NULL, NULL, NULL, NULL, NULL,
FCHILD, FOPEN, FREADBUF, FCLOSE, FINFO, FITER, NULL, FSEEK,
MOUNTDRV, UNMOUNTDRV, DRVRD, DRVWR, NULL, NULL, NULL, NULL,
};
@@ -857,13 +856,16 @@ static char *opnames[OPCNT-0x28] = {
"maybeword", "word", "parse", "find", "(wnf)", "findmod", NULL, NULL,
"stack?", "compword", "runword", "compiling", "]", NULL, "rs+,", NULL,
"align4", "entry", "code", "code16b", "code8b", NULL, NULL, NULL,
- "-^", "*", "/mod", "lshift", "rshift", "<", NULL, NULL,
- "and", "or", "xor", NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, "/mod", NULL, "<", NULL, NULL,
"bye", "byefail", "quit", "(abort)", "dbg", "_usleep", NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"_fchild", "_fopen", "_freadbuf", "_fclose", "_finfo", "_fiter", NULL, "_fseek",
"_mountdrv", "_unmountdrv", "_drv@", "_drv!", NULL, NULL, NULL, NULL
};
@@ -892,8 +894,6 @@ static void buildsysdict() {
sysconst("Z)", CONDZ); sysconst("NZ)", CONDNZ);
sysconst("C)", CONDC); sysconst("NC)", CONDNC);
sysconst("<)", CONDC); sysconst(">=)", CONDNC);
- entry("16b)"); ornwr(OP16B); retwr();
- entry("8b)"); ornwr(OP8B); retwr();
for (int i=0; i<OPCNT-0x28; i++) {
if (opnames[i]) wentry(opnames[i], i+0x28);
}
@@ -920,14 +920,11 @@ static void buildsysdict() {
entry("%,"); compopwr(0x6b); retwr();
entry("<<,"); compopwr(0x6c); retwr();
entry(">>,"); compopwr(0x6d); retwr();
+ entry("and,"); compopwr(0x80); retwr();
+ entry("or,"); compopwr(0x81); retwr();
+ entry("xor,"); compopwr(0x82); retwr();
entry("lea,"); compopwr(0x28); retwr();
- entry("cmpn,"); compileop(0x2f); writewr(); retwr();
entry("neg,"); compileop(0x4e); retwr();
- entry("<<n,"); compileop(0x60); cwritewr(); retwr();
- entry(">>n,"); compileop(0x61); cwritewr(); retwr();
- entry("andn,"); compileop(0x62); writewr(); retwr();
- entry("orn,"); compileop(0x63); writewr(); retwr();
- entry("xorn,"); compileop(0x64); writewr(); retwr();
entry("W=0>Z,"); compileop(0x65); retwr();
entry("Z>W,"); compileop(0x66); retwr();
entry("A=0>Z,"); compileop(0x67); retwr();
@@ -939,11 +936,25 @@ static void buildsysdict() {
entry("branch!"); storewr(); retwr();
entry("yield"); compileop(0x07); retwr(); makeimm();
entry(";"); compileop(0x02); cwrite(0x3d); retwr(); makeimm();
- entry("i)"); callwr(find("m)")); ornwr(1); retwr();
entry("dup,");
- litwr(0xfffffffc); callwr(find("ps+,"));
- callwr(find("PSP)")); callwr(find("!,")); retwr();
+ 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("*"); wopwr(0x69, OPPSP); nipwr(); retwr();
+ entry("and"); wopwr(0x80, OPPSP); nipwr(); retwr();
+ entry("or"); wopwr(0x81, OPPSP); nipwr(); retwr();
+ entry("xor"); wopwr(0x82, OPPSP); nipwr(); retwr();
+ entry("lshift"); wopwr(0x12 /* @! */, OPPSP); wopwr(0x6c, OPPSP); nipwr(); retwr();
+ entry("rshift"); wopwr(0x12 /* @! */, OPPSP); wopwr(0x6d, OPPSP); nipwr(); retwr();
+ entry("<<n,"); callwr(find("i)")); callwr(find("<<,")); retwr();
+ entry(">>n,"); callwr(find("i)")); callwr(find(">>,")); retwr();
+ entry("cmpn,"); callwr(find("i)")); callwr(find("cmp,")); retwr();
+ entry("andn,"); callwr(find("i)")); callwr(find("and,")); retwr();
+ entry("orn,"); callwr(find("i)")); callwr(find("or,")); retwr();
+ entry("xorn,"); callwr(find("i)")); callwr(find("xor,")); retwr();
+ entry("16b)"); litwr(OP16B); callwr(find("or")); retwr();
+ entry("8b)"); litwr(OP8B); callwr(find("or")); retwr();
sysalias("in<", "boot<");
sysalias("rtype", "byefail");
sysalias("abort", "byefail");