main.zig
1 const std = @import("std"); 2 3 const boot = @import("boot.zig"); 4 const debug = @import("debug.zig"); 5 6 var buffer: [0]u8 = undefined; 7 var writer = debug.writer(&buffer); 8 9 pub fn main(info: boot.Info) !void { 10 _ = info; 11 std.log.info("Lightning 🗲", .{}); 12 } 13 14 // load the proper entry point for the architecture 15 const builtin = @import("builtin"); 16 17 comptime { 18 _ = switch (builtin.cpu.arch) { 19 .riscv64, .riscv32 => @import("riscv/setup.zig"), 20 else => @compileError("Unsupported architecture"), 21 }; 22 } 23 24 // std setup 25 pub const panic = std.debug.FullPanic(panicFn); 26 27 fn panicFn(msg: []const u8, maybe_addr: ?usize) noreturn { 28 if (maybe_addr) |addr| { 29 std.log.err("PANIC: {s} at {x}", .{ msg, addr }); 30 } else { 31 std.log.err("PANIC: {s}", .{msg}); 32 } 33 while (true) {} 34 } 35 36 pub const std_options: std.Options = .{ 37 .log_level = .debug, 38 39 .logFn = logFn, 40 }; 41 42 fn logFn( 43 comptime level: std.log.Level, 44 comptime scope: @Type(.enum_literal), 45 comptime format: []const u8, 46 args: anytype, 47 ) void { 48 const prefix = "[" ++ comptime level.asText() ++ "] " ++ "(" ++ @tagName(scope) ++ "): "; 49 50 writer.print(prefix ++ format ++ "\n", args) catch {}; 51 }