summaryrefslogtreecommitdiff
path: root/sanctuary.s
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-03-15 19:49:20 +1100
committerkitty <nepeta@canaglie.net>2026-03-15 19:49:20 +1100
commit9f311bce41eb76a46213867b8762ee517d33b6ba (patch)
tree3cd5744cbb57a05999e9fc9a97db36a275226189 /sanctuary.s
parentfe2443a10773bfa1890342fc4240e9da71ff7527 (diff)
some basic words and documentation thereof
i Willâ„¢ maintain the documentation alongside the code
Diffstat (limited to 'sanctuary.s')
-rw-r--r--sanctuary.s69
1 files changed, 63 insertions, 6 deletions
diff --git a/sanctuary.s b/sanctuary.s
index 5859ac1..b511d68 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -1,8 +1,6 @@
; sanctuary
; macros {{{
-; in this forth pspush and pspop are only necessary if you need to
-; go deeper into the stack.
; TODO: error handling (once i add that)
%macro pspush 1
lea r14, [r14-8]
@@ -16,6 +14,10 @@
lea r14, [r14+8]
%endmacro
+%macro psdrop 0
+ lea r14, [r14+8]
+%endmacro
+
%define s_latest 0
%macro defdict 3 ; name label flags
@@ -37,14 +39,20 @@
; to how user variables are planned to work in sanctuary
; so todo make better later? i don't know if it really matters
; because it will only apply to builtin variables.
-%macro defvar 3
+%macro defvar 4
%2: dq %4
defdict %1, %2, %3
- ; pspush qword %2 ; todo
- %2:
+ pspush qword %2
%endmacro
; }}}
+%assign INTERPRET 0x0
+%assign COMPILING (~0x1)
+
+%assign __NR_mprotect 10
+%assign __NR_brk 12
+%assign __NR_exit 60
+
section .bss
resq 4091
wstk: resq 1
@@ -52,6 +60,55 @@ wstk: resq 1
section .text
global _start
_start:
+ lea r14, [wstk + 8]
+
+ call brk@
+ mov qword [dp], r15
+ mov qword [dp0], r15
+ mov r15, 0x9c400
+ call grow
+ call bye
+
+defcode "brk@", brk@, 0
+ xor rdi, rdi
+ mov rax, __NR_brk
+ syscall
+ pspush rax
+ ret
+
+defcode "grow", grow, 0
+ call brk@
+ pspop rdi
+ pspop r13
+ add rdi, r13
+ mov rax, __NR_brk
+ syscall
+ mov qword [dp$], rax
+ ret
+
+defcode "executable", executable, 0
+ mov rdx, 0x7 ; PROT_{READ,WRITE,EXEC}
+ pspop rdi ; addr
+ pspop rsi
+ mov rax, __NR_mprotect
+ syscall
+ ret
+
+defcode "here", here, 0
+ pspush qword [dp]
+ ret
+
+defcode "bye", bye, 0
mov rdi, 0
- mov rax, 60
+ mov rax, __NR_exit
syscall
+ ret
+
+defvar "state", state, 0, INTERPRET
+defvar "dp", dp, 0, 0
+defvar "dp0", dp0, 0, 0
+defvar "dp$", dp$, 0, 0
+defvar "tib", tib, 0, 0 ; todo set correct initial value
+defvar "#tib", n_tib, 0, 0 ; todo set correct initial value
+defvar ">in", to_in, 0, 0
+defvar "latest", latest, 0, lfa_latest