62 lines
1.8 KiB
Zig
62 lines
1.8 KiB
Zig
const std = @import("std");
|
|
const processor = @import("arch").processor;
|
|
const mem = @import("arch").mem;
|
|
const PFType = mem.PFType;
|
|
const early_serial_console = @import("early_serial_console.zig");
|
|
const assert = std.debug.assert;
|
|
|
|
var pgtable_buffer: struct {
|
|
buffer: [*][mem.PAGE_SIZE]u8,
|
|
size: usize,
|
|
used_pages: usize,
|
|
} = undefined;
|
|
|
|
fn allocPgtablePage() error.OutOfMemory![4096]u8 {
|
|
// if (used + mem.PAGE_SIZE > size) {
|
|
// early_serial_console.dprint("Out of page table memory!\n", .{});
|
|
// return error.OutOfMemory;
|
|
// }
|
|
// const page = buffer + used;
|
|
// return page;
|
|
}
|
|
// fn pgdIdentInit() {
|
|
|
|
// }
|
|
|
|
// fn pudIdentInit() {
|
|
|
|
// }
|
|
|
|
fn kernelAddIdentityMap(pgdt_page: [*]mem.PGDEntry, start: u64, end: u64) void {
|
|
assert(start % mem.PMD_SIZE == 0);
|
|
assert(end % mem.PMD_SIZE == 0);
|
|
var address = start;
|
|
while (address < end) {
|
|
// var pgd = &pgdt_page[mem.PGDEntry.getIndex(address)];
|
|
// if ()
|
|
address += mem.PMD_SIZE;
|
|
}
|
|
}
|
|
export fn initializeIdentMap() void {
|
|
// var pgd_table = processor.readCr3();
|
|
// if (pgdtable == _pgtable) {
|
|
|
|
// }
|
|
}
|
|
fn printPF(msg: []const u8, errorCode: u64, faultAddress: u64, ip: u64) void {
|
|
early_serial_console.dprint(
|
|
\\{s}:
|
|
\\error code: 0x{x}
|
|
\\fault address: 0x{x}
|
|
\\instruction pointer: 0x{x}
|
|
\\
|
|
, .{msg, errorCode, faultAddress, ip});
|
|
}
|
|
export fn doBootPageFault(regs: processor.PtRegs, errorCode: u64) void {
|
|
const faultAddress = processor.readCr2();
|
|
if (errorCode & (PFType.PROT | PFType.USER | PFType.RSVD) == 0) {
|
|
printPF("Unexpected page fault", errorCode, faultAddress, regs.ip);
|
|
}
|
|
const address = faultAddress & mem.PMD_MASK;
|
|
kernelAddIdentityMap(address, address + mem.PMD_SIZE);
|
|
} |