d600be874c
Fix TSS Also change to .{} syntax where appropriate. Added the SS segment Fixed spelling Refactoring GDT Multitasking working for now WIP scheduler Refactored Bitmap a bit WIP still Task switching working Handlers return the stack pointer that will be used to restore the tasks stack, normal handlers will return the same stack pointer it was called with where task switching will return the stack pointer of the next task and restore its state using the interrupt stub. Initial scheduler done Created a stage 2 init task Change u32 to usize Move Task to arch specific WIP WIP2 Removed esp from task, replaced with stack_pointer Removed the debug logs Fixed init task stack Change pickNextTask to pointer manipulation This allows less allocations so faster switching Temporary enable interrupts for some runtime tests PIT and RTC need interrupts enabled to run their runtime tests Renamed schedule => pickNextTask, comptime bitmap for pids not task init And some other stuff: No pub for the task anymore Use the leak detector allocator Fmt Fix unit tests And some other stuff :P PR review Moved Task out of arch and have the stack init in the arch file Mocking clean up Removed commented code Renamed createTask to scheduleTask where the user will have to provide a task to schedule Removed redundant pub in log runtime test Removed global allocator for scheduler Cleaner assembly in paging Fmt Added new Scheduler test mode Added new test mode to CI Removed one of the prints Added doc comment, task test for i386 Removed test WIP Runtime tests work Have a global set in one task and reacted to in another. Also test that local variables are preserved after a task switch. Removed new lines Increased line length Move the allocation of the bool above the task creation
165 lines
3.5 KiB
Zig
165 lines
3.5 KiB
Zig
// Can't do: TODO: https://github.com/SamTebbs33/pluto/issues/77
|
|
//const src_gdt = @import("arch").gdt;
|
|
const src_gdt = @import("../../../src/kernel/arch/x86/gdt.zig");
|
|
|
|
const mock_framework = @import("mock_framework.zig");
|
|
pub const initTest = mock_framework.initTest;
|
|
pub const freeTest = mock_framework.freeTest;
|
|
pub const addTestParams = mock_framework.addTestParams;
|
|
pub const addConsumeFunction = mock_framework.addConsumeFunction;
|
|
pub const addRepeatFunction = mock_framework.addRepeatFunction;
|
|
|
|
const AccessBits = packed struct {
|
|
accessed: u1,
|
|
read_write: u1,
|
|
direction_conforming: u1,
|
|
executable: u1,
|
|
descriptor: u1,
|
|
privilege: u2,
|
|
present: u1,
|
|
};
|
|
|
|
const FlagBits = packed struct {
|
|
reserved_zero: u1,
|
|
is_64_bit: u1,
|
|
is_32_bit: u1,
|
|
granularity: u1,
|
|
};
|
|
|
|
const GdtEntry = packed struct {
|
|
limit_low: u16,
|
|
base_low: u24,
|
|
access: AccessBits,
|
|
limit_high: u4,
|
|
flags: FlagBits,
|
|
base_high: u8,
|
|
};
|
|
|
|
const Tss = packed struct {
|
|
prev_tss: u32,
|
|
esp0: u32,
|
|
ss0: u32,
|
|
esp1: u32,
|
|
ss1: u32,
|
|
esp2: u32,
|
|
ss2: u32,
|
|
cr3: u32,
|
|
eip: u32,
|
|
eflags: u32,
|
|
eax: u32,
|
|
ecx: u32,
|
|
edx: u32,
|
|
ebx: u32,
|
|
esp: u32,
|
|
ebp: u32,
|
|
esi: u32,
|
|
edi: u32,
|
|
es: u32,
|
|
cs: u32,
|
|
ss: u32,
|
|
ds: u32,
|
|
fs: u32,
|
|
gs: u32,
|
|
ldtr: u32,
|
|
trap: u16,
|
|
io_permissions_base_offset: u16,
|
|
};
|
|
|
|
// Need to use the type from the source file so that types match
|
|
pub const GdtPtr = src_gdt.GdtPtr;
|
|
|
|
const NUMBER_OF_ENTRIES: u16 = 0x06;
|
|
|
|
const TABLE_SIZE: u16 = @sizeOf(GdtEntry) * NUMBER_OF_ENTRIES - 1;
|
|
|
|
const NULL_INDEX: u16 = 0x00;
|
|
const KERNEL_CODE_INDEX: u16 = 0x01;
|
|
const KERNEL_DATA_INDEX: u16 = 0x02;
|
|
const USER_CODE_INDEX: u16 = 0x03;
|
|
const USER_DATA_INDEX: u16 = 0x04;
|
|
const TSS_INDEX: u16 = 0x05;
|
|
|
|
const NULL_SEGMENT: AccessBits = AccessBits{
|
|
.accessed = 0,
|
|
.read_write = 0,
|
|
.direction_conforming = 0,
|
|
.executable = 0,
|
|
.descriptor = 0,
|
|
.privilege = 0,
|
|
.present = 0,
|
|
};
|
|
|
|
const KERNEL_SEGMENT_CODE: AccessBits = AccessBits{
|
|
.accessed = 0,
|
|
.read_write = 1,
|
|
.direction_conforming = 0,
|
|
.executable = 1,
|
|
.descriptor = 1,
|
|
.privilege = 0,
|
|
.present = 1,
|
|
};
|
|
|
|
const KERNEL_SEGMENT_DATA: AccessBits = AccessBits{
|
|
.accessed = 0,
|
|
.read_write = 1,
|
|
.direction_conforming = 0,
|
|
.executable = 0,
|
|
.descriptor = 1,
|
|
.privilege = 0,
|
|
.present = 1,
|
|
};
|
|
|
|
const USER_SEGMENT_CODE: AccessBits = AccessBits{
|
|
.accessed = 0,
|
|
.read_write = 1,
|
|
.direction_conforming = 0,
|
|
.executable = 1,
|
|
.descriptor = 1,
|
|
.privilege = 3,
|
|
.present = 1,
|
|
};
|
|
|
|
const USER_SEGMENT_DATA: AccessBits = AccessBits{
|
|
.accessed = 0,
|
|
.read_write = 1,
|
|
.direction_conforming = 0,
|
|
.executable = 0,
|
|
.descriptor = 1,
|
|
.privilege = 3,
|
|
.present = 1,
|
|
};
|
|
|
|
const TSS_SEGMENT: AccessBits = AccessBits{
|
|
.accessed = 1,
|
|
.read_write = 0,
|
|
.direction_conforming = 0,
|
|
.executable = 1,
|
|
.descriptor = 0,
|
|
.privilege = 0,
|
|
.present = 1,
|
|
};
|
|
|
|
const NULL_FLAGS: FlagBits = FlagBits{
|
|
.reserved_zero = 0,
|
|
.is_64_bit = 0,
|
|
.is_32_bit = 0,
|
|
.granularity = 0,
|
|
};
|
|
|
|
const PAGING_32_BIT: FlagBits = FlagBits{
|
|
.reserved_zero = 0,
|
|
.is_64_bit = 0,
|
|
.is_32_bit = 1,
|
|
.granularity = 1,
|
|
};
|
|
|
|
pub const NULL_OFFSET: u16 = 0x00;
|
|
pub const KERNEL_CODE_OFFSET: u16 = 0x08;
|
|
pub const KERNEL_DATA_OFFSET: u16 = 0x10;
|
|
pub const USER_CODE_OFFSET: u16 = 0x18;
|
|
pub const USER_DATA_OFFSET: u16 = 0x20;
|
|
pub const TSS_OFFSET: u16 = 0x28;
|
|
|
|
pub fn init() void {
|
|
return mock_framework.performAction("init", void);
|
|
}
|