diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-23 22:47:35 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-23 22:47:35 -0700 |
| commit | fa77a37199208fa207202e62f409e1371c5f03f3 (patch) | |
| tree | fc58aee7e0fbd3dc012277724622a75a3f4a9ff0 /linux.e | |
| parent | d65031570a3f678b03b29ea8a2293e0b8fad7907 (diff) | |
added a couple new instructions
this turns out to be fairly involved. hex bootstrap can't come fast enough ;) Force-Push: yes Change-Id: Ide5d2207d745ad07c40d3c9f457cd6b491bfbcf0
Diffstat (limited to 'linux.e')
| -rw-r--r-- | linux.e | 101 |
1 files changed, 98 insertions, 3 deletions
diff --git a/linux.e b/linux.e index c7e9bb3..bf5a3e1 100644 --- a/linux.e +++ b/linux.e @@ -8,9 +8,104 @@ ~ ~ Notice that rsi is our control stack, so we have to save it (for ~ syscalls with at least two parameters). We can use the value stack to do -~ that, since rsp is preserved. We don't save other registers because our -~ caller should do that, if it cares. -~ +~ that, since rsp is preserved, or we can use one of the other registers. We +~ don't ourselves save other registers because our caller should do that, if +~ it cares. + + +~ (call number -- return value) +: syscall-0 + [ here @ + :rax pop-reg64 ~ syscall number + syscall + :rax push-reg64 ~ return value + here ! ] ;asm + +~ (call number, first param -- return value) +: syscall-1 + [ here @ + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rax push-reg64 ~ return value + here ! ] ;asm + +~ (call number, first param, second param -- return value) +: syscall-2 + [ here @ + :rsi :rbx mov-reg64-reg64 ~ save rsi + :rsi pop-reg64 ~ second param + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rbx :rsi mov-reg64-reg64 ~ restore rsi + :rax push-reg64 ~ return value + here ! ] ;asm + +~ (call number, first param, second param, third param -- return value) +: syscall-3 + [ here @ + :rsi :rbx mov-reg64-reg64 ~ save rsi + :rdx pop-reg64 ~ third param + :rsi pop-reg64 ~ second param + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rbx :rsi mov-reg64-reg64 ~ restore rsi + :rax push-reg64 ~ return value + here ! ] ;asm + +~ (call number, first param, second param, third param, fourth param +~ -- return value) +: syscall-4 + [ here @ + :rsi :rbx mov-reg64-reg64 ~ save rsi + :r10 pop-extrareg64 ~ fourth param + :rdx pop-reg64 ~ third param + :rsi pop-reg64 ~ second param + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rbx :rsi mov-reg64-reg64 ~ restore rsi + :rax push-reg64 ~ return value + here ! ] ;asm + + +~ (call number, first param, second param, third param, fourth param, +~ fifth param -- return value) +: syscall-5 + [ here @ + :rsi :rbx mov-reg64-reg64 ~ save rsi + :r8 pop-extrareg64 ~ fifth param + :r10 pop-extrareg64 ~ fourth param + :rdx pop-reg64 ~ third param + :rsi pop-reg64 ~ second param + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rbx :rsi mov-reg64-reg64 ~ restore rsi + :rax push-reg64 ~ return value + here ! ] ;asm + + +~ (call number, first param, second param, third param, fourth param, +~ fifth param, sixth param -- return value) +: syscall-6 + [ here @ + :rsi :rbx mov-reg64-reg64 ~ save rsi + :r9 pop-extrareg64 ~ sixth param + :r8 pop-extrareg64 ~ fifth param + :r10 pop-extrareg64 ~ fourth param + :rdx pop-reg64 ~ third param + :rsi pop-reg64 ~ second param + :rdi pop-reg64 ~ first param + :rax pop-reg64 ~ syscall number + syscall + :rbx :rsi mov-reg64-reg64 ~ restore rsi + :rax push-reg64 ~ return value + here ! ] ;asm + + ~ This does the Linux exit() system call, passing it an exit code taken ~ from the stack. It does not return. |