Skip to content

Commit

Permalink
fixing merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Jul 20, 2024
2 parents 84ddec5 + 0d7ede9 commit 3eeef41
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 62 deletions.
17 changes: 17 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
pkgs ? import <nixpkgs> {},
}:

pkgs.mkShell {
nativeBuildInputs = with pkgs; [
qemu
grub2
mtools
neovim
nodejs_22
];
shellHook =
''
exec zsh
'';
}
2 changes: 1 addition & 1 deletion sources/drivers/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn initDrivers() void
kernel.logs.klogln("[Drivers Manager] loading drivers...");
kernel.logs.beginSection();
kb.init();
vga.init("RatiOS 0.2", vga.computeColor(vga.Color.BLACK, vga.Color.LIGHT_GREY), vga.computeColor(vga.Color.WHITE, vga.Color.DARK_GREY), vga.computeColor(vga.Color.RED, vga.Color.DARK_GREY));
vga.init("RatiOS 0.2", vga.computeColor(vga.Color.BLACK, vga.Color.LIGHT_GREY), vga.computeColor(vga.Color.WHITE, vga.Color.DARK_GREY), vga.computeColor(vga.Color.LIGHT_BLUE, vga.Color.DARK_GREY));
power.init();
kernel.logs.endSection();
kernel.logs.klogln("[Drivers Manager] loaded drivers");
Expand Down
27 changes: 12 additions & 15 deletions sources/drivers/vga/vga.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,24 @@ pub fn changeScreen(targetScreen: u8) void
fn updateNavbar() void
{
vga.color = vga.nav_color;
for(63..80) |i|
const values = [_]u8{'1','2','3','4','5','6','S','L'};
var i : u32 = 63;
for(values) |c|
{
if(i % 2 == 1)
putCharAt(' ', i, 0);
if(i % 2 == 0)
putCharAt(17 + @as(u8, @truncate(i / 2)), i, 0);
if(@as(u8, @truncate((i - 63) / 2)) == vga.currentScreen and i % 2 == 0)
putCharAt(' ', i, 0);
i += 1;
if(@as(u8, @truncate((i - 63) / 2)) == vga.currentScreen)
{
vga.color = vga.nav_triggered_color;
putCharAt(17 + @as(u8, @truncate(i / 2)), i, 0);
putCharAt(c, i, 0);
vga.color = vga.nav_color;
}
else
putCharAt(c, i, 0);
i += 1;
}
vga.color = computeColor(vga.curr_fg, vga.curr_bg);
putCharAt(' ', i, 0);
vga.color = computeColor(vga.curr_fg, vga.curr_bg);
}

pub fn init(title : []const u8, title_color : u8, navbar_color : u8, triggered_color : u8) void
Expand All @@ -144,13 +148,6 @@ pub fn init(title : []const u8, title_color : u8, navbar_color : u8, triggered_c
vga.color = navbar_color;
vga.nav_color = navbar_color;
vga.nav_triggered_color = triggered_color;
for(63..80) |i|
{
if(i % 2 == 1)
putCharAt(' ', i, 0);
if(i % 2 == 0)
putCharAt(17 + @as(u8, @truncate(i / 2)), i, 0);
}
vga.color = computeColor(vga.curr_fg, vga.curr_bg);
vga.column = 1;
updateCursor();
Expand Down
2 changes: 1 addition & 1 deletion sources/kernel/arch/x86/arch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ pub fn disableInts() void

pub fn init() void
{
idt.idtInit();
gdt.gdtInit();
idt.idtInit();
}
3 changes: 2 additions & 1 deletion sources/kernel/arch/x86/boot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ comptime
);
}

export var kernel_stack: [32 * 1024]u8 align(16) linksection(".bss") = undefined;
pub export var kernel_stack: [32 * 1024]u8 align(16) linksection(".bss") = undefined;
pub export var user_stack: [64 * 1024]u8 align(16) linksection(".bss") = undefined;

extern fn kmain() void;

Expand Down
17 changes: 11 additions & 6 deletions sources/kernel/arch/x86/gdt.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub const console = @import("../../io/out.zig");
const boot = @import("boot.zig");

const GDTEntry = packed struct
{
limit: u16,
Expand Down Expand Up @@ -45,7 +48,7 @@ const GDTPointer = packed struct
base: *GDTEntry
};

var gdt_entries: [6]GDTEntry = undefined;
var gdt_entries: *[8]GDTEntry = @ptrFromInt(0x800);

var tss_entry: TSSEntry = .{
.prev_tss = 0,
Expand Down Expand Up @@ -104,7 +107,7 @@ comptime
(
\\ .type tssFlush, @function
\\ tssFlush:
\\ mov $0x2B, %ax
\\ mov $0x38, %ax
\\ ltr %ax
\\ ret
);
Expand Down Expand Up @@ -133,15 +136,17 @@ fn writeTSS(num: u32, ss0: u16, esp0: u32) void

pub fn gdtInit() void
{
gdt_pointer.limit = @sizeOf(GDTEntry) * 6 - 1;
gdt_pointer.limit = @sizeOf(GDTEntry) * 8 - 1;
gdt_pointer.base = &gdt_entries[0];

gdtSetGate(0, 0, 0, 0, 0);
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdtSetGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
gdtSetGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
writeTSS(5, 0x10, 0x0);
gdtSetGate(3, @intFromPtr(&boot.kernel_stack), @sizeOf(@TypeOf(boot.kernel_stack)) - 1, 0x92, 0xCF);
gdtSetGate(4, 0, 0xFFFFFFFF, 0xFA, 0xCF);
gdtSetGate(5, 0, 0xFFFFFFFF, 0xF2, 0xCF);
gdtSetGate(6, @intFromPtr(&boot.user_stack), @sizeOf(@TypeOf(boot.user_stack)) - 1, 0xF2, 0xCF);
writeTSS(7, 0x10, @intFromPtr(&boot.kernel_stack));
gdtFlush(&gdt_pointer);
tssFlush();
}
Expand Down
90 changes: 53 additions & 37 deletions sources/kernel/io/out.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,88 +15,104 @@ const ArgTypes = enum
Null
};

pub fn kprintf(comptime fmt: []const u8, args: anytype) void
pub fn kprintf(fmt: [*:0]const u8, ...) callconv(.C) c_int
{
comptime var arg_idx: usize = 0;
comptime var arg_insert: bool = false;
comptime var arg_type: ArgTypes = .Null;
var ap = @cVaStart();
defer @cVaEnd(&ap);

inline for(fmt) |c|
var arg_insert: bool = false;
var arg_type: ArgTypes = .Null;
var number_char_printed: i32 = 0;

var i: usize = 0;
while(fmt[i] != 0)
{
if(c == '{')
if(fmt[i] == '{')
{
arg_insert = true;
i += 1;
continue;
}

if(arg_insert)
{
if(c == '}')
if(fmt[i] == '}')
{
if(arg_type == .Null)
@compileError("invalid type identifier between the brackets");
printArg(args[arg_idx], arg_type);
return -1;

switch(arg_type)
{
ArgTypes.Char =>
{
vga.putChar(@cVaArg(&ap, u8));
number_char_printed += 1;
},
ArgTypes.Int => number_char_printed += putNb(@cVaArg(&ap, i32)),
ArgTypes.Float => _ = @cVaArg(&ap, f32),
ArgTypes.String => _ = @cVaArg(&ap, *u8),
ArgTypes.Pointer => _ = @cVaArg(&ap, *u32),
else => {},
}

arg_insert = false;
arg_idx += 1;
arg_type = .Null;
}
else if(arg_type != .Null)
@compileError("too much type identifiers between the brackets")
return -1
else
{
switch(c)
switch(fmt[i])
{
'c' => arg_type = .Char,
'i' => arg_type = .Int,
'f' => arg_type = .Float,
'p' => arg_type = .Pointer,
's' => arg_type = .String,

else => @compileError("invalid type identifier between the brackets"),
else => return -1,
}
}
}
else
vga.putChar(c);
}

comptime
{
if(args.len != arg_idx)
@compileError("unused arguments");
{
vga.putChar(fmt[i]);
number_char_printed += 1;
}
i += 1;
}
return number_char_printed;
}

fn printArg(arg: anytype, T: ArgTypes) void
pub fn putNb(nbr: i64) i32
{
switch(T)
{
.Char => vga.putChar(arg),
.Int => putNb(arg),
.Float => {},
.String => {},
.Pointer => {},
else => {},
}
}
var print_size: i32 = 0;

pub fn putNb(nbr: i64) void
{
if(nbr <= -2147483648)
vga.putString("-2147483648")
{
vga.putString("-2147483648");
return 11;
}
else if(nbr >= 2147483647)
vga.putString("2147483647")
{
vga.putString("2147483647");
return 10;
}
else if(nbr < 0)
{
vga.putChar('-');
putNb(-nbr);
print_size += putNb(-nbr);
}
else if(nbr >= 10)
{
putNb(@divFloor(nbr, 10));
print_size += putNb(@divFloor(nbr, 10));
vga.putChar(@intCast(@mod(nbr, 10) + @as(u8, 48)));
print_size += 1;
}
else
{
vga.putChar(@intCast(nbr + 48));
print_size += 1;
}
return print_size;
}
4 changes: 3 additions & 1 deletion sources/kernel/kmain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export fn kmain() void
arch.init();
drivers.initDrivers();
logs.klogln("Welcome to RatiOS !");
console.kputs(logs.getLogBuffer());
const caca: i32 = 1048;
_ = console.kprintf("caca ;{i};, ;{f};, ;{s};\n", caca);
_ = console.putNb(caca);
drivers.shutdownDrivers();
}

0 comments on commit 3eeef41

Please sign in to comment.