pub const aux = @import("aux.zig"); pub const mm = @import("mm/root.zig"); pub const scheduler = @import("scheduler.zig"); pub const loadElf = loader.loadElf; const arch = @import("arch"); const std = @import("std"); const loader = @import("loader.zig"); // Arch init must set up appropriate fields! pub var init_data: aux.InitState = .{}; // Generic bsp init pub fn generic_init() callconv(.c) noreturn { const log = std.log.scoped(.generic_init); // First, do early arch init arch.boot.early_init(); // Now, set up the bootmem and console mm.bootmem.init(); // Now, do the rest of the arch init arch.boot.bsp_init(); // Next, set up the console aux.initConsole(); // Now, set up interrupts arch.interrupts.init(); arch.interrupts.init_syscalls(); log.info("Loading attached tasks...", .{}); arch.boot.loadTasks(); log.info("Dropping to userspace!", .{}); arch.interrupts.startScheduling(); } pub fn loadTask(scratch: *arch.structures.Task, task_slice: []align(4096) u8) void { // 1. Create a user address space var user_ctx = arch.mm.paging.Context.make_user() catch |err| { std.log.err("Failed to make user context! {}", .{err}); @panic("make_user_ctx"); }; // 2. Allocate a user stack mm.paging.map(.{ .vaddr = 0x7ffe_0000_0000, .size = 65536, .memory_type = .MemoryWriteBack, .perms = .{ .x = false, .u = true, .w = true, }, .context = &user_ctx, }) catch @panic("couldn't map user stack"); // 3. Map ELF into address space const entry = loadElf(&user_ctx, task_slice) catch |err| { std.log.err("Couldn't load the root task! {}", .{err}); @panic("ggz"); }; // 4. Add task to scheduler scratch.* = .{ .cr3_val = user_ctx.cr3_val, .regs = .default, .rip = entry, .rsp = 0x7ffe_0001_0000, }; scheduler.pushTask(scratch); } // std options etc. pub const panic = std.debug.FullPanic(aux.panic); pub const std_options: std.Options = .{ .logFn = aux.logFn, .page_size_min = arch.page_size.min, .page_size_max = arch.page_size.max, .queryPageSize = arch.page_size.get, }; comptime { // Entry point (_start) @export(&generic_init, .{ .name = "_start", .linkage = .strong }); }