Skip to content

Commit

Permalink
Merge remote-tracking branch 'shinezyy/boom' into bump-rocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Wonicon committed Jul 11, 2019
2 parents 624d19f + 71f46a5 commit 3bb823b
Show file tree
Hide file tree
Showing 177 changed files with 6,851 additions and 1,933 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,14 @@ ControlPlanes.v
src/main/scala/.idea/
src/main/scala/build.sbt
src/main/scala/project/

.idea/
boom-ether.err
bootrom/bootrom.txt
emulator/boom-failed.md
emulator/log.txt
emulator/serial6*
fpga/.Xil/
fpga/bbl.elf.txt
fpga/vivado_*.str
fpga/vmlinux.txt
6 changes: 3 additions & 3 deletions .gitmodules
@@ -1,6 +1,3 @@
[submodule "riscv-tools"]
path = riscv-tools
url = https://github.com/riscv/riscv-tools.git
[submodule "hardfloat"]
path = hardfloat
url = https://github.com/ucb-bar/berkeley-hardfloat.git
Expand All @@ -13,3 +10,6 @@
[submodule "firrtl"]
path = firrtl
url = https://github.com/ucb-bar/firrtl.git
[submodule "src/main/scala/boom"]
path = src/main/scala/boom
url = https://github.com/shinezyy/BOOM-inside-LvNA.git
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -70,8 +70,8 @@ jobs:
- &test
stage: Test
script:
- travis_wait 80 make emulator-ndebug -C regression SUITE=UnittestSuite JVM_MEMORY=3G
- travis_wait 80 make emulator-regression-tests -C regression SUITE=UnittestSuite JVM_MEMORY=3G
- travis_wait 100 make emulator-ndebug -C regression SUITE=UnittestSuite JVM_MEMORY=3G VERILATOR_THREADS=1
- travis_wait 100 make emulator-regression-tests -C regression SUITE=UnittestSuite JVM_MEMORY=3G VERILATOR_THREADS=1
- <<: *test
script:
- travis_wait 80 make emulator-ndebug -C regression SUITE=JtagDtmSuite JVM_MEMORY=3G
Expand Down
1 change: 1 addition & 0 deletions bootrom/Makefile
Expand Up @@ -13,3 +13,4 @@ all: $(bootrom_img)

%.elf: %.S linker.ld
$(GCC) -Tlinker.ld $< -nostdlib -static -Wl,--no-gc-sections -o $@
riscv64-unknown-elf-objdump -d $@ >bootrom.txt
6 changes: 4 additions & 2 deletions bootrom/bootrom.S
@@ -1,18 +1,20 @@
// #define DRAM_BASE 0x80000000
#define DRAM_BASE 0x100000000

.section .text.start, "ax", @progbits
.globl _start
_start:
csrwi 0x7c1, 0 // disable chicken bits
// csrwi 0x7c1, 0 // disable chicken bits
li s0, DRAM_BASE
csrr a0, mhartid
la a1, _dtb

jr s0

.section .text.hang, "ax", @progbits
.globl _hang
_hang:
csrwi 0x7c1, 0 // disable chicken bits
// csrwi 0x7c1, 0 // disable chicken bits
csrr a0, mhartid
la a1, _dtb
csrwi mie, 0
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -16,7 +16,7 @@ lazy val commonSettings = Seq(
traceLevel := 15,
scalacOptions ++= Seq("-deprecation","-unchecked","-Xsource:2.11"),
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value),
libraryDependencies ++= Seq("org.json4s" %% "json4s-jackson" % "3.5.3"),
libraryDependencies ++= Seq("org.json4s" %% "json4s-jackson" % "3.6.1"),
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
)

Expand Down
2 changes: 1 addition & 1 deletion chisel3
10 changes: 6 additions & 4 deletions emulator/Makefile
Expand Up @@ -14,11 +14,13 @@ LDFLAGS := $(LDFLAGS) -L$(RISCV)/lib -Wl,-rpath,$(RISCV)/lib -L$(abspath $(sim_d

emu = emulator-$(PROJECT)-$(CONFIG)
emu_debug = emulator-$(PROJECT)-$(CONFIG)-debug
origin_emu = emulator-$(PROJECT)-$(CONFIG)-origin # without init mem

include $(sim_dir)/Makefrag-verilator

all: $(emu)
debug: $(emu_debug)
emu_origin: $(origin_emu)

clean:
rm -rf *.o *.a emulator-* $(generated_dir) $(generated_dir_debug) DVEfiles $(output_dir)
Expand All @@ -33,11 +35,11 @@ ifneq ($(filter run% %.run %.out %.vpd %.vcd,$(MAKECMDGOALS)),)
-include $(generated_dir)/$(long_name).d
endif

$(output_dir)/%.run: $(output_dir)/% $(emu)
./$(emu) +max-cycles=$(timeout_cycles) $< 2> /dev/null 2> $@ && [ $$PIPESTATUS -eq 0 ]
$(output_dir)/%.run: $(output_dir)/% $(origin_emu)
./$(origin_emu) +max-cycles=$(timeout_cycles) $< 2> /dev/null 2> $@ && [ $$PIPESTATUS -eq 0 ]

$(output_dir)/%.out: $(output_dir)/% $(emu)
./$(emu) +max-cycles=$(timeout_cycles) +verbose $< $(disasm) $@ && [ $$PIPESTATUS -eq 0 ]
$(output_dir)/%.out: $(output_dir)/% $(origin_emu)
./$(origin_emu) +max-cycles=$(timeout_cycles) +verbose $< $(disasm) $@ && [ $$PIPESTATUS -eq 0 ]

$(output_dir)/%.vcd: $(output_dir)/% $(emu_debug)
./$(emu_debug) +max-cycles=$(timeout_cycles) +verbose -v$@ $< $(disasm) $(patsubst %.vcd,%.out,$@) && [ $$PIPESTATUS -eq 0 ]
Expand Down
24 changes: 21 additions & 3 deletions emulator/Makefrag-verilator
Expand Up @@ -8,7 +8,11 @@ verilog = \
$(generated_dir)/$(long_name).v \
$(generated_dir)/$(long_name).behav_srams.v \

.SECONDARY: $(firrtl) $(verilog)
origin_verilog = \
$(generated_dir)/$(long_name).v \
$(generated_dir)/$(long_name).origin_behav_srams.v \

.SECONDARY: $(firrtl) $(verilog) $(origin_verilog)

$(generated_dir)/%.fir $(generated_dir)/%.d: $(FIRRTL_JAR) $(chisel_srcs) $(bootrom_img)
mkdir -p $(dir $@)
Expand All @@ -24,8 +28,12 @@ $(generated_dir)/$(long_name).behav_srams.v : $(generated_dir)/$(long_name).conf
$(mem_init) $@.tmp mem_ext bin.txt $(generated_dir)/$(long_name).json > $@
rm -f $@.tmp

$(generated_dir)/$(long_name).origin_behav_srams.v : $(generated_dir)/$(long_name).conf $(VLSI_MEM_GEN)
cd $(generated_dir) && \
$(VLSI_MEM_GEN) $(generated_dir)/$(long_name).conf > $@

# Build and install our own Verilator, to work around versionining issues.
VERILATOR_VERSION=4.004
VERILATOR_VERSION=4.008
VERILATOR_SRCDIR ?= verilator/src/verilator-$(VERILATOR_VERSION)
VERILATOR_TARGET := $(abspath verilator/install/bin/verilator)
INSTALLED_VERILATOR ?= $(VERILATOR_TARGET)
Expand Down Expand Up @@ -55,13 +63,14 @@ verilator: $(INSTALLED_VERILATOR)

# Run Verilator to produce a fast binary to emulate this circuit.
VERILATOR := $(INSTALLED_VERILATOR) --cc --exe
VERILATOR_THREADS ?= 2
VERILATOR_FLAGS := --top-module $(MODEL) \
+define+PRINTF_COND=\$$c\(\"verbose\",\"\&\&\"\,\"done_reset\"\) \
+define+RANDOMIZE_GARBAGE_ASSIGN \
+define+STOP_COND=\$$c\(\"done_reset\"\) --assert \
--output-split 20000 \
--output-split-cfuncs 20000 \
--threads 4 \
--threads $(VERILATOR_THREADS) \
-Wno-STMTDLY --x-assign unique \
-I$(vsrc) \
-O3 -CFLAGS "$(CXXFLAGS) -DVERILATOR -DTEST_HARNESS=V$(MODEL) -include $(csrc)/verilator.h -include $(generated_dir)/$(PROJECT).$(CONFIG).plusArgs"
Expand All @@ -84,3 +93,12 @@ $(emu_debug): $(verilog) $(cppfiles) $(headers) $(generated_dir)/$(long_name).d
-o $(abspath $(sim_dir))/$@ $(verilog) $(cppfiles) -LDFLAGS "$(LDFLAGS)" \
-CFLAGS "-I$(generated_dir_debug) -include $(model_header_debug)"
$(MAKE) VM_PARALLEL_BUILDS=1 -C $(generated_dir_debug)/$(long_name) -f V$(MODEL).mk

$(origin_emu): $(origin_verilog) $(cppfiles) $(headers) $(INSTALLED_VERILATOR)
mkdir -p $(generated_dir)/$(long_name)
$(VERILATOR) $(VERILATOR_FLAGS) -Mdir $(generated_dir)/$(long_name) \
-o $(abspath $(sim_dir))/$@ $(origin_verilog) $(cppfiles) -LDFLAGS "$(LDFLAGS)" \
-CFLAGS "-I$(generated_dir) -include $(model_header)"
$(MAKE) VM_PARALLEL_BUILDS=1 -C $(generated_dir)/$(long_name) -f V$(MODEL).mk


2 changes: 1 addition & 1 deletion firrtl
7 changes: 6 additions & 1 deletion fpga/emu/Makefile
Expand Up @@ -5,6 +5,8 @@ build_dir = $(fpga_dir)/build
generated_dir = $(build_dir)/generated-src

CONFIG ?= LvNAConfigemu
NUMA_CONFIG ?=
SEED ?=

-include $(base_dir)/Makefrag

Expand All @@ -19,6 +21,8 @@ emu_gen_script = gen_bin.sh
emu_bin_hex_file = $(build_dir)/bin.txt
nohype_dtb = $(build_dir)/c0.dtb
nohype_dtb_hex_file = $(build_dir)/c0.dtb.txt
# max_cycles = 40000000
max_cycles = 2209069

$(emu): $(original_emu)
ln -sf $< $@
Expand Down Expand Up @@ -46,7 +50,8 @@ DEBUG_ARGS = +jtag_rbb_enable=1 -r 4040
endif

run-emu: $(emu) $(emu_bin_hex_file) $(nohype_dtb_hex_file)
cd $(dir $(emu)) && $(emu) $(DEBUG_ARGS) +verbose . 3>&1 1>&2 2>&3 | spike-dasm > $(dir $(emu))/emu.log
cd $(dir $(emu)) && time $< $(DEBUG_ARGS) $(SEED) +verbose -m $(max_cycles) . 3>&1 1>&2 2>&3 \
| spike-dasm > $(dir $(emu))/emu.log

dtb-clean:
-rm -f $(build_dir)/c*.dtb{,.txt}
Expand Down
2 changes: 2 additions & 0 deletions fpga/emu/gen_dtb_bin.sh
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

BUILD_DIR=$1

for i in $(ls $1/c*.dtb)
do
sh gen_bin.sh $i $i.txt
Expand Down
2 changes: 2 additions & 0 deletions fpga/emu/python/.gitignore
@@ -0,0 +1,2 @@
ts
__pycache__
115 changes: 115 additions & 0 deletions fpga/emu/python/common.py
@@ -0,0 +1,115 @@
import sh
import os
import errno
from pathlib import Path
import binascii as ba
from os.path import join as pjoin


# hex_dump == hexdump -ve '2/ "%08x " "\n"' $1 | awk '{print $2$1}' > $2
def hex_dump(in_file, out_file):
assert os.path.isfile(in_file)
print(in_file)
with open(in_file, 'rb') as f, open(out_file, 'w') as out_f:
chunks = iter(lambda : f.read(1), b'')
hex_bytes = map(ba.hexlify, chunks)

buffer = []
for b in hex_bytes:
buffer.append(b.decode())
if len(buffer) == 8:
buffer.reverse()
out_f.write(''.join(buffer) + '\n')
buffer.clear()


def safe_mkdir(dir: str):
if not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError as e:
# when another thread create this directory
assert e.errno == errno.EEXIST


def is_older(left, right):
if not os.path.isfile(right):
return False
assert os.path.isfile(left)
return os.path.getmtime(left) < os.path.getmtime(right)


def avoid_repeating(
emu: str, input_file: str, output_dir: str,
force_run: bool, ok, func):
# this function avoid repeated run for most common situations
input_file_n = os.path.basename(input_file)
emu_n = os.path.basename(emu)

# python 3.6 please
running_lock_name = f'running-{func.__name__}-{emu_n}-{input_file_n}'
running_lock_file = pjoin(output_dir, running_lock_name)

if os.path.isfile(running_lock_file):
print('running lock found in {}, skip!'.format(output_dir))
return
else:
sh.touch(running_lock_file)

script_ts_dir = pjoin(str(Path(__file__).resolve().parent), 'ts')
safe_mkdir(script_ts_dir)
# python 3.6 please
ts_name = f'ts-{func.__name__}-{emu_n}-{input_file_n}'

out_ts_file = pjoin(output_dir, ts_name)
if os.path.isfile(out_ts_file):
out_ts = os.path.getmtime(out_ts_file)
else:
out_ts = 0.0

script_ts_file = pjoin(script_ts_dir, ts_name)
if not os.path.isfile(script_ts_file):
sh.touch(script_ts_file)
script_ts = os.path.getmtime(script_ts_file)

program_ts = os.path.getmtime(emu)
input_binary_ts = os.path.getmtime(input_file)

cmd_ts = max(script_ts, program_ts, input_binary_ts)

if out_ts < cmd_ts or force_run:
try:
func()
sh.touch(out_ts_file)
except Exception as e:
if (ok()):
sh.touch(out_ts_file)
else:
print(e)
sh.rm(running_lock_file)
else:
print('none of the inputs is older than output, skip!')
if os.path.isfile(running_lock_file):
sh.rm(running_lock_file)


def get_am_apps():
assert 'AM_HOME' in os.environ.keys()
app_dir = pjoin(os.environ['AM_HOME'], 'apps')
apps = set(os.listdir(app_dir))
with open('./am_app_filter.txt') as f:
filters = set([line.strip() for line in f.readlines()])
return list(apps & filters)


def get_am_app_dir(app: str):
assert 'AM_HOME' in os.environ.keys()
app_base_dir = pjoin(os.environ['AM_HOME'], 'apps')
app_dir = pjoin(app_base_dir, app)
assert os.path.isdir(app_dir)
return app_dir


if __name__ == '__main__':
hex_dump('/home/zyy/projects/nexus-am/apps/cache-flush/build/cache-flush'
'-riscv64-rocket.bin', 'test.txt')

0 comments on commit 3bb823b

Please sign in to comment.