2019-09-08 21:48:23 +02:00
|
|
|
const std = @import("std");
|
2019-09-16 23:19:21 +02:00
|
|
|
const Allocator = std.mem.Allocator;
|
|
|
|
const mem = @import("mem_mock.zig");
|
|
|
|
const MemProfile = mem.MemProfile;
|
|
|
|
const gdt = @import("gdt_mock.zig");
|
2019-09-17 19:24:27 +02:00
|
|
|
const idt = @import("idt_mock.zig");
|
2020-01-09 17:16:51 +01:00
|
|
|
const vmm = @import("vmm_mock.zig");
|
2019-09-10 00:38:06 +02:00
|
|
|
const paging = @import("paging_mock.zig");
|
2020-06-04 15:39:37 +02:00
|
|
|
const Serial = @import("../../../src/kernel/serial.zig").Serial;
|
2020-06-12 13:05:50 +02:00
|
|
|
const TTY = @import("../../../src/kernel/tty.zig").TTY;
|
2019-09-08 21:48:23 +02:00
|
|
|
|
2020-07-18 23:46:24 +02:00
|
|
|
pub const task = @import("task_mock.zig");
|
|
|
|
|
2019-09-08 21:48:23 +02:00
|
|
|
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;
|
|
|
|
|
2020-07-18 23:46:24 +02:00
|
|
|
pub const CpuState = struct {
|
|
|
|
ss: u32,
|
2019-09-08 21:48:23 +02:00
|
|
|
gs: u32,
|
|
|
|
fs: u32,
|
|
|
|
es: u32,
|
|
|
|
ds: u32,
|
|
|
|
edi: u32,
|
|
|
|
esi: u32,
|
|
|
|
ebp: u32,
|
|
|
|
esp: u32,
|
|
|
|
ebx: u32,
|
|
|
|
edx: u32,
|
|
|
|
ecx: u32,
|
|
|
|
eax: u32,
|
|
|
|
int_num: u32,
|
|
|
|
error_code: u32,
|
|
|
|
eip: u32,
|
|
|
|
cs: u32,
|
|
|
|
eflags: u32,
|
|
|
|
user_esp: u32,
|
2020-07-18 23:46:24 +02:00
|
|
|
user_ss: u32,
|
2019-09-08 21:48:23 +02:00
|
|
|
};
|
|
|
|
|
2020-01-09 17:16:51 +01:00
|
|
|
pub const VmmPayload = u8;
|
|
|
|
pub const KERNEL_VMM_PAYLOAD: usize = 0;
|
|
|
|
pub const MEMORY_BLOCK_SIZE: u32 = paging.PAGE_SIZE_4KB;
|
2020-07-18 23:46:24 +02:00
|
|
|
pub const STACK_SIZE: u32 = MEMORY_BLOCK_SIZE / @sizeOf(u32);
|
2020-01-09 17:16:51 +01:00
|
|
|
pub const VMM_MAPPER: vmm.Mapper(VmmPayload) = undefined;
|
2020-05-14 18:34:50 +02:00
|
|
|
pub const BootPayload = u8;
|
2020-07-18 23:46:24 +02:00
|
|
|
pub const Task = task.Task;
|
2020-05-14 18:34:50 +02:00
|
|
|
|
|
|
|
// The virtual/physical start/end of the kernel code
|
|
|
|
var KERNEL_PHYSADDR_START: u32 = 0x00100000;
|
|
|
|
var KERNEL_PHYSADDR_END: u32 = 0x01000000;
|
|
|
|
var KERNEL_VADDR_START: u32 = 0xC0100000;
|
|
|
|
var KERNEL_VADDR_END: u32 = 0xC1100000;
|
|
|
|
var KERNEL_ADDR_OFFSET: u32 = 0xC0000000;
|
2019-09-10 00:38:06 +02:00
|
|
|
|
2019-09-08 21:48:23 +02:00
|
|
|
pub fn outb(port: u16, data: u8) void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("outb", void, .{ port, data });
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inb(port: u16) u8 {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("inb", u8, .{port});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ioWait() void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("ioWait", void, .{});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 23:19:21 +02:00
|
|
|
pub fn lgdt(gdt_ptr: *const gdt.GdtPtr) void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("lgdt", void, .{gdt_ptr});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 23:19:21 +02:00
|
|
|
pub fn sgdt() gdt.GdtPtr {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("sgdt", gdt.GdtPtr, .{});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 23:19:21 +02:00
|
|
|
pub fn ltr(offset: u16) void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("ltr", void, .{offset});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lidt(idt_ptr: *const idt.IdtPtr) void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("lidt", void, .{idt_ptr});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
2019-09-17 19:24:27 +02:00
|
|
|
pub fn sidt() idt.IdtPtr {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("sidt", idt.IdtPtr, .{});
|
2019-09-17 19:24:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 21:48:23 +02:00
|
|
|
pub fn enableInterrupts() void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("enableInterrupts", void, .{});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn disableInterrupts() void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("disableInterrupts", void, .{});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn halt() void {
|
2020-01-01 20:12:36 +01:00
|
|
|
return mock_framework.performAction("halt", void, .{});
|
2019-09-08 21:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn spinWait() noreturn {
|
|
|
|
while (true) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn haltNoInterrupts() noreturn {
|
|
|
|
while (true) {}
|
|
|
|
}
|
2019-09-16 23:19:21 +02:00
|
|
|
|
2020-06-09 14:47:06 +02:00
|
|
|
pub fn initSerial(boot_payload: BootPayload) Serial {
|
2020-06-04 15:39:37 +02:00
|
|
|
return .{ .write = undefined };
|
|
|
|
}
|
|
|
|
|
2020-06-12 13:05:50 +02:00
|
|
|
pub fn initTTY(boot_payload: BootPayload) TTY {
|
|
|
|
return .{
|
|
|
|
.print = undefined,
|
|
|
|
.setCursor = undefined,
|
|
|
|
.cols = undefined,
|
|
|
|
.rows = undefined,
|
|
|
|
.clear = null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-25 00:51:27 +02:00
|
|
|
pub fn initMem(payload: BootPayload) Allocator.Error!mem.MemProfile {
|
2020-05-14 18:34:50 +02:00
|
|
|
return MemProfile{
|
|
|
|
.vaddr_end = @ptrCast([*]u8, &KERNEL_VADDR_END),
|
|
|
|
.vaddr_start = @ptrCast([*]u8, &KERNEL_VADDR_START),
|
|
|
|
.physaddr_end = @ptrCast([*]u8, &KERNEL_PHYSADDR_END),
|
|
|
|
.physaddr_start = @ptrCast([*]u8, &KERNEL_PHYSADDR_START),
|
|
|
|
// Total memory available including the initial 1MiB that grub doesn't include
|
|
|
|
.mem_kb = 0,
|
|
|
|
.fixed_allocator = undefined,
|
|
|
|
.virtual_reserved = undefined,
|
|
|
|
.physical_reserved = undefined,
|
|
|
|
.modules = undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-18 23:46:24 +02:00
|
|
|
pub fn initTaskStack(entry_point: usize, allocator: *Allocator) Allocator.Error!struct { stack: []u32, pointer: usize } {
|
|
|
|
const ret = .{ .stack = &([_]u32{}), .pointer = 0 };
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-25 00:51:27 +02:00
|
|
|
pub fn init(mem_profile: *const MemProfile) void {
|
2020-07-18 23:46:24 +02:00
|
|
|
// I'll get back to this as this doesn't effect the current testing.
|
2019-09-16 23:19:21 +02:00
|
|
|
// When I come on to the mem.zig testing, I'll fix :)
|
|
|
|
//return mock_framework.performAction("init", void, mem_profile, allocator);
|
|
|
|
}
|
2019-11-06 22:21:27 +01:00
|
|
|
|
|
|
|
// User defined mocked functions
|
|
|
|
|
|
|
|
pub fn mock_disableInterrupts() void {}
|
|
|
|
|
|
|
|
pub fn mock_enableInterrupts() void {}
|
2020-01-15 20:50:41 +01:00
|
|
|
|
|
|
|
pub fn mock_ioWait() void {}
|