Rework syscall ABI.

Syscalls now accept two parameters, allowing for things like "int count = read(buf, len)"
Rather than providing safe signatures for syscalls, the user is now given helper functions to safely parse incoming values, c-strings and slices.
This commit is contained in:
Toby Jaffey 2025-12-09 21:51:35 +00:00
parent f046a590c0
commit 76fba39a21
28 changed files with 543 additions and 537 deletions

View file

@ -8,4 +8,5 @@
#define UVM32_SYSCALL_PRINTDEC 0x00000004
#define UVM32_SYSCALL_PRINTHEX 0x00000005
#define UVM32_SYSCALL_MILLIS 0x00000006
#define UVM32_SYSCALL_PRINTBUF 0x00000007

View file

@ -32,30 +32,32 @@ size_assert(int32_t, 4);
size_assert(int16_t, 2);
size_assert(int8_t, 1);
static uint32_t syscall(uint32_t id, uint32_t param) {
register uint32_t a0 asm("a0") = (uint32_t)(param);
register uint32_t a1 asm("a1");
static uint32_t syscall(uint32_t id, uint32_t param1, uint32_t param2) {
register uint32_t a0 asm("a0") = (uint32_t)(param1);
register uint32_t a1 asm("a1") = (uint32_t)(param2);
register uint32_t a2 asm("a2");
register uint32_t a7 asm("a7") = (uint32_t)(id);
asm volatile (
"ecall"
: "=r"(a1) // output
: "r"(a0), "r"(a7) // input
: "=r"(a2) // output
: "r"(a7), "r"(a0), "r"(a1) // input
: "memory"
);
return a1;
return a2;
}
#define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x)
#define syscall_cast(id, p1, p2) syscall((uint32_t)id, (uint32_t)p1, (uint32_t)p2)
#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x)
#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x)
#define printdec(x) syscall_cast(UVM32_SYSCALL_PRINTDEC, x)
#define printhex(x) syscall_cast(UVM32_SYSCALL_PRINTHEX, x)
#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0)
#define putc(x) syscall_cast(UVM32_SYSCALL_PUTC, x)
#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0)
#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0)
#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x, 0)
#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x, 0)
#define printdec(x) syscall_cast(UVM32_SYSCALL_PRINTDEC, x, 0)
#define printhex(x) syscall_cast(UVM32_SYSCALL_PRINTHEX, x, 0)
#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0, 0)
#define putc(x) syscall_cast(UVM32_SYSCALL_PUTC, x, 0)
#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0, 0)
#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0, 0)
#define printbuf(x, y) syscall_cast(UVM32_SYSCALL_PRINTBUF, x, y)
#include "uvm32_common_custom.h"