Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hero: New patch plus bumped to main
Browse files Browse the repository at this point in the history
CyrilKoe committed Feb 23, 2024
1 parent 68e3d75 commit bb8edb7
Showing 11 changed files with 2,731 additions and 74 deletions.
3 changes: 2 additions & 1 deletion sw/hero/device/toolchain.mk
Original file line number Diff line number Diff line change
@@ -4,5 +4,6 @@
#
# Luca Colagrande <[email protected]>

BENDER ?= bender
RISCV_LDFLAGS += -L$(HERO_INSTALL)/lib/clang/15.0.0/rv32imafdvzfh-ilp32d/lib/
RISCV_CFLAGS += --sysroot=$(HERO_INSTALL)/rv32imafd-ilp32d/riscv32-unknown-elf
include $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/../../../vendor/snitch/target/snitch_cluster/sw/toolchain.mk
1,326 changes: 1,326 additions & 0 deletions vendor/patches/snitch/01_add_deps.patch

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/snitch.lock.hjson
Original file line number Diff line number Diff line change
@@ -9,6 +9,6 @@
upstream:
{
url: https://github.com/pulp-platform/snitch_cluster.git
rev: 4b3f76e5ad6bdde7af15559401c47d3a64262db9
rev: d325300c8c2f6dd6b81b6612428e787adf133464
}
}
914 changes: 914 additions & 0 deletions vendor/snitch/sw/deps/printf/printf.c

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions vendor/snitch/sw/deps/printf/printf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////

Check failure on line 31 in vendor/snitch/sw/deps/printf/printf.h

GitHub Actions / lint-license

FAILED: First comment ended before licence notice
#ifndef _PRINTF_H_
#define _PRINTF_H_

#include <stdarg.h>
#include <stddef.h>


#ifdef __cplusplus
extern "C" {
#endif


/**
* Output a character to a custom device like UART, used by the printf() function
* This function is declared here only. You have to write your custom implementation somewhere
* \param character Character to output
*/
void _putchar(char character);


/**
* Tiny printf implementation
* You have to implement _putchar if you use printf()
* To avoid conflicts with the regular printf() API it is overridden by macro defines
* and internal underscore-appended functions like printf_() are used
* \param format A string that specifies the format of the output
* \return The number of characters that are written into the array, not counting the terminating null character
*/
#define printf printf_
int printf_(const char* format, ...);


/**
* Tiny sprintf implementation
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
* \param format A string that specifies the format of the output
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define sprintf sprintf_
int sprintf_(char* buffer, const char* format, ...);


/**
* Tiny snprintf/vsnprintf implementation
* \param buffer A pointer to the buffer where to store the formatted string
* \param count The maximum number of characters to store in the buffer, including a terminating null character
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
* null character. A value equal or larger than count indicates truncation. Only when the returned value
* is non-negative and less than count, the string has been completely written.
*/
#define snprintf snprintf_
#define vsnprintf vsnprintf_
int snprintf_(char* buffer, size_t count, const char* format, ...);
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);


/**
* Tiny vprintf implementation
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define vprintf vprintf_
int vprintf_(const char* format, va_list va);


/**
* printf with output function
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
* \param out An output function which takes one character and an argument pointer
* \param arg An argument pointer for user data passed to output function
* \param format A string that specifies the format of the output
* \return The number of characters that are sent to the output function, not counting the terminating null character
*/
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);


#ifdef __cplusplus
}
#endif


#endif // _PRINTF_H_
277 changes: 277 additions & 0 deletions vendor/snitch/sw/deps/riscv-opcodes/encoding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
/* See LICENSE for license details. */

Check failure on line 1 in vendor/snitch/sw/deps/riscv-opcodes/encoding.h

GitHub Actions / lint-license

FAILED: File does not start with comment

#ifndef RISCV_CSR_ENCODING_H
#define RISCV_CSR_ENCODING_H

#define MSTATUS_UIE 0x00000001
#define MSTATUS_SIE 0x00000002
#define MSTATUS_HIE 0x00000004
#define MSTATUS_MIE 0x00000008
#define MSTATUS_UPIE 0x00000010
#define MSTATUS_SPIE 0x00000020
#define MSTATUS_HPIE 0x00000040
#define MSTATUS_MPIE 0x00000080
#define MSTATUS_SPP 0x00000100
#define MSTATUS_VS 0x00000600
#define MSTATUS_MPP 0x00001800
#define MSTATUS_FS 0x00006000
#define MSTATUS_XS 0x00018000
#define MSTATUS_MPRV 0x00020000
#define MSTATUS_SUM 0x00040000
#define MSTATUS_MXR 0x00080000
#define MSTATUS_TVM 0x00100000
#define MSTATUS_TW 0x00200000
#define MSTATUS_TSR 0x00400000
#define MSTATUS32_SD 0x80000000
#define MSTATUS_UXL 0x0000000300000000
#define MSTATUS_SXL 0x0000000C00000000
#define MSTATUS_GVA 0x0000004000000000
#define MSTATUS_MPV 0x0000008000000000
#define MSTATUS64_SD 0x8000000000000000

#define SSTATUS_UIE 0x00000001
#define SSTATUS_SIE 0x00000002
#define SSTATUS_UPIE 0x00000010
#define SSTATUS_SPIE 0x00000020
#define SSTATUS_SPP 0x00000100
#define SSTATUS_VS 0x00000600
#define SSTATUS_FS 0x00006000
#define SSTATUS_XS 0x00018000
#define SSTATUS_SUM 0x00040000
#define SSTATUS_MXR 0x00080000
#define SSTATUS32_SD 0x80000000
#define SSTATUS_UXL 0x0000000300000000
#define SSTATUS64_SD 0x8000000000000000

#define SSTATUS_VS_MASK (SSTATUS_SIE | SSTATUS_SPIE | \
SSTATUS_SPP | SSTATUS_SUM | \
SSTATUS_MXR | SSTATUS_UXL)

#define HSTATUS_VSXL 0x300000000
#define HSTATUS_VTSR 0x00400000
#define HSTATUS_VTW 0x00200000
#define HSTATUS_VTVM 0x00100000
#define HSTATUS_VGEIN 0x0003f000
#define HSTATUS_HU 0x00000200
#define HSTATUS_SPVP 0x00000100
#define HSTATUS_SPV 0x00000080
#define HSTATUS_GVA 0x00000040
#define HSTATUS_VSBE 0x00000020

#define USTATUS_UIE 0x00000001
#define USTATUS_UPIE 0x00000010

#define DCSR_XDEBUGVER (3U<<30)
#define DCSR_NDRESET (1<<29)
#define DCSR_FULLRESET (1<<28)
#define DCSR_EBREAKM (1<<15)
#define DCSR_EBREAKH (1<<14)
#define DCSR_EBREAKS (1<<13)
#define DCSR_EBREAKU (1<<12)
#define DCSR_STOPCYCLE (1<<10)
#define DCSR_STOPTIME (1<<9)
#define DCSR_CAUSE (7<<6)
#define DCSR_DEBUGINT (1<<5)
#define DCSR_HALT (1<<3)
#define DCSR_STEP (1<<2)
#define DCSR_PRV (3<<0)

#define DCSR_CAUSE_NONE 0
#define DCSR_CAUSE_SWBP 1
#define DCSR_CAUSE_HWBP 2
#define DCSR_CAUSE_DEBUGINT 3
#define DCSR_CAUSE_STEP 4
#define DCSR_CAUSE_HALT 5
#define DCSR_CAUSE_GROUP 6

#define MCONTROL_TYPE(xlen) (0xfULL<<((xlen)-4))
#define MCONTROL_DMODE(xlen) (1ULL<<((xlen)-5))
#define MCONTROL_MASKMAX(xlen) (0x3fULL<<((xlen)-11))

#define MCONTROL_SELECT (1<<19)
#define MCONTROL_TIMING (1<<18)
#define MCONTROL_ACTION (0x3f<<12)
#define MCONTROL_CHAIN (1<<11)
#define MCONTROL_MATCH (0xf<<7)
#define MCONTROL_M (1<<6)
#define MCONTROL_H (1<<5)
#define MCONTROL_S (1<<4)
#define MCONTROL_U (1<<3)
#define MCONTROL_EXECUTE (1<<2)
#define MCONTROL_STORE (1<<1)
#define MCONTROL_LOAD (1<<0)

#define MCONTROL_TYPE_NONE 0
#define MCONTROL_TYPE_MATCH 2

#define MCONTROL_ACTION_DEBUG_EXCEPTION 0
#define MCONTROL_ACTION_DEBUG_MODE 1
#define MCONTROL_ACTION_TRACE_START 2
#define MCONTROL_ACTION_TRACE_STOP 3
#define MCONTROL_ACTION_TRACE_EMIT 4

#define MCONTROL_MATCH_EQUAL 0
#define MCONTROL_MATCH_NAPOT 1
#define MCONTROL_MATCH_GE 2
#define MCONTROL_MATCH_LT 3
#define MCONTROL_MATCH_MASK_LOW 4
#define MCONTROL_MATCH_MASK_HIGH 5

#define MIP_USIP (1 << IRQ_U_SOFT)
#define MIP_SSIP (1 << IRQ_S_SOFT)
#define MIP_VSSIP (1 << IRQ_VS_SOFT)
#define MIP_MSIP (1 << IRQ_M_SOFT)
#define MIP_UTIP (1 << IRQ_U_TIMER)
#define MIP_STIP (1 << IRQ_S_TIMER)
#define MIP_VSTIP (1 << IRQ_VS_TIMER)
#define MIP_MTIP (1 << IRQ_M_TIMER)
#define MIP_UEIP (1 << IRQ_U_EXT)
#define MIP_SEIP (1 << IRQ_S_EXT)
#define MIP_VSEIP (1 << IRQ_VS_EXT)
#define MIP_MEIP (1 << IRQ_M_EXT)
#define MIP_SGEIP (1 << IRQ_S_GEXT)
#define MIP_SCIP (1 << IRQ_S_CLUSTER)
#define MIP_MCIP (1 << IRQ_M_CLUSTER)

#define MIP_S_MASK (MIP_SSIP | MIP_STIP | MIP_SEIP)
#define MIP_VS_MASK (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)
#define MIP_HS_MASK (MIP_VS_MASK | MIP_SGEIP)

#define MIDELEG_FORCED_MASK MIP_HS_MASK

#define SIP_SSIP MIP_SSIP
#define SIP_STIP MIP_STIP

#define PRV_U 0
#define PRV_S 1
#define PRV_M 3

#define PRV_HS (PRV_S + 1)

#define SATP32_MODE 0x80000000
#define SATP32_ASID 0x7FC00000
#define SATP32_PPN 0x003FFFFF
#define SATP64_MODE 0xF000000000000000
#define SATP64_ASID 0x0FFFF00000000000
#define SATP64_PPN 0x00000FFFFFFFFFFF

#define SATP_MODE_OFF 0
#define SATP_MODE_SV32 1
#define SATP_MODE_SV39 8
#define SATP_MODE_SV48 9
#define SATP_MODE_SV57 10
#define SATP_MODE_SV64 11

#define HGATP32_MODE 0x80000000
#define HGATP32_VMID 0x1FC00000
#define HGATP32_PPN 0x003FFFFF

#define HGATP64_MODE 0xF000000000000000
#define HGATP64_VMID 0x03FFF00000000000
#define HGATP64_PPN 0x00000FFFFFFFFFFF

#define HGATP_MODE_OFF 0
#define HGATP_MODE_SV32X4 1
#define HGATP_MODE_SV39X4 8
#define HGATP_MODE_SV48X4 9

#define PMP_R 0x01
#define PMP_W 0x02
#define PMP_X 0x04
#define PMP_A 0x18
#define PMP_L 0x80
#define PMP_SHIFT 2

#define PMP_TOR 0x08
#define PMP_NA4 0x10
#define PMP_NAPOT 0x18

#define IRQ_U_SOFT 0
#define IRQ_S_SOFT 1
#define IRQ_VS_SOFT 2
#define IRQ_M_SOFT 3
#define IRQ_U_TIMER 4
#define IRQ_S_TIMER 5
#define IRQ_VS_TIMER 6
#define IRQ_M_TIMER 7
#define IRQ_U_EXT 8
#define IRQ_S_EXT 9
#define IRQ_VS_EXT 10
#define IRQ_M_EXT 11
#define IRQ_S_GEXT 12
#define IRQ_COP 12
#define IRQ_HOST 13
#define IRQ_S_CLUSTER 17
#define IRQ_M_CLUSTER 19

#define DEFAULT_RSTVEC 0x00001000
#define CLINT_BASE 0x02000000
#define CLINT_SIZE 0x000c0000
#define EXT_IO_BASE 0x40000000
#define DRAM_BASE 0x80000000

/* page table entry (PTE) fields */
#define PTE_V 0x001 /* Valid */
#define PTE_R 0x002 /* Read */
#define PTE_W 0x004 /* Write */
#define PTE_X 0x008 /* Execute */
#define PTE_U 0x010 /* User */
#define PTE_G 0x020 /* Global */
#define PTE_A 0x040 /* Accessed */
#define PTE_D 0x080 /* Dirty */
#define PTE_SOFT 0x300 /* Reserved for Software */

#define PTE_PPN_SHIFT 10

#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)

#ifdef __riscv

#if __riscv_xlen == 64
# define MSTATUS_SD MSTATUS64_SD
# define SSTATUS_SD SSTATUS64_SD
# define RISCV_PGLEVEL_BITS 9
# define SATP_MODE SATP64_MODE
#else
# define MSTATUS_SD MSTATUS32_SD
# define SSTATUS_SD SSTATUS32_SD
# define RISCV_PGLEVEL_BITS 10
# define SATP_MODE SATP32_MODE
#endif
#define RISCV_PGSHIFT 12
#define RISCV_PGSIZE (1 << RISCV_PGSHIFT)

#ifndef __ASSEMBLER__

#ifdef __GNUC__

#define read_csr(reg) ({ unsigned long __tmp; \
asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \
__tmp; })

#define write_csr(reg, val) ({ \
asm volatile ("csrw " #reg ", %0" :: "rK"(val)); })

#define swap_csr(reg, val) ({ unsigned long __tmp; \
asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "rK"(val)); \
__tmp; })

#define set_csr(reg, bit) ({ unsigned long __tmp; \
asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \
__tmp; })

#define clear_csr(reg, bit) ({ unsigned long __tmp; \
asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \
__tmp; })

#define rdtime() read_csr(time)
#define rdcycle() read_csr(cycle)
#define rdinstret() read_csr(instret)

#endif

#endif

#endif

#endif
35 changes: 3 additions & 32 deletions vendor/snitch/target/common/common.mk
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@ TB_DIR ?= $(SNITCH_ROOT)/target/common/test
UTIL_DIR ?= $(SNITCH_ROOT)/util
LOGS_DIR = $(SIM_DIR)/logs

# Files
BENDER_LOCK ?= $(ROOT)/Bender.lock

# SEPP packages
QUESTA_SEPP ?=
VCS_SEPP ?=
@@ -167,38 +170,6 @@ define VERILATE
touch $@
endef

############
# Modelsim #
############

$(VSIM_BUILDDIR):
mkdir -p $@

# Expects vlog/vcom script in $< (e.g. as output by bender)
# Expects the top module name in $1
# Produces a binary used to run the simulation at the path specified by $@
define QUESTASIM
${VSIM} -c -do "source $<; quit" | tee $(dir $<)vlog.log
@! grep -P "Errors: [1-9]*," $(dir $<)vlog.log
$(VOPT) $(VOPT_FLAGS) -work $(VSIM_BUILDDIR) $1 -o $(1)_opt | tee $(dir $<)vopt.log
@! grep -P "Errors: [1-9]*," $(dir $<)vopt.log
@mkdir -p $(dir $@)
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo '${VSIM} +permissive ${VSIM_FLAGS} $$3 -work ${MKFILE_DIR}/${VSIM_BUILDDIR} -c \
-ldflags "-Wl,-rpath,${FESVR}/lib -L${FESVR}/lib -lfesvr -lutil" \
$(1)_opt +permissive-off ++$$binary ++$$2' >> $@
@chmod +x $@
@echo "#!/bin/bash" > $@.gui
@echo 'binary=$$(realpath $$1)' >> $@.gui
@echo 'echo $$binary > .rtlbinary' >> $@.gui
@echo '${VSIM} +permissive ${VSIM_FLAGS} -work ${MKFILE_DIR}/${VSIM_BUILDDIR} \
-ldflags "-Wl,-rpath,${FESVR}/lib -L${FESVR}/lib -lfesvr -lutil" \
$(1)_opt +permissive-off ++$$binary ++$$2' >> $@.gui
@chmod +x $@.gui
endef

#######
# VCS #
#######
34 changes: 32 additions & 2 deletions vendor/snitch/target/common/test/SnitchSim.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: SHL-0.51
#
# Paul Scheffler <paulsc@iis.ee.ethz.ch>
# Luca Colagrande <colluca@iis.ee.ethz.ch>
#
# This class implements a minimal wrapping IPC server for `tb_lib`.
# `__main__` shows a demonstrator for it, running a simulation and accessing its memory.
@@ -14,6 +15,12 @@
import subprocess
import struct
import functools
import threading
import time
import signal

# Simulation monitor polling period (in seconds)
SIM_MONITOR_POLL_PERIOD = 2


class SnitchSim:
@@ -38,16 +45,34 @@ def start(self):
# Open FIFOs
self.tx = open(tx_fd, 'wb', buffering=0) # Unbuffered
self.rx = open(rx_fd, 'rb')
# Create thread to monitor simulation
self.stop_sim_monitor = threading.Event()
self.sim_monitor = threading.Thread(target=self.__monitor_sim)
self.sim_monitor.start()

def __sim_active(func):
@functools.wraps(func)
def inner(self, *args, **kwargs):
if self.sim is None:
raise RuntimeError(f'Snitch is not running (simulation `{self.sim_bin}`'
f'binary `{self.snitch_bin}`)')
return func(self, *args, **kwargs)
# Catch SIGINT raised by simulation monitor
try:
return func(self, *args, **kwargs)
except KeyboardInterrupt:
print('Simulation monitor detected a simulation failure.')
self.stop_sim_monitor.set()
self.sim_monitor.join()
sys.exit(1)
return inner

def __monitor_sim(self):
while not self.stop_sim_monitor.is_set():
if self.sim.poll() is not None:
# Raise SIGINT to interrupt main thread, could be blocked on a read
os.kill(os.getpid(), signal.SIGINT)
time.sleep(SIM_MONITOR_POLL_PERIOD)

@__sim_active
def read(self, addr: int, length: int) -> bytes:
op = struct.pack('=QQQ', 0, addr, length)
@@ -73,15 +98,20 @@ def poll(self, addr: int, mask32: int, exp32: int):
bytestring = self.rx.read(4)
return int.from_bytes(bytestring, byteorder='little')

# Simulator can exit only once TX FIFO closes
@__sim_active
def finish(self, wait_for_sim: bool = True):
# Close FIFOs (simulator can exit only once TX FIFO closes)
self.rx.close()
self.tx.close()
# Close simulation monitor
self.stop_sim_monitor.set()
self.sim_monitor.join()
# Wait for simulation or terminate
if (wait_for_sim):
self.sim.wait()
else:
self.sim.terminate()
# Cleanup
self.tmpdir.cleanup()
self.sim = None

7 changes: 3 additions & 4 deletions vendor/snitch/target/common/test/tb_bin.cc
Original file line number Diff line number Diff line change
@@ -7,15 +7,14 @@
#include "sim.hh"

int main(int argc, char **argv, char **env) {
// Write binary path to logs/binary for the `make annotate` target
// Write binary path to .rtlbinary for the `make annotate` target
FILE *fd;
fd = fopen("logs/.rtlbinary", "w");
fd = fopen(".rtlbinary", "w");
if (fd != NULL && argc >= 2) {
fprintf(fd, "%s\n", argv[1]);
fclose(fd);
} else {
fprintf(stderr,
"Warning: Failed to write binary name to logs/.rtlbinary\n");
fprintf(stderr, "Warning: Failed to write binary name to .rtlbinary\n");
}

auto sim = std::make_unique<sim::Sim>(argc, argv);
41 changes: 41 additions & 0 deletions vendor/snitch/target/common/vsim.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

$(VSIM_BUILDDIR):
mkdir -p $@

$(VSIM_BUILDDIR)/compile.vsim.tcl: $(BENDER_LOCK) | $(VSIM_BUILDDIR)
$(VLIB) $(dir $@)
$(BENDER) script vsim $(VSIM_BENDER) --vlog-arg="$(VLOG_FLAGS) -work $(dir $@) " > $@
echo '$(VLOG) -work $(dir $@) $(TB_CC_SOURCES) -vv -ccflags "$(TB_CC_FLAGS)"' >> $@
echo 'return 0' >> $@

$(BIN_DIR):
mkdir -p $@

# Build compilation script and compile all sources for Questasim simulation
$(BIN_DIR)/$(TARGET).vsim: $(VSIM_BUILDDIR)/compile.vsim.tcl $(VSIM_SOURCES) $(TB_SRCS) $(TB_CC_SOURCES) work/lib/libfesvr.a | $(BIN_DIR)
$(VSIM) -c -do "source $<; quit" | tee $(dir $<)vlog.log
@! grep -P "Errors: [1-9]*," $(dir $<)vlog.log
$(VOPT) $(VOPT_FLAGS) -work $(VSIM_BUILDDIR) tb_bin -o tb_bin_opt | tee $(dir $<)vopt.log
@! grep -P "Errors: [1-9]*," $(dir $<)vopt.log
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo '$(VSIM) +permissive $(VSIM_FLAGS) $$3 -work $(MKFILE_DIR)/$(VSIM_BUILDDIR) -c \
-ldflags "-Wl,-rpath,$(FESVR)/lib -L$(FESVR)/lib -lfesvr -lutil" \
tb_bin_opt +permissive-off ++$$binary ++$$2' >> $@
@chmod +x $@
@echo "#!/bin/bash" > $@.gui
@echo 'binary=$$(realpath $$1)' >> $@.gui
@echo 'echo $$binary > .rtlbinary' >> $@.gui
@echo '$(VSIM) +permissive $(VSIM_FLAGS) -work $(MKFILE_DIR)/$(VSIM_BUILDDIR) \
-ldflags "-Wl,-rpath,$(FESVR)/lib -L$(FESVR)/lib -lfesvr -lutil" \
tb_bin_opt +permissive-off ++$$binary ++$$2' >> $@.gui
@chmod +x $@.gui

# Clean all build directories and temporary files for Questasim simulation
.PHONY: clean-vsim
clean-vsim: clean-work
rm -rf $(BIN_DIR)/$(TARGET).vsim $(BIN_DIR)/$(TARGET).vsim.gui $(VSIM_BUILDDIR) vsim.wlf
49 changes: 15 additions & 34 deletions vendor/snitch/target/snitch_cluster/Makefile
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@ MKFILE_DIR := $(dir $(MKFILE_PATH))
ROOT := ${MKFILE_DIR}../..
SNITCH_ROOT := $(ROOT)

TARGET = snitch_cluster

include $(ROOT)/target/common/common.mk

############
@@ -42,6 +44,7 @@ CLUSTER_GEN_SRC ?= $(wildcard $(ROOT)/util/clustergen/*.py)
#########################

SW_DIR = sw
BIN_DIR ?= bin
TARGET_C_HDRS_DIR ?= $(SW_DIR)/runtime/common
GENERATED_DIR ?= $(MKFILE_DIR)generated

@@ -203,9 +206,9 @@ $(GENERATED_DIR)/bootdata.cc: ${CFG} ${CLUSTER_GEN_PREREQ} | $(GENERATED_DIR)

.PHONY: clean-vlt

# Clean all build directories and temporary files for Questasim simulation
# Clean all build directories and temporary files for Verilator simulation
clean-vlt: clean-work
rm -rf bin/snitch_cluster.vlt $(VLT_BUILDDIR)
rm -rf $(BIN_DIR)/$(TARGET).vlt $(VLT_BUILDDIR)

$(VLT_AR): ${VLT_SOURCES} ${TB_SRCS}
$(call VERILATE,testharness)
@@ -224,37 +227,15 @@ $(VLT_BUILDDIR)/generated/%.o: $(GENERATED_DIR)/%.cc ${VLT_BUILDDIR}/lib/libfesv

# Build compilation script and compile all sources for Verilator simulation
# Link verilated archive with $(VLT_COBJ)
bin/.snitch_cluster.vlt.elf: $(VLT_AR) $(VLT_COBJ) ${VLT_BUILDDIR}/lib/libfesvr.a
$(BIN_DIR)/$(TARGET).vlt: $(VLT_AR) $(VLT_COBJ) ${VLT_BUILDDIR}/lib/libfesvr.a
mkdir -p $(dir $@)
$(CXX) $(LDFLAGS) -std=c++14 -L ${VLT_BUILDDIR}/lib -o $@ $(VLT_COBJ) $(VLT_AR) -lfesvr -lpthread

# Build wrapper around Verilator binary, needed to create .rtlbinary
bin/snitch_cluster.vlt: bin/.snitch_cluster.vlt.elf
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo '$(abspath $<) $$binary $$2' >> $@
@chmod +x $@

############
# Modelsim #
############

.PHONY: clean-vsim

# Clean all build directories and temporary files for Questasim simulation
clean-vsim: clean-work
rm -rf bin/snitch_cluster.vsim bin/snitch_cluster.vsim.gui $(VSIM_BUILDDIR) vsim.wlf

${VSIM_BUILDDIR}/compile.vsim.tcl:
$(VLIB) $(dir $@)
${BENDER} script vsim ${VSIM_BENDER} --vlog-arg="${VLOG_FLAGS} -work $(dir $@) " > $@
echo '${VLOG} -work $(dir $@) ${TB_CC_SOURCES} ${TB_ASM_SOURCES} -vv -ccflags "$(TB_CC_FLAGS)"' >> $@
echo 'return 0' >> $@

# Build compilation script and compile all sources for Questasim simulation
bin/snitch_cluster.vsim: ${VSIM_BUILDDIR}/compile.vsim.tcl $(VSIM_SOURCES) ${TB_SRCS} ${TB_CC_SOURCES} ${TB_ASM_SOURCES} work/lib/libfesvr.a
$(call QUESTASIM,tb_bin)
include $(ROOT)/target/common/vsim.mk

#######
# VCS #
@@ -264,13 +245,13 @@ bin/snitch_cluster.vsim: ${VSIM_BUILDDIR}/compile.vsim.tcl $(VSIM_SOURCES) ${TB_

# Clean all build directories and temporary files for VCS simulation
clean-vcs: clean-work
rm -rf bin/snitch_cluster.vcs $(VCS_BUILDDIR) vc_hdrs.h
rm -rf $(BIN_DIR)/$(TARGET).vcs $(VCS_BUILDDIR) vc_hdrs.h

# Build compilation script and compile all sources for VCS simulation
bin/snitch_cluster.vcs: ${VCS_SOURCES} ${TB_SRCS} $(TB_CC_SOURCES) $(TB_ASM_SOURCES) $(VCS_BUILDDIR)/compile.sh work/lib/libfesvr.a
mkdir -p bin
$(VCS) -Mlib=$(VCS_BUILDDIR) -Mdir=$(VCS_BUILDDIR) -o bin/snitch_cluster.vcs -cc $(CC) -cpp $(CXX) \
-assert disable_cover -override_timescale=1ns/1ps -full64 tb_bin $(TB_CC_SOURCES) $(TB_ASM_SOURCES) \
$(BIN_DIR)/$(TARGET).vcs: ${VCS_SOURCES} ${TB_SRCS} $(TB_CC_SOURCES) $(VCS_BUILDDIR)/compile.sh work/lib/libfesvr.a
mkdir -p $(BIN_DIR)
$(VCS) -Mlib=$(VCS_BUILDDIR) -Mdir=$(VCS_BUILDDIR) -o $(BIN_DIR)/$(TARGET).vcs -cc $(CC) -cpp $(CXX) \
-assert disable_cover -override_timescale=1ns/1ps -full64 tb_bin $(TB_CC_SOURCES) \
-CFLAGS "$(TB_CC_FLAGS)" -LDFLAGS "-L${FESVR}/lib" -lfesvr

########
@@ -300,9 +281,9 @@ help:
@echo -e ""
@echo -e "${Blue}help ${Black}Show an overview of all Makefile targets."
@echo -e ""
@echo -e "${Blue}bin/snitch_cluster.vcs ${Black}Build compilation script and compile all sources for VCS simulation."
@echo -e "${Blue}bin/snitch_cluster.vlt ${Black}Build compilation script and compile all sources for Verilator simulation."
@echo -e "${Blue}bin/snitch_cluster.vsim ${Black}Build compilation script and compile all sources for Questasim simulation."
@echo -e "${Blue}$(BIN_DIR)/$(TARGET).vcs ${Black}Build compilation script and compile all sources for VCS simulation."
@echo -e "${Blue}$(BIN_DIR)/$(TARGET).vlt ${Black}Build compilation script and compile all sources for Verilator simulation."
@echo -e "${Blue}$(BIN_DIR)/$(TARGET).vsim ${Black}Build compilation script and compile all sources for Questasim simulation."
@echo -e ""
@echo -e "${Blue}sw ${Black}Build all software."
@echo -e ""

0 comments on commit bb8edb7

Please sign in to comment.