Skip to content

Commit

Permalink
Better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bagggage committed Dec 9, 2024
1 parent f888147 commit 1d16bb0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/kernel/dev.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/dev/Bus.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/dev/drivers/blk/nvme.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/dev/drivers/uart.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/dev/intr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/dev/stds/pci.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/dev/stds/pci/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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});
}
25 changes: 16 additions & 9 deletions src/kernel/vfs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
};
}
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 {
Expand Down

0 comments on commit 1d16bb0

Please sign in to comment.