Skip to content
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

GPF on bootloaded kernel interrupts with blog_os-like project #196

Closed
SnowyCoder opened this issue Aug 27, 2021 · 2 comments
Closed

GPF on bootloaded kernel interrupts with blog_os-like project #196

SnowyCoder opened this issue Aug 27, 2021 · 2 comments

Comments

@SnowyCoder
Copy link

SnowyCoder commented Aug 27, 2021

Hello, this is my first kernel-like project so please pardon my ingenuity.
I'm running a (very) little kernel in private that is a fork of the blog_os one.
Trying to update the bootloader to the 0.10 branch is giving me a very strange error: everything is working except the iretq that gives me a General Protection Fault on every interrupt I receive.
I don't really know how to build a minimal functioning example for this so I made a blog_os fork with the following changes:

  • bootloader is updated to 0.10 (I also added the boot sub-project)
  • The PICS is disabled (so we don't get the timer interrupts)
  • a fn call_breakpoint() { int3() } is added and called from main (it's easier to break on from gdb)
  • the breakpoint_handler body is commented (easier gdb debugging)
  • I copied a simple framebuffer implementation (It could be used for debugging)

You can find it here: https://github.com/SnowyCoder/blog_os/tree/gpf_help .
In this version (that I tried to keep as similar as possible to the blog_os one) the kernel executes up until the iretq and then jumps into the general protection fault handler.

The only useful thing in the registers that changes seems to be the ss register (that should be useless?).
You can find a gdb run log here: original vs updated. (the updated version also has the PIC disabled)

Other useful infos:
rustc --version: rustc 1.56.0-nightly (0afc20860 2021-08-25)
uname -r: 5.10.59-1-MANJARO

@phil-opp
Copy link
Member

Sounds like you're hitting #190. The problem is indeed the ss register: It must be either 0, or point to a valid data segment in the GDT. In your code, you're loading a new GDT without reloading the ss register: https://github.com/SnowyCoder/blog_os/blob/313f491ec3229254b85b6e8f39d9ddec689e3fa0/src/gdt.rs#L43-L52

The iretq commands checks the ss segment in the GDT if it isn't 0, which is probably the cause of the GPF. To fix this, you could either add a data segment to your GDT and load es/ds/ss accordingly, or load ss with 0 in your init function. The former is probably the cleaner solution.

Sorry about the lack of documentation! I didn't have the time to update the blog and write a proper migration guide yet.

@SnowyCoder
Copy link
Author

Thanks a lot! I don't have the computer near but I'll fix this when I can.
You don't need documentation on migration but a line of it could be useful in the README (since I'm not the only one that fell in this).
I'll also read segmentation more to have a better understanding of it all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants