Refactor and use the Multiboot info struct
This commit is contained in:
parent
a5c560d2b9
commit
2e9292be6e
2 changed files with 125 additions and 15 deletions
44
src/main.zig
44
src/main.zig
|
|
@ -1,21 +1,23 @@
|
|||
const lazy = @import("utils/Lazy.zig").lazy;
|
||||
const Console = @import("Console.zig");
|
||||
const MultibootInfo = @import("multiboot.zig").Info;
|
||||
|
||||
const MultibootHeader = packed struct {
|
||||
magic: i32,
|
||||
flags: i32,
|
||||
checksum: i32,
|
||||
padding: u32,
|
||||
};
|
||||
|
||||
const ALIGN = 1 << 0;
|
||||
const MEMINFO = 1 << 1;
|
||||
const MAGIC = 0x1BADB002;
|
||||
const FLAGS = ALIGN | MEMINFO;
|
||||
|
||||
const MultibootHeader = packed struct {
|
||||
magic: i32 = MAGIC,
|
||||
flags: i32,
|
||||
checksum: i32,
|
||||
padding: u32 = 0,
|
||||
};
|
||||
|
||||
export var mutliboot: MultibootHeader align(4) linksection(".multiboot") = .{
|
||||
.magic = MAGIC,
|
||||
.flags = FLAGS,
|
||||
.checksum = -(MAGIC + FLAGS),
|
||||
.padding = 0,
|
||||
};
|
||||
|
||||
var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
|
||||
|
|
@ -24,6 +26,8 @@ export fn _start() callconv(.naked) noreturn {
|
|||
asm volatile (
|
||||
\\ movl %[stack_top], %%esp
|
||||
\\ movl %%esp, %%ebp
|
||||
\\ push %%ebx
|
||||
\\ push %%eax
|
||||
\\ call %[kmain:P]
|
||||
:
|
||||
: [stack_top] "i" (@as([*]align(16) u8, @ptrCast(&stack_bytes)) + @sizeOf(@TypeOf(stack_bytes))),
|
||||
|
|
@ -33,13 +37,23 @@ export fn _start() callconv(.naked) noreturn {
|
|||
|
||||
var console = lazy(Console, .init);
|
||||
|
||||
fn kmain() callconv(.C) void {
|
||||
std.log.info("This is an info message", .{});
|
||||
std.log.debug("This is a debug message!", .{});
|
||||
std.log.warn("This is a warning message!", .{});
|
||||
std.log.err("This is an error message!", .{});
|
||||
fn kmain(magic: u32, info: *const MultibootInfo) callconv(.c) void {
|
||||
std.debug.assert(magic == MAGIC);
|
||||
|
||||
@panic("Uh oh");
|
||||
std.log.info("{any}", .{info});
|
||||
|
||||
if (info.isValid(.boot_loader_name)) {
|
||||
std.log.info("Booted by {s}", .{info.boot_loader_name});
|
||||
}
|
||||
if (info.isValid(.cmdline)) {
|
||||
std.log.info("Booted with cmdline \"{s}\"", .{info.cmdline});
|
||||
}
|
||||
|
||||
hang();
|
||||
}
|
||||
|
||||
fn hang() noreturn {
|
||||
while (true) asm volatile ("hlt");
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
|
|
@ -51,7 +65,7 @@ fn kpanic(msg: []const u8, first_trace_addr: ?usize) noreturn {
|
|||
|
||||
std.log.err("PANIC: {s}", .{msg});
|
||||
|
||||
while (true) {}
|
||||
hang();
|
||||
}
|
||||
|
||||
pub const std_options = std.Options{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue