aboutsummaryrefslogtreecommitdiff
path: root/system.old/libraries/io
diff options
context:
space:
mode:
Diffstat (limited to 'system.old/libraries/io')
-rw-r--r--system.old/libraries/io/attachment.zig33
-rw-r--r--system.old/libraries/io/io.zig36
-rw-r--r--system.old/libraries/io/io.zon10
-rw-r--r--system.old/libraries/io/letter.zig36
-rw-r--r--system.old/libraries/io/location.zig30
-rw-r--r--system.old/libraries/io/stream.zig41
-rw-r--r--system.old/libraries/io/types.zig39
7 files changed, 225 insertions, 0 deletions
diff --git a/system.old/libraries/io/attachment.zig b/system.old/libraries/io/attachment.zig
new file mode 100644
index 0000000..4672fec
--- /dev/null
+++ b/system.old/libraries/io/attachment.zig
@@ -0,0 +1,33 @@
+//! Attachment operations
+
+const sys = @import("sys");
+const types = @import("types.zig");
+
+const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
+
+pub fn attach(location: []const u8, flags: u32) types.Error!types.Descriptor {
+ const result = sys.syscall(.attach, .{ @intFromPtr(location.ptr), flags });
+ if (result == ERROR_RESULT) {
+ return types.Error.NotFound;
+ }
+ return @truncate(result);
+}
+
+pub fn seal(fd: types.Descriptor) void {
+ _ = sys.syscall(.seal, .{fd});
+}
+
+pub fn viewstack(location: []const u8, entries: []types.StackEntry) types.Error!usize {
+ const result = sys.syscall(.viewstack, .{
+ @intFromPtr(location.ptr),
+ location.len,
+ @intFromPtr(entries.ptr),
+ entries.len,
+ });
+
+ if (result == ERROR_RESULT) {
+ return types.Error.InvalidLocation;
+ }
+
+ return @intCast(result);
+}
diff --git a/system.old/libraries/io/io.zig b/system.old/libraries/io/io.zig
new file mode 100644
index 0000000..f7c0da3
--- /dev/null
+++ b/system.old/libraries/io/io.zig
@@ -0,0 +1,36 @@
+//! I/O operations
+
+pub const attachment = @import("attachment.zig");
+pub const stream_ops = @import("stream.zig");
+pub const location = @import("location.zig");
+pub const letter = @import("letter.zig");
+pub const types = @import("types.zig");
+
+pub const attach = attachment.attach;
+pub const seal = attachment.seal;
+pub const viewstack = attachment.viewstack;
+
+pub const view = stream_ops.view;
+pub const mark = stream_ops.mark;
+pub const getchar = stream_ops.getchar;
+pub const wipe = stream_ops.wipe;
+
+pub const getlocation = location.get;
+pub const setlocation = location.set;
+
+pub const sendLetter = letter.send;
+pub const readLetter = letter.read;
+
+pub const StackEntry = types.StackEntry;
+pub const Descriptor = types.Descriptor;
+pub const Letter = types.Letter;
+pub const Error = types.Error;
+
+pub const source = types.source;
+pub const stream = types.stream;
+pub const trace = types.trace;
+
+pub const VIEW_ONLY = types.VIEW_ONLY;
+pub const MARK_ONLY = types.MARK_ONLY;
+pub const BOTH = types.BOTH;
+pub const CREATE = types.CREATE;
diff --git a/system.old/libraries/io/io.zon b/system.old/libraries/io/io.zon
new file mode 100644
index 0000000..c6a1bc4
--- /dev/null
+++ b/system.old/libraries/io/io.zon
@@ -0,0 +1,10 @@
+.{
+ .name = "io",
+ .version = "1.0.0",
+ .type = .library,
+ .dependencies = .{
+ .sys,
+ .kata,
+ },
+ .entry = "io.zig",
+}
diff --git a/system.old/libraries/io/letter.zig b/system.old/libraries/io/letter.zig
new file mode 100644
index 0000000..3cde330
--- /dev/null
+++ b/system.old/libraries/io/letter.zig
@@ -0,0 +1,36 @@
+//! Letter (postman) operations
+
+const sys = @import("sys");
+const types = @import("types.zig");
+
+const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
+
+const MODE_SEND: u64 = 0;
+const MODE_READ: u64 = 1;
+
+pub fn send(letter_type: u8, data: []const u8) types.Error!void {
+ const result = sys.syscall(.postman, .{
+ MODE_SEND,
+ @as(u64, letter_type),
+ @intFromPtr(data.ptr),
+ data.len,
+ });
+
+ if (result == ERROR_RESULT) {
+ return types.Error.SendFailed;
+ }
+}
+
+pub fn read(buffer: []u8) types.Error!u8 {
+ const result = sys.syscall(.postman, .{
+ MODE_READ,
+ @intFromPtr(buffer.ptr),
+ buffer.len,
+ });
+
+ if (result == ERROR_RESULT) {
+ return types.Error.ReadFailed;
+ }
+
+ return @intCast(result);
+}
diff --git a/system.old/libraries/io/location.zig b/system.old/libraries/io/location.zig
new file mode 100644
index 0000000..0f1e114
--- /dev/null
+++ b/system.old/libraries/io/location.zig
@@ -0,0 +1,30 @@
+//! Location operations
+
+const sys = @import("sys");
+const types = @import("types.zig");
+
+const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
+
+pub fn get(buffer: []u8) types.Error![]u8 {
+ const result = sys.syscall(.getlocation, .{
+ @intFromPtr(buffer.ptr),
+ buffer.len,
+ });
+
+ if (result == ERROR_RESULT) {
+ return types.Error.GetLocationFailed;
+ }
+
+ return buffer[0..@intCast(result)];
+}
+
+pub fn set(location: []const u8) types.Error!void {
+ const result = sys.syscall(.setlocation, .{
+ @intFromPtr(location.ptr),
+ location.len,
+ });
+
+ if (result == ERROR_RESULT) {
+ return types.Error.InvalidLocation;
+ }
+}
diff --git a/system.old/libraries/io/stream.zig b/system.old/libraries/io/stream.zig
new file mode 100644
index 0000000..8e65473
--- /dev/null
+++ b/system.old/libraries/io/stream.zig
@@ -0,0 +1,41 @@
+//! Stream operations
+
+const kata = @import("kata");
+const sys = @import("sys");
+const types = @import("types.zig");
+
+const ERROR_RESULT: u64 = @bitCast(@as(i64, -1));
+const EAGAIN_RESULT: u64 = @bitCast(@as(i64, -2));
+
+pub fn view(fd: types.Descriptor, buffer: []u8) types.Error!usize {
+ const result = sys.syscall(.view, .{ fd, @intFromPtr(buffer.ptr), buffer.len });
+ if (result == ERROR_RESULT) {
+ return types.Error.ReadFailed;
+ }
+ return result;
+}
+
+pub fn mark(fd: types.Descriptor, data: []const u8, color: u32) types.Error!usize {
+ const result = sys.syscall(.mark, .{ fd, @intFromPtr(data.ptr), data.len, color });
+ if (result == ERROR_RESULT) {
+ return types.Error.WriteFailed;
+ }
+ return result;
+}
+
+pub fn getchar() types.Error!u8 {
+ while (true) {
+ const result = sys.syscall(.getkeychar, .{});
+ if (result != EAGAIN_RESULT) {
+ if (result != ERROR_RESULT) {
+ return @truncate(result);
+ }
+ return types.Error.ReadFailed;
+ }
+ kata.yield();
+ }
+}
+
+pub fn wipe() void {
+ _ = sys.syscall(.wipe, .{});
+}
diff --git a/system.old/libraries/io/types.zig b/system.old/libraries/io/types.zig
new file mode 100644
index 0000000..1b4336b
--- /dev/null
+++ b/system.old/libraries/io/types.zig
@@ -0,0 +1,39 @@
+//! I/O types and constants
+
+pub const Error = error{
+ NotFound,
+ PermissionDenied,
+ InvalidDescriptor,
+ ReadFailed,
+ WriteFailed,
+ InvalidLocation,
+ SendFailed,
+ GetLocationFailed,
+};
+
+pub const Descriptor = u32;
+
+pub const source: Descriptor = 0;
+pub const stream: Descriptor = 1;
+pub const trace: Descriptor = 2;
+
+pub const VIEW_ONLY: u32 = 0x01;
+pub const MARK_ONLY: u32 = 0x02;
+pub const BOTH: u32 = 0x03;
+pub const CREATE: u32 = 0x0100;
+
+pub const StackEntry = extern struct {
+ identity: [64]u8,
+ identity_len: u8,
+ is_stack: bool,
+ owner_name_len: u8,
+ permission_type: u8,
+ size: u32,
+ modified_time: u64,
+ owner_name: [64]u8,
+};
+
+pub const Letter = struct {
+ pub const NONE: u8 = 0;
+ pub const NAVIGATE: u8 = 1;
+};