Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/kernel/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ pub const keyboard_event: types.EventDefaultInstall_T = .{ .bus = 0, .line = 7,
pub const mouse_event: types.EventDefaultInstall_T = .{ .bus = 1, .line = 7, .who = 32 };
pub const csi_event: types.EventDefaultInstall_T = .{ .bus = 2, .line = 7, .who = 64};
pub const timer_event: types.EventDefaultInstall_T = .{ .bus = 3, .line = 7, .who = 128};
pub const kparam_enable: bool = true;
pub const kparam_dynamic: bool = false;
pub const kparam_config_file: ?[]const u8 = null; // default ".kparam.config";
28 changes: 16 additions & 12 deletions kernel/kernel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ pub const modules: type = saturn.modules;
pub const decls: type = saturn.decls;
pub const fusioners: type = saturn.fusioners;
pub const codes: type = saturn.codes;
pub const modsys: type = struct {
const core: type = saturn.modsys.core;
pub const kparam: type = opaque {
pub const params_search = saturn.kparam.params_search;
const params_loader = saturn.kparam.params_loader;
};
pub const modsys: type = opaque {
pub const modules: type = saturn.modsys.modules;
pub const smll: type = saturn.modsys.smll;
const core: type = saturn.modsys.core;
};

const fusium: type = saturn.fusium;
Expand Down Expand Up @@ -54,7 +58,15 @@ comptime {
_ = csl; // carregado c sources
}

fn saturn_main() callconv(.c) noreturn {
fn saturn_main(kparams: []const u8) callconv(.c) noreturn {
// carregamos e os parametros do kernel que foi passado pelo
// bootloader ou estaticamente na compilacao
if(comptime config.kernel.options.kparam_enable) {
@call(.always_inline, kparam.params_loader, .{
if(config.kernel.options.kparam_dynamic) kparams else
@embedFile(config.kernel.options.kparam_config_file)
});
}
// Aqui existe um pequeno detalhe, bem interessante por sinal.
// Quando passamos um ponteiro para uma funcao conhecida em tempo
// de compilacao para o @call, o compilador precisa considerar que
Expand All @@ -74,14 +86,6 @@ fn saturn_main() callconv(.c) noreturn {
// Depois da arquitetura resolver todos os seus detalhes, podemos iniciar
// os modulos linkados ao kernel
@call(.always_inline, modsys.core.saturn_modules_loader, .{});
//@call(.always_inline, fusium.saturn_fusium_loader, .{ .after });

//modules.__SaturnAllMods__[1].create_device_node() catch {
// asm volatile(
// \\ jmp .
// \\ jmp 0xAA000
// );
//};

@call(.always_inline, fusium.saturn_fusium_loader, .{ .after });
@call(.always_inline, opaque { pub fn trap() noreturn { while(true) {} } }.trap, .{}); // noreturn fn
}
12 changes: 12 additions & 0 deletions kernel/kparam/allocator.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ┌─────────────────────────────────────────────────┐
// │ (c) 2026 Linuxperoxo • FILE: allocator.zig │
// │ Author: Linuxperoxo │
// └─────────────────────────────────────────────────┘

const buildByteAllocator = @import("root").lib.memory.sba.buildByteAllocator;

pub const sba: type = struct {
pub var allocator = buildByteAllocator(null, .{
.resize = true,
}) {};
};
33 changes: 33 additions & 0 deletions kernel/kparam/kparam.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ┌──────────────────────────────────────────────┐
// │ (c) 2026 Linuxperoxo • FILE: kparam.zig │
// │ Author: Linuxperoxo │
// └──────────────────────────────────────────────┘

const types: type = @import("types.zig");
const parser: type = @import("parser.zig");
const allocator: type = @import("allocator.zig");

var sys_param: types.Params_T = .{};

pub inline fn params_loader(params: []const u8) void {
const parsed_params: []const types.Param_T = parser.params_parser(params) catch |err| {
_ = err;
// KLOG()
return;
};
for(0..parsed_params.len) |i| {
sys_param.add(
parsed_params[i].param,
parsed_params[i].value,
&allocator.sba.allocator
) catch |err| {
_ = err;
// KLOG()
};
}
}

pub noinline fn params_search(param: []const u8) types.KParamErr_T!types.Value_T {
return sys_param.search(param)
catch return types.KParamErr_T.SysParamNotFound;
}
95 changes: 95 additions & 0 deletions kernel/kparam/parser.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ┌──────────────────────────────────────────────┐
// │ (c) 2026 Linuxperoxo • FILE: parser.zig │
// │ Author: Linuxperoxo │
// └──────────────────────────────────────────────┘

const builtin: type = @import("builtin");
const types: type = @import("types.zig");
const allocator: type = @import("allocator.zig");
const mem: type = @import("root").lib.utils.mem;

pub inline fn params_parser(params: []const u8) types.KParamErr_T![]const types.Param_T {
var rvalue: bool = false;
var local_index: usize = 0;
var parsed_index: usize = 0;

const parsed_params: []types.Param_T = allocator.sba.allocator.alloc(
types.Param_T,
params_counter(params)
) catch return types.KParamErr_T.AllocatorInternalError;
errdefer allocator.sba.allocator.free(parsed_params)
catch {};

var i: usize = 0;
for(params) |char| {
sw: switch(char) {
';', '\n' => {
defer {
local_index = i + 1;
parsed_index += 1;
rvalue = false;
}
if(mem.eql(params[local_index..i], @tagName(types.Value_T.yes), .{})) {
parsed_params[parsed_index].value = types.Value_T.yes;
break :sw {};
}
if(mem.eql(params[local_index..i], @tagName(types.Value_T.no), .{})) {
parsed_params[parsed_index].value = types.Value_T.no;
break :sw {};
}
return types.KParamErr_T.ParserInvalidValue;
},

'=' => {
if(rvalue) return types.KParamErr_T.ParserSyntaxError;
if(local_index >= i) return types.KParamErr_T.ParserMissingParameter;
if((i + 1) == params.len) return types.KParamErr_T.ParserMissingValue;

switch(params[i + 1]) {
'\n', ' ' => return types.KParamErr_T.ParserMissingValue,
else => {},
}

parsed_params[parsed_index].param = params[local_index..i];
local_index = i + 1;
rvalue = true;
},

' ' => {
if(rvalue) continue :sw '\n';
local_index += 1;
},

else => {
if((i + 1) >= params.len) {
i += 1;
continue :sw '\n';
}
},
}
i += 1;
}
return parsed_params;
}

inline fn params_counter(params: []const u8) usize {
var counter: usize = 0;
for(params) |char|
counter += @intFromBool(char == '=');
return counter;
}

test "Parsing Test" {
const std: type = @import("std");
const kernel_param: []const u8 =
\\sysmod_disable_devfs=yes
\\sysmod_enable_devfs=no
;

for(try params_parser(kernel_param)) |parsed_param| {
std.debug.print("{s} = {s}\n", .{
parsed_param.param,
@tagName(parsed_param.value),
});
}
}
32 changes: 32 additions & 0 deletions kernel/kparam/types.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ┌─────────────────────────────────────────────┐
// │ (c) 2026 Linuxperoxo • FILE: types.zig │
// │ Author: Linuxperoxo │
// └─────────────────────────────────────────────┘

const hashtable: type = @import("root").lib.utils.hashtable;

pub const KParamErr_T: type = error {
SysParamNotFound,
AllocatorInternalError,
ParserSyntaxError,
ParserInvalidValue,
ParserMissingParameter,
ParserMissingValue,
};

pub const Params_T: type = hashtable.buildHashTable(
[]const u8,
Value_T,
8,
null
);

pub const Value_T: type = enum(u1) {
yes = 1,
no = 0,
};

pub const Param_T: type = struct {
param: []const u8,
value: Value_T,
};
22 changes: 14 additions & 8 deletions lib/saturn/kernel/utils/hashtable/hashtable.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn buildHashTable(
KeyNotFound,
};

table: [table_size orelse 24]ListHead_T = [_]ListHead_T {
table: [table_size orelse 16]ListHead_T = [_]ListHead_T {
ListHead_T {
.first = null,
.last = null,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn buildHashTable(
};
}

test "Add" {
test "String Test" {
const std: type = @import("std");
const HashTable_T: type = buildHashTable([]const u8, bool, null, null);
var gpa = std.heap.GeneralPurposeAllocator(.{}) {};
Expand All @@ -204,13 +204,19 @@ test "Add" {
try hashtable.add("tty_output_buffer", true, &allocator);
try hashtable.add("tty_input_buffer", false, &allocator);

std.debug.print("{any}\n{any}\n", .{
try hashtable.search("tty_output_buffer"),
try hashtable.search("tty_input_buffer"),
});
var found: bool = undefined;

found = try hashtable.search("tty_output_buffer");
if(found != true)
return error.InvalidData;

found = try hashtable.search("tty_input_buffer");
if(found != false)
return error.InvalidData;

try hashtable.del("tty_output_buffer", &allocator);
try hashtable.del("tty_input_buffer", &allocator);

//_ = try hashtable.search("tty_output_buffer");
_ = try hashtable.search("tty_input_buffer");
if(hashtable.search("tty_output_buffer")) |_| return error.FoundDel else |_| {}
if(hashtable.search("tty_input_buffer")) |_| return error.FoundDel else |_| {}
}
1 change: 1 addition & 0 deletions lib/saturn/kernel/utils/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub const mem: type = @import("mem/mem.zig");
pub const fmt: type = @import("fmt/fmt.zig");
pub const list: type = @import("list/list.zig");
pub const tree: type = @import("tree/tree.zig");
pub const hashtable: type = @import("hashtable/hashtable.zig");
pub const c: type = @import("c/c.zig");
pub const compile: type = @import("comptime/comptime.zig");
1 change: 1 addition & 0 deletions saturn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const decls: type = @import("kernel/decls.zig");
pub const ar: type = @import("kernel/ar/ar.zig");
pub const asl: type = @import("kernel/asl/asl.zig");
pub const csl: type = @import("kernel/csl/csl.zig");
pub const kparam: type = @import("kernel/kparam/kparam.zig");
pub const codes: type = @import("codes.zig");

pub const core: type = struct {
Expand Down