Interrupt Issues
Interrupt Issues
Hello everyone, I am trying to write a 32 bit protected mode operating system from scratch to learn about stuff. I took a break after getting my GDT set up, and now I am trying to get interrupts working.
For the life of me, I cannot figure out what I am doing wrong. I am almost certain I set up the descriptor tables right, but if someone could look at the code, it is available at https://github.com/Simponic/SimponicOS.
When I try to run my kernel with the interrupt in the kernel, I get really weird glitches all over the screen, text popping into and out of existence. It is really weird.
For the life of me, I cannot figure out what I am doing wrong. I am almost certain I set up the descriptor tables right, but if someone could look at the code, it is available at https://github.com/Simponic/SimponicOS.
When I try to run my kernel with the interrupt in the kernel, I get really weird glitches all over the screen, text popping into and out of existence. It is really weird.
-
- Member
- Posts: 5515
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Interrupt Issues
What kind of debugging have you done so far?
It looks like you're using QEMU. Try adding "-no-reboot" and "-d int" to your command line. (You may also need to disable hardware acceleration.)
It looks like you're using QEMU. Try adding "-no-reboot" and "-d int" to your command line. (You may also need to disable hardware acceleration.)
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: Interrupt Issues
Nothing super obvious stands out.
I agree with Octocontrabass to add "-no-reboot -d int" and see what QEMU says.
Btw, how did you make the animated gif?
I agree with Octocontrabass to add "-no-reboot -d int" and see what QEMU says.
Btw, how did you make the animated gif?
My OS is Perception.
Re: Interrupt Issues
Ok I will try that
I made the gif by recording with "peek".
I made the gif by recording with "peek".
Re: Interrupt Issues
Here https://pastebin.com/kfFpjYSZ is the output of
Code: Select all
qemu-system-i386 -kernel os.bin -no-reboot -d int
-
- Member
- Posts: 5515
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Interrupt Issues
Code: Select all
0: v=01 e=0000 i=1 cpl=0 IP=0008:00101091
Code: Select all
1: v=0d e=000a i=0 cpl=0 IP=0008:00101091
Code: Select all
2: v=08 e=0000 i=0 cpl=0 IP=0008:00101091
There is also a problem with your IDT entry for #DF, so the CPU triple faults.
How did you come up with [1*8 - 1]?
Re: Interrupt Issues
I got 1*8 - 1 because each IDT entry is 8 bytes long, and - 1 because array starts at 0.
To me the IDT entry for 1 looks right, what is wrong with it?
To me the IDT entry for 1 looks right, what is wrong with it?
-
- Member
- Posts: 5515
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Interrupt Issues
If the first entry is at offset 0 and each entry is 8 bytes long, the second entry should be at offset 8.
You're putting it at offset 7.
You're putting it at offset 7.
Re: Interrupt Issues
Still same thing happens when I apply [8*n] instead of [8*n - 1]:
https://pastebin.com/THWdScqJ
https://pastebin.com/THWdScqJ
-
- Member
- Posts: 5515
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Interrupt Issues
Try "info idt" in the QEMU monitor to see if there are any other problems with how you're building your IDT.
Edit: But I've just spotted the one issue it will show you.
Your IDT limit is 0.
Edit: But I've just spotted the one issue it will show you.
Code: Select all
IDT= 00108000 00000000
-
- Member
- Posts: 5515
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Interrupt Issues
Your inline assembly is wrong. The input operand is a pointer to the struct instead of the struct itself. Since the struct is not an input operand, the compiler may not initialize its value.
Change your inline assembly so that the struct is the input operand.
If it still doesn't work after fixing this, try "info idt" in the QEMU monitor.
Change your inline assembly so that the struct is the input operand.
Code: Select all
asm("lidt %0" : :"m" (idt_ptr));
Re: Interrupt Issues
Hmm I can't do that for some reason in the qemu monitor
Code: Select all
qemu-system-i386 -kernel os.bin -monitor stdio
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) info idt
unknown command: 'info idt'
Re: Interrupt Issues
Oh my god that was it. All it took was changing the inline assembly and the index numbers.
Now it is printing to the screen that it got an interrupt a lot of times. Should this be expected of interrupts? I think it should only print once.
Now it is printing to the screen that it got an interrupt a lot of times. Should this be expected of interrupts? I think it should only print once.