mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-30 06:48:22 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const pl = b.pl;
|
||||
const ke = b.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
var thread0: ke.Thread = undefined;
|
||||
|
||||
fn idle(_: ?*anyopaque) void {
|
||||
while (true) {
|
||||
std.atomic.spinLoopHint();
|
||||
}
|
||||
}
|
||||
|
||||
var stack: [8192]u8 align(16) = undefined;
|
||||
|
||||
fn handler(_: ?*anyopaque) void {
|
||||
std.log.info("Hi! CPU {}", .{ke.curcpu().id});
|
||||
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
fn make_thread(entry: *const fn (?*anyopaque) void, td: *ke.Thread) void {
|
||||
const _stack = std.heap.page_allocator.alloc(u8, 16384) catch @panic("wtf");
|
||||
|
||||
td.init(@intFromPtr(_stack.ptr), 16384, entry, null);
|
||||
}
|
||||
|
||||
var threads: [10]ke.Thread = undefined;
|
||||
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
pl.early_init();
|
||||
ki.bootstrap_cpu.init(&thread0);
|
||||
|
||||
thread0.init(@intFromPtr(&stack), 8192, idle, null);
|
||||
thread0.priority = 0;
|
||||
thread0.priority_class = .Idle;
|
||||
|
||||
std.log.info("hello, world", .{});
|
||||
std.log.info("Zag for {s}, cmdline is {?s}", .{ pl.name, boot_info.cmdline });
|
||||
|
||||
pl.late_init();
|
||||
|
||||
_ = ke.ipl.raise(.Dispatch);
|
||||
|
||||
for (0..10) |i| {
|
||||
make_thread(handler, &threads[i]);
|
||||
ke.sched.enqueue(&threads[i]);
|
||||
}
|
||||
|
||||
ke.ipl.lower(.Zero);
|
||||
|
||||
while (true) {}
|
||||
}
|
||||
Reference in New Issue
Block a user