From 6392033c9bee3da55f4e755059331ebf37c1b1c5 Mon Sep 17 00:00:00 2001 From: kitty Date: Wed, 18 Mar 2026 16:11:37 +1100 Subject: syscalls --- readme.md | 19 +++++++++++++++++++ sanctuary.s | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/readme.md b/readme.md index a9fa679..a4aaad5 100644 --- a/readme.md +++ b/readme.md @@ -118,6 +118,25 @@ a variable containing a boolean value. if 0 (false), the system is in interpreting mode, if -1 (true), the system is in compiling mode. +### `syscall0 ( rax -- u )` +perform the syscall with the id in `rax`, +and push the value of the `rax` register to the stack. + +### `syscall1 ( rdi rax -- u )` +perform the syscall with the id in `rax`, +taking one parameter placed in `rdi`, +and push the value of the `rax` register to the stack. + +### `syscall2 ( rsi rdi rax -- u )` +perform the syscall with the id in `rax`, +taking two parameters placed in `rdi` and `rsi`, +and push the value of the `rax` register to the stack. + +### `syscall3 ( rdx rsi rdi rax -- u )` +perform the syscall with the id in `rax`, +taking three parameters placed in `rdi`, `rsi` and `rdx`, +and push the value of the `rax` register to the stack. + ### `tib ( -- a )` a variable containing the address of the current input buffer. diff --git a/sanctuary.s b/sanctuary.s index a2ba5dd..89db85f 100644 --- a/sanctuary.s +++ b/sanctuary.s @@ -551,10 +551,47 @@ defcode "number", number, 0 ; ( c-addr u -- ?n flag ) ret ; }}} +; syscall {{{ +defcode "syscall0", syscall0, 0 + pspop rax + syscall + pspush rax + ret + +defcode "syscall1", syscall1, 0 + pspop rax + pspop rdi + syscall + pspush rax + ret + +defcode "syscall2", syscall2, 0 + pspop rax + pspop rdi + pspop rsi + syscall + pspush rax + ret + +defcode "syscall3", syscall3, 0 + pspop rax + pspop rdi + pspop rsi + pspop rdx + syscall + pspush rax + ret +; }}} + +; stack {{{ defcode "dup", dup, 0 mov r11, [r15] pspush r11 ret +; }}} + +; math + comparison {{{ +; }}} ; TEMPORARY WONKY DEBUGGING FUNCTIONS {{{ ; .s {{{ -- cgit v1.2.3