From e681b848d50f3da026a98acb5acaf039ee3971d2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 5 Apr 2024 17:02:16 +0200 Subject: [PATCH] Makefile tuning --- makefile | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/makefile b/makefile index 1f81cfc..33620fb 100644 --- a/makefile +++ b/makefile @@ -10,8 +10,10 @@ SIZE = ${CROSS}-size TARGET = bin.elf # QEMU command and flags -QEMU = qemu-riscv64-static -QEMU_FLAGS = +# QEMU = qemu-riscv64-static +QEMU = qemu-system-riscv64 +QEMU_FLAGS += --machine virt# # Use the virt machine +QEMU_FLAGS += --nographic# # No graphical output # Flags for compiler and assembler CFLAGS += -static# # Use static linking @@ -23,6 +25,13 @@ CFLAGS += -march=rv64i # Use RV64I ISA, i.e., integer only CFLAGS += -mabi=lp64 # Use LP64 ABI, i.e., 64-bit longs and pointers, 32-bit ints CFLAGS += -Os# # Optimize for size +LDFLAGS += -T link.ld # Use the linker script +LDFLAGS += --no-dynamic-linker +LDFLAGS += -m elf64lriscv +LDFLAGS += -static +LDFLAGS += -nostdlib +LDFLAGS += -s + # Use GC=0 to disable garbage collection ifneq ($(GC), 0) CFLAGS += -ffreestanding @@ -43,7 +52,7 @@ OBJS := $(AS_SRCS:.s=.o) # Default target all: $(OBJS) - @$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) + @$(LD) $(LDFLAGS) -o $(TARGET) $(OBJS) @echo "LD $(OBJS)" # Compile assembly sources @@ -52,8 +61,9 @@ all: $(OBJS) @echo "CC $<" # Run the binary in QEMU -run: all - $(QEMU) $(QEMU_FLAGS) ./$(TARGET) +run: all + @echo "To exit: Ctrl+A, X" + @$(QEMU) $(QEMU_FLAGS) -bios $(TARGET) # View the text section of the binary inspect: all