From db21f7cf05f73d08ef4c513840a6f789a75ec9a6 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Oct 2013 14:58:05 +0200 Subject: [PATCH] =?UTF-8?q?simplified=20Makefile=20for=20building=2064bit?= =?UTF-8?q?=20code=20and=20added=20new=20debug=20target=20(see=20L=C2=B2P:?= =?UTF-8?q?=20Howto=20QEmu=20und=20GDB)y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.example | 93 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/Makefile.example b/Makefile.example index 7745279a..148293dd 100644 --- a/Makefile.example +++ b/Makefile.example @@ -1,8 +1,12 @@ -TOPDIR = $(shell pwd) -ARCH = x86 -# For 64bit support, you have define BIT as 64 -BIT=32 NAME = metalsvm + +# For 64bit support, you have define BIT as 64 +# Note: do not forget to 'make veryclean' after changing BIT!!! +BIT=64 +ARCH = x86 +SMP=1 + +TOPDIR = $(shell pwd) LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif DRIVERDIRS = drivers/net drivers/char KERNDIRS = libkern kernel mm fs apps arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS) @@ -30,35 +34,56 @@ RANLIB_FOR_TARGET = $(CROSSCOMPREFIX)ranlib STRIP_FOR_TARGET = $(CROSSCOMPREFIX)strip READELF_FOR_TARGET = $(CROSSCOMPREFIX)readelf +# Tools MAKE = make RM = rm -rf NASM = nasm -# For 64bit code, you have to use qemu-system-x86_64 -QEMU = qemu-system-i386 GDB = gdb -# For 64bit support, you have to define -felf64 instead of -felf32 -NASMFLAGS = -felf32 -g -i$(TOPDIR)/include/metalsvm/ -INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers -# For 64bit support, you have to define "-m64 -mno-red-zone" instead of "-m32 -march=i586" +ifeq ($(BIT), 32) + QEMU = qemu-system-i386 +else ifeq ($(BIT), 64) + QEMU = qemu-system-x86_64 +endif + + +INCLUDE = -I$(TOPDIR)/include \ + -I$(TOPDIR)/arch/$(ARCH)/include \ + -I$(TOPDIR)/lwip/src/include \ + -I$(TOPDIR)/lwip/src/include/ipv4 \ + -I$(TOPDIR)/drivers + + # Compiler options for final code -CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT) +CFLAGS = -g -O2 -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding -fstrength-reduce -finline-functions $(INCLUDE) $(STACKPROT) + # Compiler options for debuging -#CFLAGS = -g -O -m32 -march=i586 -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT) +#CFLAGS = -g -O -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT) + +NASMFLAGS = -felf$(BIT) -g -i$(TOPDIR)/include/metalsvm/ ARFLAGS = rsv LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S') + STRIP_DEBUG = --strip-debug KEEP_DEBUG = --only-keep-debug + +# Do not change to elf64! +# The Multiboot spec can only boot elf32 binaries OUTPUT_FORMAT = -O elf32-i386 -# For 64bit support, you have to define -m64 instead of "-m32 -march=i586" -CFLAGS_FOR_NEWLIB = -m32 -march=i586 -O2 $(STACKPROT) -# For 64bit support, you have to define -m64 instead of "-m32 -march=i586" -LDFLAGS_FOR_NEWLIB = -m32 -march=i586 -# For 64bit support, you have to define -m64 instead of "-m32" -CFLAGS_FOR_TOOLS = -m32 -O2 -Wall + +CFLAGS_FOR_NEWLIB = -m$(BIT) -O2 $(STACKPROT) +LDFLAGS_FOR_NEWLIB = -m$(BIT) +CFLAGS_FOR_TOOLS = -m$(BIT) -O2 -Wall LDFLAGS_FOR_TOOLS = -# For 64bit support, you have to define -felf64 instead of -felf32 -NASMFLAGS_FOR_NEWLIB = -felf32 +NASMFLAGS_FOR_NEWLIB = -felf$(BIT) + +ifeq ($(BIT), 32) + CFLAGS += -march=i586 + CFLAGS_FOR_NEWLIB += -march=i586 + LDFLAGS_FOR_NEWLIB += -march=i586 +else ifeq ($(BIT), 64) + CFLAGS += -mno-red-zone +endif # Prettify output V = 0 @@ -68,11 +93,15 @@ ifeq ($V,0) endif default: all - + all: newlib tools $(NAME).elf - + newlib: - $(MAKE) ARCH=$(ARCH) BIT=$(BIT) LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" CFLAGS="$(CFLAGS_FOR_NEWLIB)" NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" CC_FOR_TARGET=$(CC_FOR_TARGET) \ + $(MAKE) ARCH=$(ARCH) BIT=$(BIT) \ + LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" \ + CFLAGS="$(CFLAGS_FOR_NEWLIB)" \ + NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" \ + CC_FOR_TARGET=$(CC_FOR_TARGET) \ CXX_FOR_TARGET=$(CXX_FOR_TARGET) \ GCC_FOR_TARGET=$(GCC_FOR_TARGET) \ AR_FOR_TARGET=$(AR_FOR_TARGET) \ @@ -96,14 +125,20 @@ $(NAME).elf: $Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf qemu: newlib tools $(NAME).elf - $(QEMU) -monitor stdio -serial tcp::12346,server -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img + $(QEMU) -monitor stdio -serial tcp::12346,server,nowait -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img qemudbg: newlib tools $(NAME).elf - $(QEMU) -s -S -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img + $(QEMU) -s -S -monitor stdio -serial tcp::12346,server -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img gdb: $(NAME).elf - make qemudbg > /dev/null & - $(GDB) -x script.gdb + $(GDB) -q -x script.gdb + +debug: newlib tools $(NAME).elf + gnome-terminal --working-directory=$(TOPDIR) \ + --tab --title=Debug --command="bash -c 'sleep 1 && telnet localhost 12346'" \ + --tab --title=Shell --command="bash -c 'sleep 1 && telnet localhost 12345'" \ + --tab --title=QEmu --command="make qemudbg" \ + --tab --title=GDB --command="make gdb" clean: $Q$(RM) $(NAME).elf $(NAME).sym *~ @@ -112,7 +147,7 @@ clean: veryclean: clean $Q$(MAKE) -C newlib veryclean - @echo Very cleaned + @echo Very cleaned. #depend: # for i in $(SUBDIRS); do $(MAKE) -k -C $$i depend; done @@ -134,6 +169,6 @@ include/metalsvm/config.inc: include/metalsvm/config.h @echo [ASM] $@ $Q$(NASM) $(NASMFLAGS) -o $@ $< -.PHONY: default all clean emu gdb newlib tools +.PHONY: default all clean qemu qemudbg gdb debug newlib tools include $(addsuffix /Makefile,$(SUBDIRS))