build test code into build directory

This commit is contained in:
Brendan Haines 2021-07-02 01:28:23 -06:00
parent 180f05fb0a
commit efd4cb6e48
4 changed files with 34 additions and 29 deletions

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
BUILD_DIR = build
SOURCE_V = $(wildcard hdl/*.v)
TESTBENCH_V = $(wildcard hdl/tb/*.v)
all: sim
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/tb.out: $(SOURCE_V) $(TESTBENCH_V) | $(BUILD_DIR)
iverilog $^ -o $@
sim: $(BUILD_DIR)/tb.out
cd $(BUILD_DIR) && ./tb.out
clean:
rm -rf $(BUILD_DIR)
.SECONDARY:
.PHONY: all clean sim

View File

@ -1,19 +0,0 @@
# SOURCE_V = $(wildcard *.v)
# TESTBENCH_V = $(wildcard tb/*.v)
SOURCE_V = core.v
TESTBENCH_V = tb/core_tb.v
all: sim
tb.out: $(SOURCE_V) $(TESTBENCH_V)
iverilog $^ -o $@
sim: tb.out
./tb.out
clean:
rm -rf tb.out tb.vcd
.SECONDARY:
.PHONY: all clean sim

View File

@ -1,8 +1,7 @@
all: text.hex data.hex
BUILD_DIR = build
CC = riscv64-linux-gnu-gcc
# CFLAGS = -march=rv32i -mabi=ilp32
CFLAGS = -march=rv64i -mabi=lp64 -o0
CFLAGS = -march=rv64i -mabi=lp64
AS = riscv64-linux-gnu-as
ASFLAGS = $(CFLAGS)
@ -10,20 +9,25 @@ ASFLAGS = $(CFLAGS)
LD = riscv64-linux-gnu-ld
LDFLAGS = -T test.ld
%.o: %.S
all: $(BUILD_DIR)/text.hex $(BUILD_DIR)/data.hex
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.S | $(BUILD_DIR)
$(AS) $(ASFLAGS) $^ -o $@
%.o: %.c
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $^ -o $@
%.elf: %.o %.ld
$(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.o %.ld
$(LD) $(LDFLAGS) $< -o $@
text.hex: test.elf
$(BUILD_DIR)/text.hex: $(BUILD_DIR)/test.elf
riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
data.hex: test.elf
$(BUILD_DIR)/data.hex: $(BUILD_DIR)/test.elf
riscv64-linux-gnu-objdump -s $^ | sed -n '/.data/,$$p' | tail -n+2 | sed -n '/.bss/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
clean:
rm test.elf text.hex data.hex
rm -rf $(BUILD_DIR)