From 1d16bb0d676d77a78c553f2f5e58318715988e56 Mon Sep 17 00:00:00 2001 From: bagggage Date: Tue, 10 Dec 2024 01:44:48 +0300 Subject: [PATCH] Better logs --- src/kernel/dev.zig | 2 ++ src/kernel/dev/Bus.zig | 5 +++++ src/kernel/dev/drivers/blk/nvme.zig | 4 ++-- src/kernel/dev/drivers/uart.zig | 2 +- src/kernel/dev/intr.zig | 2 +- src/kernel/dev/stds/pci.zig | 2 +- src/kernel/dev/stds/pci/config.zig | 4 ++-- src/kernel/vfs.zig | 25 ++++++++++++++++--------- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/kernel/dev.zig b/src/kernel/dev.zig index 3cc76a0..8b6adfc 100644 --- a/src/kernel/dev.zig +++ b/src/kernel/dev.zig @@ -118,6 +118,8 @@ pub export fn registerBus(bus: *BusNode) void { defer buses_lock.unlock(); buses.prepend(bus); + + log.info("{s} bus was registered", .{bus.data.name}); } pub inline fn registerDevice( diff --git a/src/kernel/dev/Bus.zig b/src/kernel/dev/Bus.zig index a99642e..581767d 100644 --- a/src/kernel/dev/Bus.zig +++ b/src/kernel/dev/Bus.zig @@ -5,6 +5,7 @@ const std = @import("std"); const Device = @import("Device.zig"); const dev = @import("../dev.zig"); const Driver = @import("Driver.zig"); +const log = std.log.scoped(.@"dev.bus"); const utils = @import("../utils.zig"); const vm = @import("../vm.zig"); @@ -104,6 +105,8 @@ pub export fn addDriver(self: *Self, driver: *dev.DriverNode) void { self.drivers.prepend(driver); } + log.info("{s}: {s} driver was attached", .{self.name,driver.data.name}); + self.matchDriver(&driver.data); } @@ -116,6 +119,8 @@ pub export fn removeDriver(self: *Self, driver: *dev.DriverNode) void { } self.onRemoveDriver(&driver.data); + + log.info("{s}: {s} driver was removed", .{self.name,driver.data.name}); } fn matchDevice(self: *Self, device: *dev.DeviceNode) void { diff --git a/src/kernel/dev/drivers/blk/nvme.zig b/src/kernel/dev/drivers/blk/nvme.zig index 28e7ebb..1adb7ab 100644 --- a/src/kernel/dev/drivers/blk/nvme.zig +++ b/src/kernel/dev/drivers/blk/nvme.zig @@ -823,7 +823,7 @@ const Controller = struct { } }; -var pci_driver = pci.Driver.init("nvme driver", +var pci_driver = pci.Driver.init("nvme-ctrl", .{ .probe = .{ .universal = probe }, .remove = remove, @@ -839,7 +839,7 @@ pub fn init() !void { } fn probe(device: *dev.Device) dev.Driver.Operations.ProbeResult { - log.debug("controller: {s}", .{device.name.str()}); + log.info("controller: {s}", .{device.name.str()}); const pci_dev = pci.Device.from(device); const controller = vm.alloc(Controller) orelse return .no_resources; diff --git a/src/kernel/dev/drivers/uart.zig b/src/kernel/dev/drivers/uart.zig index 737a7cb..f367439 100644 --- a/src/kernel/dev/drivers/uart.zig +++ b/src/kernel/dev/drivers/uart.zig @@ -52,7 +52,7 @@ const regs_base = switch (builtin.cpu.arch) { const regs = UartRegs{ .dyn_base = regs_base }; -var driver = dev.Driver.init("uart driver", .{ +var driver = dev.Driver.init("uart rs-232", .{ .probe = .{ .platform = probe }, .remove = remove }); diff --git a/src/kernel/dev/intr.zig b/src/kernel/dev/intr.zig index e1bf310..c77383e 100644 --- a/src/kernel/dev/intr.zig +++ b/src/kernel/dev/intr.zig @@ -286,7 +286,7 @@ pub fn init() !void { @memset(std.mem.asBytes(&msis.buffer), 0); @memset(std.mem.asBytes(&irqs.buffer), 0); - log.info("Interrupt controller: {s}", .{chip.name}); + log.info("controller: {s}", .{chip.name}); } pub fn deinit() void { diff --git a/src/kernel/dev/stds/pci.zig b/src/kernel/dev/stds/pci.zig index 21bc2e2..987326c 100644 --- a/src/kernel/dev/stds/pci.zig +++ b/src/kernel/dev/stds/pci.zig @@ -186,7 +186,7 @@ fn enumDevice(seg_idx: u16, bus_idx: u8, dev_idx: u8, func_idx: u8) !bool { pci_dev.device = device; - log.debug("PCI:{}: 0x{x:0>4} : 0x{x:0>4}", .{ + log.debug("device: {}: VEN_ID 0x{x:0>4} : DEV_ID 0x{x:0>4}", .{ device.name, vendor_id, pci_dev.id.device_id }); diff --git a/src/kernel/dev/stds/pci/config.zig b/src/kernel/dev/stds/pci/config.zig index a53380d..a487419 100644 --- a/src/kernel/dev/stds/pci/config.zig +++ b/src/kernel/dev/stds/pci/config.zig @@ -143,7 +143,7 @@ pub fn init() !void { cfg_io.write = PortsIo.write; cfg_io.getBase = PortsIo.getBase; - log.info("PCI config. space: i/o ports", .{}); + log.info("i/o ports", .{}); } } else if (entry) |hdr| { @@ -681,5 +681,5 @@ fn initMmio(mcfg_hdr: *const acpi.SdtHeader) !void { return error.IoRegionBusy; } - log.info("PCI config. space: mmio: 0x{x}: max seg: {}", .{entries[0].base, max_seg}); + log.info("mmio: 0x{x}: max seg: {}", .{entries[0].base, max_seg}); } \ No newline at end of file diff --git a/src/kernel/vfs.zig b/src/kernel/vfs.zig index d8b7825..c7faff8 100644 --- a/src/kernel/vfs.zig +++ b/src/kernel/vfs.zig @@ -405,7 +405,7 @@ pub fn init() !void { inline for (AutoInit.file_systems) |Fs| { Fs.init() catch |err| { - log.err("Failed to initialize '"++@typeName(Fs)++"' filesystem: {s}", .{@errorName(err)}); + log.err("failed to initialize '"++@typeName(Fs)++"' filesystem: {s}", .{@errorName(err)}); }; } } @@ -461,19 +461,24 @@ pub fn mount(dentry: *Dentry, fs_name: []const u8, drive: ?*Drive, part_idx: u32 pub export fn registerFs(fs: *FsNode) bool { if (fs.next != null or fs.prev != null) return false; - fs_lock.lock(); - defer fs_lock.unlock(); - - // Check if fs with same name exists { - var fs_node = fs_list.first; + fs_lock.lock(); + defer fs_lock.unlock(); - while (fs_node) |other_fs| : (fs_node = other_fs.next) { - if (other_fs.data.hash == fs.data.hash) return false; + // Check if fs with same name exists + { + var fs_node = fs_list.first; + + while (fs_node) |other_fs| : (fs_node = other_fs.next) { + if (other_fs.data.hash == fs.data.hash) return false; + } } + + fs_list.append(fs); } - fs_list.append(fs); + log.info("{s} was registered", .{fs.data.name}); + return true; } @@ -487,6 +492,8 @@ pub export fn unregisterFs(fs: *FsNode) void { fs.next = null; fs.prev = null; + + log.info("{s} was removed", .{fs.data.name}); } pub inline fn getFs(name: []const u8) ?*FileSystem {