Compare commits

...

10 Commits

6 changed files with 30 additions and 128 deletions

View File

@ -4,16 +4,8 @@ endif()
if (NOT DEFINED ISA)
set(ISA imc)
endif()
message(STATUS "Building firmware using ${BOARD} board configuration")
add_custom_target(fw-hello-world ALL
COMMAND make -C ${riscvfw_SOURCE_DIR}/hello-world BOARD=${BOARD} ISA=${ISA}
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(fw-dhrystone ALL
COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA}
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(fw-coremark ALL
COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/coremark BOARD=${BOARD} ISA=${ISA}
message(STATUS "Building firmware using ${BOARD} board configuration and isa ${ISA}")
add_custom_target(fw-common ALL
COMMAND make -C hello-world BOARD=${BOARD} ISA=${ISA} && make -C benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA} && make -C benchmarks/coremark BOARD=${BOARD} ISA=${ISA}
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,3 +1,25 @@
# Firmware
# MINRES Firmware Repository
## Structure
This repository comes with several executables ready to be built, such as `hello-world` or `coremark` and `dhrystone` in the `benchmark` directory.
Creating the executables in the easiest way possible is done by calling `make`in the corresponding directory.
Using `make clean && bear -- make ` will cause a correct compile_commands.json to be emitted. This allows using completion tools like clangd.
## Prerequisite
This repository requires `riscv64-unknown-elf-gcc` to be located in `$PATH`.
## How to Use
When compiling executables, the target platform needs to be specified using the 'BOARD' variable. When compiling for the TGC5C for example, use `make BOARD=tgc_vp`, when compiling for RTL `make BOARD=rtl`. The default value for the Board variable is 'iss'.
The arch can be set with the 'ISA' variable, the default value is 'imc'.
When compiling for the TGC5A VP for example, the call to create the correct binary is the following:
```
make BOARD=tgc_vp ISA=e
```
## Useful information
Using `bear -- <build-command>` will cause a compile_commands.json to be emitted. This allows using completion tools like clangd.
## Current Limitations
Currently, this repository only supports creation of 32-bit executables (Even when setting the `RISCV_ARCH` and `RISCV_ABI` manually).
Compiling for the 'e' extension / ISA together with any other extension (`ISA=emc` for example), requires setting the `RISCV_ABI=ilp32e` explicitly.
When switching ABI or ARCH ensure that object files in the corresponding 'env' dir in the 'bare-metal-bsp' submodule are removed, so they get created with the appropriate flags (namely the 'init.o' file).

View File

@ -664,7 +664,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
void
uart_send_char(char c)
{
#if defined(BOARD_ehrenberg)
#if defined(BOARD_ehrenberg) || defined(BOARD_tgc_vp)
while (get_uart_rx_tx_reg_tx_free(uart)==0) ;
uart_write(uart, c);
if (c == '\n') {

View File

@ -15,9 +15,9 @@ else
RISCV_ABI:=ilp32
endif
# '-lgcc -lm' are needed to add softfloat routines
CFLAGS := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
CFLAGS := -g -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
-funroll-loops -fpeel-loops -fgcse-sm -fgcse-las
LDFLAGS := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -Wl,--wrap=scanf -Wl,--wrap=printf -Wl,--wrap=exit -lgcc -lm
LDFLAGS := -Wl,--wrap=scanf
TOOL_DIR=$(dir $(compiler))

View File

@ -1,91 +0,0 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
SET(BOARD "iss" CACHE STRING "board to be compiled for")
OPTION(SEMIHOSTING "Enable Semihosting" ON)
SET(RISCV_ARCH "rv32imc" CACHE STRING "arch")
SET(RISCV_ABI "ilp32" CACHE STRING "abi")
EXECUTE_PROCESS(
COMMAND which riscv64-unknown-elf-gcc
OUTPUT_VARIABLE COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE)
GET_FILENAME_COMPONENT(TOOL_DIR ${COMPILER} DIRECTORY)
SET(TRIPLET "riscv64-unknown-elf")
SET(CMAKE_C_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
SET(CMAKE_CXX_COMPILER ${TOOL_DIR}/${TRIPLET}-g++)
SET(CMAKE_ASM_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
SET(CMAKE_LINKER ${TOOL_DIR}/${TRIPLET}-ld)
SET(CMAKE_OBJCOPY ${TOOL_DIR}/${TRIPLET}-objcopy)
SET(CMAKE_AR ${TOOL_DIR}/${TRIPLET}-ar)
PROJECT(semihosting_test)
SET(BSP_BASE "../bare-metal-bsp")
SET(ENV_DIR ${BSP_BASE}/env)
SET(PLATFORM_DIR ${ENV_DIR}/${BOARD})
SET(SEMIHOSTING TRUE)
INCLUDE(${BSP_BASE}/libwrap/CMakeLists.txt)
INCLUDE_DIRECTORIES(
${BSP_BASE}/include
${BSP_BASE}/drivers
${BSP_BASE}/libwrap/semihosting
${PLATFORM_DIR}
${ENV_DIR}
)
# Source files
SET(ASM_SRCS
${ENV_DIR}/entry.S
${ENV_DIR}/start.S
)
SET(C_SRCS
${PLATFORM_DIR}/init.c
test.c
)
SET_SOURCE_FILES_PROPERTIES(${ASM_SRCS} PROPERTIES LANGUAGE C)
# Compiler Flags
SET(COMMON_FLAGS "")
# GCC Version Check
EXECUTE_PROCESS(
COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE GCC_VERSION
)
IF(GCC_VERSION MATCHES "9.2")
LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}")
ELSE()
LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}_zicsr_zifencei")
ENDIF()
LIST(APPEND COMMON_FLAGS "-mabi=${RISCV_ABI}" "-mcmodel=medany" "-DBOARD_${BOARD}")
# Compiler Options
ADD_COMPILE_OPTIONS("${COMMON_FLAGS}")
IF(SEMIHOSTING)
ADD_DEFINITIONS(-DSEMIHOSTING=1)
ELSE ()
ADD_DEFINITIONS(-DSEMIHOSTING=0)
ENDIF()
ADD_EXECUTABLE(${PROJECT_NAME} ${ASM_SRCS} ${C_SRCS} ${SRC_FILES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${LIBWRAP_TGC_LDFLAGS} LIBWRAP_TGC)
# Linker Flags
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
PUBLIC
-march=${RISCV_ARCH} -mabi=${RISCV_ABI}
-T../${PLATFORM_DIR}/link.lds #TODO Path
-Wl,-Map=${PROJECT_NAME}.map
-nostartfiles
-L${ENV_DIR}
)

View File

@ -1,21 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "platform.h"
#include "encoding.h"
#include "semihosting.h"
int main()
{
char new[]="/scratch/gabriel/Documents/test_file";
//puts(new);
//char buf[10];
printf("TEST!!!");
//int fh = open(new, 0, 0);
//unlink(new);
//read(fh, buf, 10);
//printf(buf);
//read(fh, buf, 10);
return 0;
}