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

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
j4cobgarby
Member
Member
Posts: 64
Joined: Fri Jan 26, 2018 11:43 am

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

Post 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!
Octocontrabass
Member
Member
Posts: 5581
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
j4cobgarby
Member
Member
Posts: 64
Joined: Fri Jan 26, 2018 11:43 am

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

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