2021-07-02 01:28:23 -06:00
|
|
|
BUILD_DIR = build
|
2021-07-02 01:42:11 -06:00
|
|
|
|
|
|
|
# ================
|
|
|
|
# Hardware options
|
|
|
|
# ================
|
2021-07-02 01:28:53 -06:00
|
|
|
# SOURCE_V = $(wildcard hdl/*.v)
|
|
|
|
# TESTBENCH_V = $(wildcard hdl/tb/*.v)
|
|
|
|
SOURCE_V = hdl/core.v
|
|
|
|
TESTBENCH_V = hdl/tb/core_tb.v
|
2021-07-02 01:28:23 -06:00
|
|
|
|
2021-07-02 01:42:11 -06:00
|
|
|
# ================
|
|
|
|
# Software options
|
|
|
|
# ================
|
2021-07-02 05:16:30 -06:00
|
|
|
# SOURCE_C = $(wildcard test/*.c)
|
|
|
|
SOURCE_C =
|
|
|
|
SOURCE_AS = $(wildcard test/*.S)
|
|
|
|
OBJ = $(addprefix $(BUILD_DIR)/, $(notdir $(SOURCE_AS:.S=.o)))
|
|
|
|
OBJ += $(addprefix $(BUILD_DIR)/, $(notdir $(SOURCE_C:.c=.o)))
|
|
|
|
|
|
|
|
CC = riscv64-linux-gnu-gcc-8
|
2021-07-02 01:42:11 -06:00
|
|
|
# CFLAGS = -march=rv32i -mabi=ilp32
|
|
|
|
CFLAGS = -march=rv64i -mabi=lp64
|
2021-07-02 01:28:23 -06:00
|
|
|
|
2021-07-02 01:42:11 -06:00
|
|
|
AS = riscv64-linux-gnu-as
|
|
|
|
ASFLAGS = $(CFLAGS)
|
2021-07-02 01:28:23 -06:00
|
|
|
|
2021-07-02 01:42:11 -06:00
|
|
|
LD = riscv64-linux-gnu-ld
|
|
|
|
LDFLAGS = -T
|
|
|
|
|
|
|
|
all: sim
|
|
|
|
|
|
|
|
## Hardware
|
2021-07-02 01:28:23 -06:00
|
|
|
$(BUILD_DIR)/tb.out: $(SOURCE_V) $(TESTBENCH_V) | $(BUILD_DIR)
|
|
|
|
iverilog $^ -o $@
|
|
|
|
|
2021-07-02 01:42:11 -06:00
|
|
|
## Software
|
|
|
|
$(BUILD_DIR)/%.o: test/%.S | $(BUILD_DIR)
|
|
|
|
$(AS) $(ASFLAGS) $^ -o $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/%.o: test/%.c | $(BUILD_DIR)
|
|
|
|
$(CC) $(CFLAGS) $^ -o $@
|
|
|
|
|
2021-07-02 05:16:30 -06:00
|
|
|
$(BUILD_DIR)/%.elf: test/%.ld $(OBJ) | $(BUILD_DIR)
|
2021-07-02 01:42:11 -06:00
|
|
|
$(LD) $(LDFLAGS) $^ -o $@
|
|
|
|
|
2021-07-02 04:47:40 -06:00
|
|
|
%.hex: %.elf
|
|
|
|
riscv64-linux-gnu-objcopy --target=verilog $< $@
|
2021-07-02 04:22:33 -06:00
|
|
|
|
2021-07-02 04:58:58 -06:00
|
|
|
$(BUILD_DIR)/core_tb.vcd: $(BUILD_DIR)/tb.out $(BUILD_DIR)/test.hex
|
2021-07-02 01:28:23 -06:00
|
|
|
cd $(BUILD_DIR) && ./tb.out
|
|
|
|
|
2021-07-02 04:58:58 -06:00
|
|
|
sim: $(BUILD_DIR)/core_tb.vcd
|
2021-07-02 01:42:11 -06:00
|
|
|
|
|
|
|
## General
|
|
|
|
$(BUILD_DIR):
|
|
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
|
2021-07-02 01:28:23 -06:00
|
|
|
clean:
|
|
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
|
|
|
|
.SECONDARY:
|
|
|
|
.PHONY: all clean sim
|