Ethin wrote:So I have absolutely no idea how to catch Limine altering CR3 or anything because I'll always end up catching the firmware doing it first.
Hold on, back up. Why are you trying to catch Limine altering CR3? The triple fault is happening after Limine hands control to your kernel, isn't it?
22OsC wrote:I see something is not working right with paging, the CR2 is ffff80008018b00c but the maximum normal map is at ffff80000604a000
So, the address is actually 0xFFFF80008018B00C instead of 0xFFFFFFFF8018B00C. That's a big difference!
According to
the image you posted earlier, your new page tables don't map addresses in that range the same way the bootloader did. It looks like that address is part of the HHDM area, so the bootloader set it up with a fixed offset between virtual and physical address. You can find that offset in stivale2_struct_tag_hhdm.
Right now, you're only mapping available memory, and there's no correspondence between the virtual and physical address, but the Stivale2 HHDM maps at least 4GB whether it's available memory or not, and the offset between physical and virtual addresses is fixed to a single value.
22OsC wrote:edit: I found that when I try to access the framebuffer I get the page fault, and that infinite page faults are because I try to write to the screen the info about it. Sooooo... I think this is the last thing that is not working (i hope). I see that now my FB address is now 0xffff800080000000, I have to map it to the physical address (0xffff800080000000 - 0xFFFF800000000000)?
The framebuffer is not available memory, but it's included in the HHDM area since it's within the first 4GB of the physical address space.
22OsC wrote:edit2: I fixed the framebuffer but the page fault still the same and it's occurring
here because after the new PML4 I try to allocate a page for heap like
here, heap address is 0xFFFF800000000000 and page count is 0x10 (16).
Why are you placing your heap inside the HHDM area? I think you need to take a step back and figure out how you're currently using the virtual address space.