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
# ================
CC = riscv64-linux-gnu-gcc
# 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 $@
$(BUILD_DIR)/%.elf : test /%.ld $( BUILD_DIR ) /%.o | $( BUILD_DIR )
$( LD) $( LDFLAGS) $^ -o $@
2021-07-02 04:22:33 -06:00
$(BUILD_DIR)/test.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/' > $@
riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed 's/ //g' | sed 's/\(..\)/\1 /g' > $@
# riscv64-linux-gnu-objdump -s test.elf | sed -n '/Contents of section /,$p' | tail -n+2 | sed '/Contents of section .data/d' | cut -f2-6 -d ' ' | sed 's/./&:/4' | sed 's/./0x&/1' | sed 's/^[ \t]*//;s/[ \t]*$//' | sed 's/ /\n/g'
2021-07-02 04:32:25 -06:00
# riscv64-linux-gnu-objdump -s $^ | sed -n '/Contents of section /,$p' | tail -n+2 | sed '/Contents of section .data/d' | cut -f2-6 -d ' ' | sed 's/./&:/4' | sed 's/./0x&/1' | sed 's/^[ \t]*//;s/[ \t]*$//' | sed 's/./& /10' | sed 's/./& /13' | sed 's/./& /16' | sed 's/./& /22' | sed 's/./& /25' | sed 's/./& /28' | sed 's/./& /34' | sed 's/./& /37' | sed 's/./& /40' | sed 's/./& /46' | sed 's/./& /49' | sed 's/./& /52' | sed 's/ /\n/g' > $@
2021-07-02 04:22:33 -06:00
# $(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/' > $@
sim : $( BUILD_DIR ) /tb .out $( BUILD_DIR ) /test .hex
2021-07-02 01:28:23 -06:00
cd $( BUILD_DIR) && ./tb.out
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