From cf11b17542307302fe9a883ab4e7e9c83cfd35c6 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Wed, 22 Apr 2020 23:56:05 +0100 Subject: [PATCH 1/2] Add start to alloc result --- src/kernel/vmm.zig | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index 30d9c1a..63a0270 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -270,21 +270,18 @@ pub fn VirtualMemoryManager(comptime Payload: type) type { try block_list.ensureCapacity(num); var i: u32 = 0; - var first_addr: ?usize = null; - const vaddr_start = entry * BLOCK_SIZE; + const vaddr_start = self.start + entry * BLOCK_SIZE; var vaddr = vaddr_start; // Map the blocks to physical memory while (i < num) : (i += 1) { const addr = pmm.alloc() orelse unreachable; - if (i == 0) - first_addr = addr; try block_list.append(addr); // The map function failing isn't the caller's responsibility so panic as it shouldn't happen self.mapper.mapFn(vaddr, vaddr + BLOCK_SIZE, addr, addr + BLOCK_SIZE, attrs, self.allocator, self.payload) catch |e| panic(@errorReturnTrace(), "Failed to map virtual memory: {}\n", .{e}); vaddr += BLOCK_SIZE; } _ = try self.allocations.put(vaddr_start, Allocation{ .physical = block_list }); - return first_addr; + return vaddr_start; } } return null; @@ -408,7 +405,7 @@ test "alloc and free" { should_be_set = false; } else { // Else it should have succedded and allocated the correct address - std.testing.expectEqual(@as(?usize, entry * BLOCK_SIZE), result); + std.testing.expectEqual(@as(?usize, vmm.start + entry * BLOCK_SIZE), result); try virtual_allocations.append(result orelse unreachable); } @@ -439,7 +436,7 @@ test "alloc and free" { // All later entries should not be set var later_entry = entry; while (later_entry < num_entries) : (later_entry += 1) { - std.testing.expect(!(try vmm.isSet(later_entry * BLOCK_SIZE))); + std.testing.expect(!(try vmm.isSet(vmm.start + later_entry * BLOCK_SIZE))); std.testing.expect(!(try pmm.isSet(later_entry * BLOCK_SIZE))); } } From 2646f8b74b4bed0d692c1d14f8ad6355cfb02899 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Wed, 22 Apr 2020 23:56:16 +0100 Subject: [PATCH 2/2] Start kernel VMM at second block --- src/kernel/vmm.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index 63a0270..e705b9e 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -345,7 +345,7 @@ pub fn init(mem_profile: *const mem.MemProfile, mb_info: *multiboot.multiboot_in log.logInfo("Init vmm\n", .{}); defer log.logInfo("Done vmm\n", .{}); - var vmm = try VirtualMemoryManager(arch.VmmPayload).init(0, 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD); + var vmm = try VirtualMemoryManager(arch.VmmPayload).init(BLOCK_SIZE, 0xFFFFFFFF, allocator, arch.VMM_MAPPER, arch.KERNEL_VMM_PAYLOAD); // Map in kernel // Calculate start and end of mapping