Page 1 of 1

Strange interrupt behavior when handling interrupts

Posted: Thu Nov 20, 2014 12:41 am
by Sanchezman
I've set up a basic IDT and interrupt handler and I wanted to test it out. My handler looked like this:

Code: Select all

void isr_handler(registers_t regs)
{  
  printf("Received Interrupt %d:%p\n",regs.int_no, regs.err_code);
  return;
}
After initializing my IDT to take care of the 32 basic processor exceptions, I added some inline assembly to my kernel to simulate an interrupt.

Code: Select all

asm volatile ("int $0x03");
After building the kernel and running it in qemu, I noticed that everything would load up fine until my int 0x03 code was called. The handler would say that it received interrupt 3, and then fill the screen with messages saying it had received interrupt 13 with error code 0x274B before finally resetting the machine. After looking up what error code 0x274B meant for interrupt 13, I learned that it refers to a supposed problem with the 1,270th entry in my LDT (which I don't even use). Something was obviously wrong.

I decided to keep track of how many int 13's I received before the machine triple faulted, so I changed my handler to this:

Code: Select all

int previous_interrupts

void isr_handler(registers_t regs)
{  
  printf("Received %d interrupts before this one.  Int no: %d", previous_interrupts, regs.int_no);
  ++previous_interrupts;
  return;
}
When I ran it now, however, I only got one message: "Received 0 interrupts before this one. Int no: 3". My kernel then continued to run fine as I had expected it to the first time.

I played around trying to get the int 13 to occur again and I've discovered that int 13 only happens when the last part of my ISR handler's code is a printf() call. As long as the last statement in my ISR handler is not a printf() call, then there is no issue. I've also noticed that the error codes for the int 13 are different every once in a while. The one thing they have in common is that they all refer to ridiculously large entries in my nonexistent LDT. It also doesn't seem to matter which interrupt is the one to call my handler the first time.

Does anyone have any idea as to what's going on?

Re: Strange interrupt behavior when handling interrupts

Posted: Thu Nov 20, 2014 12:48 am
by Icee
Same thing as always, I'd guess.

EDIT: that, _and_ possibly broken printf().