diff --git a/.gitignore b/.gitignore index 9574e7a..8db6706 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.stage2 *.sector *.o -img.d/ \ No newline at end of file +img.d/ +build/ \ No newline at end of file diff --git a/Makefile b/Makefile index d72e87f..7614b83 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -std=gnu11 -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector -Wno-pointer-to-int-cast -CXXFLAGS = -m32 -fno-use-cxa-atexit -mgeneral-regs-only -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -fpermissive -fno-pie -fno-stack-protector -I. +CFLAGS = -g -std=gnu11 -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector -Wno-pointer-to-int-cast +CXXFLAGS = -g -m32 -fno-use-cxa-atexit -mgeneral-regs-only -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -fpermissive -fno-pie -fno-stack-protector -I. LDFLAGS = DISK_IMG_FILES = build/kernel/kernel.bin hello.txt alpha.txt @@ -12,6 +12,9 @@ STAGE2_OBS = build/c_code_entry.o build/boot_stage2/io.o build/boot_stage2/atapi run: disk.img qemu-system-x86_64 disk.img +debug: disk.img + qemu-system-x86_64 -s -S disk.img & gdb --command=gdbscript + disk.img: clean prepare build/boot/boot.bin build/boot_stage2/boot.bin $(DISK_IMG_FILES) dd if=/dev/zero of=disk.img count=43 bs=100k dd if=build/boot/boot.bin of=disk.img conv=notrunc @@ -43,7 +46,10 @@ build/boot_stage2/%.o: src/boot_stage2/%.c gcc $(CFLAGS) -o $@ -c $< # Kernel -build/kernel/kernel.bin: src/kernel/kernel.ld $(KERNEL_OBJS) +build/kernel/kernel.bin: build/kernel/kernel.elf + objcopy -O binary build/kernel/kernel.elf build/kernel/kernel.bin + +build/kernel/kernel.elf: src/kernel/kernel.ld $(KERNEL_OBJS) ld $(LDFLAGS) -T $< $(KERNEL_OBJS) build/boot_stage2/stage2.o: src/boot_stage2/main.c diff --git a/gdbscript b/gdbscript new file mode 100644 index 0000000..fb3551f --- /dev/null +++ b/gdbscript @@ -0,0 +1,2 @@ +target remote localhost:1234 +symbol-file build/kernel/kernel.elf diff --git a/src/kernel/kernel.ld b/src/kernel/kernel.ld index 01eb987..bef12c6 100644 --- a/src/kernel/kernel.ld +++ b/src/kernel/kernel.ld @@ -1,7 +1,7 @@ -OUTPUT_FORMAT(binary) +OUTPUT_FORMAT(elf32-i386) OUTPUT_ARCH(i386:i386) -OUTPUT(build/kernel/kernel.bin) +OUTPUT(build/kernel/kernel.elf) SECTIONS { . = 0xc0000000;