mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Rework host/target interface to use ecall and proper syscalls instead of CSRs
This commit is contained in:
parent
a305fce466
commit
751f068486
26 changed files with 360 additions and 364 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Definitions needed by both host and target
|
||||
|
||||
// CSRs for exposed host functions
|
||||
// syscalls for exposed host functions
|
||||
#define IOREQ_PRINT 0x13A
|
||||
#define IOREQ_PRINTLN 0x13B
|
||||
#define IOREQ_PRINTD 0x13C
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
// Define wrapper functions for target code to call CSRs
|
||||
|
||||
DEFINE_CSR_WRITE_FUNCTION(print, IOREQ_PRINT, const char *)
|
||||
DEFINE_CSR_WRITE_FUNCTION(printd, IOREQ_PRINTD, uint32_t)
|
||||
DEFINE_CSR_WRITE_FUNCTION(printx, IOREQ_PRINTX, uint32_t)
|
||||
DEFINE_CSR_WRITE_FUNCTION(printc, IOREQ_PRINTC, char)
|
||||
DEFINE_CSR_WRITE_FUNCTION(println, IOREQ_PRINTLN, const char *)
|
||||
DEFINE_CSR_WRITE_FUNCTION_VOID(halt, IOREQ_HALT)
|
||||
DEFINE_CSR_WRITE_FUNCTION_VOID(yield, IOREQ_YIELD)
|
||||
DEFINE_CSR_WRITE_FUNCTION(millis_internal, IOREQ_MILLIS, uint32_t *)
|
||||
|
||||
static inline uint32_t millis(void) {
|
||||
static uint32_t m;
|
||||
millis_internal(&m);
|
||||
return m;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue