diff --git a/Makefile b/Makefile index 4c8b27a..322c4e8 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,16 @@ endif CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \ -Wall -ggdb -m32 -Werror -fno-omit-frame-pointer CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) +ASMFLAGS = -m32 -ffreestanding -c -g + +ifeq ($(LLVM),on) +#AS=llvm-as +LD=ld.lld +CC=clang +CFLAGS += -target elf-i386 +ASMFLAGS = -target elf-i386 -ffreestanding -c -g +LDKERNELFLAGS = --script=script.ld +endif run: image.bin qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio @@ -41,6 +51,12 @@ debug-boot: image.bin mbr.elf -ex "break *0x7c00" \ -ex "continue" +debug-server: image.bin + qemu-system-i386 -drive format=raw,file=$< -s -S + +debug-server-nox: image.bin + qemu-system-i386 -nographic -drive format=raw,file=$< -s -S + debug: image.bin qemu-system-i386 -drive format=raw,file=$< -s -S & $(GDB) kernel.bin \ @@ -67,13 +83,13 @@ image.bin: mbr.bin fs.img cat $^ >$@ kernel.bin: kernel.o console.o drivers/vga.o drivers/uart.o - $(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^ + $(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x1000 $^ %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ %.o: %.S - $(CC) -m32 -ffreestanding -c -g $^ -o $@ + $(CC) $(ASMFLAGS) $^ -o $@ mbr.bin: mbr.o $(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@ diff --git a/script.ld b/script.ld new file mode 100644 index 0000000..e8c80c1 --- /dev/null +++ b/script.ld @@ -0,0 +1,24 @@ +SECTIONS +{ +.text (0x1000) : { + startup.o( .text ) +} + +.data : ALIGN(CONSTANT(MAXPAGESIZE)) { +_DATA_START_ = .; + *(.data) +_DATA_END_ = .; +} + +.rodata : ALIGN(CONSTANT(MAXPAGESIZE)) { +_RODATA_START_ = .; + *(.rodata) +_RODATA_START_ = .; +} + +.bss : ALIGN(CONSTANT(MAXPAGESIZE)) { +_BSS_START_ = .; + *(.bss) +_BSS_END_ = .; +} +} \ No newline at end of file