2023-02-16 01:46:22 +00:00
|
|
|
# This file is part of the 9086 project.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2023 Efthymios Kritikos
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2023-05-11 11:11:17 +00:00
|
|
|
SOURCES=processor.v memory.v registers.v alu.v decoder.v general.v biu.v execute.v
|
2023-11-01 19:09:59 +00:00
|
|
|
INCLUDES=exec_state_def.v alu_header.v config.v ucode_header.v error_header.v
|
2023-02-22 01:28:23 +00:00
|
|
|
MICROCODE=ucode.txt
|
2023-12-06 18:12:57 +00:00
|
|
|
SYSTEM_VVP=system.vvp
|
|
|
|
PRINT_PATH_PREFIX=./
|
2023-02-16 01:46:22 +00:00
|
|
|
|
2023-12-06 18:12:57 +00:00
|
|
|
BOOT_CODE=boot_code.txt
|
|
|
|
VERILATOR_BIN=obj_dir/Vsystem
|
2023-02-22 01:51:14 +00:00
|
|
|
NO_ASM=0
|
2023-02-16 01:46:22 +00:00
|
|
|
include ../common.mk
|
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
################################################################################
|
|
|
|
#### SIMULATION RECIPES ####
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
EVENT_SIM_TESTBENCH=testbench.v
|
|
|
|
VERILATOR_TESTBENCH=testbench.cpp
|
|
|
|
SIMULATION_TOP_LEVEL_SOURCE=system.v
|
|
|
|
GTKWSAVE=../gtkwave_savefile.gtkw
|
|
|
|
|
2023-03-05 23:11:18 +00:00
|
|
|
#build options
|
|
|
|
VERILATOR_OPTS += --cc --exe
|
|
|
|
|
|
|
|
#binary options
|
|
|
|
VERILATOR_OPTS += --trace-fst --threads 1 --autoflush
|
|
|
|
|
|
|
|
#linter options
|
2023-11-12 00:07:33 +00:00
|
|
|
VERILATOR_OPTS += -Wall --Wno-DECLFILENAME
|
2023-03-05 23:11:18 +00:00
|
|
|
|
|
|
|
#optimisation options
|
|
|
|
VERILATOR_OPTS += -x-assign fast --x-initial fast
|
|
|
|
#For testing use:
|
2023-05-07 12:34:15 +00:00
|
|
|
#VERILATOR_OPTS += -x-assign unique --x-initial unique
|
2023-03-05 23:11:18 +00:00
|
|
|
|
2023-02-16 01:46:22 +00:00
|
|
|
# COMPILING
|
2023-12-05 21:46:46 +00:00
|
|
|
${SYSTEM_VVP} : ${SIMULATION_TOP_LEVEL_SOURCE} ${SOURCES} ${INCLUDES} ${EVENT_SIM_TESTBENCH}
|
2023-02-16 01:46:22 +00:00
|
|
|
${QUIET_IVERILOG}
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}iverilog -g2012 -D CALCULATE_IPC -D OUTPUT_JSON_STATISTICS -o "$@" ${SIMULATION_TOP_LEVEL_SOURCE} ${SOURCES} ${EVENT_SIM_TESTBENCH}
|
2023-02-16 01:46:22 +00:00
|
|
|
|
2023-03-05 23:11:18 +00:00
|
|
|
${VERILATOR_BIN}: ${VERILATOR_BIN}.mk
|
2023-12-06 18:12:57 +00:00
|
|
|
${Q}make ${MAKEOPTS} PRINT_PATH_PREFIX=${PRINT_PATH_PREFIX}obj_dir/ OPT_FAST="-O2 -march=native -mtune=native" -C obj_dir -f ../verilator_makefile Vsystem
|
2023-03-05 23:11:18 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
${VERILATOR_BIN}.mk: ${VERILATOR_TESTBENCH} ${SIMULATION_TOP_LEVEL_SOURCE} ${SOURCES} ${INCLUDES}
|
2023-03-04 08:37:43 +00:00
|
|
|
${QUIET_VERILATOR}
|
2023-12-03 19:24:12 +00:00
|
|
|
${Q}verilator -DCALCULATE_IPC -DOUTPUT_JSON_STATISTICS ${VERILATOR_OPTS} $^
|
2023-02-16 01:46:22 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
################################################################################
|
|
|
|
#### FPGA/ASIC RECIPES ####
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
BUILD_FILES_PREFIX=build/
|
|
|
|
$(shell mkdir -p $(BUILD_FILES_PREFIX))
|
|
|
|
FPGA_SEED ::= $(shell seq 1 200|sort -R|head -n1)
|
|
|
|
|
|
|
|
ifeq "${BUILD_SEED_DIFFERENTIATION}" "1"
|
|
|
|
BUILD_NAME=${FPGA_BOARD}_${FPGA_SEED}
|
|
|
|
else
|
|
|
|
BUILD_NAME=${FPGA_BOARD}
|
|
|
|
endif
|
|
|
|
|
2023-11-07 14:37:22 +00:00
|
|
|
include fpga_config/${FPGA_BOARD}/config.mk
|
|
|
|
|
2023-11-02 00:29:14 +00:00
|
|
|
# Synthesis and bitstream creation for ECP5
|
|
|
|
ifeq "${ECP5_DEVICE}" "25F"
|
|
|
|
NEXTPNR_ECP5_DEV=--25k
|
|
|
|
else ifeq "${ECP5_DEVICE}" "85F"
|
|
|
|
NEXTPNR_ECP5_DEV=--85k
|
|
|
|
else
|
|
|
|
$(error invalid ECP5 device ${ECP5_DEVICE})
|
|
|
|
endif
|
|
|
|
|
2023-11-12 04:04:56 +00:00
|
|
|
simplified_ucode.txt:ucode.txt
|
|
|
|
${Q}tr 'x' '0' < $^ | sed 's@//.*@@' | grep ^@ |sort | sed 's/.* .//;s/ $$//' | tr -d _ > $@
|
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
external_ip/litedram_core_ecp5_phy.v:
|
|
|
|
${QUIET_DOWNLOAD}
|
|
|
|
${Q}../tools/gen_litedram.sh -q "$@"
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
## SYNTHESIS RECIPES
|
|
|
|
|
|
|
|
SYNTHESIS_SOURCES ::= ${SOURCES} fpga_config/${FPGA_BOARD}/fpga_top.v ${SOC_SYNTHESIS_SOURCES} ${INCLUDES}
|
|
|
|
|
2023-11-06 08:12:58 +00:00
|
|
|
#TODO: we are relying on yosys to trim the input program txt file and hope its enough for the whole program...
|
2023-12-05 21:46:46 +00:00
|
|
|
${BUILD_FILES_PREFIX}synth_ecp5_${FPGA_BOARD}.json: ${SYNTHESIS_SOURCES} ${FPGA_BOOTCODE} simplified_ucode.txt
|
2023-11-02 00:29:14 +00:00
|
|
|
${QUIET_YOSYS}
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q} yosys -q -p 'read_verilog -defer -noautowire -sv '"${SYNTHESIS_SOURCES}; attrmap -tocase keep -imap keep="true" keep=1 -imap keep="false" keep=0 -remove keep=0; synth_ecp5 -json \"$@\" -abc9 -top fpga_top"
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
##########################################
|
|
|
|
## PLACE AND ROUTE RECIPES
|
2023-11-23 23:26:13 +00:00
|
|
|
|
2023-12-06 18:12:57 +00:00
|
|
|
${BUILD_FILES_PREFIX}nextpnr-ecp5_${BUILD_NAME}.bit:${BUILD_FILES_PREFIX}synth_${FPGA_BOARD}.json
|
2023-11-02 00:29:14 +00:00
|
|
|
${QUIET_NEXTPNR}
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}printf '\e[1;30mNotice: nextpnr rng seed is : %s\e[0m\n' "${FPGA_SEED}"
|
|
|
|
${Q} nextpnr-ecp5 --seed ${FPGA_SEED} --Werror -q --json $< --textcfg "$@_config_temp" ${NEXTPNR_ECP5_DEV} --package ${ECP5_PACKAGE} --speed ${ECP5_SPEED_GRADE} --lpf fpga_config/${FPGA_BOARD}/pin_constraint.pcf --report=${BUILD_FILES_PREFIX}nextpnr_report_${BUILD_NAME}.json
|
|
|
|
${Q}../tools/parse_nextpnr_stats.sh --brief ${BUILD_FILES_PREFIX}nextpnr_report_${BUILD_NAME}.json
|
|
|
|
${Q}mv "$@_config_temp" "$@_config" # nextpnr-ecp5 will still generate a file even if it fails breaking the assumptions of the build system.
|
2023-11-02 00:29:14 +00:00
|
|
|
${QUIET_ECPPACK}
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}ecppack --compress --freq 38.8 --input $@_config --bit $@
|
|
|
|
|
|
|
|
nextpnr-gui: ${BUILD_FILES_PREFIX}synth_${FPGA_BOARD}.json
|
|
|
|
${QUIET_NEXTPNR}
|
|
|
|
${Q} nextpnr-ecp5 --seed ${FPGA_SEED} --json $< ${NEXTPNR_ECP5_DEV} --package ${ECP5_PACKAGE} --speed ${ECP5_SPEED_GRADE} --lpf fpga_config/${FPGA_BOARD}/pin_constraint.pcf --gui
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
## BITSTREAM MODIFICATION FOR/AND UPLOADING
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
${BUILD_FILES_PREFIX}bitstream_${BUILD_NAME}.dfu:${BUILD_FILES_PREFIX}bitstream_${BUILD_NAME}.bit
|
2023-11-02 00:29:14 +00:00
|
|
|
${QUIET_DFU_SUFFIX}
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}cp "$<" "$<.tempdfu"
|
2023-11-02 00:29:14 +00:00
|
|
|
@#From some testing, dfu-suffix does output errors to stderr so this should be fine
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}dfu-suffix --vid 1209 --pid 5af0 --add "$<.tempdfu" > /dev/null
|
|
|
|
${Q}mv "$<.tempdfu" "$@"
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
dfu_upload:${BUILD_FILES_PREFIX}bitstream_${BUILD_NAME}.dfu
|
2023-11-02 00:29:14 +00:00
|
|
|
${QUIET_DFU_UTIL}
|
|
|
|
${Q}stdbuf -o0 dfu-util --download "$<" |stdbuf -o0 tr '\n' '\a' | stdbuf -o0 tr '\r' '\n' | grep Download --line-buffered | stdbuf -o0 tr '\n' '\r' |stdbuf -o0 tr '\a' '\n'
|
|
|
|
|
2023-12-03 19:24:12 +00:00
|
|
|
|
2023-12-05 21:46:46 +00:00
|
|
|
################################################################################
|
|
|
|
#### CLEAN-UP ####
|
|
|
|
################################################################################
|
2023-11-23 23:26:13 +00:00
|
|
|
|
2023-11-02 00:29:14 +00:00
|
|
|
|
2023-02-16 01:46:22 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
$(call QUIET_CLEAN,system)
|
2023-12-05 21:46:46 +00:00
|
|
|
${Q}rm -rf ${SYSTEM_VVP} *.fst boot_code.txt boot_code.bin *memdump *memdumptxt obj_dir simplified_ucode.txt abc.history build
|