From 42211aab6f00d307978b791a5e024eceabcc4eaf Mon Sep 17 00:00:00 2001 From: Minep Date: Sat, 19 Feb 2022 16:40:39 +0000 Subject: [PATCH] re-factored the makefile and improved qemu debug experience. --- lunaix-os/config/make-cc | 7 ++++++ lunaix-os/config/make-debug-tool | 2 ++ lunaix-os/config/make-locations | 9 ++++++++ lunaix-os/config/make-os | 4 ++++ lunaix-os/makefile | 38 ++++++++++---------------------- 5 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 lunaix-os/config/make-cc create mode 100644 lunaix-os/config/make-debug-tool create mode 100644 lunaix-os/config/make-locations create mode 100644 lunaix-os/config/make-os diff --git a/lunaix-os/config/make-cc b/lunaix-os/config/make-cc new file mode 100644 index 0000000..416ae68 --- /dev/null +++ b/lunaix-os/config/make-cc @@ -0,0 +1,7 @@ +CC := i686-elf-gcc +AS := i686-elf-as + +O := -O2 +W := -Wall -Wextra +CFLAGS := -std=gnu99 -ffreestanding $(O) $(W) +LDFLAGS := -ffreestanding $(O) -nostdlib -lgcc \ No newline at end of file diff --git a/lunaix-os/config/make-debug-tool b/lunaix-os/config/make-debug-tool new file mode 100644 index 0000000..2817534 --- /dev/null +++ b/lunaix-os/config/make-debug-tool @@ -0,0 +1,2 @@ +QEMU_MON_TERM := gnome-terminal +QEMU_MON_PORT := 45454 \ No newline at end of file diff --git a/lunaix-os/config/make-locations b/lunaix-os/config/make-locations new file mode 100644 index 0000000..b60503e --- /dev/null +++ b/lunaix-os/config/make-locations @@ -0,0 +1,9 @@ +BUILD_DIR := build +KERNEL_DIR := kernel +OBJECT_DIR := $(BUILD_DIR)/obj +BIN_DIR := $(BUILD_DIR)/bin +ISO_DIR := $(BUILD_DIR)/iso +ISO_BOOT_DIR := $(ISO_DIR)/boot +ISO_GRUB_DIR := $(ISO_BOOT_DIR)/grub + +INCLUDES_DIR := includes \ No newline at end of file diff --git a/lunaix-os/config/make-os b/lunaix-os/config/make-os new file mode 100644 index 0000000..e3c26b7 --- /dev/null +++ b/lunaix-os/config/make-os @@ -0,0 +1,4 @@ +OS_ARCH := x86 +OS_NAME = lunaix +OS_BIN = $(OS_NAME).bin +OS_ISO = $(OS_NAME).iso \ No newline at end of file diff --git a/lunaix-os/makefile b/lunaix-os/makefile index 2ff30c0..4993318 100644 --- a/lunaix-os/makefile +++ b/lunaix-os/makefile @@ -1,28 +1,9 @@ -OS_ARCH := x86 +include config/make-locations +include config/make-os +include config/make-cc +include config/make-debug-tool -BUILD_DIR := build -KERNEL_DIR := kernel -OBJECT_DIR := $(BUILD_DIR)/obj -BIN_DIR := $(BUILD_DIR)/bin -ISO_DIR := $(BUILD_DIR)/iso -ISO_BOOT_DIR := $(ISO_DIR)/boot -ISO_GRUB_DIR := $(ISO_BOOT_DIR)/grub - -INCLUDES_DIR := includes INCLUDES := $(patsubst %, -I%, $(INCLUDES_DIR)) - -OS_NAME = lunaix -OS_BIN = $(OS_NAME).bin -OS_ISO = $(OS_NAME).iso - -CC := i686-elf-gcc -AS := i686-elf-as - -O := -O2 -W := -Wall -Wextra -CFLAGS := -std=gnu99 -ffreestanding $(O) $(W) -LDFLAGS := -ffreestanding $(O) -nostdlib -lgcc - SOURCE_FILES := $(shell find -name "*.[cS]") SRC := $(patsubst ./%, $(OBJECT_DIR)/%.o, $(SOURCE_FILES)) @@ -59,17 +40,22 @@ all-debug: O := -O0 all-debug: CFLAGS := -g -std=gnu99 -ffreestanding $(O) $(W) -fomit-frame-pointer all-debug: LDFLAGS := -ffreestanding $(O) -nostdlib -lgcc all-debug: clean $(BUILD_DIR)/$(OS_ISO) - @i686-elf-objdump -D $(BIN_DIR)/$(OS_BIN) > dump + @echo "Dumping the disassembled kernel code to $(BUILD_DIR)/kdump.txt" + @i686-elf-objdump -S $(BIN_DIR)/$(OS_BIN) > $(BUILD_DIR)/kdump.txt clean: @rm -rf $(BUILD_DIR) run: $(BUILD_DIR)/$(OS_ISO) - @qemu-system-i386 -cdrom $(BUILD_DIR)/$(OS_ISO) + @qemu-system-i386 -cdrom $(BUILD_DIR)/$(OS_ISO) -monitor telnet::45454,server,nowait & + @sleep 1 + @telnet 127.0.0.1 $(QEMU_MON_PORT) debug-qemu: all-debug @objcopy --only-keep-debug $(BIN_DIR)/$(OS_BIN) $(BUILD_DIR)/kernel.dbg - @qemu-system-i386 -s -S -kernel $(BIN_DIR)/$(OS_BIN) & + @qemu-system-i386 -s -S -kernel $(BIN_DIR)/$(OS_BIN) -monitor telnet::$(QEMU_MON_PORT),server,nowait & + @sleep 1 + @$(QEMU_MON_TERM) -e "telnet 127.0.0.1 $(QEMU_MON_PORT)" @gdb -s $(BUILD_DIR)/kernel.dbg -ex "target remote localhost:1234" debug-bochs: all-debug -- 2.27.0