Interrupt Issues

Programming, for all ages and all languages.
Post Reply
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Interrupt Issues

Post by Simponic »

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.

Image
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interrupt Issues

Post by Octocontrabass »

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.)
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Interrupt Issues

Post by AndrewAPrice »

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?
My OS is Perception.
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

Ok I will try that

I made the gif by recording with "peek".
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

Here https://pastebin.com/kfFpjYSZ is the output of

Code: Select all

qemu-system-i386 -kernel os.bin -no-reboot -d int
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interrupt Issues

Post by Octocontrabass »

Code: Select all

     0: v=01 e=0000 i=1 cpl=0 IP=0008:00101091
It reached your INT 1 instruction.

Code: Select all

     1: v=0d e=000a i=0 cpl=0 IP=0008:00101091
#GP(0x000A) - there is a problem with your IDT entry for interrupt 1.

Code: Select all

     2: v=08 e=0000 i=0 cpl=0 IP=0008:00101091
#DF - There is also a problem with your IDT entry for #GP.

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]?
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

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?
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interrupt Issues

Post by Octocontrabass »

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.
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

Still same thing happens when I apply [8*n] instead of [8*n - 1]:
https://pastebin.com/THWdScqJ
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interrupt Issues

Post by Octocontrabass »

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.

Code: Select all

IDT=     00108000 00000000
Your IDT limit is 0.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interrupt Issues

Post by Octocontrabass »

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.

Code: Select all

asm("lidt %0" : :"m" (idt_ptr));
If it still doesn't work after fixing this, try "info idt" in the QEMU monitor.
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

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'
Simponic
Posts: 7
Joined: Tue Mar 09, 2021 4:24 pm

Re: Interrupt Issues

Post by Simponic »

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.
Post Reply