Hi All,
I have setup my IDT to dispatch interrupts to dummy handlers (that just print which interrupt occurred). In testing it, I realized I get a GP fault on the first iretq. I believe whats going on is that it tries to load the stack segment and fails because the selector is not valid (beyond the limit of my tiny GDT). I never setup my SS once I got to long mode because I was under the impression it wasn't used at all under long mode. Am I misunderstanding something? Should I just setup a data segment and point all the unused segments to it?
64 bit mode interrupts and the stack selector
Re: 64 bit mode interrupts and the stack selector
Read the Intel/amd manuals. Of course you'll need a stack (and therefore an appropriate selector in ss). There's a special case when it can be unconfigured (ss=null) but I'm pretty sure it's not your case.dschatz wrote:Hi All,
I have setup my IDT to dispatch interrupts to dummy handlers (that just print which interrupt occurred). In testing it, I realized I get a GP fault on the first iretq. I believe whats going on is that it tries to load the stack segment and fails because the selector is not valid (beyond the limit of my tiny GDT). I never setup my SS once I got to long mode because I was under the impression it wasn't used at all under long mode. Am I misunderstanding something? Should I just setup a data segment and point all the unused segments to it?
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: 64 bit mode interrupts and the stack selector
I had the same problem when I started my x86_64 kernel and I solved it by setting SS to 0 right at the beginning. Anyway, I think this should be documented somewhere in the Intel / AMD manuals...
Re: 64 bit mode interrupts and the stack selector
Yes, I ended up doing the same thing (also setting ds, es, fs, and gs all to 0 for good measure) and it now works. I was wondering why this is necessary? It doesn't make use of the descriptor (obvious because the invalid descriptor works). So why should it try to switch stack segments with an iretq?XenOS wrote:I had the same problem when I started my x86_64 kernel and I solved it by setting SS to 0 right at the beginning. Anyway, I think this should be documented somewhere in the Intel / AMD manuals...
Re: 64 bit mode interrupts and the stack selector
Because x86_64 switches unconditionally. Think about it: cpu spend most of it's time in userspace (ss ring 3), then an interrupt happens, which passes control to a routine somewhere in kernelspace (ring 0). After the ISR finishes, you have to switch back to userspace (ring 3). You can also use IST stack switch mechanism for that, but switching to a safer stack for ISR is mandatory anyhow. Now it's more simpler to have the same mechanism for the rest cases, instead of pushing ss conditionally like x86_32 does.dschatz wrote:So why should it try to switch stack segments with an iretq?