diff --git a/system/drivers/ps2-bus/keyboard.zig b/system/drivers/ps2-bus/keyboard.zig index 3b2edbd..a38f826 100644 --- a/system/drivers/ps2-bus/keyboard.zig +++ b/system/drivers/ps2-bus/keyboard.zig @@ -109,7 +109,7 @@ pub fn main(init: runtime.process.Init) void { return; }; if (attached.len < @sizeOf(ps2.AttachReply) or - std.mem.bytesToValue(ps2.AttachReply, attach_reply[0..@sizeOf(ps2.AttachReply)]).status != 0) + std.mem.bytesToValue(ps2.AttachReply, attach_reply[0..@sizeOf(ps2.AttachReply)]).status != @intFromEnum(ps2.AttachStatus.ok)) { _ = runtime.system.write("system/drivers/ps2-bus/keyboard: attach refused\n"); return; diff --git a/system/drivers/ps2-bus/mouse.zig b/system/drivers/ps2-bus/mouse.zig index f144a5a..c70d0a0 100644 --- a/system/drivers/ps2-bus/mouse.zig +++ b/system/drivers/ps2-bus/mouse.zig @@ -82,7 +82,7 @@ pub fn main(init: runtime.process.Init) void { return; }; if (attached.len < @sizeOf(ps2.AttachReply) or - std.mem.bytesToValue(ps2.AttachReply, attach_reply[0..@sizeOf(ps2.AttachReply)]).status != 0) + std.mem.bytesToValue(ps2.AttachReply, attach_reply[0..@sizeOf(ps2.AttachReply)]).status != @intFromEnum(ps2.AttachStatus.ok)) { _ = runtime.system.write("system/drivers/ps2-bus/mouse: attach refused\n"); return; diff --git a/system/drivers/ps2-bus/ps2-bus.zig b/system/drivers/ps2-bus/ps2-bus.zig index 9d02198..d211de9 100644 --- a/system/drivers/ps2-bus/ps2-bus.zig +++ b/system/drivers/ps2-bus/ps2-bus.zig @@ -67,25 +67,25 @@ var port_device_types = [_]?ps2.DeviceType{ null, null }; /// Writes an `AttachReply` into `out` and returns its length. fn handleAttach(message: []const u8, got: ipc.Received, out: []u8) usize { const reply = struct { - fn write(buffer: []u8, status: i32) usize { - const header = ps2.AttachReply{ .status = status }; + fn write(buffer: []u8, status: ps2.AttachStatus) usize { + const header = ps2.AttachReply{ .status = @intFromEnum(status) }; @memcpy(buffer[0..@sizeOf(ps2.AttachReply)], std.mem.asBytes(&header)); return @sizeOf(ps2.AttachReply); } }; - if (message.len < @sizeOf(ps2.AttachRequest)) return reply.write(out, -1); + if (message.len < @sizeOf(ps2.AttachRequest)) return reply.write(out, .invalid_request); const request = std.mem.bytesToValue(ps2.AttachRequest, message[0..@sizeOf(ps2.AttachRequest)]); - const endpoint = got.cap orelse return reply.write(out, -1); // no endpoint passed + const endpoint = got.cap orelse return reply.write(out, .missing_endpoint); for (&port_device_types, 0..) |maybe_type, port_index| { const device_type = maybe_type orelse continue; if (@intFromEnum(device_type) != request.device_type) continue; port_endpoints[port_index] = endpoint; writeLine("system/drivers/ps2-bus: {s} driver attached\n", .{@tagName(device_type)}); - return reply.write(out, 0); + return reply.write(out, .ok); } - return reply.write(out, -1); // no port identified as that device type + return reply.write(out, .no_such_device); } pub fn main() void { diff --git a/system/drivers/ps2-bus/ps2-library.zig b/system/drivers/ps2-bus/ps2-library.zig index d256523..932e826 100644 --- a/system/drivers/ps2-bus/ps2-library.zig +++ b/system/drivers/ps2-bus/ps2-library.zig @@ -285,7 +285,18 @@ pub const AttachRequest = extern struct { device_type: u32, }; -/// Reply to an `AttachRequest`. `status` is 0 on success or a negative errno. +/// How the bus answered an `AttachRequest` (`AttachReply.status`). +pub const AttachStatus = enum(i32) { + ok = 0, + /// The request was malformed (too short to be an `AttachRequest`). + invalid_request = -1, + /// The call carried no endpoint capability to forward to. + missing_endpoint = -2, + /// No port identified a device of the requested type. + no_such_device = -3, +}; + +/// Reply to an `AttachRequest`. `status` is an `AttachStatus` value. pub const AttachReply = extern struct { status: i32, _padding: u32 = 0,