Example:
Code: Select all
IDT_set_gate(0, ISR0, ...)
Code: Select all
mov -0x...(%rip), %rsi
Code: Select all
lea -0x...(%rip), %rsi
Code: Select all
IDT_set_gate(0, IDT_initialize, ...)
What is causing this and how can I fix this?
Code: Select all
IDT_set_gate(0, ISR0, ...)
Code: Select all
mov -0x...(%rip), %rsi
Code: Select all
lea -0x...(%rip), %rsi
Code: Select all
IDT_set_gate(0, IDT_initialize, ...)
Code: Select all
extern const char ISR0[];
Code: Select all
extern unsigned long ISR0;
Code: Select all
void ISR0();
Code: Select all
void ISR0();
void ISR1();
void ISR2();
void ISR3();
void ISR4();
...
void ISR_initialize()
{
IDT_set_gate(0, ISR_initialize, GDT_KCS, 0, 0xf); // "Works"
// -> lea -0x1e(%rip), %rsi
IDT_set_gate(0, ISR0, GDT_KCS, 0, 0xf); // Does not work
// -> mov -0x33a(%rip), %rsi
IDT_set_gate(1, ISR1, GDT_KCS, 0, 0xf);
IDT_set_gate(2, ISR2, GDT_KCS, 0, 0xf);
IDT_set_gate(3, ISR3, GDT_KCS, 0, 0xf);
IDT_set_gate(4, ISR4, GDT_KCS, 0, 0xf);
...
}
Code: Select all
void IDT_set_gate(int interrupt, void (*base)(), uint16_t segment, int privilege, int type)
{
if(interrupt > 255)return;
idt[interrupt].base_low = ((uintptr_t)base) & 0xffff;
idt[interrupt].base_mid = (((uintptr_t)base) >> 16) & 0xffff;
idt[interrupt].base_high = ((uintptr_t)base) >> 32;
idt[interrupt].segment = segment;
idt[interrupt].flags = (privilege << 13) | ((type & 0xf) << 8);
idt[interrupt].flags |= IDT_ENABLE_FLAG;
}
Code: Select all
void (*isrs[])() = {
ISR0, ISR1, ISR2, ISR3,
ISR4, ISR5, ISR6, ISR7,
ISR8, ISR9, ISR10, ISR11,
ISR12, ISR13, ISR14, ISR15,
ISR16, ISR17, ISR18, ISR19,
ISR20, ISR21, ISR22, ISR23,
ISR24, ISR25, ISR26, ISR27,
ISR28, ISR29, ISR30, ISR31,
ISR32, ISR33, ISR34, ISR35,
ISR36, ISR37, ISR38, ISR39,
ISR40, ISR41, ISR42, ISR43,
ISR44, ISR45, ISR46, ISR47,
};
Code: Select all
IDT_set_gate(0, isrs[0], GDT_KCS, 0, 0xf);
Code: Select all
KERNEL_PM = 0x100000
KERNEL_VM = 0xffff800000100000
KERNEL_VM_OFFSET = KERNEL_VM - KERNEL_PM
ENTRY(k32_entry)
OUTPUT_FORMAT("binary")
SECTIONS
{
. = KERNEL_PM;
... k32 stuff
. = ALIGN(4096);
. += KERNEL_VM_OFFSET;
.text : AT(ADDR(.text) - KERNEL_VM_OFFSET) {...}
+ other sections
+ discards
}
You should use a cross-compiler. Since you're not using a cross-compiler, you get whatever default options the package maintainers decided to use when they built your copy of GCC, and I'd guess they decided to enable PIC by default. I'm not sure why your resulting binary isn't statically linked correctly, but disabling PIC (-fno-pic) will fix that. If you disable PIC you'll also need to specify the code model according to the address where your kernel is linked. The current address you're using requires the large code model (-mcmodel=large), but if you change it to 0xFFFFFFFF80000000 or higher, you can use the kernel code model (-mcmodel=kernel).SomePerson wrote: ↑Sun Sep 15, 2024 3:33 pmgcc -Wall -Wextra -O3 -ffreestanding -nostdlib -c $< -o $@