From e42481c2d37527e228060081402bf933665b1d61 Mon Sep 17 00:00:00 2001 From: Linuxperoxo Date: Mon, 1 Sep 2025 21:34:25 -0300 Subject: [PATCH 1/2] adding klog on boot --- config/modules/options.zig | 1 - kernel/klog/core.zig | 5 +++++ kernel/klog/types.zig | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 kernel/klog/core.zig create mode 100644 kernel/klog/types.zig diff --git a/config/modules/options.zig b/config/modules/options.zig index 4554b76..99b9fe8 100644 --- a/config/modules/options.zig +++ b/config/modules/options.zig @@ -5,5 +5,4 @@ pub const UseMenuconfigAsRef: bool = true; pub const IgnoreModuleWithArchNotSupported: bool = false; -pub const DinamicModulesLoad: bool = true; pub const AllowDynamicModulesLoad: bool = true; diff --git a/kernel/klog/core.zig b/kernel/klog/core.zig new file mode 100644 index 0000000..cb10570 --- /dev/null +++ b/kernel/klog/core.zig @@ -0,0 +1,5 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: core.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ + diff --git a/kernel/klog/types.zig b/kernel/klog/types.zig new file mode 100644 index 0000000..8053bf3 --- /dev/null +++ b/kernel/klog/types.zig @@ -0,0 +1,4 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: types.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ From 004aa03dd165b6b649fe5f38c98d96436ec977b5 Mon Sep 17 00:00:00 2001 From: Linuxperoxo Date: Mon, 29 Sep 2025 12:34:48 -0300 Subject: [PATCH 2/2] adding base to saturn kprint --- .../klog/core.zig => config/boot/config.zig | 3 +- config/boot/options.zig | 9 +++++ kernel/init/kprint.zig | 0 kernel/kernel.zig | 9 +++++ kernel/stage/stage.zig | 16 +++++++++ kernel/{klog/types.zig => stage/type.zig} | 6 ++++ lib/saturn/kernel/x86/io/console/console.zig | 20 +++++++++++ lib/saturn/kernel/x86/io/console/impl.zig | 34 +++++++++++++++++++ lib/saturn/kernel/x86/io/io.zig | 1 + saturn.zig | 2 ++ 10 files changed, 99 insertions(+), 1 deletion(-) rename kernel/klog/core.zig => config/boot/config.zig (76%) create mode 100644 config/boot/options.zig delete mode 100644 kernel/init/kprint.zig create mode 100644 kernel/stage/stage.zig rename kernel/{klog/types.zig => stage/type.zig} (85%) create mode 100644 lib/saturn/kernel/x86/io/console/console.zig create mode 100644 lib/saturn/kernel/x86/io/console/impl.zig diff --git a/kernel/klog/core.zig b/config/boot/config.zig similarity index 76% rename from kernel/klog/core.zig rename to config/boot/config.zig index cb10570..88d4384 100644 --- a/kernel/klog/core.zig +++ b/config/boot/config.zig @@ -1,5 +1,6 @@ // ┌──────────────────────────────────────────────┐ -// │ (c) 2025 Linuxperoxo • FILE: core.zig │ +// │ (c) 2025 Linuxperoxo • FILE: config.zig │ // │ Author: Linuxperoxo │ // └──────────────────────────────────────────────┘ +pub const options: type = @import("options.zig"); diff --git a/config/boot/options.zig b/config/boot/options.zig new file mode 100644 index 0000000..953f823 --- /dev/null +++ b/config/boot/options.zig @@ -0,0 +1,9 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: options.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ + +pub const VerboseMode: bool = true; +pub const MultiBootScreen: bool = true; +pub const SaturnLogo: bool = true; +pub const RecoveryModeEnable: bool = true; diff --git a/kernel/init/kprint.zig b/kernel/init/kprint.zig deleted file mode 100644 index e69de29..0000000 diff --git a/kernel/kernel.zig b/kernel/kernel.zig index a94aa31..d8a026a 100644 --- a/kernel/kernel.zig +++ b/kernel/kernel.zig @@ -16,6 +16,9 @@ pub const userspace: type = saturn.lib.userspace; pub const utils: type = saturn.lib.utils; pub const config: type = saturn.config; pub const modules: type = saturn.modules; +pub const stage: type = struct { + pub const get = saturn.stage.stageGet; +}; const loader: type = saturn.loader; @@ -67,8 +70,14 @@ fn @"saturn.main"() callconv(.c) void { // ou usando somente loader.SaturnArch, isso evita de criar um possivel .never_inline // implicito @call(.always_inline, loader.SaturnArch, .{}); + @call(.always_inline, saturn.stage.stageSwitch, .{ + .init + }); // Depois da arquitetura resolver todos os seus detalhes, podemos iniciar // os modulos linkados ao kernel @call(.always_inline, loader.SaturnModules, .{}); + @call(.always_inline, saturn.stage.stageSwitch, .{ + .runtime + }); } diff --git a/kernel/stage/stage.zig b/kernel/stage/stage.zig new file mode 100644 index 0000000..f33725a --- /dev/null +++ b/kernel/stage/stage.zig @@ -0,0 +1,16 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: stage.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ + +const Stage_T: type = @import("stage.zig").Stage_T; + +var saturnStage: Stage_T = .boot; + +pub fn stageSwitch(stage: Stage_T) void { + saturnStage = stage; +} + +pub fn stageGet() Stage_T { + return saturnStage; +} diff --git a/kernel/klog/types.zig b/kernel/stage/type.zig similarity index 85% rename from kernel/klog/types.zig rename to kernel/stage/type.zig index 8053bf3..3990943 100644 --- a/kernel/klog/types.zig +++ b/kernel/stage/type.zig @@ -2,3 +2,9 @@ // │ (c) 2025 Linuxperoxo • FILE: types.zig │ // │ Author: Linuxperoxo │ // └──────────────────────────────────────────────┘ + +pub const Stage_T: type = enum { + boot, + init, + runtime, +}; diff --git a/lib/saturn/kernel/x86/io/console/console.zig b/lib/saturn/kernel/x86/io/console/console.zig new file mode 100644 index 0000000..9d234f8 --- /dev/null +++ b/lib/saturn/kernel/x86/io/console/console.zig @@ -0,0 +1,20 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: console.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ + +const impl: type = @import("impl.zig"); +const stage: type = @import("root").stage; + +const vtable = [_]*const fn([]u8) void { + &impl.boot.kprint, + &impl.init.kprint, + &impl.runtime.kprint, +}; + +// Global kprint +pub fn kprint(str: []u8) void { + @call(.never_inline, vtable[@intFromEnum(stage.get)], .{ + str + }); +} diff --git a/lib/saturn/kernel/x86/io/console/impl.zig b/lib/saturn/kernel/x86/io/console/impl.zig new file mode 100644 index 0000000..2c32d34 --- /dev/null +++ b/lib/saturn/kernel/x86/io/console/impl.zig @@ -0,0 +1,34 @@ +// ┌──────────────────────────────────────────────┐ +// │ (c) 2025 Linuxperoxo • FILE: impl.zig │ +// │ Author: Linuxperoxo │ +// └──────────────────────────────────────────────┘ + +pub const init: type = struct { + pub fn kprint(str: []u8) void { + @call(.never_inline, boot.kprint, .{ + str + }); + } +}; +pub const boot: type = struct { + const ScreenContext_T: type = struct { + fb: []u8, + row: usize, + col: usize, + }; + + var screenContext: ScreenContext_T = .{ + .fb = @as([*]u8, @ptrFromInt(0xB8000))[0..80 * 25], + .row = 0, + .col = 0, + }; + + pub fn kprint(str: []u8) void { + + } +}; +pub const runtime: type = struct { + pub fn kprint(str: []u8) void { + + } +}; diff --git a/lib/saturn/kernel/x86/io/io.zig b/lib/saturn/kernel/x86/io/io.zig index 01be429..9d0573c 100644 --- a/lib/saturn/kernel/x86/io/io.zig +++ b/lib/saturn/kernel/x86/io/io.zig @@ -5,3 +5,4 @@ pub const ports: type = @import("ports.zig"); pub const pci: type = @import("pci.zig"); +pub const console: type = @import("console.zig"); diff --git a/saturn.zig b/saturn.zig index 0b0ca5d..844bc3b 100644 --- a/saturn.zig +++ b/saturn.zig @@ -87,6 +87,7 @@ pub const core: type = struct { pub const fs: type = @import("kernel/core/fs/fs.zig"); pub const drivers: type = @import("kernel/core/drivers/drivers.zig"); }; +pub const stage: type = @import("kernel/stage/stage.zig"); pub const loader: type = @import("kernel/loader.zig"); pub const modules: type = @import("modules.zig"); pub const memory: type = @import("kernel/memory/memory.zig"); @@ -107,4 +108,5 @@ pub const lib: type = struct { pub const config: type = struct { pub const modules: type = @import("config/modules/config.zig"); pub const arch: type = @import("config/arch/config.zig"); + pub const boot: type = @import("config/boot/config.zig"); };