diff --git a/apps/conio/conio.c b/apps/conio/conio.c index fdc83c5..bdeaecd 100644 --- a/apps/conio/conio.c +++ b/apps/conio/conio.c @@ -7,7 +7,7 @@ void main(void) { while(c = getc()) { if (c != 0xFFFFFFFF) { print("Got: "); - printx(c); + printhex(c); println(""); } } diff --git a/apps/fib/fib.c b/apps/fib/fib.c index 064eb4d..502331e 100644 --- a/apps/fib/fib.c +++ b/apps/fib/fib.c @@ -11,11 +11,11 @@ void printFib(int n) { int curr = prev1 + prev2; prev2 = prev1; prev1 = curr; - printd(curr); + printdec(curr); } else if (i == 1) { - printd(prev2); + printdec(prev2); } 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; - printd(curr); + printdec(curr); return fib_recursive(n - 1, prev2, curr); } void printFibRec(int n) { - printd(0); - printd(1); + printdec(0); + printdec(1); fib_recursive(n, 0, 1); } diff --git a/apps/helloworld/helloworld.c b/apps/helloworld/helloworld.c index 90cf4b9..13ccbf4 100644 --- a/apps/helloworld/helloworld.c +++ b/apps/helloworld/helloworld.c @@ -3,7 +3,7 @@ void main(void) { for (int i=0;i<10;i++) { - printd(i); + printdec(i); } } diff --git a/apps/rust-hello/src/main.rs b/apps/rust-hello/src/main.rs index 9718286..1cb1e89 100644 --- a/apps/rust-hello/src/main.rs +++ b/apps/rust-hello/src/main.rs @@ -28,14 +28,14 @@ fn println(message: &str) { syscall(UVM32_SYSCALL_PRINTLN, addr_value); } -fn printd(n: u32) { - syscall(UVM32_SYSCALL_PRINTD, n); +fn printdec(n: u32) { + syscall(UVM32_SYSCALL_PRINTDEC, n); } #[no_mangle] pub extern "C" fn main() { for i in 0..10 { - printd(i); + printdec(i); } println("Hello, world!\0"); } diff --git a/apps/sketch/sketch.c b/apps/sketch/sketch.c index cf249fe..94c92f5 100644 --- a/apps/sketch/sketch.c +++ b/apps/sketch/sketch.c @@ -3,7 +3,7 @@ uint32_t count; bool loop(void) { - printd(count); + printdec(count); if (count++ >= 10) { return false; } else { diff --git a/apps/zig-mandel/src/main.zig b/apps/zig-mandel/src/main.zig index 145e1bb..5a0f13e 100644 --- a/apps/zig-mandel/src/main.zig +++ b/apps/zig-mandel/src/main.zig @@ -26,10 +26,10 @@ fn mandel() void { y2 = (y * y) >> 12; uvm.yield(); } - uvm.printc(' ' + @as(u8, @intCast(iter))); + uvm.putc(' ' + @as(u8, @intCast(iter))); cx += dx; } - uvm.printc('\n'); + uvm.putc('\n'); cy += dy; } } diff --git a/apps/zig-mandel/src/uvm.zig b/apps/zig-mandel/src/uvm.zig index c3d2474..adfa6a2 100644 --- a/apps/zig-mandel/src/uvm.zig +++ b/apps/zig-mandel/src/uvm.zig @@ -22,7 +22,7 @@ pub inline fn yield() void { _ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0); } -pub inline fn printc(c:u8) void { - _ = syscall(uvm32.UVM32_SYSCALL_PRINTC, c); +pub inline fn putc(c:u8) void { + _ = syscall(uvm32.UVM32_SYSCALL_PUTC, c); } diff --git a/apps/zigtris/src/main.zig b/apps/zigtris/src/main.zig index e171753..47ed3c5 100644 --- a/apps/zigtris/src/main.zig +++ b/apps/zigtris/src/main.zig @@ -18,7 +18,7 @@ export fn main() void { while(gameRunning) { const now = uvm.millis(); - if (uvm.getch()) |key| { + if (uvm.getc()) |key| { switch(key) { ' ' => nextEvent = mibu.events.Event{.key = .{.code = .{.char = ' '}}}, 'a' => nextEvent = mibu.events.Event{.key = .{.code = .left}}, diff --git a/apps/zigtris/src/uvm.zig b/apps/zigtris/src/uvm.zig index 27ac526..344a3f4 100644 --- a/apps/zigtris/src/uvm.zig +++ b/apps/zigtris/src/uvm.zig @@ -14,7 +14,7 @@ pub inline fn syscall(id: u32, param: u32) u32 { return val; } -pub inline fn getch() ?u8 { +pub inline fn getc() ?u8 { const key = syscall(uvm32.UVM32_SYSCALL_GETC, 0); if (key == 0xFFFFFFFF) { return null; @@ -49,7 +49,7 @@ pub inline fn yield() void { _ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0); } -pub inline fn printc(c:u8) void { - _ = syscall(uvm32.UVM32_SYSCALL_PRINTC, c); +pub inline fn putc(c:u8) void { + _ = syscall(uvm32.UVM32_SYSCALL_PUTC, c); } diff --git a/common/uvm32_common_custom.h b/common/uvm32_common_custom.h index 5e58ce9..8ad60d7 100644 --- a/common/uvm32_common_custom.h +++ b/common/uvm32_common_custom.h @@ -1,11 +1,11 @@ // Definitions needed by both host and target // 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_PRINT 0x00000002 #define UVM32_SYSCALL_PRINTLN 0x00000003 -#define UVM32_SYSCALL_PRINTD 0x00000004 -#define UVM32_SYSCALL_PRINTX 0x00000005 +#define UVM32_SYSCALL_PRINTDEC 0x00000004 +#define UVM32_SYSCALL_PRINTHEX 0x00000005 #define UVM32_SYSCALL_MILLIS 0x00000006 diff --git a/common/uvm32_target.h b/common/uvm32_target.h index 9a9c6b1..b004c49 100644 --- a/common/uvm32_target.h +++ b/common/uvm32_target.h @@ -2,13 +2,36 @@ #include "uvm32_sys.h" -// Basic types -typedef long uint32_t; -typedef char uint8_t; -typedef int bool; +// +typedef unsigned long long uint64_t; +typedef unsigned long uint32_t; +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; + +// +typedef unsigned char bool; #define true 1 #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) { register uint32_t a0 asm("a0") = (uint32_t)(param); register uint32_t a1 asm("a1"); @@ -24,14 +47,15 @@ static uint32_t syscall(uint32_t id, uint32_t param) { } #define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x) -#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x) -#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x) -#define printd(x) syscall_cast(UVM32_SYSCALL_PRINTD, x) -#define printx(x) syscall_cast(UVM32_SYSCALL_PRINTX, x) -#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0) -#define printc() syscall_cast(UVM32_SYSCALL_PRINTC, 0) -#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0) -#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0) + +#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x) +#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x) +#define printdec(x) syscall_cast(UVM32_SYSCALL_PRINTDEC, x) +#define printhex(x) syscall_cast(UVM32_SYSCALL_PRINTHEX, x) +#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0) +#define putc() syscall_cast(UVM32_SYSCALL_PUTC, 0) +#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0) +#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0) #include "uvm32_common_custom.h" diff --git a/host-arduino/host-arduino.ino b/host-arduino/host-arduino.ino index 98c0f35..65d99b0 100644 --- a/host-arduino/host-arduino.ino +++ b/host-arduino/host-arduino.ino @@ -3,41 +3,41 @@ #include "common/uvm32_common_custom.h" // 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[] = { - 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, - 0x37, 0xe6, 0xff, 0xff, 0x93, 0x06, 0xf0, 0x01, 0x13, 0x07, 0xd5, 0xcc, - 0x93, 0x87, 0x35, 0x33, 0x13, 0x08, 0x76, 0xe6, 0x93, 0x82, 0x35, 0xb3, - 0x37, 0x43, 0x00, 0x00, 0x63, 0xc8, 0xe7, 0x08, 0x93, 0x03, 0x08, 0x00, - 0x63, 0xca, 0x02, 0x07, 0x93, 0x08, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00, - 0x13, 0x0e, 0x00, 0x00, 0x93, 0x0e, 0x00, 0x00, 0x13, 0x06, 0x00, 0x02, - 0x13, 0x05, 0x06, 0xfe, 0x63, 0xe2, 0xa6, 0x04, 0x33, 0x85, 0x15, 0x01, - 0x63, 0x6e, 0xa3, 0x02, 0x13, 0x05, 0x00, 0x00, 0x33, 0x8e, 0xce, 0x03, - 0xb3, 0x8e, 0x15, 0x41, 0x93, 0x08, 0x90, 0x13, 0x73, 0x00, 0x00, 0x00, - 0x13, 0x5e, 0xbe, 0x40, 0xb3, 0x8e, 0x7e, 0x00, 0x33, 0x0e, 0xee, 0x00, - 0xb3, 0x85, 0xde, 0x03, 0x93, 0xd5, 0xc5, 0x00, 0x33, 0x05, 0xce, 0x03, - 0x93, 0x58, 0xc5, 0x00, 0x13, 0x06, 0x16, 0x00, 0x6f, 0xf0, 0xdf, 0xfb, - 0x93, 0x08, 0x00, 0x14, 0x13, 0x05, 0x06, 0x00, 0x73, 0x00, 0x00, 0x00, - 0x93, 0x83, 0x13, 0x09, 0xe3, 0xda, 0x72, 0xf8, 0x13, 0x05, 0xa0, 0x00, - 0x93, 0x08, 0x00, 0x14, 0x73, 0x00, 0x00, 0x00, 0x13, 0x07, 0x97, 0x19, - 0xe3, 0xdc, 0xe7, 0xf6, 0x37, 0x05, 0x00, 0x80, 0x13, 0x05, 0x05, 0x0e, - 0x93, 0x08, 0xb0, 0x13, 0x73, 0x00, 0x00, 0x00, 0x67, 0x80, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, + 0x37, 0xe6, 0xff, 0xff, 0x13, 0x07, 0xf0, 0x01, 0xb7, 0x47, 0x00, 0x00, + 0xb7, 0x06, 0x00, 0x01, 0x13, 0x08, 0xd5, 0xcc, 0x93, 0x82, 0x35, 0x33, + 0x13, 0x03, 0x76, 0xe6, 0x93, 0x83, 0x35, 0xb3, 0x13, 0x86, 0x16, 0x00, + 0x63, 0xc8, 0x02, 0x09, 0x13, 0x0e, 0x03, 0x00, 0x63, 0xca, 0x63, 0x06, + 0x93, 0x0e, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00, 0x13, 0x0f, 0x00, 0x00, + 0x93, 0x0f, 0x00, 0x00, 0x93, 0x06, 0x00, 0x02, 0x13, 0x85, 0x06, 0xfe, + 0x63, 0x62, 0xa7, 0x04, 0x33, 0x85, 0xd5, 0x01, 0x63, 0xee, 0xa7, 0x02, + 0x13, 0x05, 0x00, 0x00, 0x93, 0x08, 0x06, 0x00, 0x33, 0x8f, 0xef, 0x03, + 0xb3, 0x8f, 0xd5, 0x41, 0x73, 0x00, 0x00, 0x00, 0x13, 0x5f, 0xbf, 0x40, + 0xb3, 0x8f, 0xcf, 0x01, 0x33, 0x0f, 0x0f, 0x01, 0xb3, 0x85, 0xff, 0x03, + 0x93, 0xd5, 0xc5, 0x00, 0x33, 0x05, 0xef, 0x03, 0x93, 0x5e, 0xc5, 0x00, + 0x93, 0x86, 0x16, 0x00, 0x6f, 0xf0, 0xdf, 0xfb, 0x13, 0x85, 0x06, 0x00, + 0x93, 0x08, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x13, 0x0e, 0x1e, 0x09, + 0xe3, 0xda, 0xc3, 0xf9, 0x13, 0x05, 0xa0, 0x00, 0x93, 0x08, 0x00, 0x00, + 0x73, 0x00, 0x00, 0x00, 0x13, 0x08, 0x98, 0x19, 0xe3, 0xdc, 0x02, 0xf7, + 0x37, 0x05, 0x00, 0x80, 0x13, 0x05, 0x05, 0x0e, 0x93, 0x08, 0x30, 0x00, + 0x73, 0x00, 0x00, 0x00, 0x67, 0x80, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00 }; // Create an identifier for our host handler typedef enum { - F_PRINTD, + F_PRINTDEC, F_PRINTLN, - F_PRINTC, + F_PUTC, } 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[] = { - { UVM32_SYSCALL_PRINTD, F_PRINTD, UVM32_SYSCALL_TYP_U32_WR }, - { UVM32_SYSCALL_PRINTC, F_PRINTC, UVM32_SYSCALL_TYP_U32_WR }, + { UVM32_SYSCALL_PRINTDEC, F_PRINTDEC, 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 }, }; @@ -70,10 +70,10 @@ void loop(void) { break; case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL switch((f_code_t)evt.data.syscall.code) { - case F_PRINTD: + case F_PRINTDEC: Serial.println(evt.data.syscall.val.u32); break; - case F_PRINTC: + case F_PUTC: Serial.print((char)evt.data.syscall.val.u32); break; case F_PRINTLN: diff --git a/host-mini/host-mini.c b/host-mini/host-mini.c index 9a5fc26..e113c02 100644 --- a/host-mini/host-mini.c +++ b/host-mini/host-mini.c @@ -15,12 +15,12 @@ uint8_t rom[] = { // Create an identifier for our host handler typedef enum { - F_PRINTD, + F_PRINTDEC, } f_code_t; // Map VM syscall UVM32_SYSCALL_PRINTD (0x13C) to F_PRINTD, tell VM to expect write of a U32 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[]) { @@ -40,8 +40,8 @@ int main(int argc, char *argv[]) { break; case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL switch((f_code_t)evt.data.syscall.code) { - case F_PRINTD: - // Type of F_PRINTD is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32 + case F_PRINTDEC: + // 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); break; } diff --git a/host-parallel/host-parallel.c b/host-parallel/host-parallel.c index 1f7fe8e..6210d16 100644 --- a/host-parallel/host-parallel.c +++ b/host-parallel/host-parallel.c @@ -23,12 +23,12 @@ uint8_t rom[] = { // Create an identifier for our host handler typedef enum { - F_PRINTD, + F_PRINTDEC, } 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[] = { - { .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[]) { @@ -57,8 +57,8 @@ int main(int argc, char *argv[]) { break; case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL switch((f_code_t)evt.data.syscall.code) { - case F_PRINTD: - // Type of F_PRINTD is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32 + case F_PRINTDEC: + // 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); break; } diff --git a/host/host.c b/host/host.c index e70280a..1f231bd 100644 --- a/host/host.c +++ b/host/host.c @@ -15,9 +15,9 @@ static struct termios orig_termios; // syscalls exposed to vm environement typedef enum { F_PRINT, - F_PRINTD, - F_PRINTX, - F_PRINTC, + F_PRINTDEC, + F_PRINTHEX, + F_PUTC, F_PRINTLN, F_MILLIS, F_GETC, @@ -27,9 +27,9 @@ typedef enum { const uvm32_mapping_t env[] = { { .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_PRINTD, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTD }, - { .syscall = UVM32_SYSCALL_PRINTX, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTX }, - { .syscall = UVM32_SYSCALL_PRINTC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTC }, + { .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC }, + { .syscall = UVM32_SYSCALL_PRINTHEX, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTHEX }, + { .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_GETC, .typ = UVM32_SYSCALL_TYP_U32_RD, .code = F_GETC }, }; @@ -189,13 +189,13 @@ int main(int argc, char *argv[]) { case F_PRINTLN: printf("%.*s\n", evt.data.syscall.val.buf.len, evt.data.syscall.val.buf.ptr); break; - case F_PRINTD: + case F_PRINTDEC: printf("%d\n", evt.data.syscall.val.u32); break; - case F_PRINTC: + case F_PUTC: printf("%c", evt.data.syscall.val.u32); break; - case F_PRINTX: + case F_PRINTHEX: printf("%08x", evt.data.syscall.val.u32); break; case F_GETC: { diff --git a/precompiled/fib.bin b/precompiled/fib.bin index 9d95c6d..124bfaa 100755 Binary files a/precompiled/fib.bin and b/precompiled/fib.bin differ diff --git a/precompiled/sketch.bin b/precompiled/sketch.bin index abf3805..cc1a4df 100755 Binary files a/precompiled/sketch.bin and b/precompiled/sketch.bin differ