mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-27 13:58:20 +00:00
feat: use scoped logs
This commit is contained in:
+6
-3
@@ -44,10 +44,12 @@ pub fn log(
|
||||
args: anytype,
|
||||
) void {
|
||||
_ = level;
|
||||
_ = scope;
|
||||
|
||||
|
||||
const scope_str = if (scope == .default) "" else @tagName(scope) ++ ": ";
|
||||
|
||||
// Calculate the length required.
|
||||
const required_len = std.fmt.count(fmt ++ "\n", args);
|
||||
const required_len = std.fmt.count(scope_str ++ fmt ++ "\n", args);
|
||||
|
||||
// Reserve space in the ring buffer.
|
||||
var res = ringbuffer.reserve(required_len) catch return;
|
||||
@@ -55,8 +57,9 @@ pub fn log(
|
||||
res.info.timestamp = ke.time.read_time_nano();
|
||||
res.info.length = @truncate(required_len);
|
||||
|
||||
|
||||
// Format the log message into the reserved buffer.
|
||||
res.buf = std.fmt.bufPrint(res.buf, fmt ++ "\n", args) catch return;
|
||||
res.buf = std.fmt.bufPrint(res.buf, scope_str ++ fmt ++ "\n", args) catch return;
|
||||
|
||||
ringbuffer.publish(res);
|
||||
|
||||
|
||||
+5
-3
@@ -14,6 +14,8 @@ const mm = b.mm;
|
||||
const mi = mm.private;
|
||||
const ke = b.ke;
|
||||
|
||||
const log = std.log.scoped(.@"mm/phys");
|
||||
|
||||
// === Early state ===
|
||||
var bootstrapped = false;
|
||||
var early_alloc_entry_idx: usize = 0;
|
||||
@@ -202,12 +204,12 @@ pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
memory_map = &boot_info.memory_map;
|
||||
|
||||
var total_usable_memory: usize = 0;
|
||||
std.log.info("mm/phys: physical memory map:", .{});
|
||||
log.info("physical memory map:", .{});
|
||||
|
||||
for (0..boot_info.memory_map.entry_count) |i| {
|
||||
const entry = boot_info.memory_map.entries[i];
|
||||
|
||||
std.log.info("mm/phys: [{x:0>16}-{x:0>16}] {s}", .{ entry.base, entry.base + entry.size, @tagName(entry.type) });
|
||||
log.info("[{x:0>16}-{x:0>16}] {s}", .{ entry.base, entry.base + entry.size, @tagName(entry.type) });
|
||||
|
||||
if (entry.type == .Free) {
|
||||
total_usable_memory += entry.size;
|
||||
@@ -216,7 +218,7 @@ pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
|
||||
const pfndb_size_required = @sizeOf(mm.Page) * (std.math.divCeil(usize, total_usable_memory, mm.page_size) catch unreachable);
|
||||
|
||||
std.log.info("mm: using {} KiB for pfndb", .{pfndb_size_required / 1024});
|
||||
log.info("using {} KiB for pfndb", .{pfndb_size_required / 1024});
|
||||
|
||||
// Create the kernel pagemap from the early allocator.
|
||||
mi.impl.init_kernel();
|
||||
|
||||
@@ -6,6 +6,8 @@ const std = @import("std");
|
||||
const timer = @import("timer.zig");
|
||||
const hpet = @import("hpet.zig");
|
||||
|
||||
const log = std.log.scoped(.acpi);
|
||||
|
||||
const rsdp_signature = "RSD PTR ";
|
||||
const rsdt_signature = "RSDT";
|
||||
const xsdt_signature = "XSDT";
|
||||
@@ -270,7 +272,7 @@ pub fn find_table(signature: []const u8) ?*SdtHeader {
|
||||
}
|
||||
|
||||
fn format_table(hdr: *SdtHeader, phys_addr: u64) void {
|
||||
std.log.info("acpi: {s} 0x{x:0>16} {x:0>6} (v{d:0>2} {s} {s} {x:0>8} {s} {x:0>8})", .{
|
||||
log.info("{s} 0x{x:0>16} {x:0>6} (v{d:0>2} {s} {s} {x:0>8} {s} {x:0>8})", .{
|
||||
hdr.signature,
|
||||
phys_addr,
|
||||
hdr.length,
|
||||
@@ -312,10 +314,10 @@ pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
|
||||
if (rsdp.revision >= 2 and rsdp.xsdt_address != 0) {
|
||||
xsdt = @ptrFromInt(mm.p2v(rsdp.xsdt_address));
|
||||
std.log.info("acpi: XSDT found at {x:0>16}", .{rsdp.xsdt_address});
|
||||
log.info("XSDT found at {x:0>16}", .{rsdp.xsdt_address});
|
||||
} else {
|
||||
rsdt = @ptrFromInt(mm.p2v(rsdp.rsdt_address));
|
||||
std.log.info("acpi: RSDT found at {x:0>16}", .{rsdp.rsdt_address});
|
||||
log.info("RSDT found at {x:0>16}", .{rsdp.rsdt_address});
|
||||
}
|
||||
|
||||
enumerate_tables();
|
||||
|
||||
@@ -11,6 +11,8 @@ pub const name = "PC";
|
||||
|
||||
const com1 = 0x3F8;
|
||||
|
||||
const log = std.log.scoped(.@"amd64/pc");
|
||||
|
||||
fn com1_init() linksection(b.init) void {
|
||||
amd64.outb(com1 + 0x3, 0x80);
|
||||
amd64.outb(com1 + 0x0, 0x0c);
|
||||
@@ -35,8 +37,8 @@ pub fn early_init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
|
||||
const f = amd64.cpu_features;
|
||||
|
||||
std.log.info("amd64/cpu: {s}", .{&f.brand_string});
|
||||
std.log.info("amd64/cpu: vendor={s} features={}{}{}{}{}{}{}{}{}{}{}{}", .{
|
||||
log.info("CPU: {s}", .{&f.brand_string});
|
||||
log.info("vendor={s} features={}{}{}{}{}{}{}{}{}{}{}{}", .{
|
||||
&f.vendor_string,
|
||||
@intFromBool(f.x2apic),
|
||||
@intFromBool(f.five_level_paging),
|
||||
@@ -53,7 +55,7 @@ pub fn early_init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
});
|
||||
|
||||
if (amd64.hypervisor_info) |h| {
|
||||
std.log.info("amd64/cpu: running on hypervisor {s}", .{@tagName(h.vendor)});
|
||||
log.info("running on hypervisor {s}", .{@tagName(h.vendor)});
|
||||
}
|
||||
_ = boot_info;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ const amd64 = @import("arch");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
|
||||
const log = std.log.scoped(.@"amd64/tsc");
|
||||
|
||||
var tsc_timer: ke.TimeCounter = .{
|
||||
.name = "TSC",
|
||||
.quality = 100,
|
||||
@@ -18,9 +20,9 @@ pub fn init() linksection(b.init) void {
|
||||
const features = amd64.cpu_features;
|
||||
|
||||
if (!features.invariant_tsc) {
|
||||
std.log.info("tsc: invariant TSC not supported (get a new PC)", .{});
|
||||
log.info("invariant TSC not supported (get a new PC), using fallback", .{});
|
||||
if (ke.time.best()) |best| {
|
||||
std.log.info("pc: using {s} as timecounter source", .{best.name});
|
||||
log.info("using {s} as timecounter source", .{best.name});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -30,7 +32,7 @@ pub fn init() linksection(b.init) void {
|
||||
|
||||
if (cpuid_state.ebx != 0 and cpuid_state.ecx != 0) {
|
||||
const tsc_freq = (cpuid_state.ebx / cpuid_state.eax) * cpuid_state.ecx;
|
||||
std.log.info("tsc: TSC frequency determined via CPUID: {} Hz", .{tsc_freq});
|
||||
log.info("TSC frequency determined via CPUID: {} Hz", .{tsc_freq});
|
||||
tsc_timer.frequency = tsc_freq;
|
||||
|
||||
ke.time.register_source(&tsc_timer);
|
||||
@@ -75,7 +77,7 @@ pub fn init() linksection(b.init) void {
|
||||
|
||||
ke.time.register_source(&tsc_timer);
|
||||
|
||||
std.log.info("pc: TSC frequency calibrated using {s}: {}.{} MHz", .{ best.name, tsc_timer.frequency / 1_000_000, (tsc_timer.frequency % 1_000_000) / 1000 });
|
||||
log.info("frequency calibrated using {s}: {}.{} MHz", .{ best.name, tsc_timer.frequency / 1_000_000, (tsc_timer.frequency % 1_000_000) / 1000 });
|
||||
}
|
||||
|
||||
fn read_tsc() u64 {
|
||||
|
||||
Reference in New Issue
Block a user