rust-osdev / bootloader

An experimental pure-Rust x86 bootloader
Apache License 2.0
1.37k stars 209 forks source link

Hang after loading first level 4 table on uefi #462

Open Colepng opened 2 days ago

Colepng commented 2 days ago

I tried my os on real hardware for the first time and found that the bootloader is hanging. I tracked the issue down to this line. I'm still a beginner in os development so any help is appreciated.

I am running it on my laptop which is a lenvo legion 7 which has a AMD Ryzen 7 5800H.

Freax13 commented 2 days ago

Hmm, there's not much to go on. How did you track this hang down to this line? Can you share the log output?

Colepng commented 2 days ago

I cloned the repo locally, linked my kernel to the local version and added debug statements. I put 1 statement after the line I linked to and 1 after. Only the first 1 ran. The best photo I can add would be from my phone.

Image

As you can see in the photo it no longer hang. Instead of only copying over the first entry of the old page table, I started copying over all entries and now it works. The panic you can see in the photo seems to be from the fact my system uses huge page table while the bootloader expects 4KiB tables. If you know, could you explain to me why copying over all the old entries would fix it.

Freax13 commented 2 days ago

The frame buffer (0xfc_1000_0000) address is in the second pml4 entry, interesting. Currently, we only copy the first pml4 entry, but when the bootloader tries to access the frame buffer it needs the second pml4e. The assumption in this comment was incorrect. Your fix (copying more entries) seems reasonable unless maybe that's what's causing the panic below? Freel free to open at PR. I'll investigate some more later this evening.