How can i load the IDT?

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.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How can i load the IDT?

Post 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.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post 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.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: How can i load the IDT?

Post 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.
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How can i load the IDT?

Post 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
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post 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.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post 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);
}
Last edited by NunoLava1998 on Mon Jan 02, 2017 9:29 am, edited 1 time in total.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: How can i load the IDT?

Post by alexfru »

:shock:
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post by NunoLava1998 »

alexfru wrote::shock:
did i cause a M7.5 earthquake or what (sarcasm)
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: How can i load the IDT?

Post by glauxosdever »

Hi,


Your post count overflowed!


Regards,
glauxosdever
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post by NunoLava1998 »

glauxosdever wrote:Hi,


Your post count overflowed!


Regards,
glauxosdever
:P
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post 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.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: How can i load the IDT?

Post 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
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How can i load the IDT?

Post 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.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: How can i load the IDT?

Post 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)
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How can i load the IDT?

Post by iansjack »

And have you created a table at that location?
Post Reply