I’ve got a file called idt.c, and in this file, I need to call the function idt_load from assembly. Now, this would work just fine, except that I need to access a variable, idtp from the assembly file, and the variable is declared in idt.c
This won’t work, because the linker will tell me that either idt_load is undefined or idtp is undefined. How can I get this to work?
Relevant parts of idt.c
struct idt_entry
{
unsigned short base_lo;
unsigned short sel;
unsigned char always0;
unsigned char flags;
unsigned short base_hi;
} __attribute__((packed));
struct idt_ptr
{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
struct idt_entry idt[256];
struct idt_ptr idtp;
extern void idt_load();
//Later in the code...
idt_load();
idt.asm
global idt_load
extern idtp
idt_load:
lidt [idtp]
ret
Two things to think out:
idtis of what type? (Ans: it’s a pointer toidt_entry, or strictly it’s the name of the addressidt[0].)How would you declare an external reference to a pointer in the asm file?
The easiest way to get all this stuff is to compile the C code with the appropriate flag (at least in gcc I think it’s -S) and see the generated assembly code.
You don’t have any circular reference, you just need to make the linker aware that you want to refer to the memory defined in the C code named
idt.