Everything went fine until I reached the part of GDT.
Although my Assembly code can call C functions, calling Assembly functions from C causes a linker error. Although both gcc and nasm compile properly, ld fails.
Code: Select all
out/gdt.o: In function `gdt_install':
gdt.c:(.text+0x102): undefined reference to `gdt_flush'
I've tried messing with leading underscores, but with no luck...
My assembly "gdt_flush" function:
Code: Select all
global gdt_flush ; Allows the C code to link to this
extern gp ; Says that 'gp' is in another file
gdt_flush:
lgdt [gp] ; Load the GDT with our 'gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
Code: Select all
extern void gdt_flush();
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(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 = .;
}
(sorry if this is a duplicate. I've searched for quite some time now and I didn't find anything yet.)
EDIT: Ah, before I forget, I'm calling ld using this command:
Code: Select all
ld -Ttext 0x100000 -T src/link.ld out/*.o -o iso/$COREFOLDER/kernel.bin