C++ IDTR Loader

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
Tolga

C++ IDTR Loader

Post 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.
paulbarker

Re:C++ IDTR Loader

Post by paulbarker »

Limit comes before base in the tIDTR structure.
Tolga

Re:C++ IDTR Loader

Post by Tolga »

I'm sorry. In forum, i wrote it wrong. In code, it is true. Another, what can be?
Mark

Re:C++ IDTR Loader

Post by Mark »

Have you set any idt entries? This seems to be missing. Check out the articles on OSDEV regarding interupts
viral

Re:C++ IDTR Loader

Post 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));
Post Reply