I just asked on the irc because this seemed like it could be possible with lifetimes. They suggested using PhantomData to add a lifetime parameter to the index and the stack pointers could be replaced by Option<&_>, which is easily obtained by an as_ref() method on a raw pointer.
The biggest issue here is verifying that the Option is the correct size.
Hey. This post seems to break returning from interruptions.
Eg. int!(3) produces a double fault while it returned correctly in the previous post
Aside from that, thanks for this series. It is superbly written with lots of useful info :)
You're right, I don't know how I didn't notice this.
It seems like the problem is our new GDT, which doesn't have a data segment descriptor. This alone is fine, but the `ss` register still holds a value which is saved to the stack when an exception occurs and checked by `iretq` when we return. One possible solution is to load 0 into the `ss` register after entering long mode (null descriptors are explicitely allowed in `ss` in 64-bit mode). Another solution is to add a valid writable data segment to our new GDT.
This issue is tracked in #277 and I plan to fix it in the next few days. Thanks a lot for reporting!
Thanks so much!
For all people that have the same problem:
The problem is that the
sssegment register still contains a selector of the previous GDT that is no longer valid. Theiretqinstruction expects a valid data segment selector or a null selector. So the easiest way to fix this problem is to add the following to thelong_mode_init.asm:(You only need to reload
ss. However, the other registers also no longer point to valid data segments, so it's cleaner to invalidate them, too.)