Offset errors occurred when changing segment base address
Posted: Sat Oct 27, 2012 11:51 am
Hi there,
I ran into some really silly problems and cannot find any solution.
First of all, I setup a flat memory model. All the kernel segments have a base address of 0 (But in fact kernel code begin from 0x100000) and everything went well.
But today when I set the code segment descriptor to a base of 0x100000, things began to go mad. Seems that the IDT initializing C function had a wrong offset of my ISRs (For instance, INT 3 handling routine should be 0x68 instead of 0x100068 I used before. By the way, ISRs are written in asm) . I really don't know how to deal with it.
Thanks.
Compiling environment: Linux
ASM compiler: NASM
C compiler: cc
Linker: ld with script
Flags:
Linking scripts:
I ran into some really silly problems and cannot find any solution.
First of all, I setup a flat memory model. All the kernel segments have a base address of 0 (But in fact kernel code begin from 0x100000) and everything went well.
But today when I set the code segment descriptor to a base of 0x100000, things began to go mad. Seems that the IDT initializing C function had a wrong offset of my ISRs (For instance, INT 3 handling routine should be 0x68 instead of 0x100068 I used before. By the way, ISRs are written in asm) . I really don't know how to deal with it.
Thanks.
Compiling environment: Linux
ASM compiler: NASM
C compiler: cc
Linker: ld with script
Flags:
Code: Select all
NASMFLAGS=-f elf
CCFLAGS= -ffreestanding -c -m32 -nostdlib
LDFLAGS=-Ttext 0x100000 -shared --oformat binary -Bsymbolic -z defs -m elf_i386 -T ./link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(boot_start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}