diff options
| author | Bobby <[email protected]> | 2026-02-15 21:44:15 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-15 21:44:15 +0530 |
| commit | 85ea61c58c96b5ae052e40fce777f8e3d2b7ca62 (patch) | |
| tree | ab7e84dd64e8600d6c102ed12a8f598962b88aff /system/libraries/sys/sys.zig | |
| parent | 71e5250b05d06505612dc5a0fcf3d25fb5277cf5 (diff) | |
| download | akiba-85ea61c58c96b5ae052e40fce777f8e3d2b7ca62.tar.xz akiba-85ea61c58c96b5ae052e40fce777f8e3d2b7ca62.zip | |
feat: Add core libraries for color, formatting, I/O, string manipulation, and memory utilities
Diffstat (limited to 'system/libraries/sys/sys.zig')
| -rw-r--r-- | system/libraries/sys/sys.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/system/libraries/sys/sys.zig b/system/libraries/sys/sys.zig new file mode 100644 index 0000000..d37e4c8 --- /dev/null +++ b/system/libraries/sys/sys.zig @@ -0,0 +1,58 @@ +//! System runtime + +pub const start = @import("start.zig"); + +comptime { + _ = start; +} + +pub const Invocation = enum(u64) { + exit = 0x01, + attach = 0x02, + seal = 0x03, + view = 0x04, + mark = 0x05, + spawn = 0x06, + wait = 0x07, + yield = 0x08, + getkeychar = 0x09, + viewstack = 0x0A, + getlocation = 0x0B, + setlocation = 0x0C, + postman = 0x0D, + wipe = 0x0E, +}; + +pub inline fn syscall(invocation: Invocation, args: anytype) u64 { + const Args = @TypeOf(args); + const fields = @typeInfo(Args).@"struct".fields; + + const arg0: u64 = if (fields.len > 0) toU64(args[0]) else 0; + const arg1: u64 = if (fields.len > 1) toU64(args[1]) else 0; + const arg2: u64 = if (fields.len > 2) toU64(args[2]) else 0; + const arg3: u64 = if (fields.len > 3) toU64(args[3]) else 0; + const arg4: u64 = if (fields.len > 4) toU64(args[4]) else 0; + const arg5: u64 = if (fields.len > 5) toU64(args[5]) else 0; + + return asm volatile ("syscall" + : [ret] "={rax}" (-> u64), + : [number] "{rax}" (@intFromEnum(invocation)), + [arg0] "{rdi}" (arg0), + [arg1] "{rsi}" (arg1), + [arg2] "{rdx}" (arg2), + [arg3] "{r10}" (arg3), + [arg4] "{r8}" (arg4), + [arg5] "{r9}" (arg5), + : .{ .rcx = true, .r11 = true, .memory = true } + ); +} + +inline fn toU64(value: anytype) u64 { + const T = @TypeOf(value); + return switch (@typeInfo(T)) { + .int, .comptime_int => @intCast(value), + .pointer => @intFromPtr(value), + .@"enum" => @intFromEnum(value), + else => @bitCast(value), + }; +} |
