refactor: rework init

This commit is contained in:
Loïc Grégoire
2026-03-29 18:53:33 -04:00
parent 73ae92b460
commit 572ab0e47c
8 changed files with 34 additions and 69 deletions
+15
View File
@@ -0,0 +1,15 @@
const std = @import("std");
const b = @import("base");
const pl = b.pl;
const ke = b.ke;
pub fn init(boot_info: *pl.BootInfo) void {
_ = boot_info;
pl.late_init();
ke.sched.late_init();
while (true) {
std.atomic.spinLoopHint();
}
}
+3
View File
@@ -0,0 +1,3 @@
pub const init_mod = @import("init.zig");
pub const init = init_mod.init;
+1
View File
@@ -1 +1,2 @@
pub const fireworks = @import("fireworks.zig");
pub const private = @import("private.zig");
+3 -46
View File
@@ -3,34 +3,11 @@ const b = @import("base");
const pl = b.pl;
const ke = b.ke;
const ki = ke.private;
const ex = b.ex;
var thread0: ke.Thread = undefined;
var stack: [8192]u8 align(16) = undefined;
fn handler(_: ?*anyopaque) void {
std.log.info("Hi! CPU {}", .{ke.curcpu().id});
while (true) {}
}
var temp_stack1: [8192]u8 align(16) = undefined;
var temp_stack2: [8192]u8 align(16) = undefined;
var temp_stack3: [8192]u8 align(16) = undefined;
var stacks: []const []u8 = &.{&temp_stack1, &temp_stack2, &temp_stack3};
var which_stack: usize = 0;
fn make_thread(entry: *const fn (?*anyopaque) void, td: *ke.Thread, arg: ?*anyopaque) void {
std.debug.assert(which_stack < 3);
const _stack = stacks[which_stack];
which_stack += 1;
td.init(@intFromPtr(_stack.ptr), 16384, entry, arg);
}
var threads: [1]ke.Thread = undefined;
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
pl.early_init();
ki.bootstrap_cpu.init(&thread0);
@@ -40,27 +17,7 @@ pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
thread0.priority_class = .Idle;
std.log.info("hello, world", .{});
std.log.info("Zag for {s}, cmdline is {?s}", .{ pl.name, boot_info.cmdline });
std.log.info("Zag for {s}, cmdline is \"{?s}\"", .{ pl.name, boot_info.cmdline });
pl.late_init();
ki.sched.late_init();
if (boot_info.framebuffer == null) {
const ipl = ke.ipl.raise(.Dispatch);
for (&threads) |*td| {
make_thread(&handler, td, null);
td.priority = ke.Thread.Priority.default;
td.priority_class = .Batch;
ke.sched.enqueue(td);
}
ke.ipl.lower(ipl);
} else {
// make_thread(&b.ex.fireworks.start, &threads[0], boot_info);
// ke.sched.enqueue(&threads[0]);
}
while (true) {}
ex.private.init(boot_info);
}
+1
View File
@@ -43,6 +43,7 @@ pub const sched = struct {
pub const enqueue = p.sched.enqueue;
pub const block = p.sched.block;
pub const unblock = p.sched.unblock;
pub const late_init = p.sched.late_init;
};
pub const timer = struct {
+8 -20
View File
@@ -42,8 +42,8 @@ pub export var cmdline_request: limine.CmdlineRequest linksection(".limine_reque
.response = null,
};
pub export var kernel_address_request: limine.KernelAddressRequest linksection(".limine_requests") = .{
.id = limine.kernel_address_request_id,
pub export var kernel_address_request: limine.ExecutableAddressRequest linksection(".limine_requests") = .{
.id = limine.executable_address_request_id,
.revision = 0,
.response = null,
};
@@ -76,26 +76,14 @@ fn build_memory_map() void {
}
export fn kmain() callconv(.c) void {
boot_info.cmdline = if (cmdline_request.response) |cmdline_response| {
cmdline_response.cmdline;
} else {
null;
};
boot_info.cmdline = if (cmdline_request.response) |cmdline_response| std.mem.span(cmdline_response.cmdline) else null;
boot_info.rsdp = if (rsdp_request.response) |rsdp_response| {
rsdp_response.rsdp;
} else {
0;
};
boot_info.rsdp = if (rsdp_request.response) |rsdp_response| @intFromPtr(rsdp_response.rsdp) else null;
boot_info.kernel_address = if (kernel_address_request.response) |ka_response| {
.{
.physical_base = ka_response.kernel_address.physical_base,
.virtual_base = ka_response.kernel_address.virtual_base,
};
} else {
.{ .physical_base = 0, .virtual_base = 0 };
};
boot_info.kernel_address = if (kernel_address_request.response) |ka_response| .{
.physical_base = ka_response.physical_base,
.virtual_base = ka_response.virtual_base,
} else .{ .physical_base = 0, .virtual_base = 0 };
build_memory_map();
+2 -2
View File
@@ -79,7 +79,7 @@ pub const RsdpRequest = extern struct {
pub const RsdpResponse = extern struct {
revision: u64,
rsdp_address: ?*anyopaque,
rsdp: ?*anyopaque,
};
pub const cmdline_request_id: [4]u64 = .{
@@ -97,7 +97,7 @@ pub const CmdlineRequest = extern struct {
pub const CmdlineResponse = extern struct {
revision: u64,
cmdline: ?[*]u8,
cmdline: ?[*:0]u8,
};
pub const executable_address_request_id: [4]u64 = .{
+1 -1
View File
@@ -70,7 +70,7 @@ pub const BootInfo = struct {
pub const KernelAddress = struct { physical_base: usize, virtual_base: usize };
/// RSDP on ACPI machines
rsdp: usize,
rsdp: ?usize,
/// Kernel command-line arguments
cmdline: ?[]const u8,