build: phase 2 wave B — drivers build as packages

ps2-bus (bus + keyboard + mouse artifacts from one package),
usb-xhci-bus, usb-hid (keyboard + mouse), usb-storage, and virtio-gpu
convert on the pci-bus template. Their unit tests — PS/2 decode, HID
boot reports, Bulk-Only Transport/SCSI encodings, and the virtio-gpu
size checks the plan flagged as a wave carry-along — move into their
packages; the root aggregate delegates. Boot-image file list
unchanged.
This commit is contained in:
Daniel Samson
2026-07-30 04:04:50 +01:00
parent 3b23b11b0e
commit 4701fbd123
2 changed files with 29 additions and 55 deletions
+24 -55
View File
@@ -251,10 +251,6 @@ pub fn build(b: *std.Build) void {
const abi_module = kernel_library.module("abi");
const device_abi_module = device_library.module("device-abi");
const pci_class_module = device_library.module("pci-class");
const usb_abi_module = device_library.module("usb-abi");
const usb_ids_module = device_library.module("usb-ids");
const usb_transfer_protocol_module = protocol_library.module("usb-transfer-protocol");
const block_protocol_module = protocol_library.module("block-protocol");
// Kernel tunables (maximum_cpus, stack sizes, tick rate). A dependency-free module of
// compile-time constants, imported wherever a knob is read; keeps the trade-offs
@@ -296,18 +292,14 @@ pub fn build(b: *std.Build) void {
},
});
// The wire protocols some binaries name as per-binary extras, exported by
// the protocol package.
const input_protocol_module = protocol_library.module("input-protocol");
// The wire protocols some test fixtures name as per-binary extras,
// exported by the protocol package.
const device_manager_protocol_module = protocol_library.module("device-manager-protocol");
const display_protocol_module = protocol_library.module("display-protocol");
const scanout_protocol_module = protocol_library.module("scanout-protocol");
// The driver-side libraries some binaries name as per-binary extras. (The
// rest of the domain modules reach the root only through build-support's
// defaultImports below.)
// The driver-side PCI library some test fixtures name as a per-binary
// extra. (The rest of the domain modules reach the root only through
// build-support's defaultImports below.)
const pci_module = device_library.module("pci");
const usb_module = device_library.module("usb");
// The initial_ramdisk container format, shared by the kernel (unpacks it) and
// the EFI loader (packs it in RAM from the boot volume's /system tree). No
@@ -380,37 +372,19 @@ pub fn build(b: *std.Build) void {
// the boot volume (see `bundled` below). The EFI loader walks the tree at boot
// and hands the kernel an in-RAM initial_ramdisk of it (system/initial-ramdisk.zig).
const vfstest_exe = addUserBinary(b, kernel_target, &default_imports, "vfs-test", "test/system/services/vfs-test/vfs-test.zig");
const ps2_bus_exe = addUserBinary(b, kernel_target, &default_imports, "ps2-bus", "system/drivers/ps2-bus/ps2-bus.zig");
const ps2_keyboard_exe = addUserBinary(b, kernel_target, &default_imports, "ps2-keyboard", "system/drivers/ps2-bus/keyboard.zig");
programModule(ps2_keyboard_exe).addImport("input-protocol", input_protocol_module);
const ps2_mouse_exe = addUserBinary(b, kernel_target, &default_imports, "ps2-mouse", "system/drivers/ps2-bus/mouse.zig");
programModule(ps2_mouse_exe).addImport("input-protocol", input_protocol_module);
const usb_xhci_bus_exe = addUserBinary(b, kernel_target, &default_imports, "usb-xhci-bus", "system/drivers/usb-xhci-bus/usb-xhci-bus.zig");
programModule(usb_xhci_bus_exe).addImport("device-manager-protocol", device_manager_protocol_module);
// MSI setup: the claimed-function view (enable bits + MSI capability programming).
programModule(usb_xhci_bus_exe).addImport("pci", pci_module);
// The xHCI bus driver builds chapter-9 requests and decodes descriptors from
// usb-abi, and reports each interface's (class,subclass,protocol) identity via
// usb-ids.packTriple.
programModule(usb_xhci_bus_exe).addImport("usb-abi", usb_abi_module);
programModule(usb_xhci_bus_exe).addImport("usb-ids", usb_ids_module);
programModule(usb_xhci_bus_exe).addImport("usb-transfer-protocol", usb_transfer_protocol_module);
// The USB HID class drivers: keyboard and mouse. They own no hardware — each
// opens its device through runtime.usb (the transfer protocol) and publishes to
// the input service. They build chapter-9 class requests from usb-abi.
const usb_hid_keyboard_exe = addUserBinary(b, kernel_target, &default_imports, "usb-hid-keyboard", "system/drivers/usb-hid/keyboard.zig");
programModule(usb_hid_keyboard_exe).addImport("usb", usb_module);
programModule(usb_hid_keyboard_exe).addImport("usb-abi", usb_abi_module);
programModule(usb_hid_keyboard_exe).addImport("input-protocol", input_protocol_module);
const usb_hid_mouse_exe = addUserBinary(b, kernel_target, &default_imports, "usb-hid-mouse", "system/drivers/usb-hid/mouse.zig");
programModule(usb_hid_mouse_exe).addImport("usb", usb_module);
programModule(usb_hid_mouse_exe).addImport("usb-abi", usb_abi_module);
programModule(usb_hid_mouse_exe).addImport("input-protocol", input_protocol_module);
// The USB mass-storage class driver: opens its device via runtime.usb, drives it
// with Bulk-Only Transport + SCSI, and serves the block protocol under `.block`.
const usb_storage_exe = addUserBinary(b, kernel_target, &default_imports, "usb-storage", "system/drivers/usb-storage/usb-storage.zig");
programModule(usb_storage_exe).addImport("usb", usb_module);
programModule(usb_storage_exe).addImport("block-protocol", block_protocol_module);
// The drivers, each directory its own package: the PS/2 bus family (bus +
// keyboard + mouse from one package), the xHCI bus driver, the USB HID
// class drivers, and USB mass storage. Their unit tests ride along.
const ps2_bus_package = b.dependency("ps2-bus", .{});
const ps2_bus_exe = ps2_bus_package.artifact("ps2-bus");
const ps2_keyboard_exe = ps2_bus_package.artifact("ps2-keyboard");
const ps2_mouse_exe = ps2_bus_package.artifact("ps2-mouse");
const usb_xhci_bus_exe = b.dependency("usb-xhci-bus", .{}).artifact("usb-xhci-bus");
const usb_hid_package = b.dependency("usb-hid", .{});
const usb_hid_keyboard_exe = usb_hid_package.artifact("usb-hid-keyboard");
const usb_hid_mouse_exe = usb_hid_package.artifact("usb-hid-mouse");
const usb_storage_package = b.dependency("usb-storage", .{});
const usb_storage_exe = usb_storage_package.artifact("usb-storage");
// The FAT filesystem server and the display stack, each its own package
// (fat's and display's unit tests ride along in their packages).
const fat_package = b.dependency("fat", .{});
@@ -418,10 +392,8 @@ pub fn build(b: *std.Build) void {
const display_package = b.dependency("display", .{});
const display_exe = display_package.artifact("display");
const display_demo_exe = b.dependency("display-demo", .{}).artifact("display-demo");
const virtio_gpu_exe = addUserBinary(b, kernel_target, &default_imports, "virtio-gpu", "system/drivers/virtio-gpu/virtio-gpu.zig");
programModule(virtio_gpu_exe).addImport("pci", pci_module); // library/device/pci — the claimed-function view
programModule(virtio_gpu_exe).addImport("display-protocol", display_protocol_module);
programModule(virtio_gpu_exe).addImport("scanout-protocol", scanout_protocol_module);
const virtio_gpu_package = b.dependency("virtio-gpu", .{});
const virtio_gpu_exe = virtio_gpu_package.artifact("virtio-gpu");
const shared_memory_server_exe = addUserBinary(b, kernel_target, &default_imports, "shared-memory-server", "test/system/services/shared-memory-server/shared-memory-server.zig");
const shared_memory_client_exe = addUserBinary(b, kernel_target, &default_imports, "shared-memory-client", "test/system/services/shared-memory-client/shared-memory-client.zig");
const fat_test_exe = addUserBinary(b, kernel_target, &default_imports, "fat-test", "test/system/services/fat-test/fat-test.zig");
@@ -823,13 +795,6 @@ pub fn build(b: *std.Build) void {
"system/boot-handoff.zig",
"system/abi.zig",
"system/initial-ramdisk.zig", // v2 path-named entries: find/basename/magic
"system/drivers/ps2-bus/scancode.zig", // set-2 decode + keyboard state machine
"system/drivers/ps2-bus/mouse-packet.zig", // 3-byte mouse packet assembly
"system/drivers/usb-hid/hid-report.zig", // HID boot-report keyboard/mouse decode
"system/drivers/usb-storage/bulk-only-transport.zig", // CBW/CSW wrapper sizes
"system/drivers/usb-storage/scsi.zig", // SCSI CDB encodings (big-endian)
"system/drivers/virtio-gpu/virtio-gpu-protocol.zig", // virtio-gpu command struct sizes
"system/drivers/virtio-gpu/virtio-pci.zig", // virtio 1.0 PCI transport struct sizes
}) |root| {
const mod_tests = b.addTest(.{
.root_module = b.createModule(.{
@@ -856,6 +821,10 @@ pub fn build(b: *std.Build) void {
xkeyboard_config_library,
fat_package,
display_package,
ps2_bus_package,
usb_hid_package,
usb_storage_package,
virtio_gpu_package,
}) |package| {
test_step.dependOn(&package.builder.top_level_steps.get("test").?.step);
}
+5
View File
@@ -53,6 +53,11 @@
.logger = .{ .path = "system/services/logger" },
.acpi = .{ .path = "system/services/acpi" },
.fdt = .{ .path = "system/services/fdt" },
.@"ps2-bus" = .{ .path = "system/drivers/ps2-bus" },
.@"usb-xhci-bus" = .{ .path = "system/drivers/usb-xhci-bus" },
.@"usb-hid" = .{ .path = "system/drivers/usb-hid" },
.@"usb-storage" = .{ .path = "system/drivers/usb-storage" },
.@"virtio-gpu" = .{ .path = "system/drivers/virtio-gpu" },
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding