2023-02-16 23:26:32 +00:00
|
|
|
.PRECIOUS:${BOOT_CODE}
|
2023-03-04 08:37:43 +00:00
|
|
|
|
2023-11-02 00:29:14 +00:00
|
|
|
########## BUILD OPTIONS ##########
|
|
|
|
|
2023-02-16 01:46:22 +00:00
|
|
|
QUIET=1
|
2023-03-04 08:37:43 +00:00
|
|
|
# QUIET: 1=clean, non-verbose output
|
|
|
|
# 2=normal make output
|
|
|
|
|
2023-11-02 00:29:14 +00:00
|
|
|
####### SIMULATION OPTIONS ########
|
|
|
|
|
2023-03-04 08:37:43 +00:00
|
|
|
SIM=VERILATOR
|
|
|
|
# SIM: VERILATOR: use Verilator
|
|
|
|
# ICARUS: use Icarus Verilog
|
|
|
|
|
2023-03-05 00:10:55 +00:00
|
|
|
NUMACTL=#numactl -m 0 -C 0,1 --
|
|
|
|
|
2023-11-02 00:29:14 +00:00
|
|
|
######## SYNTHESIS OPTIONS ########
|
|
|
|
|
|
|
|
# BOARD: the options are the directories in system/fpga_config/.
|
|
|
|
# Select the one you have
|
2023-12-05 21:46:46 +00:00
|
|
|
FPGA_BOARD=OrangeCrab_r0.2.1
|
|
|
|
|
|
|
|
# If this options is set to 1, builds with different seeds will be
|
|
|
|
# considered separate, in combination with the fact that this build
|
|
|
|
# system by default is generating a new seed for each build, it means
|
|
|
|
# that for each build a new set of files gets created in the build
|
|
|
|
# directory with the seed number on the filename without overwriting
|
|
|
|
# the old ones.
|
|
|
|
BUILD_SEED_DIFFERENTIATION=0
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-11-07 14:37:22 +00:00
|
|
|
VERSION="v0.3.0-dev"
|
|
|
|
|
2023-12-06 00:23:24 +00:00
|
|
|
# TODO: handle case where the source code is not part of a git repository
|
|
|
|
COMMIT=$(shell if which git >/dev/null 2>/dev/null ;then git log --pretty=format:'%H' -1 |cat ;else echo git-not-installed; fi)
|
2023-02-16 01:46:22 +00:00
|
|
|
|
|
|
|
ifeq "${QUIET}" "1"
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_AS = @echo ' AS '${PRINT_PATH_PREFIX}$@;
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_VVP = @echo ' VVP '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_IVERILOG = @echo ' IVERILOG '${PRINT_PATH_PREFIX}$@;
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_VERILATOR = @echo ' VERILATOR '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_CC = @echo ' CC '${PRINT_PATH_PREFIX}$@;
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_YOSYS = @echo ' YOSYS '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_NEXTPNR = @echo ' NEXTPNR '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_ECPPACK = @echo ' ECPPACK '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_DFU_SUFFIX = @echo ' DFU-SUFFIX '${PRINT_PATH_PREFIX}$@;
|
|
|
|
QUIET_DFU_UTIL = @echo ' DFU-UTIL '${PRINT_PATH_PREFIX}$<;
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_DOWNLOAD = @echo ' DOWNLOAD '${PRINT_PATH_PREFIX}$@;
|
2023-12-03 19:24:12 +00:00
|
|
|
|
2023-12-06 18:38:32 +00:00
|
|
|
QUIET_CLEAN = @echo ' CLEAN '${PRINT_PATH_PREFIX};
|
2023-12-08 22:10:11 +00:00
|
|
|
QUIET_MRPROPER = @echo ' MRPROPER '${PRINT_PATH_PREFIX};
|
2023-12-09 02:39:14 +00:00
|
|
|
QUIET_VERILATOR_RUN = @printf ' %s %s\n' $(shell basename "$1") $2;
|
2023-02-16 01:46:22 +00:00
|
|
|
Q = @
|
|
|
|
MAKEOPTS=--no-print-directory
|
|
|
|
.SILENT:
|
|
|
|
else
|
|
|
|
Q =
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2023-02-16 23:26:32 +00:00
|
|
|
.PHONY: run wave disas
|
|
|
|
run: $(subst .txt,.run,${BOOT_CODE})
|
2023-02-16 01:46:22 +00:00
|
|
|
wave: $(subst .txt,.wave,${BOOT_CODE})
|
|
|
|
disas: $(subst .txt,.disas,${BOOT_CODE})
|
|
|
|
|
2023-12-03 19:24:12 +00:00
|
|
|
# Assembling code
|
|
|
|
%.stxt: %.bin
|
|
|
|
${Q}dd if=/dev/zero bs=1 count=2048 of="$(subst .bin,.stage,$<)" status=none
|
|
|
|
${Q}dd if="$<" bs=1 skip=63488 of="$(subst .bin,.stage,$<)" conv=notrunc,nocreat status=none
|
|
|
|
${Q}xxd -ps -c 2 "$(subst .bin,.stage,$<)" > "$@"
|
|
|
|
${Q}rm "$(subst .bin,.stage,$<)"
|
|
|
|
|
2023-02-16 01:46:22 +00:00
|
|
|
# Assembling code
|
|
|
|
%.txt:%.bin
|
2023-12-07 18:44:31 +00:00
|
|
|
${Q}dd if=/dev/zero bs=1 count=65536 of="$(subst .bin,.stage_short,$<)" status=none
|
|
|
|
${Q}dd if="$<" of="$(subst .bin,.stage_short,$<)" conv=notrunc,nocreat status=none
|
|
|
|
${Q}xxd -ps -c 2 "$(subst .bin,.stage_short,$<)" > "$@"
|
|
|
|
${Q}rm "$(subst .bin,.stage_short,$<)"
|
2023-02-16 01:46:22 +00:00
|
|
|
|
2023-12-03 19:24:12 +00:00
|
|
|
|
2023-02-22 01:51:14 +00:00
|
|
|
ifeq "${NO_ASM}" "0"
|
2023-02-16 01:46:22 +00:00
|
|
|
%.bin:%.asm
|
|
|
|
${QUIET_AS}
|
|
|
|
${Q}as86 -0 "$<" -b "$@"
|
2023-02-22 01:51:14 +00:00
|
|
|
endif
|
2023-02-16 01:46:22 +00:00
|
|
|
|
|
|
|
# Running simulation
|
2023-03-04 08:37:43 +00:00
|
|
|
ifeq "${SIM}" "ICARUS"
|
2023-03-05 00:10:55 +00:00
|
|
|
%.fst %.memdump: %.txt ${SYSTEM_VVP} ${MICROCODE}
|
2023-02-16 01:46:22 +00:00
|
|
|
${QUIET_VVP}
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q}vvp "${SYSTEM_VVP}" -fst +VERSION=${VERSION} +COMMIT=${COMMIT} +BOOT_CODE="$<" +WAVEFORM="$(subst .txt,.fst,$<)" +MEMDUMP="$(subst .txt,.memdumptxt,$<)" +MICROCODE="${MICROCODE}"
|
2023-02-16 01:46:22 +00:00
|
|
|
${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)"
|
|
|
|
${Q}rm "$(subst .txt,.memdumptxt,$<)"
|
|
|
|
|
2023-03-04 08:37:43 +00:00
|
|
|
%.run: %.txt ${SYSTEM_VVP} ${MICROCODE}
|
2023-02-16 23:26:32 +00:00
|
|
|
${QUIET_VVP}
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q}vvp -i "${SYSTEM_VVP}" +VERSION=${VERSION} +COMMIT=${COMMIT} +BOOT_CODE="$<" +MICROCODE="${MICROCODE}"
|
2023-05-14 15:06:33 +00:00
|
|
|
%.json: %.txt ${SYSTEM_VVP} ${MICROCODE}
|
|
|
|
${QUIET_VVP}
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q}vvp -i "${SYSTEM_VVP}" +VERSION=${VERSION} +COMMIT=${COMMIT} +STATS="$@" +BOOT_CODE="$<" +MICROCODE="${MICROCODE}"
|
2023-03-04 08:37:43 +00:00
|
|
|
else ifeq "${SIM}" "VERILATOR"
|
2023-03-05 00:10:55 +00:00
|
|
|
%.fst %.memdump: %.txt ${VERILATOR_BIN} ${MICROCODE}
|
2023-03-04 08:37:43 +00:00
|
|
|
$(call QUIET_VERILATOR_RUN,$(word 2,$^),$<)
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q}"${VERILATOR_BIN}" +VERSION=${VERSION} +COMMIT=${COMMIT} +BOOT_CODE="$<" +WAVEFORM="$(subst .txt,.fst,$<)" +MEMDUMP="$(subst .txt,.memdumptxt,$<)" +MICROCODE="${MICROCODE}"
|
2023-03-04 08:37:43 +00:00
|
|
|
${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)"
|
|
|
|
${Q}rm "$(subst .txt,.memdumptxt,$<)"
|
|
|
|
|
2023-05-14 15:06:33 +00:00
|
|
|
%.json: %.txt ${VERILATOR_BIN} ${MICROCODE}
|
|
|
|
$(call QUIET_VERILATOR_RUN,$(word 2,$^),$<)
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q} ${NUMACTL} "${VERILATOR_BIN}" +VERSION=${VERSION} +COMMIT=${COMMIT} +STATS=$@ +BOOT_CODE="$<" +MICROCODE="${MICROCODE}"
|
2023-03-04 08:37:43 +00:00
|
|
|
%.run: %.txt ${VERILATOR_BIN} ${MICROCODE}
|
|
|
|
$(call QUIET_VERILATOR_RUN,$(word 2,$^),$<)
|
2023-11-01 06:03:53 +00:00
|
|
|
${Q} ${NUMACTL} "${VERILATOR_BIN}" +VERSION=${VERSION} +COMMIT=${COMMIT} +BOOT_CODE="$<" +MICROCODE="${MICROCODE}"
|
2023-03-04 08:37:43 +00:00
|
|
|
endif
|
2023-02-16 23:26:32 +00:00
|
|
|
|
2023-02-16 01:46:22 +00:00
|
|
|
%.disas: %.bin
|
|
|
|
objdump -D -b binary -m i8086 $^ | less
|
|
|
|
|
|
|
|
# Tools
|
2023-03-05 00:10:55 +00:00
|
|
|
%.wave : %.fst
|
2023-02-16 01:46:22 +00:00
|
|
|
gtkwave "$<" "${GTKWSAVE}"
|