[solved]tripfault on x86 hardware after restoring interrupts

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
User avatar
eino
Member
Member
Posts: 49
Joined: Fri Sep 16, 2011 10:00 am
Location: Finland

[solved]tripfault on x86 hardware after restoring interrupts

Post by eino »

Hi. I'm writing a sort of hobby os with C and the mandatory assembly. I've been reading the Intel I-32 manual, lots of asm books etc and my goal is basically to gain more understanding on how things work.

Anyways I've been using Bran's tutorial as a reference and I'm now facing a strange problem. I'm loading my IDT successfully (thou I have no entries in it and no ISRs yet) but after restoring interrupts with: __asm__ __volatile__ ("sti"); my kernel tripfaults on real hardware. On qemu it seems to work ok.

After loading the IDT I'm able to print out messages on to the screen so I know it crashes on that line.

Does this behaviour sound familiar to anyone? Do I need to implement the IDT entries and ISRs to get it to work? This question is something I can't seem to find info anywhere si I'm asking here to get this clear before I start work on those.
Last edited by eino on Sun Sep 18, 2011 4:01 am, edited 1 time in total.
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: trip fault on x86 hardware after restoring interrupts

Post by mark3094 »

You will need some sort of interrupt handler, even if it's just an empty one. You will also need an End of Interrupt routine to tell the PIC that the hardware interrupt is done.
I'd suggest a plan something like this:
  • Setup empty interrupts for the first 32 system interrupts
    Install IDT
    Test with INT instructions
When that works, add to it:
  • Add empty interrupts for hardware
    Remap the PIC's IRQs to the new interrupts
    Install updated IDT
    Enable interrupts with STI
    Test

Once you've done that you can go on with writing meaningful interrupt handlers and programming the PIT
User avatar
eino
Member
Member
Posts: 49
Joined: Fri Sep 16, 2011 10:00 am
Location: Finland

Re: trip fault on x86 hardware after restoring interrupts

Post by eino »

Hi. Just as I thought it would be. I didn't want to start writing the ISR's & IRQ's before I knew the facts above because I wanted to make sure that the code so far was not buggy.

Anyways I added the ISR's and IRQ's and am sending the 20h to PIC's correctly. The thing didn't work but after a while I noticed I had a bug on my function that sets an IDT entry.

Works now! Thank you so much and see you again cause this will most likely not be the last question =)
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev
Post Reply