mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Rework syscall ABI.
Syscalls now accept two parameters, allowing for things like "int count = read(buf, len)" Rather than providing safe signatures for syscalls, the user is now given helper functions to safely parse incoming values, c-strings and slices.
This commit is contained in:
parent
f046a590c0
commit
76fba39a21
28 changed files with 543 additions and 537 deletions
|
|
@ -4,18 +4,18 @@ const uvm32 = @cImport({
|
|||
});
|
||||
const std = @import("std");
|
||||
|
||||
pub inline fn syscall(id: u32, param: u32) u32 {
|
||||
pub inline fn syscall(id: u32, param1: u32, param2: u32) u32 {
|
||||
var val: u32 = undefined;
|
||||
asm volatile ("ecall"
|
||||
: [val] "={a1}" (val),
|
||||
: [param] "{a0}" (param),
|
||||
: [val] "={a2}" (val),
|
||||
: [param1] "{a0}" (param1), [param2] "{a1}" (param2),
|
||||
[id] "{a7}" (id),
|
||||
: .{ .memory = true });
|
||||
return val;
|
||||
}
|
||||
|
||||
pub inline fn getc() ?u8 {
|
||||
const key = syscall(uvm32.UVM32_SYSCALL_GETC, 0);
|
||||
const key = syscall(uvm32.UVM32_SYSCALL_GETC, 0, 0);
|
||||
if (key == 0xFFFFFFFF) {
|
||||
return null;
|
||||
} else {
|
||||
|
|
@ -24,7 +24,7 @@ pub inline fn getc() ?u8 {
|
|||
}
|
||||
|
||||
pub inline fn millis() u32 {
|
||||
return syscall(uvm32.UVM32_SYSCALL_MILLIS, 0);
|
||||
return syscall(uvm32.UVM32_SYSCALL_MILLIS, 0, 0);
|
||||
}
|
||||
|
||||
// dupeZ would be better, but want to avoid using an allocator
|
||||
|
|
@ -35,21 +35,21 @@ pub inline fn print(m: []const u8) void {
|
|||
@memcpy(termination_buf[0..m.len], m);
|
||||
termination_buf[m.len] = 0;
|
||||
const s = termination_buf[0..m.len :0];
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINT, @intFromPtr(s.ptr));
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINT, @intFromPtr(s.ptr), 0);
|
||||
}
|
||||
|
||||
pub inline fn println(m: []const u8) void {
|
||||
@memcpy(termination_buf[0..m.len], m);
|
||||
termination_buf[m.len] = 0;
|
||||
const s = termination_buf[0..m.len :0];
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINTLN, @intFromPtr(s.ptr));
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PRINTLN, @intFromPtr(s.ptr), 0);
|
||||
}
|
||||
|
||||
pub inline fn yield() void {
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0);
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_YIELD, 0, 0);
|
||||
}
|
||||
|
||||
pub inline fn putc(c:u8) void {
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PUTC, c);
|
||||
_ = syscall(uvm32.UVM32_SYSCALL_PUTC, c, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue