duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 96df13b9c7a89d003496762fdb56ad996db96ef0
parent 82d1ab78f30379c0e65f53af7082f4101ed3f78b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 13 Mar 2023 21:11:02 -0400

hal: dont use binary width modulator for HAL compiler words

Use assembler-style 8b) and 16b) operand modifiers. It is simpler and makes more
sense.

Diffstat:
Mfs/comp/c/vm/forth.fs | 8++++----
Mfs/xcomp/bootlo.fs | 52++++++++++++++++++++++++++--------------------------
Mposix/vm.c | 45+++++++++++++++++----------------------------
3 files changed, 47 insertions(+), 58 deletions(-)

diff --git a/fs/comp/c/vm/forth.fs b/fs/comp/c/vm/forth.fs @@ -104,12 +104,12 @@ UNOPMUTCNT >> wordtbl _tbl32 :w ( op++/op-- ) W>A, W) @, A) [+n], ; UNOPMUTCNT >> wordtbl _tbl16 -:w ( ++op/--op ) W) 16b [+n], W) 16b @, ; -:w ( op++/op-- ) W>A, W) 16b @, A) 16b [+n], ; +:w ( ++op/--op ) W) 16b) [+n], W) 16b) @, ; +:w ( op++/op-- ) W>A, W) 16b) @, A) 16b) [+n], ; UNOPMUTCNT >> wordtbl _tbl8 -:w ( ++op/--op ) W) 8b [+n], W) 8b @, ; -:w ( op++/op-- ) W>A, W) 8b @, A) 8b [+n], ; +:w ( ++op/--op ) W) 8b) [+n], W) 8b) @, ; +:w ( op++/op-- ) W>A, W) 8b) @, A) 8b) [+n], ; : unopmut, ( opid -- ) vmop type typesize diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -27,33 +27,33 @@ code 16b dup, MOD LIT>A, EMETA_16B LIT>W, A) !, drop, exit, immediate code 8b dup, MOD LIT>A, EMETA_8B LIT>W, A) !, drop, exit, immediate code ! W>A, PSP) @, A) !, 2drop, exit, -code16b W>A, PSP) @, A) 16b !, 2drop, exit, -code8b W>A, PSP) @, A) 8b !, 2drop, exit, +code16b W>A, PSP) @, A) 16b) !, 2drop, exit, +code8b W>A, PSP) @, A) 8b) !, 2drop, exit, : c! 8b ! ; : w! 16b ! ; code @ W) @, exit, -code16b W) 16b @, exit, -code8b W) 8b @, exit, +code16b W) 16b) @, exit, +code8b W) 8b) @, exit, : c@ 8b @ ; : w@ 16b @ ; code +! W>A, drop, A) +, A) !, drop, exit, -code16b W>A, drop, A) 16b +, A) 16b !, drop, exit, -code8b W>A, drop, A) 8b +, A) 8b !, drop, exit, +code16b W>A, drop, A) 16b) +, A) 16b) !, drop, exit, +code8b W>A, drop, A) 8b) +, A) 8b) !, drop, exit, code @! W>A, drop, A) @!, exit, -code16b W>A, drop, A) 16b @!, exit, -code8b W>A, drop, A) 8b @!, exit, +code16b W>A, drop, A) 16b) @!, exit, +code8b W>A, drop, A) 8b) @!, exit, code @+ W>A, A) @, W<>A, 4 W+n, dup, W<>A, exit, -code16b W>A, A) 16b @, W<>A, 2 W+n, dup, W<>A, exit, -code8b W>A, A) 8b @, W<>A, 1 W+n, dup, W<>A, exit, +code16b W>A, A) 16b) @, W<>A, 2 W+n, dup, W<>A, exit, +code8b W>A, A) 8b) @, W<>A, 1 W+n, dup, W<>A, exit, : c@+ 8b @+ ; code !+ W>A, drop, A) !, W<>A, 4 W+n, exit, -code16b W>A, drop, A) 16b !, W<>A, 2 W+n, exit, -code8b W>A, drop, A) 8b !, W<>A, 1 W+n, exit, +code16b W>A, drop, A) 16b) !, W<>A, 2 W+n, exit, +code8b W>A, drop, A) 8b) !, W<>A, 1 W+n, exit, : c!+ 8b !+ ; code @@+ W>A, A) [@], 4 A) [+n], exit, -code16b W>A, A) 16b [@], 2 A) [+n], exit, -code8b W>A, A) 8b [@], 1 A) [+n], exit, +code16b W>A, A) 16b) [@], 2 A) [+n], exit, +code8b W>A, A) 8b) [@], 1 A) [+n], exit, code @!+ W>A, drop, A) [!], 4 A) [+n], drop, exit, -code16b W>A, drop, A) 16b [!], 2 A) [+n], drop, exit, -code8b W>A, drop, A) 8b [!], 1 A) [+n], drop, exit, +code16b W>A, drop, A) 16b) [!], 2 A) [+n], drop, exit, +code8b W>A, drop, A) 8b) [!], 1 A) [+n], drop, exit, : , HERE @!+ ; :16b HERE 16b @!+ ; :8b HERE 8b @!+ ; : c, 8b , ; code execute W>A, drop, branchA, @@ -133,7 +133,7 @@ code (cell) r> exit, \ execword param: addr \ compileword param: HAL operand create toptr 0 , \ pointer to 8b struct [execword, compileword] -: _@, ( operand -- ) dup, @, ; :16b dup, 16b @, ; :8b dup, 8b @, ; +: _@, ( operand -- ) dup, @, ; :16b dup, 16b) @, ; :8b dup, 8b) @, ; create toptrdef ' @ , ' _@, , : toptr@ ( -- w ) 0 toptr @! ?dup not if toptrdef then @@ -150,18 +150,18 @@ code (does) r> W>A, W) @, W<>A, CELLSZ W+n, branchA, : does' ( w -- 'data ) CALLSZ + CELLSZ + ; : _to doer ' , ' , immediate does> toptr ! ; -: _!, !, drop, ; :16b 16b !, drop, ; :8b 8b !, drop, ; +: _!, !, drop, ; :16b 16b) !, drop, ; :8b 8b) !, drop, ; _to to ! _!, -: _+!, dup +, _!, ; :16b dup 16b +, 16b _!, ; :8b dup 8b +, 8b _!, ; +: _+!, dup +, _!, ; :16b dup 16b) +, 16b _!, ; :8b dup 8b) +, 8b _!, ; _to to+ +! _+!, _to to@! @! @!, : _@@+, dup, dup [@], 4 swap [+n], ; -:16b dup, dup 16b [@], 2 swap [+n], ; -:8b dup, dup 8b [@], 1 swap [+n], ; +:16b dup, dup 16b) [@], 2 swap [+n], ; +:8b dup, dup 8b) [@], 1 swap [+n], ; _to to@+ @@+ _@@+, : _@!+, dup [!], 4 swap [+n], drop, ; -:16b dup 16b [!], 2 swap [+n], drop, ; -:8b dup 8b [!], 1 swap [+n], drop, ; +:16b dup 16b) [!], 2 swap [+n], drop, ; +:8b dup 8b) [!], 1 swap [+n], drop, ; _to to!+ @!+ _@!+, : _lea, dup, lea, ; :16b dup, lea, ; :8b dup, lea, ; _to to' noop _lea, @@ -250,7 +250,7 @@ create _repl LF c, CR c, 0 c, drop in< dup _escapes 3 [c]? dup 0>= if nip _repl + c@ else drop then then then ; : ," begin "< dup -1 <> while c, repeat drop ; -code (s) r@ W>A, W) 8b @, 1 W+n, RSP) +, rdrop W<>A, branchA, +code (s) r@ W>A, W) 8b) @, 1 W+n, RSP) +, rdrop W<>A, branchA, : S" ( comp: -- ) ( not-comp: -- str ) compiling if compile (s) else here then here 1 allot here ," here -^ ( 'len len ) swap c! ; immediate @@ -262,7 +262,7 @@ code (s) r@ W>A, W) 8b @, 1 W+n, RSP) +, rdrop W<>A, branchA, code []= ( a1 a2 u -- f ) =0>Z, 0 Z) branchC, PSP) @!, W>A, begin \ P+4=a1 P+0=u A=a2 - PSP) 4 +) 8b [@], A) 8b cmp, 0 Z) branchC, + PSP) 4 +) 8b) [@], A) 8b) cmp, 0 Z) branchC, 8 ps+, 0 LIT>W, exit, then 1 A+n, 1 PSP) 4 +) [+n], -1 PSP) [+n], NZ) branchC, drop then 8 ps+, 1 LIT>W, exit, @@ -276,7 +276,7 @@ $01 const EMETA_DOCLINE \ a doc strings that ends with LF code move ( src dst u -- ) =0>Z, 0 Z) branchC, W>A, begin \ A=u - PSP) 4 +) 8b [@], 8b PSP) [!], + PSP) 4 +) 8b) [@], PSP) 8b) [!], 1 PSP) 4 +) [+n], 1 PSP) [+n], -1 A+n, NZ) branchC, drop then 8 ps+, drop, exit, diff --git a/posix/vm.c b/posix/vm.c @@ -7,6 +7,8 @@ HAL argument structure: b2:0 type 0=W 1=A 2=PSP 3=RSP 4=memory b3 has disp? (type "memory" always has disp) b7:4 number bank id +b8 16b? +b9 8b? */ #include <inttypes.h> #include <stdio.h> @@ -44,6 +46,8 @@ b7:4 number bank id #define OPRSP 3 #define OPMEM 0xc #define OPHASDISP 0x08 +#define OP16B 0x100 +#define OP8B 0x200 #define CONDZ 0x01 #define CONDNZ 0x11 #define EMETA_8B 0x10 @@ -139,8 +143,8 @@ static void dwrite(dword d) { allot(4); } static dword hbankaddr(byte idx) { return HBANK+((idx%HBANKCNT)*4); } -static dword hbankget(byte operand) { return gd(hbankaddr(operand >> 4)); } -static byte hbankset(byte operand, dword val) { +static dword hbankget(dword operand) { return gd(hbankaddr((operand >> 4)&0xf)); } +static dword hbankset(dword operand, dword val) { byte idx = (++vm.hbankidx) % HBANKCNT; sd(hbankaddr(idx), val); return operand | (idx << 4); @@ -148,14 +152,15 @@ static byte hbankset(byte operand, dword val) { static void retwr() { cwrite(0x02); } static void psaddwr(dword n) { cwrite(0x08); dwrite(n); } -static void wopwr(byte opcode, byte operand) { +static void wopwr(byte opcode, dword operand) { + opcode += (operand&(OP8B|OP16B)) >> 5; cwrite(opcode); cwrite(operand&0xf); - if (operand&OPHASDISP) dwrite(hbankget(operand)); } -static void wfetchwr(byte op) { wopwr(0x10, op); } -static void wstorewr(byte op) { wopwr(0x11, op); } -static void maddnwr(byte op, dword n) { wopwr(0x13, op); dwrite(n); } -static void wistorewr(byte op) { wopwr(0x16, op); } -static void wistorewr8(byte op) { wopwr(0x26, op); } + if (operand&OPHASDISP) dwrite(hbankget(operand)); +} +static void wfetchwr(dword op) { wopwr(0x10, op); } +static void wstorewr(dword op) { wopwr(0x11, op); } +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); } static void nipwr() { psaddwr(4); } static void dropwr() { wfetchwr(OPPSP); nipwr(); } @@ -165,7 +170,7 @@ static void litwr(dword n) { dupwr(); wlitwr(n); } static void callwr(dword a) { cwrite(0x01); dwrite(a); } static void brwr(dword a) { cwrite(0x00); dwrite(a); } static void writewr() { alitwr(HERE); wistorewr(OPA); maddnwr(OPA, 4); dropwr(); } -static void cwritewr() { alitwr(HERE); wistorewr8(OPA); maddnwr(OPA, 1); 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(); } @@ -845,6 +850,8 @@ static void buildsysdict() { sysconst("[rcnt]", _RCNT_); sysconst("W)", OPW); sysconst("A)", OPA); sysconst("PSP)", OPPSP); sysconst("RSP)", OPRSP); + entry("16b)"); cwrite(0x63); /* ORN */ dwrite(OP16B); retwr(); + entry("8b)"); cwrite(0x63); /* ORN */ dwrite(OP8B); retwr(); for (int i=0; i<OPCNT-0x28; i++) { if (opnames[i]) wentry(opnames[i], i+0x28); } @@ -857,33 +864,15 @@ static void buildsysdict() { entry("W>A,"); compileop(0x0e); retwr(); entry("W<>A,"); compileop(0x0f); retwr(); entry("@,"); compopwr(0x10); retwr(); - CODE16(); compopwr(0x18); retwr(); - CODE8(); compopwr(0x20); retwr(); entry("!,"); compopwr(0x11); retwr(); - CODE16(); compopwr(0x19); retwr(); - CODE8(); compopwr(0x21); retwr(); entry("@!,"); compopwr(0x12); retwr(); - CODE16(); compopwr(0x1a); retwr(); - CODE8(); compopwr(0x22); retwr(); // ( n ?disp operand -- ) entry("[+n],"); compopwr(0x13); writewr(); retwr(); - CODE16(); compopwr(0x1b); writewr(); retwr(); - CODE8(); compopwr(0x23); writewr(); retwr(); entry("cmp,"); compopwr(0x14); retwr(); - CODE16(); compopwr(0x1c); retwr(); - CODE8(); compopwr(0x24); retwr(); entry("[@],"); compopwr(0x15); retwr(); - CODE16(); compopwr(0x1d); retwr(); - CODE8(); compopwr(0x25); retwr(); entry("[!],"); compopwr(0x16); retwr(); - CODE16(); compopwr(0x1e); retwr(); - CODE8(); compopwr(0x26); retwr(); entry("+,"); compopwr(0x17); retwr(); - CODE16(); compopwr(0x1f); retwr(); - CODE8(); compopwr(0x27); retwr(); entry("lea,"); compopwr(0x28); retwr(); - CODE16(); compopwr(0x28); retwr(); - CODE8(); compopwr(0x28); retwr(); entry("<<n,"); compileop(0x60); cwritewr(); retwr(); entry(">>n,"); compileop(0x61); cwritewr(); retwr(); entry("andn,"); compileop(0x62); writewr(); retwr();