about summary refs log tree commit diff
path: root/linux.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-22 18:52:50 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-23 02:27:52 -0700
commitd5030a4cf75b3600c957b0d48e0e68946367e919 (patch)
tree328e4d8741978d8f458acc21e528dad3b1213888 /linux.e
parenta569f93740bbbac3230434ee56bc51aa38be21ac (diff)
all the syscall parameters are in the kernel's order now
there was never a good reason for them not to be

plus, the formerly bespoke ones use the generic helpers now; sys-open and sys-close are implemented; and a bug in push-input-buffer and pop-output-buffer is fixed

unfortunately these were breaking changes, so there's another evoke.hex in this one

Change-Id: Ifad58fc2fd757adcf89a69c59575565a10406ec2
Force-Push: yes
Diffstat (limited to 'linux.e')
-rw-r--r--linux.e59
1 files changed, 14 insertions, 45 deletions
diff --git a/linux.e b/linux.e
index 60bc54e..e757ee2 100644
--- a/linux.e
+++ b/linux.e
@@ -129,55 +129,24 @@
 ~ from the stack. It does not return.
 ~
 ~ (exit code -- *)
-: sys-exit
-  [ here @
-    60 :rax mov-reg64-imm64      ~ syscall number
-    :rdi pop-reg64               ~ exit code
-    syscall
-
-    ~ In the event we're still here, let's minimize confusion.
-    hlt
-
-    ~ This one, uniquely, doesn't need to be followed by the "next" macro. It
-    ~ is, though, since ;asm does that anyway.
-    here ! ] ;asm
-
+: sys-exit 60 syscall-1
+  ~ In the event we're still here, let's minimize confusion.
+  crash ;
 
 ~   This does the Linux write() system call, passing it an address from the
 ~ top of the stack and a length from the second position on the stack. It
-~ writes to file descriptor 1, which is stdout.
-~
-~   For our length parameter, we can pop directly from the stack into rdx,
-~ which directly becomes the syscall parameter. For our address parameter,
-~ the syscall wants it in rsi, which we also care about, so we have to do a
-~ little juggling.
+~ uses a Unix file descriptor, which is a non-negative integer, to tell it
+~ where to write to. For stdout, use fd 1.
 ~
-~ (length to write, base address, file descriptor -- result code or length)
-: sys-write
-  [ here @
-    :rdi pop-reg64               ~ file descriptor from stack
-    :rcx pop-reg64               ~ address from stack
-    :rdx pop-reg64               ~ length from stack, passed directly
-    :rsi push-reg64              ~ save rsi
-    1 :rax mov-reg64-imm64       ~ syscall number
-    :rcx :rsi mov-reg64-reg64    ~ pass address
-    syscall
-    :rsi pop-reg64               ~ restore rsi
-    :rax push-reg64              ~ return length
-    here ! ] ;asm
+~ (file descriptor, base address, length to write -- result code or length)
+: sys-write 1 syscall-3 ;
 
+~ (file descriptor, base address, length to read -- result code or length)
+: sys-read 0 syscall-3 ;
 
-~ (length to read, base address, file descriptor -- result code or length)
-: sys-read
-  [ here @
-    :rdi pop-reg64               ~ file descriptor from stack
-    :rcx pop-reg64               ~ address from stack
-    :rdx pop-reg64               ~ length from stack, passed directly
-    :rsi push-reg64              ~ save rsi
-    0 :rax mov-reg64-imm64       ~ syscall number
-    :rcx :rsi mov-reg64-reg64    ~ pass address
-    syscall
-    :rsi pop-reg64               ~ restore rsi
-    :rax push-reg64              ~ return length
-    here ! ] ;asm
+~ (filename, flags, mode -- result code or file descriptor)
+: sys-open 2 syscall-3 ;
+
+~ (file descriptor -- result code)
+: sys-close 3 syscall-1 ;