Switch to loadmem-by-elf instead of loadmem-by-hex

This commit is contained in:
Jerry Zhao
2023-04-12 01:55:37 -07:00
parent b3a4c82fd2
commit f28d114f12
5 changed files with 22 additions and 56 deletions

View File

@@ -318,29 +318,25 @@ run-binary-debug: $(SIM_DEBUG_PREREQ) check-binary | $(output_dir)
run-fast: run-asm-tests-fast run-bmark-tests-fast
#########################################################################################
# helper rules to run simulator with fast loadmem via hex files
# helper rules to run simulator with fast loadmem
#########################################################################################
$(binary_hex): $(firstword $(BINARY)) | $(output_dir)
$(base_dir)/scripts/smartelf2hex.sh $(firstword $(BINARY)) > $(binary_hex)
run-binary-loadmem: check-binary
run-binary-loadmem: $(SIM_PREREQ) | $(output_dir)
run-binary-loadmem: run-binary
run-binary-loadmem: override SIM_FLAGS += +loadmem=$(BINARY)
run-binary-debug-loadmem: check-binary
run-binary-debug-loadmem: $(SIM_DEBUG_REREQ) | $(output_dir)
run-binary-debug-loadmem: run-binary-debug
run-binary-debug-loadmem: override SIM_FLAGS += +loadmem=$(BINARY)
run-binary-fast-loadmem: check-binary
run-binary-fast-loadmem: $(SIM_PREREQ) | $(output_dir)
run-binary-fast-loadmem: run-binary-fast
run-binary-fast-loadmem: override SIM_FLAGS += +loadmem=$(BINARY)
run-binary-hex: check-binary
run-binary-hex: $(SIM_PREREQ) $(binary_hex) | $(output_dir)
run-binary-hex: run-binary
run-binary-hex: override LOADMEM_ADDR = 80000000
run-binary-hex: override LOADMEM = $(binary_hex)
run-binary-hex: override SIM_FLAGS += +loadmem=$(LOADMEM) +loadmem_addr=$(LOADMEM_ADDR)
run-binary-debug-hex: check-binary
run-binary-debug-hex: $(SIM_DEBUG_REREQ) $(binary_hex) | $(output_dir)
run-binary-debug-hex: run-binary-debug
run-binary-debug-hex: override LOADMEM_ADDR = 80000000
run-binary-debug-hex: override LOADMEM = $(binary_hex)
run-binary-debug-hex: override SIM_FLAGS += +loadmem=$(LOADMEM) +loadmem_addr=$(LOADMEM_ADDR)
run-binary-fast-hex: check-binary
run-binary-fast-hex: $(SIM_PREREQ) $(binary_hex) | $(output_dir)
run-binary-fast-hex: run-binary-fast
run-binary-fast-hex: override LOADMEM_ADDR = 80000000
run-binary-fast-hex: override LOADMEM = $(binary_hex)
run-binary-fast-hex: override SIM_FLAGS += +loadmem=$(LOADMEM) +loadmem_addr=$(LOADMEM_ADDR)
# Legacy targets for backwards compat
run-binary-hex: run-binary-loadmem
run-binary-debug-hex: run-binary-debug-loadmem
run-binary-fast-hex: run-binary-fast-loadmem
#########################################################################################
# run assembly/benchmarks rules

View File

@@ -151,25 +151,17 @@ Fast Memory Loading
-------------------
The simulator loads the program binary over a simulated serial line. This can be quite slow if there is a lot of static data, so the simulator also allows data to be loaded from a file directly into the DRAM model.
Loadmem files should be ELF files. In the most common use case, this can be the binary.
.. code-block:: shell
make run-binary BINARY=test.riscv LOADMEM=testdata.hex LOADMEM_ADDR=81000000
make run-binary BINARY=test.riscv EXTRA_SIM_FLAGS="+loadmem=test.riscv"
The ``.hex`` file should be a text file with a hexadecimal number on each line.
.. code-block:: text
deadbeef
0123
Each line uses little-endian order, so this file would produce the bytes "ef be ad de 01 23". ``LOADMEM_ADDR`` specifies which address in memory (in hexadecimal) to write the first byte to. The default is 0x81000000.
A special target that facilitates automatically generating a hex file for an entire elf RISC-V exectuable and then running the simulator with the appropriate flags is also available.
For convenience, special ``-loadmem`` targets are provided to automatically rely on loadmem to read in the binary.
.. code-block:: shell
make run-binary-hex BINARY=test.riscv
make run-binary-loadmem BINARY=test.riscv
Generating Waveforms
-----------------------

View File

@@ -43,7 +43,7 @@ Spike-as-a-Tile can be configured with custom IPC, commit logging, and other beh
.. code-block:: shell
make CONFIG=SpikeUltraFastConfig run-binary-hex BINARY=hello.riscv EXTRA_SPIKE_FLAGS="+spike-ipc=10000 +spike-fast-clint +spike-debug"
make CONFIG=SpikeUltraFastConfig run-binary-loadmem BINARY=hello.riscv EXTRA_SPIKE_FLAGS="+spike-ipc=10000 +spike-fast-clint +spike-debug"
* ``+spike-ipc=``: Sets the maximum number of instructions Spike can retire in a single "tick", or cycle of the uncore simulation.

View File

@@ -1,16 +0,0 @@
#!/usr/bin/env bash
# This script find the appropriate arguments to pass to elf2hex by inspecting the given RISC-V elf binary
# First and only argument is the binary to be converted.
# The output of this script should be redirected to a file (as with normal elf2hex).
binary=$1
segments=`readelf --segments --wide $binary`
entry_hex=`echo -e "$segments" | grep "Entry point" | cut -f3 -d' ' | sed 's/0x//' | tr [:lower:] [:upper:]`
entry_dec=`bc <<< "ibase=16;$entry_hex"`
length_hex=`echo "$segments" | grep "LOAD\|TLS" | tail -n 1 | tr -s [:space:] | cut -f4,7 -d' '`
length_dec=`echo $length_hex | tr -d x | tr [:lower:] [:upper:] | tr ' ' + | sed 's/^/ibase=16;/' | sed "s/$/-$entry_hex/" | bc`
power_2_length=`echo "x=l($length_dec)/l(2); scale=0; 2^((x+1)/1)" | bc -l`
width=64
depth=$((power_2_length / width))
elf2hex $width $depth $binary $entry_dec

View File

@@ -245,15 +245,9 @@ output_dir=$(sim_dir)/output/$(long_name)
PERMISSIVE_ON=+permissive
PERMISSIVE_OFF=+permissive-off
BINARY ?=
LOADMEM ?=
LOADMEM_ADDR ?= 81000000
override SIM_FLAGS += +dramsim +dramsim_ini_dir=$(TESTCHIP_DIR)/src/main/resources/dramsim2_ini +max-cycles=$(timeout_cycles)
ifneq ($(LOADMEM),)
override SIM_FLAGS += +loadmem=$(LOADMEM) +loadmem_addr=$(LOADMEM_ADDR)
endif
VERBOSE_FLAGS ?= +verbose
sim_out_name = $(output_dir)/$(subst $() $(),_,$(notdir $(basename $(BINARY))))
binary_hex= $(sim_out_name).loadmem_hex
#########################################################################################
# build output directory for compilation