summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-05-17 18:24:59 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-05-17 18:24:59 +0200
commit4bdc7cb8b68e3ba3aa59b7100e855febe83a5ea8 (patch)
treef0f404f62ec3fa74badce8ed15f8f055075fa401
parent5585cc355659660f29cefa0d576d2356597fede7 (diff)
downloadabaos-4bdc7cb8b68e3ba3aa59b7100e855febe83a5ea8.tar.gz
abaos-4bdc7cb8b68e3ba3aa59b7100e855febe83a5ea8.tar.bz2
made debugging on C-language level possible with qemu and remote
debugging, building an ELF kernel first, then we create a flat binary and a symbol file from it
-rw-r--r--README8
-rw-r--r--src/Makefile18
2 files changed, 22 insertions, 4 deletions
diff --git a/README b/README
index c92d044..96e888b 100644
--- a/README
+++ b/README
@@ -43,6 +43,14 @@ break 0x8400
disassemble kernel in 32-bit mode
ndisasm -b32 -o8400h -a kernel.bin | less
+With qemu remote (see http://wiki.osdev.org/Kernel_Debugging):
+
+make run-qemu-debug
+
+gdb) target remote localhost:1234
+gdb) symbol-file kernel.sym
+gdb) break entry
+gdb) c
links
-----
diff --git a/src/Makefile b/src/Makefile
index 1a4f71f..45498bb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@ CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror
LD := ld
LDFLAGS := -f elf32
-all: image.bin
+all: image.bin kernel.sym
image.bin: boot.bin kernel.bin magic.bin
cat boot.bin kernel.bin > image.tmp
@@ -19,8 +19,14 @@ image.bin: boot.bin kernel.bin magic.bin
boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm
nasm boot.asm -f bin -o boot.bin
-kernel.bin: kernel.o console.o vga.o serial.o port.o port_asm.o string.o stdlib.o
- $(LD) -o kernel.bin -N -n -Ttext 0x8400 --oformat binary \
+kernel.bin: kernel.elf
+ objcopy -O binary kernel.elf kernel.bin
+
+kernel.sym: kernel.elf
+ objcopy --only-keep-debug kernel.elf kernel.sym
+
+kernel.elf: kernel.o console.o vga.o serial.o port.o port_asm.o string.o stdlib.o
+ $(LD) -o kernel.elf -N -n -Ttext 0x8400 --oformat elf32-i386 \
kernel.o console.o vga.o serial.o port.o port_asm.o \
string.o stdlib.o
@@ -52,11 +58,15 @@ stdlib.o: stdlib.c stdlib.h
$(CC) $(CFLAGS) -c -o stdlib.o stdlib.c
clean:
- -rm -f boot.bin kernel.bin image.bin magic.bin *.o boot.map image.tmp
+ -rm -f boot.bin kernel.bin kernel.sym kernel.elf image.bin magic.bin *.o boot.map image.tmp
run-qemu: image.bin
qemu-system-i386 -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
-serial file:serial.log
+run-qemu-debug: image.bin
+ qemu-system-i386 -S -s -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
+ -serial file:serial.log
+
run-bochs:
bochs -q -f bochs.config 'boot:floppy' 'floppya: 1_44=image.bin, status=inserted'