Add virtual memory manager
This commit is contained in:
parent
638ad81e82
commit
02ce6a5923
11 changed files with 1024 additions and 170 deletions
|
@ -5,6 +5,7 @@ const MemProfile = mem.MemProfile;
|
|||
const gdt = @import("gdt_mock.zig");
|
||||
const idt = @import("idt_mock.zig");
|
||||
const multiboot = @import("../../../src/kernel/multiboot.zig");
|
||||
const vmm = @import("vmm_mock.zig");
|
||||
const paging = @import("paging_mock.zig");
|
||||
|
||||
const mock_framework = @import("mock_framework.zig");
|
||||
|
@ -36,7 +37,10 @@ pub const InterruptContext = struct {
|
|||
ss: u32,
|
||||
};
|
||||
|
||||
pub const MEMORY_BLOCK_SIZE = paging.PAGE_SIZE_4KB;
|
||||
pub const VmmPayload = u8;
|
||||
pub const KERNEL_VMM_PAYLOAD: usize = 0;
|
||||
pub const MEMORY_BLOCK_SIZE: u32 = paging.PAGE_SIZE_4KB;
|
||||
pub const VMM_MAPPER: vmm.Mapper(VmmPayload) = undefined;
|
||||
|
||||
pub fn outb(port: u16, data: u8) void {
|
||||
return mock_framework.performAction("outb", void, .{ port, data });
|
||||
|
|
|
@ -8,6 +8,7 @@ pub const MemProfile = struct {
|
|||
mem_kb: u32,
|
||||
fixed_alloc_size: u32,
|
||||
mem_map: []multiboot.multiboot_memory_map_t,
|
||||
boot_modules: []multiboot.multiboot_module_t,
|
||||
};
|
||||
|
||||
// The virtual/physical start/end of the kernel code
|
||||
|
@ -30,5 +31,24 @@ pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile {
|
|||
.mem_kb = mb_info.mem_upper + mb_info.mem_lower + 1024,
|
||||
.fixed_alloc_size = FIXED_ALLOC_SIZE,
|
||||
.mem_map = undefined,
|
||||
.boot_modules = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn virtToPhys(virt: var) @TypeOf(virt) {
|
||||
const T = @TypeOf(virt);
|
||||
return switch (@typeInfo(T)) {
|
||||
.Pointer => @intToPtr(T, @ptrToInt(virt) - KERNEL_ADDR_OFFSET),
|
||||
.Int => virt - KERNEL_ADDR_OFFSET,
|
||||
else => @compileError("Only pointers and integers are supported"),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn physToVirt(phys: var) @TypeOf(phys) {
|
||||
const T = @TypeOf(phys);
|
||||
return switch (@typeInfo(T)) {
|
||||
.Pointer => @intToPtr(T, @ptrToInt(phys) + KERNEL_ADDR_OFFSET),
|
||||
.Int => phys + KERNEL_ADDR_OFFSET,
|
||||
else => @compileError("Only pointers and integers are supported"),
|
||||
};
|
||||
}
|
||||
|
|
16
test/mock/kernel/vmm_mock.zig
Normal file
16
test/mock/kernel/vmm_mock.zig
Normal file
|
@ -0,0 +1,16 @@
|
|||
const mem = @import("mem_mock.zig");
|
||||
const multiboot = @import("../../../src/kernel/multiboot.zig");
|
||||
const arch = @import("arch_mock.zig");
|
||||
const std = @import("std");
|
||||
|
||||
pub fn Mapper(comptime Payload: type) type {
|
||||
return struct {};
|
||||
}
|
||||
|
||||
pub fn VirtualMemoryManager(comptime Payload: type) type {
|
||||
return struct {};
|
||||
}
|
||||
|
||||
pub fn init(mem_profile: *const mem.MemProfile, mb_info: *multiboot.multiboot_info_t, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
|
||||
return std.mem.Allocator.Error.OutOfMemory;
|
||||
}
|
|
@ -40,20 +40,22 @@ def get_pre_archinit_cases():
|
|||
TestCase("Mem init", [r"Init mem"]),
|
||||
TestCase("Mem done", [r"Done mem"]),
|
||||
|
||||
TestCase("Panic init", [r"Init panic"]),
|
||||
TestCase("Panic done", [r"Done panic"]),
|
||||
|
||||
TestCase("PMM init", [r"Init pmm"]),
|
||||
TestCase("PMM tests", [r"PMM: Tested allocation"]),
|
||||
TestCase("PMM done", [r"Done pmm"]),
|
||||
|
||||
TestCase("VMM init", [r"Init vmm"]),
|
||||
TestCase("VMM tests", [r"VMM: Tested allocations"]),
|
||||
TestCase("VMM done", [r"Done vmm"]),
|
||||
TestCase("Arch init starts", [r"Init arch \w+"])
|
||||
]
|
||||
|
||||
def get_post_archinit_cases():
|
||||
return [
|
||||
TestCase("Arch init finishes", [r"Arch init done"]),
|
||||
|
||||
TestCase("Panic init", [r"Init panic"]),
|
||||
TestCase("Panic done", [r"Done panic"]),
|
||||
|
||||
TestCase("VGA init", [r"Init vga"]),
|
||||
TestCase("VGA tests", [r"VGA: Tested max scan line", r"VGA: Tested cursor shape", r"VGA: Tested updating cursor"]),
|
||||
TestCase("VGA done", [r"Done vga"]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue