uvm32 initial version

This commit is contained in:
Toby Jaffey 2025-12-06 16:44:23 +00:00
commit c9d30b6d28
34 changed files with 2088 additions and 0 deletions

View file

@ -0,0 +1,10 @@
// Definitions needed by both host and target
// CSRs for exposed host functions
#define IOREQ_PRINT 0x13A
#define IOREQ_PRINTLN 0x13B
#define IOREQ_PRINTD 0x13C
#define IOREQ_PRINTX 0x13D
#define IOREQ_MILLIS 0x13F
#define IOREQ_PRINTC 0x140

5
common/uvm32_sys.h Normal file
View file

@ -0,0 +1,5 @@
// System provided IOREQs
#define IOREQ_HALT 0x138
#define IOREQ_YIELD 0x139
#include "uvm32_common_custom.h"

39
common/uvm32_target.h Normal file
View file

@ -0,0 +1,39 @@
// Common to all target code
#include "uvm32_sys.h"
// Basic types
typedef long uint32_t;
typedef char uint8_t;
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"); \
}
#include "uvm32_common_custom.h"
#include "uvm32_target_custom.h"
// provide main, with setup()/loop() flow
void setup(void);
bool loop(void);
#ifndef USE_MAIN
void main(void) {
setup();
while(loop()) {
yield();
}
}
#endif

View file

@ -0,0 +1,17 @@
// 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;
}