mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-02 08:08:21 +00:00
refactor: rework init
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pub const init_mod = @import("init.zig");
|
||||||
|
|
||||||
|
pub const init = init_mod.init;
|
||||||
@@ -1 +1,2 @@
|
|||||||
pub const fireworks = @import("fireworks.zig");
|
pub const fireworks = @import("fireworks.zig");
|
||||||
|
pub const private = @import("private.zig");
|
||||||
|
|||||||
+3
-46
@@ -3,34 +3,11 @@ const b = @import("base");
|
|||||||
const pl = b.pl;
|
const pl = b.pl;
|
||||||
const ke = b.ke;
|
const ke = b.ke;
|
||||||
const ki = ke.private;
|
const ki = ke.private;
|
||||||
|
const ex = b.ex;
|
||||||
|
|
||||||
var thread0: ke.Thread = undefined;
|
var thread0: ke.Thread = undefined;
|
||||||
|
|
||||||
var stack: [8192]u8 align(16) = 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 {
|
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||||
pl.early_init();
|
pl.early_init();
|
||||||
ki.bootstrap_cpu.init(&thread0);
|
ki.bootstrap_cpu.init(&thread0);
|
||||||
@@ -40,27 +17,7 @@ pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
|||||||
thread0.priority_class = .Idle;
|
thread0.priority_class = .Idle;
|
||||||
|
|
||||||
std.log.info("hello, world", .{});
|
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();
|
ex.private.init(boot_info);
|
||||||
|
|
||||||
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) {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pub const sched = struct {
|
|||||||
pub const enqueue = p.sched.enqueue;
|
pub const enqueue = p.sched.enqueue;
|
||||||
pub const block = p.sched.block;
|
pub const block = p.sched.block;
|
||||||
pub const unblock = p.sched.unblock;
|
pub const unblock = p.sched.unblock;
|
||||||
|
pub const late_init = p.sched.late_init;
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const timer = struct {
|
pub const timer = struct {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ pub export var cmdline_request: limine.CmdlineRequest linksection(".limine_reque
|
|||||||
.response = null,
|
.response = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub export var kernel_address_request: limine.KernelAddressRequest linksection(".limine_requests") = .{
|
pub export var kernel_address_request: limine.ExecutableAddressRequest linksection(".limine_requests") = .{
|
||||||
.id = limine.kernel_address_request_id,
|
.id = limine.executable_address_request_id,
|
||||||
.revision = 0,
|
.revision = 0,
|
||||||
.response = null,
|
.response = null,
|
||||||
};
|
};
|
||||||
@@ -76,26 +76,14 @@ fn build_memory_map() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export fn kmain() callconv(.c) void {
|
export fn kmain() callconv(.c) void {
|
||||||
boot_info.cmdline = if (cmdline_request.response) |cmdline_response| {
|
boot_info.cmdline = if (cmdline_request.response) |cmdline_response| std.mem.span(cmdline_response.cmdline) else null;
|
||||||
cmdline_response.cmdline;
|
|
||||||
} else {
|
|
||||||
null;
|
|
||||||
};
|
|
||||||
|
|
||||||
boot_info.rsdp = if (rsdp_request.response) |rsdp_response| {
|
boot_info.rsdp = if (rsdp_request.response) |rsdp_response| @intFromPtr(rsdp_response.rsdp) else null;
|
||||||
rsdp_response.rsdp;
|
|
||||||
} else {
|
|
||||||
0;
|
|
||||||
};
|
|
||||||
|
|
||||||
boot_info.kernel_address = if (kernel_address_request.response) |ka_response| {
|
boot_info.kernel_address = if (kernel_address_request.response) |ka_response| .{
|
||||||
.{
|
.physical_base = ka_response.physical_base,
|
||||||
.physical_base = ka_response.kernel_address.physical_base,
|
.virtual_base = ka_response.virtual_base,
|
||||||
.virtual_base = ka_response.kernel_address.virtual_base,
|
} else .{ .physical_base = 0, .virtual_base = 0 };
|
||||||
};
|
|
||||||
} else {
|
|
||||||
.{ .physical_base = 0, .virtual_base = 0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
build_memory_map();
|
build_memory_map();
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ pub const RsdpRequest = extern struct {
|
|||||||
|
|
||||||
pub const RsdpResponse = extern struct {
|
pub const RsdpResponse = extern struct {
|
||||||
revision: u64,
|
revision: u64,
|
||||||
rsdp_address: ?*anyopaque,
|
rsdp: ?*anyopaque,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const cmdline_request_id: [4]u64 = .{
|
pub const cmdline_request_id: [4]u64 = .{
|
||||||
@@ -97,7 +97,7 @@ pub const CmdlineRequest = extern struct {
|
|||||||
|
|
||||||
pub const CmdlineResponse = extern struct {
|
pub const CmdlineResponse = extern struct {
|
||||||
revision: u64,
|
revision: u64,
|
||||||
cmdline: ?[*]u8,
|
cmdline: ?[*:0]u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const executable_address_request_id: [4]u64 = .{
|
pub const executable_address_request_id: [4]u64 = .{
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub const BootInfo = struct {
|
|||||||
pub const KernelAddress = struct { physical_base: usize, virtual_base: usize };
|
pub const KernelAddress = struct { physical_base: usize, virtual_base: usize };
|
||||||
|
|
||||||
/// RSDP on ACPI machines
|
/// RSDP on ACPI machines
|
||||||
rsdp: usize,
|
rsdp: ?usize,
|
||||||
|
|
||||||
/// Kernel command-line arguments
|
/// Kernel command-line arguments
|
||||||
cmdline: ?[]const u8,
|
cmdline: ?[]const u8,
|
||||||
|
|||||||
Reference in New Issue
Block a user