Page 1 of 1

How to create an IDT entry referring to a procedure in nasm?

Posted: Thu Oct 10, 2019 4:55 am
by j4cobgarby
Sorry about the vague title, I couldn't quite think how to phrase this properly.
My issue is, I'm in the process of setting up an IDT for an x86-32 architecture. Of course, the `offset` in an IDT entry is split in two, like this:

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
};
(from wiki.osdev.org)

I'm implementing my IDT entirely in NASM, and my issue is that when I'm using the dw and db directives to put data in the IDT, I can't work out how I would refer to my keyboard handler?
The reason for this is that I don't know what the absolute address of my keyboard handler code, so how can I put the address of it into an IDT entry?
Again sorry, I know this question is phrased horribly and might not even make sense, I don't know why I'm having such trouble wording it.
Thanks!

Re: How to create an IDT entry referring to a procedure in n

Posted: Thu Oct 10, 2019 5:10 am
by Octocontrabass
If the offset wasn't split in two, you could use its name and the linker will resolve the correct address.

Code: Select all

dd function_name_here
But the linker doesn't know how to resolve the correct address once you split it in two, so it's not possible.

You'll have to either write code to build the IDT at runtime, or patch your linker to understand how to split it up properly.

Re: How to create an IDT entry referring to a procedure in n

Posted: Thu Oct 10, 2019 5:13 am
by j4cobgarby
Octocontrabass wrote:If the offset wasn't split in two, you could use its name and the linker will resolve the correct address.

Code: Select all

dd function_name_here
But the linker doesn't know how to resolve the correct address once you split it in two, so it's not possible.

You'll have to either write code to build the IDT at runtime, or patch your linker to understand how to split it up properly.
Okay thanks! I was hoping there would be a way to do it without writing code to build it at runtime, but I guess that's what I'll do :)