Rework host/target interface to use ecall and proper syscalls instead of CSRs

This commit is contained in:
Toby Jaffey 2025-12-08 02:44:38 +00:00
parent a305fce466
commit 751f068486
26 changed files with 360 additions and 364 deletions

View file

@ -9,17 +9,29 @@ typedef int bool;
#define true 1
#define false 0
// Convenience macro for defining CSR helper functions
#define xstr(a) str(a)
#define str(a) #a
#define DEFINE_CSR_WRITE_FUNCTION(function_name, csr, typ) \
static void function_name(typ val) { \
asm volatile( ".option norvc\ncsrrw x0," xstr(csr) ", %0\n" : : "r" (val)); \
}
#define DEFINE_CSR_WRITE_FUNCTION_VOID(function_name, csr) \
static void function_name(void) { \
asm volatile( ".option norvc\ncsrwi " xstr(csr) ", 0"); \
}
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");
register uint32_t a7 asm("a7") = (uint32_t)(id);
asm volatile (
"ecall"
: "=r"(a1) // output
: "r"(a0), "r"(a7) // input
: "memory"
);
return a1;
}
#define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x)
#define println(x) syscall_cast(IOREQ_PRINTLN, x)
#define print(x) syscall_cast(IOREQ_PRINT, x)
#define printd(x) syscall_cast(IOREQ_PRINTD, x)
#define printx(x) syscall_cast(IOREQ_PRINTX, x)
#define millis() syscall_cast(IOREQ_MILLIS, 0)
#define printc() syscall_cast(IOREQ_PRINTC, 0)
#define getc() syscall_cast(IOREQ_GETC, 0)
#define yield() syscall_cast(IOREQ_YIELD, 0)
#include "uvm32_common_custom.h"
#include "uvm32_target_custom.h"