diff --git a/common/code.fs b/common/code.fs index f26cc00..e5e6ffd 100644 --- a/common/code.fs +++ b/common/code.fs @@ -16,8 +16,13 @@ : asm r| also forth definitions -vocabulary asm asm definitions -also internals +vocabulary asm +internals definitions + +: ca! ( n a -- ) dup cell-base >r cell-shift swap over lshift + swap 255 swap lshift invert r@ @ and or r> ! ; + +also asm definitions variable code-start variable code-at @@ -25,7 +30,8 @@ variable code-at DEFINED? posix [IF] also posix : reserve ( n -- ) - 0 swap PROT_READ PROT_WRITE PROT_EXEC or or MAP_ANONYMOUS -1 0 mmap code-start ! ; + 0 swap PROT_READ PROT_WRITE PROT_EXEC or or + MAP_ANONYMOUS MAP_PRIVATE or -1 0 mmap code-start ! ; previous 4096 reserve [THEN] @@ -37,14 +43,19 @@ previous 1024 reserve [THEN] -code-start code-at ! +code-start @ code-at ! : chere ( -- a ) code-at @ ; : callot ( n -- ) code-at +! ; -: code, ( n -- ) chere ! cell callot ; -: code1, ( n -- ) chere c! 1 callot ; -: code2, ( n -- ) chere w! 2 callot ; -: code4, ( n -- ) chere l! 4 callot ; +: code1, ( n -- ) chere ca! 1 callot ; +: code2, ( n -- ) dup code1, 8 rshift code1, ; +: code3, ( n -- ) dup code2, 16 rshift code1, ; +: code4, ( n -- ) dup code2, 16 rshift code2, ; +cell 8 = [IF] +: code, dup code4, 32 rshift code4, ; +[ELSE] +: code, code4, ; +[THEN] : end-code previous ; also forth definitions diff --git a/common/utils.fs b/common/utils.fs index 49787c1..941d3af 100644 --- a/common/utils.fs +++ b/common/utils.fs @@ -22,8 +22,16 @@ internals definitions +( Temporary for platforms without CALLCODE ) +DEFINED? CALLCODE 0= [IF] + create CALLCODE +[THEN] + ( Safe memory access, i.e. aligned ) -: ca@ ( a -- n ) dup cell 1- invert and @ swap cell 1- and 8 * rshift 255 and ; +cell 1- constant cell-mask +: cell-base ( a -- a ) cell-mask invert and ; +: cell-shift ( a -- a ) cell-mask and 8 * ; +: ca@ ( a -- n ) dup cell-base @ swap cell-shift rshift 255 and ; ( Print address line leaving room ) : dump-line ( a -- a ) cr <# #s #> 20 over - >r type r> spaces ; diff --git a/esp32/bindings.fs b/esp32/bindings.fs index 78e51b0..ba7dcd5 100644 --- a/esp32/bindings.fs +++ b/esp32/bindings.fs @@ -171,16 +171,14 @@ forth definitions internals definitions ( Heap Capabilities ) -binary -0001 constant MALLOC_CAP_EXEC -0010 constant MALLOC_CAP_32BIT -0100 constant MALLOC_CAP_8BIT -1000 constant MALLOC_CAP_DMA -: MALLOC_CAP_PID ( n -- ) 10000 over 11 ( 3 ) - for 2* next ; -000010000000000 constant MALLOC_CAP_SPIRAM -000100000000000 constant MALLOC_CAP_INTERNAL -001000000000000 constant MALLOC_CAP_DEFAULT -010000000000000 constant MALLOC_CAP_IRAM_8BIT -010000000000000 constant MALLOC_CAP_RETENTION -decimal +1 0 lshift constant MALLOC_CAP_EXEC +1 1 lshift constant MALLOC_CAP_32BIT +1 2 lshift constant MALLOC_CAP_8BIT +1 3 lshift constant MALLOC_CAP_DMA +1 10 lshift constant MALLOC_CAP_SPIRAM +1 11 lshift constant MALLOC_CAP_INTERNAL +1 12 lshift constant MALLOC_CAP_DEFAULT +1 13 lshift constant MALLOC_CAP_IRAM_8BIT +1 14 lshift constant MALLOC_CAP_RETENTION +1 15 lshift constant MALLOC_CAP_RTCRAM forth definitions diff --git a/examples/code_xtensa.fs b/examples/code_xtensa.fs index 5665c12..d9bbd0b 100644 --- a/examples/code_xtensa.fs +++ b/examples/code_xtensa.fs @@ -17,10 +17,11 @@ asm forth code my2* - $02 code1, $48 code1, ( l32i.n a4, a2, 0 ) - $11 code1, $44 code1, $f0 code1, ( slli a4, a4, 1 ) - $02 code1, $49 code1, ( s32i.n a4, a2, 0 ) - $f0 code1, $0d code1, ( ret.n ) + $364100 code3, ( entry a1, 32 ) + $8802 code2, ( l32i.n a8, a2, 0 ) + $f08811 code3, ( slli a8, a8, 1 ) + $8902 code2, ( s32i.n a8, a2, 0 ) + $1df0 code2, ( retw.n ) end-code see my2* diff --git a/posix/posix.fs b/posix/posix.fs index 10fe30e..86e1fe8 100644 --- a/posix/posix.fs +++ b/posix/posix.fs @@ -85,6 +85,7 @@ z" __errno_location" 0 sysfunc __errno_location 1 constant PROT_READ 2 constant PROT_WRITE 4 constant PROT_EXEC +$2 constant MAP_PRIVATE $10 constant MAP_FIXED $20 constant MAP_ANONYMOUS