osdev/kernel.zig
2025-05-04 08:42:28 -07:00

71 lines
1.5 KiB
Zig

const vga = struct {
const width = 80;
const height = 25;
const screen: *[width * height]Cell = @ptrFromInt(0xB8000);
const Cell = packed struct(u16) {
char: u8,
style: Style = .default,
const blank: Cell = .{ .char = ' ' };
};
const Style = packed struct(u8) {
fg: Color,
bg: Color,
pub const default: Style = .{
.fg = .black,
.bg = .light_cyan,
};
};
const Color = enum(u4) {
black = 0,
blue = 1,
green = 2,
cyan = 3,
red = 4,
magenta = 5,
brown = 6,
light_grey = 7,
dark_grey = 8,
light_blue = 9,
light_green = 10,
light_cyan = 11,
light_red = 12,
light_magenta = 13,
light_brown = 14,
white = 15,
};
fn init() void {
@memset(screen, .blank);
}
fn set(x: u32, y: u32, cell: Cell) void {
screen[x + y * width] = cell;
}
};
var current_x: u32 = 0;
var current_y: u32 = 0;
fn writeString(slice: []const u8, style: vga.Style) void {
for (slice) |char| {
vga.set(current_x, current_y, .{ .char = char, .style = style });
current_x += 1;
if (current_x >= vga.width) {
current_x = 0;
current_y += 1;
if (current_y >= vga.height) {
current_y = 0;
}
}
}
}
export fn kernel_main() callconv(.c) void {
vga.init();
writeString("Hello Kernel", .default);
}