mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Rename ioreq to syscall
This commit is contained in:
parent
b79a107a3d
commit
61fe0e8647
20 changed files with 187 additions and 190 deletions
|
|
@ -1,10 +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
|
||||
#define UVM32_SYSCALL_PRINT 0x13A
|
||||
#define UVM32_SYSCALL_PRINTLN 0x13B
|
||||
#define UVM32_SYSCALL_PRINTD 0x13C
|
||||
#define UVM32_SYSCALL_PRINTX 0x13D
|
||||
#define UVM32_SYSCALL_MILLIS 0x13F
|
||||
#define UVM32_SYSCALL_PRINTC 0x140
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// System provided IOREQs
|
||||
#define IOREQ_HALT 0x138
|
||||
#define IOREQ_YIELD 0x139
|
||||
// System provided UVM32_SYSCALLs
|
||||
#define UVM32_SYSCALL_HALT 0x138
|
||||
#define UVM32_SYSCALL_YIELD 0x139
|
||||
|
||||
#include "uvm32_common_custom.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "common/uvm32_common_custom.h"
|
||||
|
||||
// Precompiled binary program to print integers
|
||||
// This code expects to print via syscall 0x13C (IOREQ_PRINTD in common/uvm32_common_custom.h)
|
||||
// This code expects to print via syscall 0x13C (UVM32_SYSCALL_PRINTD in common/uvm32_common_custom.h)
|
||||
uint8_t rom[] = {
|
||||
0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x00, 0x93, 0x08, 0x80, 0x13,
|
||||
0x73, 0x00, 0x00, 0x00, 0x37, 0xf5, 0xff, 0xff, 0xb7, 0x15, 0x00, 0x00,
|
||||
|
|
@ -34,11 +34,11 @@ typedef enum {
|
|||
F_PRINTC,
|
||||
} f_code_t;
|
||||
|
||||
// Map VM ioreq IOREQ_PRINTD (0x13C) to F_PRINTD, tell VM to expect write of a U32
|
||||
// Map VM syscall UVM32_SYSCALL_PRINTD (0x13C) to F_PRINTD, tell VM to expect write of a U32
|
||||
const uvm32_mapping_t env[] = {
|
||||
{ IOREQ_PRINTD, F_PRINTD, IOREQ_TYP_U32_WR },
|
||||
{ IOREQ_PRINTC, F_PRINTC, IOREQ_TYP_U32_WR },
|
||||
{ IOREQ_PRINTLN, F_PRINTLN, IOREQ_TYP_BUF_TERMINATED_WR },
|
||||
{ UVM32_SYSCALL_PRINTD, F_PRINTD, UVM32_SYSCALL_TYP_U32_WR },
|
||||
{ UVM32_SYSCALL_PRINTC, F_PRINTC, UVM32_SYSCALL_TYP_U32_WR },
|
||||
{ UVM32_SYSCALL_PRINTLN, F_PRINTLN, UVM32_SYSCALL_TYP_BUF_TERMINATED_WR },
|
||||
};
|
||||
|
||||
uvm32_state_t vmst;
|
||||
|
|
@ -68,17 +68,17 @@ void loop(void) {
|
|||
case UVM32_EVT_END:
|
||||
isrunning = false;
|
||||
break;
|
||||
case UVM32_EVT_IOREQ: // vm has paused to handle IOREQ
|
||||
switch((f_code_t)evt.data.ioreq.code) {
|
||||
case UVM32_EVT_UVM32_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
||||
switch((f_code_t)evt.data.syscall.code) {
|
||||
case F_PRINTD:
|
||||
Serial.println(evt.data.ioreq.val.u32);
|
||||
Serial.println(evt.data.syscall.val.u32);
|
||||
break;
|
||||
case F_PRINTC:
|
||||
Serial.print((char)evt.data.ioreq.val.u32);
|
||||
Serial.print((char)evt.data.syscall.val.u32);
|
||||
break;
|
||||
case F_PRINTLN:
|
||||
for (int i=0;i<evt.data.ioreq.val.buf.len;i++) {
|
||||
Serial.print((char)evt.data.ioreq.val.buf.ptr[i]);
|
||||
for (int i=0;i<evt.data.syscall.val.buf.len;i++) {
|
||||
Serial.print((char)evt.data.syscall.val.buf.ptr[i]);
|
||||
}
|
||||
Serial.println("");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ bool uvm32_load(uvm32_state_t *vmst, uint8_t *rom, int len) {
|
|||
}
|
||||
|
||||
// Read C-string up to terminator and return len,ptr
|
||||
static void get_safeptr_terminated(uvm32_state_t *vmst, uint32_t addr, uint8_t terminator, uvm32_evt_ioreq_buf_t *buf) {
|
||||
static void get_safeptr_terminated(uvm32_state_t *vmst, uint32_t addr, uint8_t terminator, uvm32_evt_syscall_buf_t *buf) {
|
||||
uint32_t ptrstart = addr - MINIRV32_RAM_IMAGE_OFFSET;
|
||||
uint32_t p = ptrstart;
|
||||
if (p >= UVM32_MEMORY_SIZE) {
|
||||
|
|
@ -91,7 +91,7 @@ static void get_safeptr_terminated(uvm32_state_t *vmst, uint32_t addr, uint8_t t
|
|||
}
|
||||
|
||||
#if 0
|
||||
static void get_safeptr(uvm32_state_t *vmst, uint32_t addr, uint32_t len, uvm32_evt_ioreq_buf_t *buf) {
|
||||
static void get_safeptr(uvm32_state_t *vmst, uint32_t addr, uint32_t len, uvm32_evt_syscall_buf_t *buf) {
|
||||
uint32_t ptrstart = addr - MINIRV32_RAM_IMAGE_OFFSET;
|
||||
if (ptrstart + len >= UVM32_MEMORY_SIZE) {
|
||||
setStatusErr(vmst, UVM32_ERR_MEM_RD);
|
||||
|
|
@ -104,7 +104,7 @@ static void get_safeptr(uvm32_state_t *vmst, uint32_t addr, uint32_t len, uvm32_
|
|||
|
||||
uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter) {
|
||||
uint32_t num_instr = 0;
|
||||
// uvm32_evt_ioreq_buf_t b;
|
||||
// uvm32_evt_syscall_buf_t b;
|
||||
|
||||
if (vmst->status != UVM32_STATUS_PAUSED) {
|
||||
setStatusErr(vmst, UVM32_ERR_NOTREADY);
|
||||
|
|
@ -128,11 +128,11 @@ uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter)
|
|||
vmst->core->pc += 4;
|
||||
switch(syscall) {
|
||||
// inbuilt syscalls
|
||||
case IOREQ_HALT:
|
||||
case UVM32_SYSCALL_HALT:
|
||||
setStatus(vmst, UVM32_STATUS_ENDED);
|
||||
syscall_valid = true;
|
||||
break;
|
||||
case IOREQ_YIELD:
|
||||
case UVM32_SYSCALL_YIELD:
|
||||
vmst->ioevt.typ = UVM32_EVT_YIELD;
|
||||
setStatus(vmst, UVM32_STATUS_PAUSED);
|
||||
syscall_valid = true;
|
||||
|
|
@ -145,24 +145,21 @@ uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter)
|
|||
if (syscall == vmst->mappings[i].syscall) {
|
||||
// setup ioevt.data according to mapping typ
|
||||
switch(vmst->mappings[i].typ) {
|
||||
case IOREQ_TYP_VOID:
|
||||
case UVM32_SYSCALL_TYP_VOID:
|
||||
break;
|
||||
case IOREQ_TYP_U32_WR:
|
||||
vmst->ioevt.data.ioreq.val.u32 = value;
|
||||
case UVM32_SYSCALL_TYP_U32_WR:
|
||||
vmst->ioevt.data.syscall.val.u32 = value;
|
||||
break;
|
||||
case IOREQ_TYP_BUF_TERMINATED_WR:
|
||||
get_safeptr_terminated(vmst, value, 0x00, &vmst->ioevt.data.ioreq.val.buf);
|
||||
case UVM32_SYSCALL_TYP_BUF_TERMINATED_WR:
|
||||
get_safeptr_terminated(vmst, value, 0x00, &vmst->ioevt.data.syscall.val.buf);
|
||||
break;
|
||||
case IOREQ_TYP_U32_RD:
|
||||
// get_safeptr(vmst, value, 4, &b);
|
||||
vmst->ioevt.data.ioreq.val.u32p = &vmst->core->regs[11]; // r1, //(uint32_t *)b.ptr;
|
||||
case UVM32_SYSCALL_TYP_U32_RD:
|
||||
vmst->ioevt.data.syscall.val.u32p = &vmst->core->regs[11];
|
||||
break;
|
||||
}
|
||||
vmst->ioevt.typ = UVM32_EVT_IOREQ;
|
||||
vmst->ioevt.data.ioreq.code = vmst->mappings[i].code;
|
||||
vmst->ioevt.data.ioreq.typ = vmst->mappings[i].typ;
|
||||
//#warning FIXME, retval
|
||||
// vmst->core->regs[11] = 456; // r1
|
||||
vmst->ioevt.typ = UVM32_EVT_UVM32_SYSCALL;
|
||||
vmst->ioevt.data.syscall.code = vmst->mappings[i].code;
|
||||
vmst->ioevt.data.syscall.typ = vmst->mappings[i].typ;
|
||||
setStatus(vmst, UVM32_STATUS_PAUSED);
|
||||
syscall_valid = true;
|
||||
break; // stop searching
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// "well-known" system IOREQ functions
|
||||
#define IOREQ_HALT 0x138
|
||||
#define IOREQ_YIELD 0x139
|
||||
// "well-known" system UVM32_SYSCALL functions
|
||||
#define UVM32_SYSCALL_HALT 0x138
|
||||
#define UVM32_SYSCALL_YIELD 0x139
|
||||
|
||||
#define LIST_OF_UVM32_ERRS \
|
||||
X(UVM32_ERR_NONE) \
|
||||
|
|
@ -26,41 +26,41 @@ typedef enum {
|
|||
|
||||
typedef enum {
|
||||
UVM32_EVT_ERR,
|
||||
UVM32_EVT_IOREQ,
|
||||
UVM32_EVT_UVM32_SYSCALL,
|
||||
UVM32_EVT_YIELD,
|
||||
UVM32_EVT_END,
|
||||
} uvm32_evt_typ_t;
|
||||
|
||||
typedef enum {
|
||||
IOREQ_TYP_BUF_TERMINATED_WR, // data write from vm, NULL terminated string of bytes, in uvm32_evt_ioreq_t.val.buf
|
||||
IOREQ_TYP_VOID, // no data
|
||||
IOREQ_TYP_U32_WR, // data write from vm, in uvm32_evt_ioreq_t.val.u32
|
||||
IOREQ_TYP_U32_RD, // data read from vm, expects response in uvm32_evt_ioreq_t.val.u32p
|
||||
} uvm32_ioreq_typ_t;
|
||||
UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, // data write from vm, NULL terminated string of bytes, in uvm32_evt_syscall_t.val.buf
|
||||
UVM32_SYSCALL_TYP_VOID, // no data
|
||||
UVM32_SYSCALL_TYP_U32_WR, // data write from vm, in uvm32_evt_syscall_t.val.u32
|
||||
UVM32_SYSCALL_TYP_U32_RD, // data read from vm, expects response in uvm32_evt_syscall_t.val.u32p
|
||||
} uvm32_syscall_typ_t;
|
||||
|
||||
typedef uint32_t uvm32_user_ioreq_code_t;
|
||||
typedef uint32_t uvm32_user_syscall_code_t;
|
||||
|
||||
// user supplied mapping from syscall to typed ioreq
|
||||
// user supplied mapping from syscall to typed syscall
|
||||
typedef struct {
|
||||
uint32_t syscall;
|
||||
uvm32_user_ioreq_code_t code;
|
||||
uvm32_ioreq_typ_t typ;
|
||||
uvm32_user_syscall_code_t code;
|
||||
uvm32_syscall_typ_t typ;
|
||||
} uvm32_mapping_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *ptr;
|
||||
uint32_t len;
|
||||
} uvm32_evt_ioreq_buf_t;
|
||||
} uvm32_evt_syscall_buf_t;
|
||||
|
||||
typedef struct {
|
||||
uvm32_ioreq_typ_t typ;
|
||||
uvm32_user_ioreq_code_t code;
|
||||
uvm32_syscall_typ_t typ;
|
||||
uvm32_user_syscall_code_t code;
|
||||
union {
|
||||
uvm32_evt_ioreq_buf_t buf;
|
||||
uvm32_evt_syscall_buf_t buf;
|
||||
uint32_t u32;
|
||||
uint32_t *u32p;
|
||||
} val;
|
||||
} uvm32_evt_ioreq_t;
|
||||
} uvm32_evt_syscall_t;
|
||||
|
||||
typedef struct {
|
||||
uvm32_err_t errcode;
|
||||
|
|
@ -70,7 +70,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
uvm32_evt_typ_t typ;
|
||||
union {
|
||||
uvm32_evt_ioreq_t ioreq;
|
||||
uvm32_evt_syscall_t syscall;
|
||||
uvm32_evt_err_t err;
|
||||
} data;
|
||||
} uvm32_evt_t;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue