I have the following code in NASM which is shortened for the question:
idt_start:
int0:
dw isr0
dw 0x0008
db 0x00
db 10001110b
dw 0x0000
idt_end:
idtr:
dw idt_end - idt_start - 1
dd idt_start
isr0:
Normally I have 47 of these entries 32 for the protected mode exceptions and 15 to map the IRQs. I'm setting up an IDT to manage interrupts from my bootloader.
The problem arises when I try to port this code to C++ inline assembly.
I have 2 files kernel.cpp:
#include "idt.h"
void kmain(){
defineIDT();
halt:;
asm("hlt");
goto halt;
}
and idt.cpp:
void defineIDT(){
asm(
"idt_start:\n\t"
"int0:\n\t"
".hword isr0\n\t"
".hword 0x0008\n\t"
".byte 0x00\n\t"
".byte 0b10001110\n\t"
".hword 0x0000\n\t"
"idt_end:\n\t"
"idtr:\n\t"
".hword idt_end - idt_start - 1\n\t"
".word idt_start\n\t"
"isr0:\n\t"
);
return;
}
I'm using g++ to compile my code with g++ -static -ffreestanding -nostdlib -znoexecstack -mno-red-zone -s -m32 kernel.cpp idt.cpp -okernel.o
I get an error saying relocation truncated to fit: R_386_16 against `.text'. It is because of the .hword isr0, .hword idt_end - idt_start - 1 and .word idt_start lines. I don't see how else to implement this.