Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ jobs:
sudo mkdir /opt/riscv
sudo tar -xzf riscv32-unknown-elf.gcc-12.1.0.tar.gz -C /opt/riscv/
rm riscv32-unknown-elf.gcc-12.1.0.tar.gz
root=$(pwd)
echo "PATH=$PATH:/opt/riscv/bin" >> $GITHUB_ENV
- name: Build InterPRET
echo "FLEXPRET_ROOT_DIR=$root/flexpret" >> $GITHUB_ENV
echo "INTERPRET_ROOT_DIR=$root" >> $GITHUB_ENV
- name: Build and test FlexPRET
run : |
cd $FLEXPRET_ROOT_DIR
make clean && make emulator
make test
- name: Build and test InterPRET
run: |
make emulator N_CORES=4 THREADS=4 FLEX=false TRACE=0
root=$(pwd)
echo "PATH=$PATH:$root/flexpret/scripts/c:$root/emulator:$root/programs/scripts" >> $GITHUB_ENV
echo "FP_ROOT=$root" >> $GITHUB_ENV
- name: Run unit-tests
run: make unit-tests
- name: Run integration tests
run: make integration-tests
make unit-tests
make integration-tests
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.bsp/
.metals/
.idea/
.vscode/
project/
target/
build/
emulator/*.v
emulator/obj_dir
emulator/ip-emu
emulator/ip-verilator
.bloop

# Generated files
Expand All @@ -17,7 +20,6 @@ emulator/obj_dir
**/*.map
**/*.orig
**/*.dump
**/fp-emu
**/*.fir
**/*.app
**/*.binary.txt
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ SCRIPTS_DIR = flexpret/scripts
BUILD_DIR = build
RESOURCE_DIR = flexpret/src/main/resources



# Compiler options.
CXX = g++
CXXFLAGS = -g -O2
Expand Down Expand Up @@ -44,7 +42,7 @@ verilog_raw: $(VERILOG_RAW)

# --no-dedup flag is to make it possible to load programs directly into the ISpms
$(VERILOG_RAW):
sbt 'run $(CORE_CONFIG) $(SOC_CONFIG) --no-dedup --target-dir $(BUILD_DIR)'
sbt 'run verilator $(CORE_CONFIG) $(SOC_CONFIG) --no-dedup --target-dir $(BUILD_DIR)'

# FPGA Verilog generation
# FPGA_SRC_DIR = $(FPGA_DIR)/generated-$(CORE_CONFIG)
Expand Down
23 changes: 23 additions & 0 deletions Makefrag
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ifndef FLEXPRET_ROOT_DIR
$(error FLEXPRET_ROOT_DIR is not set. Please source env.bash)
endif

ifndef INTERPRET_ROOT_DIR
$(error INTERPRET_ROOT_DIR is not set. Please source env.bash)
endif

EMU:=$(INTERPRET_ROOT_DIR)/emulator/ip-emu

ifdef BOOTLOADER
LINKER_SCRIPT := $(FLEXPRET_ROOT_DIR)/programs/lib/linker/flexpret_btl.ld
endif

ifdef APP
LINKER_SCRIPT := $(FLEXPRET_ROOT_DIR)/programs/lib/linker/flexpret_app.ld
endif

include $(INTERPRET_ROOT_DIR)/lib/Makefrag


app: compile
$(INTERPRET_ROOT_DIR)/programs/scripts/serialize_app.py $(NAME).mem $(NAME).app
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ InterPRET is a multicore FlexPRET architecture that uses a time-predictable Netw
### Prerequisites
1. Verilator
2. SBT
3. RISCV 32-bit toolchain
3. RISCV toolchain on the PATH. Download prebuild [rv32i-4.0.0](https://github.com/stnolting/riscv-gcc-prebuilt)

### Clone repo and set up
```
Expand All @@ -19,7 +19,7 @@ source env.bash

### Build and run tests
```
make tests
make test
```
The final tests, which consist of bootloading an application over serial might take a few minutes to complete.

Expand Down
25 changes: 13 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
ThisBuild / scalaVersion := "2.12.10"
ThisBuild / version := "0.1.0"
ThisBuild / organization := "PRETIS"


val chiselVersion = "3.5.5"
val chiselVersion = "3.5.6"

lazy val interpret = (project in file("."))
.settings(
name := "interpret",
libraryDependencies ++= Seq(
"edu.berkeley.cs" %% "chisel3" % chiselVersion,
"edu.berkeley.cs" %% "chiseltest" % "0.5.5",
"edu.berkeley.cs" %% "chiseltest" % "0.5.6" % "test"
),
scalacOptions ++= Seq(
"-language:reflectiveCalls",
"-deprecation",
"-feature",
"-Xcheckinit",
"-P:chiselplugin:genBundleElements",
),
scalaVersion := "2.12.10", // Issue on scalamacros:paradise
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
"-language:reflectiveCalls",
),
addCompilerPlugin("edu.berkeley.cs" %% "chisel3-plugin" % chiselVersion cross CrossVersion.full),
addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full)
addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full),
).dependsOn(flexpret,soc_comm)

// Import flexpret
Expand Down
21 changes: 3 additions & 18 deletions emulator/emulator.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,10 @@
# Edward Wang <edwardw@eecs.berkeley.edu>
# Shaokai Lin <shaokai@berkeley.edu>

EMULATOR_BIN = $(EMULATOR_DIR)/fp-emu
HDL_SCRIPTS = $(SCRIPTS_DIR)/hdl
TRACE ?= 0
EMULATOR_BIN = $(EMULATOR_DIR)/ip-verilator

$(EMULATOR_BIN): $(VERILOG_RAW) $(EMULATOR_DIR)/main.cpp $(EMULATOR_DIR)/uartsim.cpp $(HDL_SCRIPTS)/simify_verilog.py
# Inject the right simulation constructs
# FIXME: Remove this alltogether, currently only used for enabling tracing
$(EMULATOR_BIN): $(VERILOG_RAW) $(EMULATOR_DIR)/main.cpp $(EMULATOR_DIR)/uartsim.cpp
cp $(RESOURCE_DIR)/DualPortBram.v $(EMULATOR_DIR)/DualPortBram.v
ifeq ($(TRACE),1)
@echo "Enabling tracing on Verilator"
$(HDL_SCRIPTS)/simify_verilog.py $(VERILOG_RAW) > $(EMULATOR_DIR)/$(MODULE).sim.v
(cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --trace --build main.cpp uartsim.cpp)
else
@echo "Disabling tracing on Verilator"
cp $(VERILOG_RAW) $(EMULATOR_DIR)/$(MODULE).sim.v
(cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --build main.cpp uartsim.cpp)
endif


(cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --trace --build main.cpp uartsim.cpp)
cp $(EMULATOR_DIR)/obj_dir/V$(MODULE) $(EMULATOR_BIN)

echo "Emulator usage: Run '$(EMULATOR_BIN)'. The emulator expects to find the program for each core stored in the directory it is invoked from with the names 'core1.mem', 'core2.mem', 'coreN.mem' etc. The programs can be built using 'scripts/c/riscv_build.sh coreN <C files...>'. The emulation will generate a VCD called 'trace.vcd'. Use flexpret_io.h to print or to terminate simulation."
39 changes: 39 additions & 0 deletions emulator/ip-emu
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# Simple wrapper around the ip-verilator emulation

# Get the directory of the script and the verilator emulation
script_dir=$(dirname "$0")
script_name=$(basename "$0")
emu="$script_dir/ip-verilator"
working_dir=$(pwd)

echo "Running InterPRET emulator:"

# Check if exactly one argument is provided
if [ $# -lt 1 ]; then
echo "Usage: $script_name ispm-file [uart_file] [--trace]"
exit 1
fi

# Check if the file exists
if [ ! -f "$1" ]; then
echo "File not found: $1"
exit 1
fi

# Check if the file exists
if [ ! -f "$emu" ]; then
echo "Did not find verilator emulator at: $emu"
exit 1
fi

# Get the filename from the path
filename=$(basename "$1")

# Copy the file to the current directory
cp "$1" "$working_dir/ispm.mem"

# Excute the verilator emulation
echo "${@:2}"
"$script_dir/ip-verilator" "${@:2}"

73 changes: 69 additions & 4 deletions emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
#include "VTop.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
#include <iostream>
#include "uartsim.h"

uint64_t timestamp = 0;
Expand All @@ -16,13 +18,56 @@ double sc_time_stamp() {

int main(int argc, char* argv[]) {
Verilated::commandArgs(argc, argv);
Verilated::traceEverOn(true);
bool trace_enabled = false;
bool uart_file = false;
int uart_file_argv = 0;

// We accept 2 optional command line args, in arbitrary order
// A) `--trace` to turn on VCD tracing
// B) file_path.bin to a binary file which will be read into the uart rx pin of the InterPRET

if (argc == 2) {
if (!strcmp(argv[1], "--trace")) {
std::cout << "Tracing enabled" << std::endl;
trace_enabled = true;
Verilated::traceEverOn(true);
} else {
uart_file = true;
uart_file_argv = 1;
}
}

if (argc == 3) {
uart_file = true;
if (!strcmp(argv[1], "--trace")) {
std::cout << "Tracing enabled" << std::endl;
trace_enabled = true;
Verilated::traceEverOn(true);
uart_file_argv = 2;
} else if (argv[2], "--trace") {
std::cout << "Tracing enabled" << std::endl;
trace_enabled = true;
Verilated::traceEverOn(true);
uart_file_argv = 1;
} else {
std::cout << "Dont recognize command line arguments:" <<argv[1] <<"," <<argv[2] <<std::endl;
std::cout << "Usage ip-verilator [uart_file] [--trace]" <<std::endl;
exit(1);
}
}


VTop* top = new VTop;
VerilatedVcdC *trace;
if (trace_enabled) {
trace = new VerilatedVcdC;
top->trace(trace, 99);
trace->open("trace.vcd");
}

if (argc == 2) {
uartsim_init(argv[1]);
if (uart_file) {
std::cout <<"Passing in uart_file: `" <<argv[uart_file_argv] <<"`" <<std::endl;
uartsim_init(argv[uart_file_argv]);
} else {
uartsim_init("");
}
Expand All @@ -35,13 +80,33 @@ int main(int argc, char* argv[]) {
top->clock = 1;
top->eval();
timestamp+=1;

if (trace_enabled) {
trace->dump(10*timestamp);
}

if (timestamp > 10) {
uartsim_print_rx( (int *) &top->io_gpio_out_1, 0);
uartsim_print_rx( (int *) &top->io_uart_tx, 0);
uartsim_write(&top->io_uart_rx);
}
top->clock = 0;
top->eval();
timestamp+=1;

if (trace_enabled) {
trace->dump(10*timestamp);
trace->flush();
}

if (top->io_stop) {
std::cout <<"Verilator received stop signal from InterPRET" <<std::endl;
break;
}
}

if (trace_enabled) {
trace->close();
delete trace;
}

delete top;
Expand Down
10 changes: 3 additions & 7 deletions env.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export FP_ROOT=$(pwd)
export INTERPRET_ROOT_DIR=$(pwd)
export FLEXPRET_ROOT_DIR=$INTERPRET_ROOT_DIR/flexpret

# Put riscv gcc compiler on the path
# export PATH="$PATH:/opt/riscv32/bin"

# Put riscv_compile.sh and riscv_clean.sh on the path
export PATH="$PATH:$FP_ROOT/flexpret/scripts/c"
# Put the generated emulator on the path
export PATH="$PATH:$FP_ROOT/emulator"
export PATH="$PATH:$INTERPRET_ROOT_DIR/emulator"
8 changes: 3 additions & 5 deletions env.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
set -Ux FP_ROOT (pwd)
set -Ux INTERPRET_ROOT_DIR (pwd)
set -Ux FLEXPRET_ROOT_DIR $INTERPRET_ROOT_DIR/flexpret

set PATH $PATH:/opt/riscv32/bin
set PATH $PATH:$FP_ROOT/flexpret/scripts/c
set PATH $PATH:$FP_ROOT/emulator
set PATH $PATH:$FP_ROOT/programs/scripts
set PATH $PATH:$INTERPRET_ROOT_DIR/emulator
2 changes: 1 addition & 1 deletion flexpret
Submodule flexpret updated 95 files
+9 −2 .gitignore
+28 −45 Makefile
+67 −0 Makefrag
+0 −53 README.md
+3 −2 azure-pipelines.yml
+20 −24 build.sbt
+0 −1 config.mk
+13 −12 emulator/emulator.mk
+60 −0 emulator/fp-emu
+40 −2 emulator/main.cpp
+1 −9 env.bash
+1 −5 env.fish
+17 −0 programs/lib/Makefrag-lib
+0 −155 programs/lib/cbuf.c
+0 −1 programs/lib/flexpret_exceptions.c
+18 −2 programs/lib/flexpret_lock.c
+0 −70 programs/lib/flexpret_printer.c
+0 −65 programs/lib/flexpret_stdio.c
+2 −6 programs/lib/flexpret_thread.c
+0 −41 programs/lib/include/cbuf.h
+13 −6 programs/lib/include/flexpret.h
+3 −2 programs/lib/include/flexpret_csrs.h
+6 −6 programs/lib/include/flexpret_exceptions.h
+27 −21 programs/lib/include/flexpret_io.h
+3 −12 programs/lib/include/flexpret_lock.h
+0 −109 programs/lib/include/flexpret_noc.h
+0 −16 programs/lib/include/flexpret_printer.h
+0 −7 programs/lib/include/flexpret_stdio.h
+6 −1 programs/lib/include/flexpret_thread.h
+0 −7 programs/lib/include/flexpret_time.h
+1 −0 programs/lib/include/flexpret_types.h
+0 −32 programs/lib/include/flexpret_uart.h
+0 −28 programs/lib/include/flexpret_wb.h
+0 −42 programs/lib/include/sdd_uart.h
+4 −2 programs/lib/linker/flexpret.ld
+67 −0 programs/lib/linker/flexpret_app.ld
+66 −0 programs/lib/linker/flexpret_btl.ld
+0 −205 programs/lib/sdd_uart.c
+7 −3 programs/lib/start.S
+5 −16 programs/lib/startup.c
+0 −13 programs/noc/Makefile
+0 −15 programs/noc/core0.c
+0 −15 programs/noc/core1.c
+0 −14 programs/noc/core2.c
+0 −12 programs/noc/core3.c
+41 −68 programs/tests/Makefile
+0 −49 programs/tests/Makefrag-tests
+4 −0 programs/tests/c-tests/add/Makefile
+1 −1 programs/tests/c-tests/add/add.c
+4 −0 programs/tests/c-tests/calloc/Makefile
+1 −1 programs/tests/c-tests/calloc/calloc.c
+0 −14 programs/tests/c-tests/devices/wishbone.h
+0 −25 programs/tests/c-tests/devices/wishbone_master.c
+4 −0 programs/tests/c-tests/fib/Makefile
+1 −1 programs/tests/c-tests/fib/fib.c
+4 −0 programs/tests/c-tests/global/Makefile
+1 −1 programs/tests/c-tests/global/global.c
+4 −0 programs/tests/c-tests/gpio/Makefile
+10 −10 programs/tests/c-tests/gpio/gpio.c
+4 −0 programs/tests/c-tests/hwlock/Makefile
+1 −1 programs/tests/c-tests/hwlock/hwlock.c
+4 −0 programs/tests/c-tests/lbu/Makefile
+1 −1 programs/tests/c-tests/lbu/lbu.c
+4 −0 programs/tests/c-tests/malloc/Makefile
+1 −1 programs/tests/c-tests/malloc/malloc.c
+4 −0 programs/tests/c-tests/realloc/Makefile
+1 −1 programs/tests/c-tests/realloc/realloc.c
+4 −0 programs/tests/c-tests/syscall/Makefile
+1 −1 programs/tests/mt-c-tests/add/add.c
+1 −1 programs/tests/mt-c-tests/lockowner/lockowner.c
+1 −1 programs/tests/mt-c-tests/swlock/swlock.c
+1 −1 programs/tests/mt-c-tests/threadcancel/threadcancel.c
+0 −3 scripts/c/riscv-clean.sh
+0 −54 scripts/c/riscv-compile.sh
+0 −1 src/main/scala/Core/ALU.scala
+1 −2 src/main/scala/Core/CSR.scala
+3 −6 src/main/scala/Core/MMIO.scala
+0 −2 src/main/scala/Core/RegisterFile.scala
+73 −0 src/main/scala/Core/Top.scala
+238 −0 src/main/scala/Core/config.scala
+3 −139 src/main/scala/Core/core.scala
+49 −0 src/main/scala/Core/main.scala
+0 −47 src/main/scala/main.scala
+2 −0 src/test/scala/core/ALUTest.scala
+5 −3 src/test/scala/core/BasicJumpsTest.scala
+5 −3 src/test/scala/core/BasicMemoryTest.scala
+2 −0 src/test/scala/core/CSRTest.scala
+6 −4 src/test/scala/core/DatapathTest.scala
+2 −0 src/test/scala/core/ImemSimulator.scala
+2 −0 src/test/scala/core/LoadStoreTest.scala
+2 −0 src/test/scala/core/LockTest.scala
+2 −0 src/test/scala/core/MMIOTest.scala
+4 −2 src/test/scala/core/RegisterFileTest.scala
+6 −4 src/test/scala/core/SimpleCoreTest.scala
+2 −0 src/test/scala/core/StoreMaskTest.scala
14 changes: 14 additions & 0 deletions lib/Makefrag
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

IP_LIB_DIR=$(INTERPRET_ROOT_DIR)/lib
ifdef BOOTLOADER
LIB_SOURCES += \
$(IP_LIB_DIR)/interpret_uart.c \
$(IP_LIB_DIR)/interpret_wb.c
else
LIB_SOURCES += \
$(IP_LIB_DIR)/interpret_noc.c \
$(IP_LIB_DIR)/interpret_uart.c \
$(IP_LIB_DIR)/interpret_wb.c \
$(IP_LIB_DIR)/interpret_stdio.c
endif
LIB_INCS += -I$(IP_LIB_DIR)/include
10 changes: 10 additions & 0 deletions lib/include/interpret.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef INTERPRET_H
#define INTERPRET_H

#include "flexpret.h"
#include "interpret_wb.h"
#include "interpret_uart.h"
#include "interpret_stdio.h"
#include "interpret_noc.h"

#endif
Empty file added lib/include/interpret_config.h
Empty file.
Loading