duskos

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

commit a5b2eabce740f2c2f5ab5fbd1e27ed7803dce6fe
parent 4965056b3aee602742e11a26baf7294d9ddd842f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 22 Aug 2022 11:59:21 -0400

Replace native r@ and rallot words with r', and r+,

The "rallot" idea didn't work: returning an address at that time won't help
having a reliable stackframe. With r+, it will work better.

There will still be issues with compensating for RS pushes that don't originate
from local variables, but I have ideas how to handle this...

Diffstat:
Mfs/xcomp/bootlo.fs | 6++++--
Mfs/xcomp/i386.fs | 33+++++++++++++++------------------
Mposix/vm.c | 38++++++++++++++++++--------------------
3 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -22,8 +22,10 @@ code : ] code ] ; : allot to+ here ; : compile ' litn ['] execute, execute, ; immediate : [compile] ' execute, ; immediate +: rdrop 4 r+, ; immediate +: r@ 0 r', compile @ ; immediate : r> [compile] r@ [compile] rdrop ; immediate -: >r [compile] rallot compile ! ; immediate +: >r -4 r+, 0 r', compile ! ; immediate : if compile (?br) here 4 allot ; immediate : then here swap ! ; immediate : else compile (br) here 4 allot here rot ! ; immediate @@ -31,7 +33,7 @@ code : ] code ] ; : again compile (br) , ; immediate : until compile (?br) , ; immediate : next compile (next) , ; immediate -: leave r> rdrop 1 >r >r ; +: leave 1 litn 0 r', compile ! ; immediate : = - not ; : \ begin in< $0a = until ; immediate \ hello, this is a comment! diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs @@ -459,29 +459,26 @@ xcode []= ( a1 a2 u -- f ) [ebp] ax mov, ret, -\ 83 c4 04 --> add esp, 4 -pc 3 nc, $83 $c4 $04 -xcode rdrop ximm +\ 83 c4 XX --> add esp, XX +pc 2 nc, $83 $c4 +xcode r+, ( n -- ) si ( pc ) i) mov, - cx 3 i) mov, - lblmovewrite abs>rel jmp, + cx 2 i) mov, + lblmovewrite abs>rel call, + xwordlbl c, abs>rel jmp, -\ 83 ec 04 --> sub esp, 4 \ 83 ed 04 --> sub ebp, 4 -\ 89 65 00 --> mov [ebp], esp -pc 9 nc, $83 $ec $04 $83 $ed $04 $89 $65 $00 -xcode rallot ximm +\ 89 45 00 --> mov [ebp], esp +pc 6 nc, $83 $ed $04 $89 $45 $00 +\ 8d 44 24 XX --> lea eax, [esp+XX] +pc 3 nc, $8d $44 $24 +xcode r', ( n -- ) si ( pc ) i) mov, - cx 9 i) mov, - lblmovewrite abs>rel jmp, - -\ 8b 04 24 --> mov eax, [esp] -\ 83 ed 04 --> sub ebp, 4 -\ 89 45 00 --> mov [ebp], eax -pc 9 nc, $8b $04 $24 $83 $ed $04 $89 $45 $00 -xcode r@ ximm + cx 3 i) mov, + lblmovewrite abs>rel call, + wcall, c, si ( pc ) i) mov, - cx 9 i) mov, + cx 6 i) mov, lblmovewrite abs>rel jmp, align4 pc to lblareg 0 , diff --git a/posix/vm.c b/posix/vm.c @@ -66,6 +66,7 @@ static byte gb(dword addr) { return vm.mem[memchk(addr)]; } static word gw(dword addr) { return gb(addr) | (gb(addr+1)<<8); } static dword gd(dword addr) { return gw(addr) | (gw(addr+2)<<16); } static dword gpc() { dword n = gd(vm.PC); vm.PC += 4; return n; } +static byte gpcb() { dword n = gb(vm.PC); vm.PC++; return n; } static void sb(dword addr, byte b) { vm.mem[memchk(addr)] = b; } static void sw(dword addr, word w) { sb(addr, w); sb(addr+1, w>>8); } static void sd(dword addr, dword d) { sw(addr, d); sw(addr+2, d>>16); } @@ -324,17 +325,25 @@ static void TUCK() { // op: 1f ppush(a); ppush(b); ppush(a); } -static void RSDROP() { // op: 20 - rpop(); +static void RSADD() { // op: 20 + byte n = gpcb(); + vm.RSP += (char)n; } -static void RSALLOT() { // op: 21 - vm.RSP -= 4; - ppush(vm.RSP); +static void RSADDWR() { // op: 21 + dword n = ppop(); + cwrite(0x20); // RSADD + cwrite(n); +} + +static void RSADDR() { // op: 22 + ppush(vm.RSP+gpcb()); } -static void RSGET() { // op: 22 - ppush(rpeek()); +static void RSADDRWR() { // op: 23 + dword n = ppop(); + cwrite(0x22); // RSADDR + cwrite(n); } static void SCNT() { // op: 24 @@ -946,7 +955,7 @@ static void (*ops[OPCNT])() = { EXECUTE, CELL, VAL, ALIAS, DOES, SLIT, BR, CBR, NEXT, SYSALIAS, _TO_, BOOTRD, STDOUT, STDERR, KEY, DROP, DUP, CDUP, SWAP, OVER, ROT, ROTR, NIP, TUCK, - RSDROP, RSALLOT, RSGET, NULL, SCNT, RCNT, ASET, AGET, + RSADD, RSADDWR, RSADDR, RSADDRWR, SCNT, RCNT, ASET, AGET, ACFETCH, ACSTORE, AINC, ADEC, A2RS, RS2A, TOSET, TOGET, INC, DEC, CFETCH, CSTORE, CWRITE, WFETCH, WSTORE, FETCH, STORE, ADDSTORE, WRITE, ADD, SUB, MUL, DIVMOD, AND, @@ -962,7 +971,7 @@ static char *opnames[OPCNT] = { "execute", "(cell)", "(val)", "(alias)", "(does)", "(s)", "(br)", "(?br)", "(next)", NULL, "(to)", "boot<", "(emit)", "stderr", "key", "drop", "dup", "?dup", "swap", "over", "rot", "rot>", "nip", "tuck", - NULL, NULL, NULL, NULL, "scnt", "rcnt", ">A", "A>", + NULL, "r+,", NULL, "r',", "scnt", "rcnt", ">A", "A>", "Ac@", "Ac!", "A+", "A-", "A>r", "r>A", "[to]", "to?", "1+", "1-", "c@", "c!", "c,", "w@", "w!", "@", "!", "+!", ",", "+", "-", "*", "/mod", "and", @@ -1008,14 +1017,6 @@ static void makeimm(char *name) { sb(a, gb(a)|0x80); } -static void makecompiler(char *name, byte op) { - entry(name); - makeimm(name); - litwr(op); - callwr(find("c,")); - retwr(); -} - static void sysalias(char *name, dword addr) { entry(name); cwrite(0x11); // SYSALIAS @@ -1058,9 +1059,6 @@ static void buildsysdict() { sysconst("curword", CURWORD); sysconst("sysdict", SYSDICT); sysconst("nextmeta", NEXTMETA); - makecompiler("rdrop", 0x20); // RSDROP - makecompiler("r@", 0x22); // RSGET - makecompiler("rallot", 0x21); // RSALLOT entry("_fsinfobuf"); allot(0x112); // used in FINFO entry("mainloop"); sd(MAINLOOP, here());