Add logging

This commit is contained in:
Sam Tebbs 2019-06-22 10:00:57 +01:00 committed by SamTebbs33
parent 1b8244adfa
commit 7e5b7b2331
6 changed files with 45 additions and 3 deletions

View file

@ -5,6 +5,7 @@ const gdt = @import("gdt.zig");
const idt = @import("idt.zig"); const idt = @import("idt.zig");
const irq = @import("irq.zig"); const irq = @import("irq.zig");
const isr = @import("isr.zig"); const isr = @import("isr.zig");
const log = @import("../../log.zig");
pub const InterruptContext = struct { pub const InterruptContext = struct {
// Extra segments // Extra segments

View file

@ -1,6 +1,7 @@
// Zig version: 0.4.0 // Zig version: 0.4.0
const arch = @import("arch.zig"); const arch = @import("arch.zig");
const log = @import("../../log.zig");
const NUMBER_OF_ENTRIES: u16 = 0x06; const NUMBER_OF_ENTRIES: u16 = 0x06;
const TABLE_SIZE: u16 = @sizeOf(GdtEntry) * NUMBER_OF_ENTRIES - 1; const TABLE_SIZE: u16 = @sizeOf(GdtEntry) * NUMBER_OF_ENTRIES - 1;
@ -295,6 +296,7 @@ pub fn setTssStack(esp0: u32) void {
/// Initialise the Global Descriptor table /// Initialise the Global Descriptor table
/// ///
pub fn init() void { pub fn init() void {
log.logInfo("Init gdt\n");
// Initiate TSS // Initiate TSS
gdt_entries[TSS_INDEX] = makeEntry(@ptrToInt(&tss), @sizeOf(TtsEntry) - 1, TSS_SEGMENT, 0); gdt_entries[TSS_INDEX] = makeEntry(@ptrToInt(&tss), @sizeOf(TtsEntry) - 1, TSS_SEGMENT, 0);

View file

@ -2,6 +2,7 @@
const gdt = @import("gdt.zig"); const gdt = @import("gdt.zig");
const arch = @import("arch.zig"); const arch = @import("arch.zig");
const log = @import("../../log.zig");
const NUMBER_OF_ENTRIES: u16 = 256; const NUMBER_OF_ENTRIES: u16 = 256;
const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1; const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1;
@ -119,5 +120,6 @@ pub fn closeInterruptGate(index: u8) void {
/// Initialise the Interrupt descriptor table /// Initialise the Interrupt descriptor table
/// ///
pub fn init() void { pub fn init() void {
log.logInfo("Init idt\n");
arch.lidt(&idt_ptr); arch.lidt(&idt_ptr);
} }

View file

@ -5,6 +5,7 @@ const arch = if (builtin.is_test) @import("../../test/kernel/arch_mock.zig") els
const multiboot = @import("multiboot.zig"); const multiboot = @import("multiboot.zig");
const tty = @import("tty.zig"); const tty = @import("tty.zig");
const vga = @import("vga.zig"); const vga = @import("vga.zig");
const log = @import("log.zig");
const serial = @import("serial.zig"); const serial = @import("serial.zig");
// Need to import this as we need the panic to be in the root source file, or zig will just use the // Need to import this as we need the panic to be in the root source file, or zig will just use the
@ -21,11 +22,14 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
pub export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void { pub export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
if (mb_magic == multiboot.MULTIBOOT_BOOTLOADER_MAGIC) { if (mb_magic == multiboot.MULTIBOOT_BOOTLOADER_MAGIC) {
// Booted with compatible bootloader // Booted with compatible bootloader
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch unreachable;
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n");
arch.init(); arch.init();
vga.init(); vga.init();
tty.init(); tty.init();
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch unreachable;
log.logInfo("Finished init\n");
tty.print("Hello Pluto from kernel :)\n"); tty.print("Hello Pluto from kernel :)\n");
// Enable interrupts // Enable interrupts

31
src/kernel/log.zig Normal file
View file

@ -0,0 +1,31 @@
const serial = @import("serial.zig");
const fmt = @import("std").fmt;
pub const Level = enum {
INFO,
DEBUG,
WARNING,
ERROR
};
fn logCallback(context: void, str: []const u8) anyerror!void {
serial.writeString(str, serial.Port.COM1);
}
pub fn log(comptime level: Level, comptime format: []const u8, args: ...) void {
fmt.format({}, anyerror, logCallback, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
}
pub fn logInfo(comptime format: []const u8, args: ...) void {
log(Level.INFO, format, args);
}
pub fn logDebug(comptime format: []const u8, args: ...) void {
log(Level.DEBUG, format, args);
}
pub fn logWarning(comptime format: []const u8, args: ...) void {
log(Level.WARNING, format, args);
}
pub fn logError(comptime format: []const u8, args: ...) void {
log(Level.ERROR, format, args);
}

View file

@ -1,6 +1,7 @@
// Zig version: 0.4.0 // Zig version: 0.4.0
const vga = @import("vga.zig"); const vga = @import("vga.zig");
const log = @import("log.zig");
const expectEqual = @import("std").testing.expectEqual; const expectEqual = @import("std").testing.expectEqual;
const expectError = @import("std").testing.expectError; const expectError = @import("std").testing.expectError;
@ -594,6 +595,7 @@ pub fn setColour(new_colour: u8) void {
/// blank /// blank
/// ///
pub fn init() void { pub fn init() void {
log.logInfo("Init tty\n");
// Video buffer in higher half // Video buffer in higher half
video_buffer = @intToPtr([*]volatile u16, 0xC00B8000)[0..VIDEO_BUFFER_SIZE]; video_buffer = @intToPtr([*]volatile u16, 0xC00B8000)[0..VIDEO_BUFFER_SIZE];
setColour(vga.entryColour(vga.COLOUR_LIGHT_GREY, vga.COLOUR_BLACK)); setColour(vga.entryColour(vga.COLOUR_LIGHT_GREY, vga.COLOUR_BLACK));