Page 2 of 2

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 7:58 am
by iansjack
Tell us what you understand an interrupt to be, how one is triggered, and how the processor responds. That may help us to understand what your problem is.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 8:14 am
by NunoLava1998
iansjack wrote:Tell us what you understand an interrupt to be, how one is triggered, and how the processor responds. That may help us to understand what your problem is.
An interrupt is a piece of data between the 0x0000 - 0x00FF sections of memory that points to a specific address, also called the "interrupt handler".

It is triggered using the "int (00-FF)" command.

The processor responds by seeing what the specified interrupt points to, and "calls" that location.

I know how interrupts know, i just want to know how to load the interrupt descriptor table, which i don't know.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 8:19 am
by matt11235
NunoLava1998 wrote:
iansjack wrote:Tell us what you understand an interrupt to be, how one is triggered, and how the processor responds. That may help us to understand what your problem is.
An interrupt is a piece of data between the 0x0000 - 0x00FF sections of memory that points to a specific address, also called the "interrupt handler".

It is triggered using the "int (00-FF)" command.

The processor responds by seeing what the specified interrupt points to, and "calls" that location.

I know how interrupts know, i just want to know how to load the interrupt descriptor table, which i don't know.
The wiki page seems quite clear to me. It provides the structure that you need:

Code: Select all

struct IDTDescr {
   uint16_t offset_1; // offset bits 0..15
   uint16_t selector; // a code segment selector in GDT or LDT
   uint8_t zero;      // unused, set to 0
   uint8_t type_attr; // type and attributes, see below
   uint16_t offset_2; // offset bits 16..31
};
You need to create an array of 256 of these, and you pass the address in of the first one to the lidt instruction.

Because the address is split into two parts (offset_1 and offset_2), you need to split it up yourself too, like so:

Code: Select all

offset_1 = base_address & 0xFFFF;
offset_2 = (base_address >> 16) & 0xFFFF;
Hopefully that clears a little bit up.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 8:39 am
by iansjack
NunoLava1998 wrote:
iansjack wrote:Tell us what you understand an interrupt to be, how one is triggered, and how the processor responds. That may help us to understand what your problem is.
An interrupt is a piece of data between the 0x0000 - 0x00FF sections of memory that points to a specific address, also called the "interrupt handler".

It is triggered using the "int (00-FF)" command.

The processor responds by seeing what the specified interrupt points to, and "calls" that location.

I know how interrupts know, i just want to know how to load the interrupt descriptor table, which i don't know.
OK.

That confirms what has been pretty obvious all along. You don't understand interrupts and you don't really know why you are trying to use them.

I'd suggest, as has already been done, that you go back and do some more reading before trying to leap into waters that are too deep for you.

This site is not really intended to teach basic concepts, but a little research on your part should turn up plenty of information. As long as you are prepared to do the work.

Here's a starting point for you: http://wiki.osdev.org/Interrupts

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 8:46 am
by NunoLava1998
zenzizenzicube wrote:
NunoLava1998 wrote:
iansjack wrote:Tell us what you understand an interrupt to be, how one is triggered, and how the processor responds. That may help us to understand what your problem is.
An interrupt is a piece of data between the 0x0000 - 0x00FF sections of memory that points to a specific address, also called the "interrupt handler".

It is triggered using the "int (00-FF)" command.

The processor responds by seeing what the specified interrupt points to, and "calls" that location.

I know how interrupts know, i just want to know how to load the interrupt descriptor table, which i don't know.
The wiki page seems quite clear to me. It provides the structure that you need:

Code: Select all

struct IDTDescr {
   uint16_t offset_1; // offset bits 0..15
   uint16_t selector; // a code segment selector in GDT or LDT
   uint8_t zero;      // unused, set to 0
   uint8_t type_attr; // type and attributes, see below
   uint16_t offset_2; // offset bits 16..31
};
You need to create an array of 256 of these, and you pass the address in of the first one to the lidt instruction.

Because the address is split into two parts (offset_1 and offset_2), you need to split it up yourself too, like so:

Code: Select all

offset_1 = base_address & 0xFFFF;
offset_2 = (base_address >> 16) & 0xFFFF;
Hopefully that clears a little bit up.
I still don't understand a few things:

"an array of 256 of these", what? Do you mean 256 of the struct, or 256 of the address?
What do i put in the lidt instruction, the inline assembly example needs 2 (void* base and uint16_t size)?

That's literally it.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 9:16 am
by NunoLava1998
Ahh, i seem to understand it a bit.

Should "do_lidt" in this case load the IDT at 0xFFFF00-0xFFFFFF? (EDIT: Changed to later, this is in the ISA Memory Hole region!)

Code: Select all

static inline void lidt(void* base, uint16_t size)
{   // This function works in 32 and 64bit mode
    struct {
        uint16_t length;
        void*    base;
    } __attribute__((packed)) IDTR = { size, base };
 
    asm ( "lidt %0" : : "m"(IDTR) );  // let the compiler choose an addressing mode
}

void do_lidt(void) {
	void *base = (void *)0x10000FF;
	uint16_t size = 0x00FF;
	lidt(void* base, uint16_t size);
}
EDIT:

I got it working perfectly with:

Code: Select all

static inline void lidt(void* base, uint16_t size)
{   // This function works in 32 and 64bit mode
    struct {
        uint16_t length;
        void*    base;
    } __attribute__((packed)) IDTR = { size, base };
 
    asm ( "lidt %0" : : "m"(IDTR) );  // let the compiler choose an addressing mode
}

void do_lidt(void) {	
	void *base = (void *)0x10000FF;
	uint16_t size = 0x00FF;
	lidt(base, size);
}

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 9:29 am
by alexfru
:shock:

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 9:31 am
by NunoLava1998
alexfru wrote::shock:
did i cause a M7.5 earthquake or what (sarcasm)

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 10:03 am
by glauxosdever
Hi,


Your post count overflowed!


Regards,
glauxosdever

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 10:05 am
by NunoLava1998
glauxosdever wrote:Hi,


Your post count overflowed!


Regards,
glauxosdever
:P

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 1:03 pm
by NunoLava1998
I just realized the code above is completely wrong (triple faults). Can someone show what to put in? Nothing in the IDT page is clear to me.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 1:06 pm
by glauxosdever
Hi,


If nothing is clear to you on the IDT page, then you probably should learn the computer science basics first.


Regards,
glauxosdever

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 1:10 pm
by iansjack
NunoLava1998 wrote:I just realized the code above is completely wrong (triple faults). Can someone show what to put in? Nothing in the IDT page is clear to me.
What did you think it was going to do? You point the IDT to a random bit of memory.

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 1:12 pm
by NunoLava1998
iansjack wrote:
NunoLava1998 wrote:I just realized the code above is completely wrong (triple faults). Can someone show what to put in? Nothing in the IDT page is clear to me.
What did you think it was going to do? You point the IDT to a random bit of memory.
So? I wanted to put the IDT in that "random bit of memory" (unused space). I don't need to make space, as it is unused (assuming you always do cold reboots to reset the RAM)

Re: How can i load the IDT?

Posted: Mon Jan 02, 2017 1:23 pm
by iansjack
And have you created a table at that location?