Page 1 of 1

C++ IDTR Loader

Posted: Wed Jun 07, 2006 1:43 pm
by Tolga
Hi. I have a problem. (So i'm writing ;D) I tried, but it doesn't run. I wrote this function.

// ---------- C++ CODE ---------------
extern "C" void set_idtr();

struct tIDTR{
unsigned int base;
unsigned short limit;
}__attribute__((packed));

struct tIDTR IDTR;

void load_idtr( unsigned int base, unsigned short limit )
{
IDTR.base = base;
IDTR.limit = limit;

set_idtr(); // ASM Extern
}

// -------- ASM CODE ------------
global _set_idtr
extern _IDTR
_set_idtr:
lidt [_IDTR]
ret

But this isn't working. When an interrupt occured, pc rebooting. Is this code wrong? or my isr's wrong? If this code not wrong, i'll continue to question ;) Thanks.

Re:C++ IDTR Loader

Posted: Wed Jun 07, 2006 3:18 pm
by paulbarker
Limit comes before base in the tIDTR structure.

Re:C++ IDTR Loader

Posted: Fri Jun 09, 2006 11:00 pm
by Tolga
I'm sorry. In forum, i wrote it wrong. In code, it is true. Another, what can be?

Re:C++ IDTR Loader

Posted: Sun Jun 11, 2006 1:55 pm
by Mark
Have you set any idt entries? This seems to be missing. Check out the articles on OSDEV regarding interupts

Re:C++ IDTR Loader

Posted: Sun Jun 11, 2006 2:05 pm
by viral
Hi..
I dont knw whether this is the problem.. but u can try it out...
My IDT Size Descriptor structure is

Code: Select all

struct IDT_Size_Descriptor
{
  unsigned short limit;      //How long is IDT
  unsigned short lowbase;      //Low of Where Table starts
  unsigned short highbase;  //High of where Table starts
} __attribute__((__packed__));
Thus when u assing the address of IDT table to this structure try to break it first in 16-16bit halfs & then assign to structure

Code: Select all

     sz.limit = (MAXIDT*8)-1;
     sz.lowbase = (unsigned int)idt & 0xFFFF;
     sz.highbase = ((unsigned int)idt & 0xFFFF0000) >> 16;
     __asm__ ("lidt (%%eax)" : : "a"(&sz));