OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:57 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Interrupt Issues
PostPosted: Tue Mar 09, 2021 7:17 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Wed Mar 10, 2021 7:03 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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.)


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Wed Mar 10, 2021 8:42 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 12:26 am 
Offline

Joined: Tue Mar 09, 2021 4:24 pm
Posts: 7
Ok I will try that

I made the gif by recording with "peek".


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 12:30 am 
Offline

Joined: Tue Mar 09, 2021 4:24 pm
Posts: 7
Here https://pastebin.com/kfFpjYSZ is the output of
Code:
qemu-system-i386 -kernel os.bin -no-reboot -d int


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 1:20 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Code:
     0: v=01 e=0000 i=1 cpl=0 IP=0008:00101091

It reached your INT 1 instruction.

Code:
     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:
     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]?


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 9:06 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 9:16 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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.


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 9:50 pm 
Offline

Joined: Tue Mar 09, 2021 4:24 pm
Posts: 7
Still same thing happens when I apply [8*n] instead of [8*n - 1]:
https://pastebin.com/THWdScqJ


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 10:04 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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:
IDT=     00108000 00000000

Your IDT limit is 0.


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 10:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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:
asm("lidt %0" : :"m" (idt_ptr));


If it still doesn't work after fixing this, try "info idt" in the QEMU monitor.


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 10:50 pm 
Offline

Joined: Tue Mar 09, 2021 4:24 pm
Posts: 7
Hmm I can't do that for some reason in the qemu monitor

Code:
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'


Top
 Profile  
 
 Post subject: Re: Interrupt Issues
PostPosted: Thu Mar 11, 2021 10:53 pm 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group