link error
Posted: Sat Feb 01, 2014 10:25 pm
I'm following Bran's Kernel Development tutorials and I am on the the GDT. I am getting a link error that I haven't been able to fix and have been searching for a bit. Any help will be very much appreciated. Thanks for your time.
Commands issued by my Makefile:
Here is my asm code:
In gdt.c I have:
as discussed in the tutorial.
Commands issued by my Makefile:
Code: Select all
i586-elf-gcc -c scrn.c -o scrn.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I.
i586-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I.
i586-elf-as boot.s -o boot.o
i586-elf-gcc -c gdt.c -o gdt.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I.
i586-elf-gcc -T linker.ld -o dtros.bin -ffreestanding -O2 -nostdlib scrn.o kernel.o boot.o gdt.o -lgcc
boot.o: In function `_gdt_flush':
(.text+0x11): undefined reference to `_gp'
gdt.o: In function `gdt_install':
gdt.c:(.text+0xfe): undefined reference to `gdt_flush'
collect2: ld returned 1 exit status
make: *** [dtros.bin] Error 1
Code: Select all
# This will set up our new segment registers. We need to do
# something special in order to set CS. We do what is called a
# far jump. A jump that includes a segment as well as an offset.
# This is declared in C as 'extern void gdt_flush();'
.section .text
.global _gdt_flush # Allows the C code to link to this
.type _gdt_flush, @function
.extern _gp
_gdt_flush:
lgdt (_gp) # Load the GDT with our '_gp' which is a special pointer
mov $0x10, %ax # 0x10 is the offset in the GDT to our data segment
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ljmp $0x8,$flush2 # 0x08 is the offset to our code segment: Far jump!
flush2:
ret # Returns back to the C code!
Code: Select all
/* Our GDT, with 3 entries, and finally our special GDT pointer */
struct gdt_entry gdt[3];
struct gdt_ptr gp;
/* This will be a function in start.asm. We use this to properly
* reload the new segment registers */
extern void gdt_flush();