Skip to content

Commit

Permalink
o\Merge branch 'master' of github.com:Kbz-8/42_KFS
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Jul 19, 2024
2 parents 605beb9 + 84998d2 commit eecc613
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
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.1 : 42", 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.RED, vga.Color.DARK_GREY));
power.init();
kernel.logs.endSection();
kernel.logs.klogln("[Drivers Manager] loaded drivers");
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();
}
4 changes: 2 additions & 2 deletions sources/kernel/arch/x86/boot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ comptime
);
}

export var kernel_stack: [32 * 1024]u8 align(16) linksection(".bss") = undefined;
export var user_stack: [64 * 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: 10 additions & 7 deletions sources/kernel/arch/x86/gdt.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub const console = @import("../../io/out.zig");
const boot = @import("boot.zig");

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

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

var tss_entry: TSSEntry = .{
.prev_tss = 0,
Expand Down Expand Up @@ -106,7 +107,7 @@ comptime
(
\\ .type tssFlush, @function
\\ tssFlush:
\\ mov $0x2B, %ax
\\ mov $0x38, %ax
\\ ltr %ax
\\ ret
);
Expand Down Expand Up @@ -135,17 +136,19 @@ 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, 0x8000000);
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();
tssFlush();
}

pub fn gdtSetGate(num: u32, base: u32, limit: u32, access: u8, flags: u8) void
Expand Down

0 comments on commit eecc613

Please sign in to comment.