commit f8d6d50226d7f379939f9b4a0e34dc7886414efd
parent ce549e15e3e655b0f460039d251a737c5421f176
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 27 Jun 2023 12:15:34 -0400
Change "align4" semantics and move it out of the kernel
Diffstat:
6 files changed, 40 insertions(+), 48 deletions(-)
diff --git a/fs/comp/c/type.fs b/fs/comp/c/type.fs
@@ -65,7 +65,7 @@ struct[ CDecl
: :new ( name type -- cdecl )
$100 SZ + _arena Arena :[
- 0 align4 here rot> 0 , , 0 , 0 , 0 , 0 , curstorage , 0 , s,
+ here# rot> 0 , , 0 , 0 , 0 , 0 , curstorage , 0 , s,
_arena Arena :] drop ;
: _f? doer , does> ( self 'w ) @ swap flags and bool ;
diff --git a/fs/doc/dict.txt b/fs/doc/dict.txt
@@ -149,6 +149,8 @@ width", a value that can be 1, 2 or 4 depending of the width of the operation.
8b -- *I* Set binary width to 8-bit
16b -- *I* Set binary width to 16-bit
+align4 a -- a Add 0, 1, 2 or 3 to "a" so that it's divisible by 4.
+alignhere -- Align here to 4b.
allot u -- Increase here by u.
allot0 u -- Allot u and fill this space with zeroes.
here# -- a Align here to 4b and return it.
@@ -157,8 +159,6 @@ move src dst u -- Copy u bytes from address src to address dst, moving
move, src u -- Copy u bytes to "here" and increase "here" by u.
-move, src u -- Rewind "here" by u, then call "move,".
fill a u c -- Fill range [a, a+u] with byte c.
-align4 n -- Allot 0, 1, 2 or 3 bytes so that "here+n" is divisible
- by 4.
nc, n -- Parse n numbers from input stream and write them as
8-bit values.
nabort, n -- Write address of word "abort" n times. Used for method
diff --git a/fs/xcomp/arm/rpi/kernel.fs b/fs/xcomp/arm/rpi/kernel.fs
@@ -271,7 +271,7 @@ xcode maybeword ( -- str-or-0 )
str) r6 rd) rTOP rn) 8b) ,)
popret, exit,
-pc ," word expected" 0 align4
+pc ," word expected" alignhere
xcode word
pushret, wcall, maybeword popret,
( pc ) r0 pc>reg,
@@ -280,7 +280,7 @@ xcode word
lblerrmsg abs>rel b) z) ,)
exit,
-pc ," word not found" 0 align4
+pc ," word not found" alignhere
xcode (wnf)
lblcurword r0 pc>reg,
ldr) rTOP rd) r0 rn) 8b) 1 +i) post) ,)
@@ -352,15 +352,6 @@ pc to lblwriterange \ r0=addr r1=len
str) r2 rd) r3 rn) ,)
exit,
-xcode align4 ( n -- )
- lblhere r0 pc>reg,
- ldr) r1 rd) r0 rn) ,)
- add) r2 rd) r1 rn) rTOP rm) ,)
- and) r2 rdn) 3 i) f) ,)
- sub) ne) r1 rdn) r2 rm) ,)
- add) ne) r1 rdn) 4 i) ,)
- str) ne) r1 rd) r0 rn) ,)
- xdrop, exit,
pc to lblnextmeta 0 le,
lblnextmeta xaddr nextmeta
@@ -375,7 +366,14 @@ xcode entry pushret, ( 'dict s -- )
mov) r6 rd) rTOP rm) ,)
ldr) r5 rd) r6 rn) 8b) 1 +i) post) ,) \ r5=a r6=len
add) rTOP rd) r5 rn) 1 i) ,) \ rTOP=len+1
- wcall, align4 \ rTOP='dict
+ lblhere r0 pc>reg,
+ ldr) r1 rd) r0 rn) ,)
+ add) r2 rd) r1 rn) rTOP rm) ,)
+ and) r2 rdn) 3 i) f) ,)
+ sub) ne) r1 rdn) r2 rm) ,)
+ add) ne) r1 rdn) 4 i) ,)
+ str) ne) r1 rd) r0 rn) ,)
+ xdrop, \ rTOP='dict
mov) r0 rd) r6 rm) ,)
mov) r1 rd) r5 rm) ,)
lblwriterange execute,
@@ -385,8 +383,7 @@ xcode entry pushret, ( 'dict s -- )
ldr) r0 rdn) ,)
lbldwrite execute,
ldr) r0 rd) rTOP rn) ,) \ r0=dict
- lblhere r1 pc>reg,
- ldr) r1 rdn) ,)
+ lblhere r1 pc@>reg,
str) r1 rd) rTOP rn) ,) \ "here" is new sysdict
xdrop,
popret,
@@ -812,7 +809,7 @@ xcode * ( a b -- n )
mul) rTOP rd) rTOP rs) r0 rm) ,)
exit,
-pc ," divide by zero" 0 align4
+pc ," divide by zero" alignhere
xcode /mod ( a b -- r q )
( pc ) r0 pc>reg,
mov) r1 rd) 14 i) ,)
@@ -886,7 +883,7 @@ xcode ; ximm pushret,
popret, wjmp, [
\ TODO: fix PS stack at boot, it has spurious elements
-pc ," stack underflow" 0 align4
+pc ," stack underflow" alignhere
xcode stack?
cmp) rPSP rn) PSTOP i) ,)
return) ls) ,)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -180,7 +180,9 @@ _to to' noop _addr,
: _toexec ( a -- ) compiling if m) then toptr@ execute ;
: value doer , immediate does> _toexec ;
: here HERE _toexec ; immediate
-: here# 0 align4 here ;
+: align4 ( a -- a ) dup 4 mod ?dup if 4 -^ + then ;
+: alignhere here align4 to here ;
+: here# alignhere here ;
: alias ' code branch, drop ;
alias @ llnext
@@ -250,11 +252,11 @@ create _repl 3 nc, LF CR 0
then then ;
: ," begin "< dup -1 <> while c, repeat drop ;
: ,[ [compile] ahead here [compile] [ ; immediate
-: ], ( jmp a -- ) here over - rot 0 align4 [compile] then swap litn litn ] ;
+: ], ( jmp a -- ) here over - rot alignhere [compile] then swap litn litn ] ;
: S"
compiling if [compile] ahead then
here 1 allot here ," here -^ ( a len ) over c!
- compiling if swap 0 align4 [compile] then litn then ; immediate
+ compiling if swap alignhere [compile] then litn then ; immediate
: ."
compiling if [compile] S" compile stype else
begin "< dup 0>= while emit repeat drop then ; immediate
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -46,11 +46,11 @@ PSTOP STACKSZ - const HEREMAX
: movewrite, ( a u ) cx swap i) mov, di swap i) mov, lblwriterange abscall, ;
\ Let's go!
-0 align4 here to org
+here# to org
forward16 jmp, to L1
pc to lblintnoop iret,
\ Interrupt Descriptor Table
-0 align4 pc to L2 $100 idtgen
+alignhere pc to L2 $100 idtgen
pc to lblidt
$100 8 * 1- w, L2 ,
L1 forward!
@@ -431,7 +431,7 @@ xcode cidx ( c a u -- ?idx f )
\ Interpret loop
-0 align4 pc to lblbootptr 0 ,
+alignhere pc to lblbootptr 0 ,
xcode boot<
dx lblbootptr m) mov,
xdup, ax dx 0 d) 8b) movzx,
@@ -541,11 +541,11 @@ xcode (wnf)
di swap ( pc ) i) mov,
lblerrmsg absjmp,
-0 align4 pc to L1 \ parse unsuccessful
+alignhere pc to L1 \ parse unsuccessful
ax ax xor,
ret,
-0 align4 pc to lblparsec ( str -- n? f ) \ eax=sa ecx=sl
+alignhere pc to lblparsec ( str -- n? f ) \ eax=sa ecx=sl
cx 3 i) cmp,
L1 abs>rel jnz, \ fail
ax 2 d) 8b) ''' i) cmp,
@@ -555,7 +555,7 @@ xcode (wnf)
ax 1 i) mov,
ret,
-0 align4 pc to lblparseh ( str -- n? f ) \ eax=sa ecx=sl
+alignhere pc to lblparseh ( str -- n? f ) \ eax=sa ecx=sl
cx 2 i) cmp,
L1 abs>rel jc, \ fail
ax inc, \ skip $
@@ -584,7 +584,7 @@ L2 forward! \ parse ok
ax 1 i) mov,
ret,
-0 align4 pc to lblparseud ( str -- n? f ) \ eax=sa ecx=sl
+alignhere pc to lblparseud ( str -- n? f ) \ eax=sa ecx=sl
cx cx test,
L1 abs>rel jz, \ fail
di ax mov, \ di=str
@@ -709,23 +709,19 @@ xcode runword ( str -- ) pc w>e lblsysdict pc>addr !
L1 absjmp,
\ Entry creation
-
-xcode align4 ( n -- ) \ Preserves all except ax
- ax lblhere m) add,
- ax 3 i) and,
- forward8 jz,
- lblhere m) ax sub,
- lblhere m) 4 i) add,
- forward!
- xdrop, ret,
-
xcode entry ( 'dict s -- )
di ax mov, \ di=s
cx di 0 d) 8b) movzx, \ cx=len
di inc,
ax cx mov,
ax inc,
- wcall, align4 \ ( 'dict -- )
+ ax lblhere m) add,
+ ax 3 i) and,
+ forward8 jz,
+ lblhere m) ax sub,
+ lblhere m) 4 i) add,
+ forward!
+ xdrop, \ ( 'dict -- )
cx push, lblwriterange abscall, cx pop,
cl cwrite,
di lblnextmeta m) mov, di dwrite,
diff --git a/posix/vm.c b/posix/vm.c
@@ -202,12 +202,9 @@ static void compbinopwr(byte binopidx) { litwr(binopidx); cwrite(0x45); }
static void storewr() { cwrite(0x0e); dropwr(); wstorewr(OPA); dropwr(); }
static void callword(dword addr); // forward declaration
-static void align4(dword n) {
- n = (here() + n) % 4;
- if (n) { allot(4-n); }
-}
static void _entry(dword dict, byte *name, byte slen) {
- align4(slen+1);
+ dword n = (here() + slen + 1) % 4;
+ if (n) { allot(4-n); }
memcpy(&vm.mem[here()], name, slen);
allot(slen);
cwrite(slen);
@@ -552,7 +549,7 @@ static void RSADDWR() {
static void COMPOP() {
dword opcode = ppop(); dword operand = ppop(); wopwr(opcode, operand); }
-static void ALIGN4() { align4(ppop()); } // 0x40
+// 0x40
// ( 'dict s -- )
static void ENTRY() {
dword s = ppop();
@@ -913,7 +910,7 @@ static void (*ops[OPCNT])() = {
MOVE, BOOTRD, STDOUT, MAYBEKEY, RANGEEQ, MAKEMEM, ADDDISP, CIDX,
MAYBEWORD, WORD, PARSE, FIND, WNF, FINDMOD, NULL, NULL,
STACKCHK, COMPWORD, RUNWORD, COMPILING, STARTCOMP, STOPCOMP, RSADDWR, COMPOP,
- ALIGN4, ENTRY, CODE, CODE16, CODE8, COMPBINOP, NULL, NULL,
+ NULL, ENTRY, CODE, CODE16, CODE8, COMPBINOP, NULL, NULL,
WBINOP, WBINOP16, WBINOP8, DIVMOD, NULL, NULL, NEG, NULL,
BYE, BYEFAIL, QUIT, ABORT_, DBG, USLEEP, MPROTECT, NULL,
NULL, NULL, NULL, NULL, NULL, WCHECKZ, STOREC, ACHECKZ,
@@ -956,7 +953,7 @@ static char *opnames[OPCNT-0x28] = {
"move", "boot<", "(emit)", "(key?)", "[]=", "m)", "+)", "cidx",
"maybeword", "word", "parse", "find", "(wnf)", "findmod", NULL, NULL,
"stack?", "compword", "runword", "compiling", "]", NULL, "rs+,", NULL,
- "align4", "entry", "code", "code16b", "code8b", NULL, NULL, NULL,
+ NULL, "entry", "code", "code16b", "code8b", NULL, NULL, NULL,
NULL, NULL, NULL, "/mod", NULL, NULL, NULL, NULL,
"bye", "byefail", "quit", "(abort)", "dbg", "_usleep", "mprotect", NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,