Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I wonder if adding -fno-leading-underscore to CFLAGS would work. Without it, some versions of GCC will put an underscore at the front of every symbol - for example gp will become _gp.
Actually, that would produce an error for kmain as well...so I don't think it can be that.
Can you run objdump -t gdt.o and see what it says? That should tell you what GCC has called all the symbols. objdump -r loader.o might help too, that will tell you what nasm expects the symbols to be called.
gdt.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 gdt.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .comment 00000000 .comment
00000000 g F .text 00000094 gdt_set_gate
00000018 O *COM* 00000001 gdt
00000094 g F .text 00000062 gdt_install
00000006 O *COM* 00000001 gp
00000000 *UND* 00000000 gdt_flush
loader.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 loader.asm
00000000 l d *ABS* 00000000
00000000 l d .text 00000000 .text
00000000 l d .setup 00000000 .setup
00000000 l d .bss 00000000 .bss
00000001 l *ABS* 00000000 MULTIBOOT_PAGE_ALIGN
00000002 l *ABS* 00000000 MULTIBOOT_MEMORY_INFO
1badb002 l *ABS* 00000000 MULTIBOOT_HEADER_MAGIC
00000003 l *ABS* 00000000 MULTIBOOT_HEADER_FLAGS
e4524ffb l *ABS* 00000000 MULTIBOOT_CHECKSUM
00000000 l .text 00000000 multiboot_header
00000028 l .text 00000000 higherhalf
00000050 l .text 00000000 flush2
00000000 l .setup 00000000 trickgdt
00000006 l .setup 00000000 gdt
0000001e l .setup 00000000 gdt_end
00001000 l .bss 00000000 sys_stack
00000000 *UND* 00000000 kmain
0000000c g .text 00000000 start
00000000 *UND* 00000000 gp
00000034 g .text 00000000 gdt_flush
I have cleaned the kernel project (deleted all files not needed for compiling like source makefile) and recompiled it and now I get this:
You might want to have something like
OBJFILES=kernel.o paging.o gdt.o loader.o
in your Makefile, and then replace the rules for compiling the .o files with
which will tell make that it can produce a .o file from a .c file or a .asm file by running the above commands. Then just change your kernel.bin line so it says
kernel.bin : $(OBJFILES)
and then to tell make about new source files you will just have to add the .o files to the OBJFILES line.