Microkernel thing OS experiment (Zig ⚡)

use ziggified flanterm

pci.express 3590420c 9d05e8fa

verified
Changed files
+59 -118
components
ukernel
+51 -50
components/ukernel/arch/amd64/boot.zig
···
const fb = common.aux.Framebuffer.from_limine(fb_response.getFramebuffers()[0]);
common.init_data.framebuffer = fb;
-
// Set the font scaling depending on screen resolution
-
const font_scale_x: usize, const font_scale_y: usize = blk: {
-
if (fb.width >= 2560 and fb.height >= 1440) {
-
break :blk .{ 2, 2 };
-
} else if (fb.width >= 5120 and fb.height >= 2880) {
-
break :blk .{ 4, 4 };
-
} else {
-
break :blk .{ 1, 1 };
-
}
-
};
-
-
common.init_data.console = flanterm.init(
-
//malloc and free
-
null,
-
null,
-
// fb info
-
fb.address,
-
fb.width,
-
fb.height,
-
fb.pitch,
-
fb.red_mask_size,
-
fb.red_mask_shift,
-
fb.green_mask_size,
-
fb.green_mask_shift,
-
fb.blue_mask_size,
-
fb.blue_mask_shift,
-
// canvas
-
null,
-
// colors
-
flanterm.ansi_colors,
-
flanterm.bold_ansi_colors,
-
// default bg and fg
-
null,
-
null,
-
// default bright bg and fg
-
null,
-
null,
-
// font
-
null,
-
// font width and height
-
0,
-
0,
-
// font spacing
-
1,
-
// font scale x and y
-
font_scale_x,
-
font_scale_y,
-
// margin
-
0,
-
);
}
}
}
···
const fb = common.aux.Framebuffer.from_limine(fb_response.getFramebuffers()[0]);
common.init_data.framebuffer = fb;
+
common.init_data.console = flanterm.Context.init(.{
+
.fb = fb.address,
+
.width = fb.width,
+
.height = fb.height,
+
.pitch = fb.pitch,
+
.red_mask_size = fb.red_mask_size,
+
.red_mask_shift = fb.red_mask_shift,
+
.green_mask_size = fb.green_mask_size,
+
.green_mask_shift = fb.green_mask_shift,
+
.blue_mask_size = fb.blue_mask_size,
+
.blue_mask_shift = fb.blue_mask_shift,
+
});
+
// common.init_data.console = flanterm.init(
+
// //malloc and free
+
// null,
+
// null,
+
// // fb info
+
// fb.address,
+
// fb.width,
+
// fb.height,
+
// fb.pitch,
+
// fb.red_mask_size,
+
// fb.red_mask_shift,
+
// fb.green_mask_size,
+
// fb.green_mask_shift,
+
// fb.blue_mask_size,
+
// fb.blue_mask_shift,
+
// // canvas
+
// null,
+
// // colors
+
// flanterm.ansi_colors,
+
// flanterm.bold_ansi_colors,
+
// // default bg and fg
+
// null,
+
// null,
+
// // default bright bg and fg
+
// null,
+
// null,
+
// // font
+
// null,
+
// // font width and height
+
// 0,
+
// 0,
+
// // font spacing
+
// 1,
+
// // font scale x and y
+
// font_scale_x,
+
// font_scale_y,
+
// // margin
+
// 0,
+
// );
}
}
}
+1 -6
components/ukernel/build.zig
···
const limine_mod = limine_dep.module("limine");
const spinlock_mod = spinlock_dep.module("spinlock");
-
const flanterm_mod = b.createModule(.{
-
.root_source_file = b.path("common/aux/flanterm.zig"),
-
});
-
flanterm_mod.addIncludePath(flanterm_dep.path("src"));
-
flanterm_mod.addCSourceFile(.{ .file = flanterm_dep.path("src/flanterm.c") });
-
flanterm_mod.addCSourceFile(.{ .file = flanterm_dep.path("src/flanterm_backends/fb.c") });
const common_mod = b.createModule(.{
.root_source_file = b.path("common/root.zig"),
···
const limine_mod = limine_dep.module("limine");
const spinlock_mod = spinlock_dep.module("spinlock");
+
const flanterm_mod = flanterm_dep.module("flanterm");
const common_mod = b.createModule(.{
.root_source_file = b.path("common/root.zig"),
+2 -3
components/ukernel/build.zig.zon
···
.dependencies = .{
.limine = .{ .path = "deps/limine-zig" },
.spinlock = .{ .path = "deps/spinlock" },
-
.console = .{ .path = "deps/console" },
.build_helpers = .{ .path = "../build_helpers" },
.flanterm = .{
-
.url = "git+https://codeberg.org/Mintsuki/Flanterm.git?ref=trunk#55d228ff16234513b0df0dd12de8bc58160fc196",
-
.hash = "N-V-__8AAIPRAQD-ppISTB_g_r_WTCC2e2vDOaJYZc5uhy4w",
},
},
.paths = .{
···
.dependencies = .{
.limine = .{ .path = "deps/limine-zig" },
.spinlock = .{ .path = "deps/spinlock" },
.build_helpers = .{ .path = "../build_helpers" },
.flanterm = .{
+
.url = "git+https://tangled.sh/@sydney.blue/flanterm.zig?ref=trunk#8071c825750c415b9e5502cdff34efc9c6dfeab7",
+
.hash = "flanterm-2.0.0-QnufngHlAQCGtHyca0PrvRvoOldHdJG4DdSz437r9fRr",
},
},
.paths = .{
-54
components/ukernel/common/aux/flanterm.zig
···
-
pub const c = @cImport({
-
@cInclude("flanterm.h");
-
@cInclude("flanterm_backends/fb.h");
-
});
-
-
pub const ctx = c.struct_flanterm_context;
-
-
pub const init = c.flanterm_fb_init;
-
-
pub const Color = enum(u8) {
-
black = 30,
-
red = 31,
-
green = 32,
-
yellow = 33,
-
blue = 34,
-
magenta = 35,
-
cyan = 36,
-
white = 37,
-
default = 39,
-
bright_black = 90,
-
bright_red = 91,
-
bright_green = 92,
-
bright_yellow = 93,
-
bright_blue = 94,
-
bright_magenta = 95,
-
bright_cyan = 96,
-
bright_white = 97,
-
};
-
-
var ansi_colors_backing = [8]u32{
-
0x000000, // Black
-
0xff0000, // Red
-
0x37dd21, // Green
-
0xfee409, // Yellow
-
0x1460d2, // Blue
-
0xff005d, // Magenta
-
0x00bbbb, // Cyan
-
0xbbbbbb, // White
-
};
-
pub const ansi_colors: [*]u32 = @ptrCast(&ansi_colors_backing);
-
-
var bold_ansi_colors_backing = [8]u32{
-
0x545454, // Black
-
0xf40d17, // Red
-
0x3bcf1d, // Green
-
0xecc809, // Yellow
-
0x5555ff, // Blue
-
0xff55ff, // Magenta
-
0x6ae3f9, // Cyan
-
0xffffff, // White
-
};
-
pub const bold_ansi_colors: [*]u32 = @ptrCast(&ansi_colors_backing);
-
-
pub const esc_end = "\x1b[0m";
···
+5 -5
components/ukernel/common/aux/root.zig
···
pub const InitState = struct {
bootmem: mm.bootmem.BootPmm = .{},
-
console: ?*flanterm.ctx = null,
framebuffer: ?common.aux.Framebuffer = null,
hardware_description: HardwareDescription = .none,
root_task: []align(4096) u8 = undefined,
···
if (common.init_data.console == null) return;
// Use the same naming as the default logger
-
const level, const color: flanterm.Color = switch (message_level) {
.debug => .{ "D", .green },
.err => .{ "E", .red },
.info => .{ "I", .cyan },
···
const prefix = std.fmt.comptimePrint("{s}{s}: ", .{ level, scope_text });
{
-
const esc_seq = std.fmt.comptimePrint("\x1b[{}m", .{@intFromEnum(color)});
stdout_lock.lock();
defer stdout_lock.unlock();
var backing_buf = std.mem.zeroes([512]u8);
-
const buf = std.fmt.bufPrint(backing_buf[0..], esc_seq ++ prefix ++ format ++ flanterm.esc_end ++ "\n", args) catch return;
-
flanterm.c.flanterm_write(common.init_data.console, buf.ptr, buf.len);
// cons.setColor(color, 0);
// cons.writer().print(prefix ++ format ++ "\n", args) catch return;
}
···
pub const InitState = struct {
bootmem: mm.bootmem.BootPmm = .{},
+
console: ?flanterm.Context = null,
framebuffer: ?common.aux.Framebuffer = null,
hardware_description: HardwareDescription = .none,
root_task: []align(4096) u8 = undefined,
···
if (common.init_data.console == null) return;
// Use the same naming as the default logger
+
const level, const color: flanterm.Colors.Color = switch (message_level) {
.debug => .{ "D", .green },
.err => .{ "E", .red },
.info => .{ "I", .cyan },
···
const prefix = std.fmt.comptimePrint("{s}{s}: ", .{ level, scope_text });
{
+
const color_default: flanterm.Colors.Color = .default;
stdout_lock.lock();
defer stdout_lock.unlock();
var backing_buf = std.mem.zeroes([512]u8);
+
const buf = std.fmt.bufPrint(backing_buf[0..], color.esc_seq() ++ prefix ++ format ++ color_default.esc_seq() ++ "\n", args) catch return;
+
common.init_data.console.?.write_slice(buf);
// cons.setColor(color, 0);
// cons.writer().print(prefix ++ format ++ "\n", args) catch return;
}