Interrupt problems

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Vladaz

Interrupt problems

Post by Vladaz »

Hello,
My OS started to do some horrible things. I am programming PIT now to IRQ0. I am in PM. Before this, all interrupts and exceptions were fine, I could call the interrupt with no problems. But now I checked and no interrupt is working at all. Here's what I get from bochs:
Bochs is exiting with the following message:
[CPU ] exception(): 3rd (13) exception with no resolution

And here's from VMWare:
Virtual machine kernel stack error (hardware reset)

Does anyone had the same problem or anyone has a good ideas about it?

Thanks in advance.
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:Interrupt problems

Post by kataklinger »

- IDT entery for IRQ0 is corrupted
- PIC/IOAPIC controller is not configured correctly (sending bad vector to CPU)
- Bad interrupt handler
- and many other things...

Be more specific, provide some code ...
Bochs is exiting with the following message:
[CPU ] exception(): 3rd (13) exception with no resolution

And here's from VMWare:
Virtual machine kernel stack error (hardware reset)
It could mean anything. This happens all the time.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Interrupt problems

Post by Kevin McGuire »

If you look in the bochs log file. It should show something like.


[start of log]

... way down at the end .... <down>


... right here it would have some (x) exception or two.
... check here to find what exception or IRQ is causing it..

[CPU ] exception(): 3rd (13) exception with no resolution


... down here is the dump_cpu information ...

[end of log]

I am not certain but that stack error could be causing the exception 13. It might be the interrupt handler starting.. using the stack with a bad SS or ESP or something.
Vladaz

Re:Interrupt problems

Post by Vladaz »

Here is my kernel's source code:
http://193.219.53.186/vladas/kernel.zip
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Interrupt problems

Post by Kevin McGuire »

Code: Select all

oid LoadIDT() {
??????idtreg.limit = &idt[0] - &idt[1] - 1;
??????idtreg.base = (unsigned long*) &idt[0];
??????asm volatile("LIDT %0 ": :"m" (idtreg));
??????
??????// Exceptions
??????SetInt(0, int00);
??????SetInt(0, int01);
??????SetInt(0, int02);
??????SetInt(0, int03);
??????SetInt(0, int04);
??????SetInt(0, int05);
??????SetInt(0, int06);
??????SetInt(0, int07);
??????SetInt(0, int08);
??????SetInt(0, int09);
??????SetInt(0, int10);
??????SetInt(0, int12);
??????SetInt(0, int13);
??????SetInt(0, int14);
??????SetInt(0, int16);
??????SetInt(0, int17);
??????SetInt(0, int18);
??????SetInt(0, int19);
??????
??????// IRQs
??????SetInt(0, int32); // PIT - Programmable Interval Timer IRQ
}

void SetInt(int number, void *handler) {
??????idt[number].low_offset = (unsigned int)handler;
??????idt[number].seg_selector = 0x08;
??????idt[number].settings = 0x8E00;
??????idt[number].high_offset = ((unsigned int)handler >> 16);
}
You only allocate enough space for 1 ISR.

Code: Select all

int_descriptor idt[1];
Go ahead and use:

Code: Select all

int_descriptor idt[255];
Try setting the exceptions to use the correct ISR, instead of all using ISR zero. No point in doing that.

Code: Select all

???init_pics();
???print("PICs remapped to 0x20 and 0x28.", white);
???
???LoadIDT();
Load the IDT before init_pics().

Code: Select all

void init_pics() {
??????outb(0x20, 0x11);
??????outb(0xA0, 0x11);

??????outb(0x21, 0x20);
??????outb(0xA1, 0x28);

??????outb(0x21, 0x04);
??????outb(0xA1, 0x02);

??????outb(0x21, 0x01);
??????outb(0xA1, 0x01);

??????outb(0x21, 0xFF);
}
You maked all the interrupts with:

Code: Select all

outb(0x21, 0xFF)
How is anything happening?

Code: Select all

[BITS 32]
[GLOBAL entry]
[EXTERN _k_main]

entry:

???call _k_main

???cli
???hlt
Where is your stack at? Does it have enough space? Try moving it somewhere else just to check.

Code: Select all

_int32: 
mov byte [0xb800], 'a'
???mov byte [0xb801], 0x07
???;jmp $
???;hlt
???;cmp byte [_isrfunc], 1
???
???;je pitsleep

???;jmp pitwrong

???;pitsleep:
???;???call _pit_sleep

???;pitwrong:
???;mov al, 20h
???;out 20h, al
???iret
Try a:

Code: Select all

cli
hlt
iret
Just to be sure, it is not crashing so fast BOCHS does not update the display with your vga code at the top.

Code: Select all

>>>> int_descriptor idt[1];
asm volatile ("int $0x1");
You are calling a interrupt that does not exist. See above, by setting all your ISRs to interrupt 0x0. You are calling 0x1. You never set a ISR for 0x1, only 0x0 multiple times in your code.

The PIC was remapped to 0x20.

Code: Select all

>>>>outb(0x21, 0x20);
>>>>outb(0xA1, 0x28);
asm volatile ("int $0x20") - calls the timer.
This sets the PIT correctly.

Code: Select all

SetInt(0x20, int32); // PIT - Programmable Interval Timer IRQ
That 0x1 could be causing the crash, but it might not be the original problem. You might have created a different problem trying to debug your kernel.
Phugoid

Re:Interrupt problems

Post by Phugoid »

Code: Select all

int_descriptor idt[1];
It appears that you have one entry in the IDT. Then, you invoke the second interrupt (interrupt 1). This causes an exception immediately.
Vladaz

Re:Interrupt problems

Post by Vladaz »

OK. Thank you very much. I think it works now:)
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:Interrupt problems

Post by kataklinger »

:o How did that work before setting PIT? :o
Vladaz

Re:Interrupt problems

Post by Vladaz »

I don't know, maybe I checked it when I didn't have exceptions yet. With one interrupt only as a test one. I think:)
Post Reply