const std = @import("std");

extern fn console_write(ptr: [*]const u8, len: usize) void;

// Embed the Subject Zero binary
export var subject_bin = @embedFile("subject.bin");

export fn launch_subject() void {
    const target_addr: usize = 0x84000000;
    const dest = @as([*]u8, @ptrFromInt(target_addr));

    console_write("[Loader] Loading Subject Zero...\n", 33);
    @memcpy(dest[0..subject_bin.len], subject_bin);

    console_write("[Loader] Jumping...\n", 20);

    const entry = @as(*const fn () void, @ptrFromInt(target_addr));
    entry();
}

pub fn panic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
    console_write("[Loader] PANIC: ", 16);
    console_write(msg.ptr, msg.len);
    console_write("\n", 1);
    while (true) {}
}
