51 lines
1.9 KiB
Zig
51 lines
1.9 KiB
Zig
//! PS/2 Mouse Driver
|
|
//!
|
|
//! Spawned by the ps2-bus driver once the controller is initialized and port 2
|
|
//! has passed its interface test and device reset. The bus driver hands us our
|
|
//! device HID as argv[1]; we use it to locate our own device descriptor.
|
|
|
|
const std = @import("std");
|
|
const runtime = @import("runtime");
|
|
const ps2 = @import("ps2-library.zig");
|
|
const device = runtime.device;
|
|
|
|
fn writeLine(comptime fmt: []const u8, arguments: anytype) void {
|
|
var line: [128]u8 = undefined;
|
|
_ = runtime.system.write(std.fmt.bufPrint(&line, fmt, arguments) catch return);
|
|
}
|
|
|
|
pub fn main() void {
|
|
const hid = runtime.argument(1);
|
|
if (hid.len == 0) {
|
|
_ = runtime.system.write("system/drivers/ps2-bus/mouse: no HID argument\n");
|
|
return;
|
|
}
|
|
writeLine("system/drivers/ps2-bus/mouse: starting for hid {s}\n", .{hid});
|
|
|
|
const buffer = runtime.allocator().alloc(device.DeviceDescriptor, 64) catch {
|
|
_ = runtime.system.write("system/drivers/ps2-bus/mouse: out of memory\n");
|
|
return;
|
|
};
|
|
const mouse_device_descriptor = device.findDeviceDescriptorByHid(buffer, hid) orelse {
|
|
writeLine("system/drivers/ps2-bus/mouse: no device for hid {s}\n", .{hid});
|
|
return;
|
|
};
|
|
|
|
// The mouse's own node (PNP0F13) carries IRQ12 and is not claimed by the bus,
|
|
// so this driver takes exclusive ownership of it. Port IO still goes through
|
|
// the bus, which owns the shared 8042 ports.
|
|
if (!device.claim(mouse_device_descriptor.id)) {
|
|
writeLine("system/drivers/ps2-bus/mouse: unable to claim device for hid {s}\n", .{hid});
|
|
return;
|
|
}
|
|
writeLine("system/drivers/ps2-bus/mouse: claimed device for hid {s}\n", .{hid});
|
|
|
|
_ = runtime.system.write("system/drivers/ps2-bus/mouse: ok\n");
|
|
while (true) runtime.system.sleep(1000);
|
|
}
|
|
|
|
pub const panic = runtime.panic;
|
|
comptime {
|
|
_ = &runtime.start._start;
|
|
}
|