From d5030a4cf75b3600c957b0d48e0e68946367e919 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Tue, 22 Sep 2026 18:52:50 -0700 Subject: 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 --- linux.e | 59 ++++++++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) (limited to 'linux.e') 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 ; -- cgit 1.4.1