is it normal to crash when enable interrupts?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm
is it normal to crash when enable interrupts?

Post by combate » Mon Oct 13, 2008 5:58 pm

im new to os programming, my kernel its very simple, it justs print to screen and halt. i didn't setup any idt or interrupt handling so far. so, my question, why the OS crash when i enable interrupts.

this is what i got

Code: Select all

void kmain(void)
{
	iniciarVideo();

	puts("HELLO WORLD\n");

	asm("sti");

	for (;;);
}
with the asm("sti"); the kernel crash and this is what appear in bochslog

Code: Select all

00009781417i[CPU0 ] >> add byte ptr ds:[eax], al : 0000
00009781417e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
is it normal or i got any bug code somewhere in kernel?

thanks
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Mon Oct 13, 2008 10:01 pm

If you are in protected mode (as it appears to be) and have not set up an IDT yet (and remap the PICs), then yes--it should crash.

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Wed Oct 15, 2008 10:52 am

Hi,

The reason the bootloader doesn't crash (due to interrupts) is because the bios creates a valid 16bit interrupt table in memory (0x0000 to 0x03FF).

When you jump into 32bit mode, this interrupt table becomes invalid and you must make a new one before you can enable interrupts

The reason it is a good idea to disable interrupts for the entirety of your bootloader, rathet than just when you jump to proteced mode, is that you have no control over any interrupts you may recieve, and you dont want to be interrupted anyway

Andrew
Image

combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm

Post by combate » Wed Oct 15, 2008 5:40 pm

Mike wrote:If you are in protected mode (as it appears to be) and have not set up an IDT yet (and remap the PICs), then yes--it should crash.
This is where i want to get. I'm trying to setup a GDT and IDT. I'm following Tutorial 15, but i have to change a few lines of code to compile on GCC.

in idt.h i change

Code: Select all

   typedef void (_cdecl *I86_IRQ_HANDLER)(void);
to this
   typedef void(*I86_VECT_HANDLER)(void);
since the cdecl is a MSVC only definition, i think.

and i changed the inline asm to load gdt and idt, so in gdt.c and idt.c i got this.

Code: Select all

static void instalar_gdt()
{
	__asm__ __volatile__ ("lgdt %0\n" : : "m" (_gdtr));
}
and
 static void instalar_idt()
{
	__asm__ __volatile__ ("lidt %0\n" : : "m" (_idtr));
}
the rest of the code its same as tutorial 15.

in my cpu_init() function, if i just call loadGDT() and loadIDT(0x8), it doesn't crash. but after i call these two functions and call an interrupt like this __asm__("int $0x15"); it crash the system without calling the i86_default_handler();

any ideas?
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Thu Oct 16, 2008 12:38 am

in my cpu_init() function, if i just call loadGDT() and loadIDT(0x8), it doesn't crash. but after i call these two functions and call an interrupt like this __asm__("int $0x15"); it crash the system without calling the i86_default_handler();
Are you certain it never gets into i86_default_handler()? Also, are hardware interrupts disabled (CLI)?

If so, you may need to change the way it is stored in the idt. More specifically, take a look at i86_install_ir() and insure that the correct function address is being stored correctly in the idt.

Post Reply