Added IDT unit and run-time tests

This commit is contained in:
ED 2019-09-17 18:24:27 +01:00
parent 9d9c5d6a39
commit 4d9b963310
12 changed files with 424 additions and 109 deletions

View file

@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
const mem = @import("mem_mock.zig");
const MemProfile = mem.MemProfile;
const gdt = @import("gdt_mock.zig");
const idt = @import("idt_mock.zig");
const mock_framework = @import("mock_framework.zig");
pub const initTest = mock_framework.initTest;
@ -61,6 +62,10 @@ pub fn lidt(idt_ptr: *const idt.IdtPtr) void {
return mock_framework.performAction("lidt", void, idt_ptr);
}
pub fn sidt() idt.IdtPtr {
return mock_framework.performAction("sidt", idt.IdtPtr);
}
pub fn enableInterrupts() void {
return mock_framework.performAction("enableInterrupts", void);
}

View file

@ -0,0 +1,47 @@
const src_idt = @import("../../../src/kernel/arch/x86/idt.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 IdtEntry = packed struct {
base_low: u16,
selector: u16,
zero: u8,
gate_type: u4,
storage_segment: u1,
privilege: u2,
present: u1,
base_high: u16,
};
// Need to use the type from the source file so that types match
pub const IdtPtr = src_idt.IdtPtr;
pub const InterruptHandler = extern fn () void;
pub const IdtError = error{IdtEntryExists};
const TASK_GATE: u4 = 0x5;
const INTERRUPT_GATE: u4 = 0xE;
const TRAP_GATE: u4 = 0xF;
const PRIVILEGE_RING_0: u2 = 0x0;
const PRIVILEGE_RING_1: u2 = 0x1;
const PRIVILEGE_RING_2: u2 = 0x2;
const PRIVILEGE_RING_3: u2 = 0x3;
const NUMBER_OF_ENTRIES: u16 = 256;
const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1;
pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void {
return mock_framework.performAction("openInterruptGate", IdtError!void, port);
}
pub fn init() void {
return mock_framework.performAction("init", void);
}

View file

@ -6,6 +6,7 @@ const GlobalAllocator = std.debug.global_allocator;
const TailQueue = std.TailQueue;
const warn = std.debug.warn;
const gdt = @import("gdt_mock.zig");
const idt = @import("idt_mock.zig");
///
/// The enumeration of types that the mocking framework supports. These include basic types like u8
@ -17,6 +18,7 @@ const DataElementType = enum {
U16,
U32,
PTR_CONST_GdtPtr,
PTR_CONST_IdtPtr,
FN_OVOID,
FN_OUSIZE,
FN_OU16,
@ -27,6 +29,7 @@ const DataElementType = enum {
FN_IU16_IU8_OVOID,
FN_IU16_IU16_OVOID,
FN_IPTRCONSTGDTPTR_OVOID,
FN_IPTRCONSTIDTPTR_OVOID,
};
///
@ -40,6 +43,7 @@ const DataElement = union(DataElementType) {
U16: u16,
U32: u32,
PTR_CONST_GdtPtr: *const gdt.GdtPtr,
PTR_CONST_IdtPtr: *const idt.IdtPtr,
FN_OVOID: fn () void,
FN_OUSIZE: fn () usize,
FN_OU16: fn () u16,
@ -50,6 +54,7 @@ const DataElement = union(DataElementType) {
FN_IU16_IU8_OVOID: fn (u16, u8) void,
FN_IU16_IU16_OVOID: fn (u16, u16) void,
FN_IPTRCONSTGDTPTR_OVOID: fn (*const gdt.GdtPtr) void,
FN_IPTRCONSTIDTPTR_OVOID: fn (*const idt.IdtPtr) void,
};
///
@ -130,6 +135,7 @@ fn Mock() type {
u16 => DataElement{ .U16 = arg },
u32 => DataElement{ .U32 = arg },
*const gdt.GdtPtr => DataElement{ .PTR_CONST_GdtPtr = arg },
*const idt.IdtPtr => DataElement{ .PTR_CONST_IdtPtr = arg },
fn () void => DataElement{ .FN_OVOID = arg },
fn () usize => DataElement{ .FN_OUSIZE = arg },
fn () u16 => DataElement{ .FN_OU16 = arg },
@ -140,6 +146,7 @@ fn Mock() type {
fn (u16, u8) void => DataElement{ .FN_IU16_IU8_OVOID = arg },
fn (u16, u16) void => DataElement{ .FN_IU16_IU16_OVOID = arg },
fn (*const gdt.GdtPtr) void => DataElement{ .FN_IPTRCONSTGDTPTR_OVOID = arg },
fn (*const idt.IdtPtr) void => DataElement{ .FN_IPTRCONSTIDTPTR_OVOID = arg },
else => @compileError("Type not supported: " ++ @typeName(@typeOf(arg))),
};
}
@ -160,6 +167,7 @@ fn Mock() type {
u16 => DataElementType.U16,
u32 => DataElementType.U32,
*const gdt.GdtPtr => DataElement.PTR_CONST_GdtPtr,
*const idt.IdtPtr => DataElement.PTR_CONST_IdtPtr,
fn () void => DataElementType.FN_OVOID,
fn () u16 => DataElementType.FN_OU16,
fn (u16) void => DataElementType.FN_IU16_OVOID,
@ -169,6 +177,7 @@ fn Mock() type {
fn (u16, u8) void => DataElementType.FN_IU16_IU8_OVOID,
fn (u16, u16) void => DataElementType.FN_IU16_IU16_OVOID,
fn (*const gdt.GdtPtr) void => DataElementType.FN_IPTRCONSTGDTPTR_OVOID,
fn (*const idt.IdtPtr) void => DataElementType.FN_IPTRCONSTIDTPTR_OVOID,
else => @compileError("Type not supported: " ++ @typeName(T)),
};
}
@ -191,6 +200,7 @@ fn Mock() type {
u16 => element.U16,
u32 => element.U32,
*const gdt.GdtPtr => element.PTR_CONST_GdtPtr,
*const idt.IdtPtr => element.PTR_CONST_IdtPtr,
fn () void => element.FN_OVOID,
fn () u16 => element.FN_OU16,
fn (u16) void => element.FN_IU16_OVOID,
@ -200,6 +210,7 @@ fn Mock() type {
fn (u16, u8) void => element.FN_IU16_IU8_OVOID,
fn (u16, u16) void => element.FN_IU16_IU16_OVOID,
fn (*const gdt.GdtPtr) void => element.FN_IPTRCONSTGDTPTR_OVOID,
fn (*const idt.IdtPtr) void => element.FN_IPTRCONSTIDTPTR_OVOID,
else => @compileError("Type not supported: " ++ @typeName(T)),
};
}

View file

@ -1,6 +0,0 @@
pub const arch = @import("arch_mock.zig");
pub const gdt = @import("gdt_mock.zig");
pub const log = @import("log_mock.zig");
pub const mem = @import("mem_mock.zig");
pub const panic = @import("panic_mock.zig");
pub const vga = @import("vga_mock.zig");