-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix higher half kernels by identity mapping context switch fn earlier #161
Conversation
@phil-opp now it works perfectly! Though setting the physical memory offset to |
Great to hear that!
Hmm, could you show the ELF program header of your kernel, e.g. via |
We used to reverve two frames to allow the context switch function to identity-map itself after creating the boot info. This works for kernels that use the standard mapping since they don't need to create new level 3/2 page tables for that. For kernels that are mapped differently (e.g. to the higher half), two frames aren't enough and a frame allocation error occurs. While we could fix this by reserving a larger number of frames, this would result in lost frames for normally-mapped kernels. So we instead do the identity-mapping already in the `set_up_mappings` function, where the normal frame allocator still exists. This way, we no longer need the `TwoFrames` workaaround at all. To ensure that this all works as intended, this PR also adds a new `higher_half` test kernel that maps itself to address `0xFFFF800000000000` via its custom target. By reading the `rip` register, the test kernel can verify that it was indeed loaded to the higher half.
d34e44f
to
3be235b
Compare
|
@Andy-Python-Programmer Thanks! I don't see anything problematic. Normally the bootloader should just ignore the |
Thanks a lot, that was quick :D. It looks like you tried to map both the kernel and the physical memory mapping at address |
Ah all good! Thanks @phil-opp! |
You're welcome! Thanks for the help in debugging this! |
Published as v0.10.4. |
We used to reverve two frames to allow the context switch function to identity-map itself after creating the boot info. This works for kernels that use the standard mapping since they don't need to create new level 3/2 page tables for that. For kernels that are mapped differently (e.g. to the higher half), two frames aren't enough and a frame allocation error occurs. While we could fix this by reserving a larger number of frames, this would result in lost frames for normally-mapped kernels. So we instead do the identity-mapping already in the
set_up_mappings
function, where the normal frame allocator still exists. This way, we no longer need theTwoFrames
workaaround at all.To ensure that this all works as intended, this PR also adds a new
higher_half
test kernel that maps itself to address0xFFFF800000000000
via its custom target. By reading therip
register, the test kernel can verify that it was indeed loaded to the higher half.Fixes #159