mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Make syscall names closer to libc
This commit is contained in:
parent
1b868adf87
commit
6735b159ac
17 changed files with 103 additions and 79 deletions
|
|
@ -7,7 +7,7 @@ void main(void) {
|
||||||
while(c = getc()) {
|
while(c = getc()) {
|
||||||
if (c != 0xFFFFFFFF) {
|
if (c != 0xFFFFFFFF) {
|
||||||
print("Got: ");
|
print("Got: ");
|
||||||
printx(c);
|
printhex(c);
|
||||||
println("");
|
println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ void printFib(int n) {
|
||||||
int curr = prev1 + prev2;
|
int curr = prev1 + prev2;
|
||||||
prev2 = prev1;
|
prev2 = prev1;
|
||||||
prev1 = curr;
|
prev1 = curr;
|
||||||
printd(curr);
|
printdec(curr);
|
||||||
} else if (i == 1) {
|
} else if (i == 1) {
|
||||||
printd(prev2);
|
printdec(prev2);
|
||||||
} else if (i == 2) {
|
} else if (i == 2) {
|
||||||
printd(prev1);
|
printdec(prev1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,14 +27,14 @@ void fib_recursive(int n, int prev1, int prev2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int curr = prev1 + prev2;
|
int curr = prev1 + prev2;
|
||||||
printd(curr);
|
printdec(curr);
|
||||||
|
|
||||||
return fib_recursive(n - 1, prev2, curr);
|
return fib_recursive(n - 1, prev2, curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printFibRec(int n) {
|
void printFibRec(int n) {
|
||||||
printd(0);
|
printdec(0);
|
||||||
printd(1);
|
printdec(1);
|
||||||
fib_recursive(n, 0, 1);
|
fib_recursive(n, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
for (int i=0;i<10;i++) {
|
for (int i=0;i<10;i++) {
|
||||||
printd(i);
|
printdec(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ fn println(message: &str) {
|
||||||
syscall(UVM32_SYSCALL_PRINTLN, addr_value);
|
syscall(UVM32_SYSCALL_PRINTLN, addr_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn printd(n: u32) {
|
fn printdec(n: u32) {
|
||||||
syscall(UVM32_SYSCALL_PRINTD, n);
|
syscall(UVM32_SYSCALL_PRINTDEC, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn main() {
|
pub extern "C" fn main() {
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
printd(i);
|
printdec(i);
|
||||||
}
|
}
|
||||||
println("Hello, world!\0");
|
println("Hello, world!\0");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
|
||||||
bool loop(void) {
|
bool loop(void) {
|
||||||
printd(count);
|
printdec(count);
|
||||||
if (count++ >= 10) {
|
if (count++ >= 10) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ fn mandel() void {
|
||||||
y2 = (y * y) >> 12;
|
y2 = (y * y) >> 12;
|
||||||
uvm.yield();
|
uvm.yield();
|
||||||
}
|
}
|
||||||
uvm.printc(' ' + @as(u8, @intCast(iter)));
|
uvm.putc(' ' + @as(u8, @intCast(iter)));
|
||||||
cx += dx;
|
cx += dx;
|
||||||
}
|
}
|
||||||
uvm.printc('\n');
|
uvm.putc('\n');
|
||||||
cy += dy;
|
cy += dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ pub inline fn yield() void {
|
||||||
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0);
|
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn printc(c:u8) void {
|
pub inline fn putc(c:u8) void {
|
||||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINTC, c);
|
_ = syscall(uvm32.UVM32_SYSCALL_PUTC, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export fn main() void {
|
||||||
|
|
||||||
while(gameRunning) {
|
while(gameRunning) {
|
||||||
const now = uvm.millis();
|
const now = uvm.millis();
|
||||||
if (uvm.getch()) |key| {
|
if (uvm.getc()) |key| {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
' ' => nextEvent = mibu.events.Event{.key = .{.code = .{.char = ' '}}},
|
' ' => nextEvent = mibu.events.Event{.key = .{.code = .{.char = ' '}}},
|
||||||
'a' => nextEvent = mibu.events.Event{.key = .{.code = .left}},
|
'a' => nextEvent = mibu.events.Event{.key = .{.code = .left}},
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub inline fn syscall(id: u32, param: u32) u32 {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn getch() ?u8 {
|
pub inline fn getc() ?u8 {
|
||||||
const key = syscall(uvm32.UVM32_SYSCALL_GETC, 0);
|
const key = syscall(uvm32.UVM32_SYSCALL_GETC, 0);
|
||||||
if (key == 0xFFFFFFFF) {
|
if (key == 0xFFFFFFFF) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -49,7 +49,7 @@ pub inline fn yield() void {
|
||||||
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0);
|
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn printc(c:u8) void {
|
pub inline fn putc(c:u8) void {
|
||||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINTC, c);
|
_ = syscall(uvm32.UVM32_SYSCALL_PUTC, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
// Definitions needed by both host and target
|
// Definitions needed by both host and target
|
||||||
|
|
||||||
// syscalls for exposed host functions, start at 0
|
// syscalls for exposed host functions, start at 0
|
||||||
#define UVM32_SYSCALL_PRINTC 0x00000000
|
#define UVM32_SYSCALL_PUTC 0x00000000
|
||||||
#define UVM32_SYSCALL_GETC 0x00000001
|
#define UVM32_SYSCALL_GETC 0x00000001
|
||||||
#define UVM32_SYSCALL_PRINT 0x00000002
|
#define UVM32_SYSCALL_PRINT 0x00000002
|
||||||
#define UVM32_SYSCALL_PRINTLN 0x00000003
|
#define UVM32_SYSCALL_PRINTLN 0x00000003
|
||||||
#define UVM32_SYSCALL_PRINTD 0x00000004
|
#define UVM32_SYSCALL_PRINTDEC 0x00000004
|
||||||
#define UVM32_SYSCALL_PRINTX 0x00000005
|
#define UVM32_SYSCALL_PRINTHEX 0x00000005
|
||||||
#define UVM32_SYSCALL_MILLIS 0x00000006
|
#define UVM32_SYSCALL_MILLIS 0x00000006
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,36 @@
|
||||||
|
|
||||||
#include "uvm32_sys.h"
|
#include "uvm32_sys.h"
|
||||||
|
|
||||||
// Basic types
|
// <stdint>
|
||||||
typedef long uint32_t;
|
typedef unsigned long long uint64_t;
|
||||||
typedef char uint8_t;
|
typedef unsigned long uint32_t;
|
||||||
typedef int bool;
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef long long int64_t;
|
||||||
|
typedef long int32_t;
|
||||||
|
typedef short int16_t;
|
||||||
|
typedef char int8_t;
|
||||||
|
|
||||||
|
// <stdbool>
|
||||||
|
typedef unsigned char bool;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
|
#ifndef size_assert
|
||||||
|
#define size_assert( what, howmuch ) \
|
||||||
|
typedef char what##_size_wrong_[( !!(sizeof(what) == howmuch) )*2-1 ]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
size_assert(uint64_t, 8);
|
||||||
|
size_assert(uint32_t, 4);
|
||||||
|
size_assert(uint16_t, 2);
|
||||||
|
size_assert(uint8_t, 1);
|
||||||
|
size_assert(int64_t, 8);
|
||||||
|
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) {
|
static uint32_t syscall(uint32_t id, uint32_t param) {
|
||||||
register uint32_t a0 asm("a0") = (uint32_t)(param);
|
register uint32_t a0 asm("a0") = (uint32_t)(param);
|
||||||
register uint32_t a1 asm("a1");
|
register uint32_t a1 asm("a1");
|
||||||
|
|
@ -24,12 +47,13 @@ static uint32_t syscall(uint32_t id, uint32_t param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x)
|
#define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x)
|
||||||
|
|
||||||
#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x)
|
#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x)
|
||||||
#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x)
|
#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x)
|
||||||
#define printd(x) syscall_cast(UVM32_SYSCALL_PRINTD, x)
|
#define printdec(x) syscall_cast(UVM32_SYSCALL_PRINTDEC, x)
|
||||||
#define printx(x) syscall_cast(UVM32_SYSCALL_PRINTX, x)
|
#define printhex(x) syscall_cast(UVM32_SYSCALL_PRINTHEX, x)
|
||||||
#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0)
|
#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0)
|
||||||
#define printc() syscall_cast(UVM32_SYSCALL_PRINTC, 0)
|
#define putc() syscall_cast(UVM32_SYSCALL_PUTC, 0)
|
||||||
#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0)
|
#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0)
|
||||||
#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0)
|
#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,41 +3,41 @@
|
||||||
#include "common/uvm32_common_custom.h"
|
#include "common/uvm32_common_custom.h"
|
||||||
|
|
||||||
// Precompiled binary program to print integers
|
// Precompiled binary program to print integers
|
||||||
// This code expects to print via syscall 0x13C (UVM32_SYSCALL_PRINTD in common/uvm32_common_custom.h)
|
// This code expects to print via syscall 0x13C (UVM32_SYSCALL_PRINTDEC in common/uvm32_common_custom.h)
|
||||||
uint8_t rom[] = {
|
uint8_t rom[] = {
|
||||||
0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x00, 0x93, 0x08, 0x80, 0x13,
|
0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x00, 0xb7, 0x08, 0x00, 0x01,
|
||||||
0x73, 0x00, 0x00, 0x00, 0x37, 0xf5, 0xff, 0xff, 0xb7, 0x15, 0x00, 0x00,
|
0x73, 0x00, 0x00, 0x00, 0x37, 0xf5, 0xff, 0xff, 0xb7, 0x15, 0x00, 0x00,
|
||||||
0x37, 0xe6, 0xff, 0xff, 0x93, 0x06, 0xf0, 0x01, 0x13, 0x07, 0xd5, 0xcc,
|
0x37, 0xe6, 0xff, 0xff, 0x13, 0x07, 0xf0, 0x01, 0xb7, 0x47, 0x00, 0x00,
|
||||||
0x93, 0x87, 0x35, 0x33, 0x13, 0x08, 0x76, 0xe6, 0x93, 0x82, 0x35, 0xb3,
|
0xb7, 0x06, 0x00, 0x01, 0x13, 0x08, 0xd5, 0xcc, 0x93, 0x82, 0x35, 0x33,
|
||||||
0x37, 0x43, 0x00, 0x00, 0x63, 0xc8, 0xe7, 0x08, 0x93, 0x03, 0x08, 0x00,
|
0x13, 0x03, 0x76, 0xe6, 0x93, 0x83, 0x35, 0xb3, 0x13, 0x86, 0x16, 0x00,
|
||||||
0x63, 0xca, 0x02, 0x07, 0x93, 0x08, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00,
|
0x63, 0xc8, 0x02, 0x09, 0x13, 0x0e, 0x03, 0x00, 0x63, 0xca, 0x63, 0x06,
|
||||||
0x13, 0x0e, 0x00, 0x00, 0x93, 0x0e, 0x00, 0x00, 0x13, 0x06, 0x00, 0x02,
|
0x93, 0x0e, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00, 0x13, 0x0f, 0x00, 0x00,
|
||||||
0x13, 0x05, 0x06, 0xfe, 0x63, 0xe2, 0xa6, 0x04, 0x33, 0x85, 0x15, 0x01,
|
0x93, 0x0f, 0x00, 0x00, 0x93, 0x06, 0x00, 0x02, 0x13, 0x85, 0x06, 0xfe,
|
||||||
0x63, 0x6e, 0xa3, 0x02, 0x13, 0x05, 0x00, 0x00, 0x33, 0x8e, 0xce, 0x03,
|
0x63, 0x62, 0xa7, 0x04, 0x33, 0x85, 0xd5, 0x01, 0x63, 0xee, 0xa7, 0x02,
|
||||||
0xb3, 0x8e, 0x15, 0x41, 0x93, 0x08, 0x90, 0x13, 0x73, 0x00, 0x00, 0x00,
|
0x13, 0x05, 0x00, 0x00, 0x93, 0x08, 0x06, 0x00, 0x33, 0x8f, 0xef, 0x03,
|
||||||
0x13, 0x5e, 0xbe, 0x40, 0xb3, 0x8e, 0x7e, 0x00, 0x33, 0x0e, 0xee, 0x00,
|
0xb3, 0x8f, 0xd5, 0x41, 0x73, 0x00, 0x00, 0x00, 0x13, 0x5f, 0xbf, 0x40,
|
||||||
0xb3, 0x85, 0xde, 0x03, 0x93, 0xd5, 0xc5, 0x00, 0x33, 0x05, 0xce, 0x03,
|
0xb3, 0x8f, 0xcf, 0x01, 0x33, 0x0f, 0x0f, 0x01, 0xb3, 0x85, 0xff, 0x03,
|
||||||
0x93, 0x58, 0xc5, 0x00, 0x13, 0x06, 0x16, 0x00, 0x6f, 0xf0, 0xdf, 0xfb,
|
0x93, 0xd5, 0xc5, 0x00, 0x33, 0x05, 0xef, 0x03, 0x93, 0x5e, 0xc5, 0x00,
|
||||||
0x93, 0x08, 0x00, 0x14, 0x13, 0x05, 0x06, 0x00, 0x73, 0x00, 0x00, 0x00,
|
0x93, 0x86, 0x16, 0x00, 0x6f, 0xf0, 0xdf, 0xfb, 0x13, 0x85, 0x06, 0x00,
|
||||||
0x93, 0x83, 0x13, 0x09, 0xe3, 0xda, 0x72, 0xf8, 0x13, 0x05, 0xa0, 0x00,
|
0x93, 0x08, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x13, 0x0e, 0x1e, 0x09,
|
||||||
0x93, 0x08, 0x00, 0x14, 0x73, 0x00, 0x00, 0x00, 0x13, 0x07, 0x97, 0x19,
|
0xe3, 0xda, 0xc3, 0xf9, 0x13, 0x05, 0xa0, 0x00, 0x93, 0x08, 0x00, 0x00,
|
||||||
0xe3, 0xdc, 0xe7, 0xf6, 0x37, 0x05, 0x00, 0x80, 0x13, 0x05, 0x05, 0x0e,
|
0x73, 0x00, 0x00, 0x00, 0x13, 0x08, 0x98, 0x19, 0xe3, 0xdc, 0x02, 0xf7,
|
||||||
0x93, 0x08, 0xb0, 0x13, 0x73, 0x00, 0x00, 0x00, 0x67, 0x80, 0x00, 0x00,
|
0x37, 0x05, 0x00, 0x80, 0x13, 0x05, 0x05, 0x0e, 0x93, 0x08, 0x30, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c,
|
0x73, 0x00, 0x00, 0x00, 0x67, 0x80, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c,
|
||||||
0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00
|
0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create an identifier for our host handler
|
// Create an identifier for our host handler
|
||||||
typedef enum {
|
typedef enum {
|
||||||
F_PRINTD,
|
F_PRINTDEC,
|
||||||
F_PRINTLN,
|
F_PRINTLN,
|
||||||
F_PRINTC,
|
F_PUTC,
|
||||||
} f_code_t;
|
} f_code_t;
|
||||||
|
|
||||||
// Map VM syscall UVM32_SYSCALL_PRINTD (0x13C) to F_PRINTD, tell VM to expect write of a U32
|
// Map VM syscall UVM32_SYSCALL_PRINTDEC to F_PRINTDEC, tell VM to expect write of a U32
|
||||||
const uvm32_mapping_t env[] = {
|
const uvm32_mapping_t env[] = {
|
||||||
{ UVM32_SYSCALL_PRINTD, F_PRINTD, UVM32_SYSCALL_TYP_U32_WR },
|
{ UVM32_SYSCALL_PRINTDEC, F_PRINTDEC, UVM32_SYSCALL_TYP_U32_WR },
|
||||||
{ UVM32_SYSCALL_PRINTC, F_PRINTC, UVM32_SYSCALL_TYP_U32_WR },
|
{ UVM32_SYSCALL_PUTC, F_PUTC, UVM32_SYSCALL_TYP_U32_WR },
|
||||||
{ UVM32_SYSCALL_PRINTLN, F_PRINTLN, UVM32_SYSCALL_TYP_BUF_TERMINATED_WR },
|
{ UVM32_SYSCALL_PRINTLN, F_PRINTLN, UVM32_SYSCALL_TYP_BUF_TERMINATED_WR },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -70,10 +70,10 @@ void loop(void) {
|
||||||
break;
|
break;
|
||||||
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
||||||
switch((f_code_t)evt.data.syscall.code) {
|
switch((f_code_t)evt.data.syscall.code) {
|
||||||
case F_PRINTD:
|
case F_PRINTDEC:
|
||||||
Serial.println(evt.data.syscall.val.u32);
|
Serial.println(evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
case F_PRINTC:
|
case F_PUTC:
|
||||||
Serial.print((char)evt.data.syscall.val.u32);
|
Serial.print((char)evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
case F_PRINTLN:
|
case F_PRINTLN:
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ uint8_t rom[] = {
|
||||||
|
|
||||||
// Create an identifier for our host handler
|
// Create an identifier for our host handler
|
||||||
typedef enum {
|
typedef enum {
|
||||||
F_PRINTD,
|
F_PRINTDEC,
|
||||||
} f_code_t;
|
} f_code_t;
|
||||||
|
|
||||||
// Map VM syscall UVM32_SYSCALL_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[] = {
|
const uvm32_mapping_t env[] = {
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTD, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTD },
|
{ .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
@ -40,8 +40,8 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
||||||
switch((f_code_t)evt.data.syscall.code) {
|
switch((f_code_t)evt.data.syscall.code) {
|
||||||
case F_PRINTD:
|
case F_PRINTDEC:
|
||||||
// Type of F_PRINTD is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32
|
// Type of F_PRINTDEC is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32
|
||||||
printf("%d\n", evt.data.syscall.val.u32);
|
printf("%d\n", evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ uint8_t rom[] = {
|
||||||
|
|
||||||
// Create an identifier for our host handler
|
// Create an identifier for our host handler
|
||||||
typedef enum {
|
typedef enum {
|
||||||
F_PRINTD,
|
F_PRINTDEC,
|
||||||
} f_code_t;
|
} f_code_t;
|
||||||
|
|
||||||
// Map VM syscall UVM32_SYSCALL_PRINTD to F_PRINTD, tell VM to expect write of a U32
|
// Map VM syscall UVM32_SYSCALL_PRINTDEC to F_PRINTDEC, tell VM to expect write of a U32
|
||||||
const uvm32_mapping_t env[] = {
|
const uvm32_mapping_t env[] = {
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTD, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTD },
|
{ .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
@ -57,8 +57,8 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL
|
||||||
switch((f_code_t)evt.data.syscall.code) {
|
switch((f_code_t)evt.data.syscall.code) {
|
||||||
case F_PRINTD:
|
case F_PRINTDEC:
|
||||||
// Type of F_PRINTD is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32
|
// Type of F_PRINTDEC is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32
|
||||||
printf("[VM %d]: %d\n", scheduler_index, evt.data.syscall.val.u32);
|
printf("[VM %d]: %d\n", scheduler_index, evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
host/host.c
18
host/host.c
|
|
@ -15,9 +15,9 @@ static struct termios orig_termios;
|
||||||
// syscalls exposed to vm environement
|
// syscalls exposed to vm environement
|
||||||
typedef enum {
|
typedef enum {
|
||||||
F_PRINT,
|
F_PRINT,
|
||||||
F_PRINTD,
|
F_PRINTDEC,
|
||||||
F_PRINTX,
|
F_PRINTHEX,
|
||||||
F_PRINTC,
|
F_PUTC,
|
||||||
F_PRINTLN,
|
F_PRINTLN,
|
||||||
F_MILLIS,
|
F_MILLIS,
|
||||||
F_GETC,
|
F_GETC,
|
||||||
|
|
@ -27,9 +27,9 @@ typedef enum {
|
||||||
const uvm32_mapping_t env[] = {
|
const uvm32_mapping_t env[] = {
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTLN, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINTLN },
|
{ .syscall = UVM32_SYSCALL_PRINTLN, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINTLN },
|
||||||
{ .syscall = UVM32_SYSCALL_PRINT, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINT },
|
{ .syscall = UVM32_SYSCALL_PRINT, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINT },
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTD, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTD },
|
{ .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC },
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTX, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTX },
|
{ .syscall = UVM32_SYSCALL_PRINTHEX, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTHEX },
|
||||||
{ .syscall = UVM32_SYSCALL_PRINTC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTC },
|
{ .syscall = UVM32_SYSCALL_PUTC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PUTC },
|
||||||
{ .syscall = UVM32_SYSCALL_MILLIS, .typ = UVM32_SYSCALL_TYP_U32_RD, .code = F_MILLIS },
|
{ .syscall = UVM32_SYSCALL_MILLIS, .typ = UVM32_SYSCALL_TYP_U32_RD, .code = F_MILLIS },
|
||||||
{ .syscall = UVM32_SYSCALL_GETC, .typ = UVM32_SYSCALL_TYP_U32_RD, .code = F_GETC },
|
{ .syscall = UVM32_SYSCALL_GETC, .typ = UVM32_SYSCALL_TYP_U32_RD, .code = F_GETC },
|
||||||
};
|
};
|
||||||
|
|
@ -189,13 +189,13 @@ int main(int argc, char *argv[]) {
|
||||||
case F_PRINTLN:
|
case F_PRINTLN:
|
||||||
printf("%.*s\n", evt.data.syscall.val.buf.len, evt.data.syscall.val.buf.ptr);
|
printf("%.*s\n", evt.data.syscall.val.buf.len, evt.data.syscall.val.buf.ptr);
|
||||||
break;
|
break;
|
||||||
case F_PRINTD:
|
case F_PRINTDEC:
|
||||||
printf("%d\n", evt.data.syscall.val.u32);
|
printf("%d\n", evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
case F_PRINTC:
|
case F_PUTC:
|
||||||
printf("%c", evt.data.syscall.val.u32);
|
printf("%c", evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
case F_PRINTX:
|
case F_PRINTHEX:
|
||||||
printf("%08x", evt.data.syscall.val.u32);
|
printf("%08x", evt.data.syscall.val.u32);
|
||||||
break;
|
break;
|
||||||
case F_GETC: {
|
case F_GETC: {
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue