52 Commits

Author SHA1 Message Date
a2cd38fbd5 updates bsp 2025-06-17 19:42:46 +02:00
c7cd0843b8 uses inherits in preset json for benchmarks and corrects typo for 64bit 2025-06-06 14:38:14 +02:00
83b2105c38 corrects type in inherits Preset 2025-06-06 13:54:51 +02:00
510695bf6e changes Presets to a Composition based approach for hello-world 2025-05-27 09:17:05 +02:00
7258684a33 updates bsp 2025-05-27 09:16:39 +02:00
15cc2ece6f updates bsp 2025-05-23 10:36:20 +02:00
3e0eaba231 changes sizes of casts for dhrystone to the correct ones 2025-05-23 10:35:19 +02:00
4bd2111c93 cleans up gitignore 2025-05-23 10:34:46 +02:00
f99db9409f updates bsp 2025-05-23 09:33:23 +02:00
87539a8433 cleans up hello.c 2025-05-23 09:31:47 +02:00
de4cf8f35a updates CMakeLists and Presets for all examples 2025-05-23 09:31:31 +02:00
7d4bcea3ba Merge branch 'cmakeflow' into develop 2025-05-22 12:26:55 +02:00
74c2ec2014 updates write for coremark 2025-05-22 12:22:11 +02:00
bccfc67926 removes unused code in cmake 2025-04-15 14:33:03 +02:00
8b3dc54e5c uses write_hex() in exit instead of tohost=0x1 2025-04-15 12:32:09 +02:00
9909769c0a updates to make 64bit compiling 2025-04-15 12:26:32 +02:00
071d9cc8eb updates bsp and cleans hello.c 2025-04-14 17:01:19 +02:00
a5825bfd67 updates preset for 64bit 2025-04-11 15:44:52 +02:00
36404dd7e0 adds -mcmodel=medany and map generation;updaes bsp 2025-04-11 15:41:29 +02:00
658ffbb405 adds map generation and updates bsp 2025-03-21 16:07:17 +01:00
c6bfaf0546 adds volatile to array passed to tohost and updates bsp submodule 2025-03-14 17:53:49 +01:00
e88c1148fb removes default release build 2025-03-14 14:26:49 +01:00
686d01ab3e adds extern to tohost/fromhost to avoid error during BSS initialization 2025-03-14 14:20:53 +01:00
339d6b0f2c updates bsp 2025-03-14 12:01:16 +01:00
884d445cb9 adds target. map generation to target_link_opinions 2025-03-11 11:49:26 +01:00
eee14af478 updates bsp 2025-03-11 11:46:23 +01:00
727fdcb7bb adds examples of write/tohost usage 2025-03-11 11:45:40 +01:00
36cb401420 updates BSP and adds options to specify link target 2025-03-07 19:32:14 +01:00
3def42153f adds preset,json 2025-02-28 14:03:21 +01:00
75ba2e7588 adds cmake for coremark 2025-02-20 14:08:53 +01:00
1629b165b5 updates bsp 2025-01-16 11:11:18 +01:00
a2e932c56f adds build to gitignore 2025-01-16 11:10:53 +01:00
cde5ae627c updates dhrystone build 2025-01-16 11:09:58 +01:00
85304d1a43 updates bsp and build System 2025-01-06 20:33:30 +01:00
fddf608418 first version of working cmake 2024-12-20 14:33:57 +01:00
90c45d7c3c add first version of cmake 2024-12-17 12:34:07 +01:00
f3dc9aea54 adds wrap for scanf in dhrystone 2024-08-28 18:13:40 +02:00
2f675e9bdd fixes tgc_vp setup in coremark 2024-06-30 17:26:58 +02:00
3114cb265a Merge remote-tracking branch 'origin/main' into develop 2024-06-30 07:54:36 +02:00
48cfa8d868 appendage 2024-06-17 19:04:12 +02:00
64d6045d43 expands README 2024-06-17 19:04:05 +02:00
765f48e85a fixes target naming 2024-06-14 20:46:09 +02:00
1ce18ee1f6 serialzes FW build in cmake build flow 2024-06-14 17:34:53 +02:00
b4a3a36b2e cleans up Makefile 2024-06-14 12:05:55 +00:00
2a541997a4 benchmarks/dhrystone/Makefile aktualisiert 2024-06-14 13:50:22 +02:00
70d94c1051 CMakeLists.txt aktualisiert 2024-06-14 13:38:31 +02:00
0df111f945 cleans up CMakeLists 2024-06-14 10:11:30 +02:00
9105f5fb14 update include paths 2024-05-31 08:55:49 +02:00
4cc156e0d0 Merge branch 'main' of https://git.minres.com/Firmware/Firmwares into main 2024-04-30 08:46:13 +02:00
fca9f04264 Merge remote-tracking branch 'origin/main' into develop 2024-03-20 12:29:57 +01:00
5955f54a4d first semihosting integration 2024-02-26 20:41:13 +01:00
fe1136c7ce fixes ISA handling 2023-12-06 10:00:33 +01:00
19 changed files with 1034 additions and 739 deletions

1
.gitignore vendored
View File

@ -151,3 +151,4 @@ compile_commands.json
CTestTestfile.cmake
*.dump
build

View File

@ -4,16 +4,11 @@ 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}
if(DEFINED LINK_TARGET)
set(LNK LINK_TARGET=${LINK_TARGET})
endif()
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} ${LNK} && make -C benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA} ${LNK} && make -C benchmarks/coremark BOARD=${BOARD} ISA=${ISA} ${LNK}
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

@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.21)
project(coremark C)
set(TARGET coremark)
set(CMAKE_BUILD_TYPE Release)
# Source files
set(SOURCES
core_portme.c
cvt.c
ee_printf.c
cm/core_list_join.c
cm/core_main.c
cm/core_matrix.c
cm/core_state.c
cm/core_util.c
)
# Create executable
add_executable(coremark ${SOURCES})
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/cm)
target_compile_options(${TARGET} PRIVATE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-builtin-strnlen -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition )
target_compile_definitions(${TARGET} PRIVATE PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 FLAGS_STR="" PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 ITERATIONS=600)
set(BOARD "iss" CACHE STRING "Target board")
add_subdirectory(../../bare-metal-bsp bsp)
target_link_libraries(${TARGET} PRIVATE bsp)
target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
COMMENT "Creating disassembly for ${TARGET}")

View File

@ -0,0 +1,118 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "32imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "64imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "iss",
"hidden": true,
"cacheVariables": {
"BOARD": "iss"
}
},
{
"name": "moonlight",
"hidden": true,
"cacheVariables": {
"BOARD": "moonlight"
}
},
{
"name": "tgc_vp",
"hidden": true,
"cacheVariables": {
"BOARD": "tgc_vp"
}
},
{
"name": "rtl",
"hidden": true,
"cacheVariables": {
"BOARD": "rtl"
}
},
{
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ISS_Debug",
"inherits": ["iss", "debug", "32imc"]
},
{
"name": "Moonlight_Debug",
"inherits": ["moonlight", "debug", "32imc"]
},
{
"name": "TGC_VP_Debug",
"inherits": ["tgc_vp", "debug", "32imc"]
},
{
"name": "ISS_Debug_64",
"inherits": ["iss", "debug", "64imc"]
},
{
"name": "Moonlight_Debug_64",
"inherits": ["moonlight", "debug", "64imc"]
},
{
"name": "TGC_VP_Debug_64",
"inherits": ["tgc_vp", "debug", "64imc"]
},
{
"name": "ISS_Release",
"inherits": ["iss", "release", "32imc"]
},
{
"name": "Moonlight_Release",
"inherits": ["moonlight", "release", "32imc"]
},
{
"name": "TGC_VP_Release",
"inherits": ["tgc_vp", "release", "32imc"]
},
{
"name": "ISS_Release_64",
"inherits": ["iss", "release", "64imc"]
},
{
"name": "Moonlight_Release_64",
"inherits": ["moonlight", "release", "64imc"]
},
{
"name": "TGC_VP_Release_64",
"inherits": ["tgc_vp", "release", "64imc"]
}
]
}

View File

@ -15,55 +15,58 @@ limitations under the License.
Original Author: Shay Gal-on
*/
#include "coremark.h"
#include "core_portme.h"
//Read cycle CSR
unsigned long long _read_cycle()
{
unsigned long long result;
unsigned long lower;
unsigned long upper1;
unsigned long upper2;
#include "coremark.h"
#include <unistd.h>
// Read cycle CSR
unsigned long long _read_cycle() {
unsigned long long result;
unsigned long lower;
unsigned long upper1;
unsigned long upper2;
asm volatile (
"repeat_cycle_%=: csrr %0, cycleh;\n"
" csrr %1, cycle;\n"
" csrr %2, cycleh;\n"
" bne %0, %2, repeat_cycle_%=;\n"
: "=r" (upper1),"=r" (lower),"=r" (upper2) // Outputs : temp variable for load result
:
:
);
*(unsigned long *)(&result) = lower;
*((unsigned long *)(&result)+1) = upper1;
asm volatile("repeat_cycle_%=: csrr %0, cycleh;\n"
" csrr %1, cycle;\n"
" csrr %2, cycleh;\n"
" bne %0, %2, repeat_cycle_%=;\n"
: "=r"(upper1), "=r"(lower),
"=r"(upper2) // Outputs : temp variable for load result
:
:);
*(unsigned long *)(&result) = lower;
*((unsigned long *)(&result) + 1) = upper1;
return result;
return result;
}
volatile int tohost;
volatile int fromhost;
// extern volatile int tohost;
// extern volatile int fromhost;
void exit(int n){
tohost = 0x1;
for (;;);
void write_hex(int fd, uint32_t hex);
void exit(int n) {
write_hex(STDERR_FILENO, 1);
// tohost = 0x1;
for (;;)
;
}
void __libc_init_array (void) {
/*
size_t count;
size_t i;
count = __preinit_array_end - __preinit_array_start;
for (i = 0; i < count; i++)
__preinit_array_start[i] ();
void __libc_init_array(void) {
/*
size_t count;
size_t i;
count = __preinit_array_end - __preinit_array_start;
for (i = 0; i < count; i++)
__preinit_array_start[i] ();
#ifdef HAVE_INIT_FINI
_init ();
#endif
#ifdef HAVE_INIT_FINI
_init ();
#endif
count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
__init_array_start[i] ();
*/
count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
__init_array_start[i] ();
*/
}
#if VALIDATION_RUN
volatile ee_s32 seed1_volatile = 0x3415;
@ -89,10 +92,7 @@ volatile ee_s32 seed5_volatile = 0;
time.h and windows.h definitions included.
*/
CORETIMETYPE
barebones_clock()
{
return (CORETIMETYPE)_read_cycle();
}
barebones_clock() { return (CORETIMETYPE)_read_cycle(); }
/* Define : TIMER_RES_DIVIDER
Divider to trade off timer resolution and total time that can be
measured.
@ -101,11 +101,11 @@ barebones_clock()
does not occur. If there are issues with the return value overflowing,
increase this value.
*/
#define GETMYTIME(_t) (*_t = barebones_clock())
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
#define TIMER_RES_DIVIDER 1
#define GETMYTIME(_t) (*_t = barebones_clock())
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
#define TIMER_RES_DIVIDER 1
#define SAMPLE_TIME_IMPLEMENTATION 1
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
/** Define Host specific (POSIX), or target specific global time variables. */
static CORETIMETYPE start_time_val, stop_time_val;
@ -118,11 +118,7 @@ static CORETIMETYPE start_time_val, stop_time_val;
example code) or zeroing some system parameters - e.g. setting the cpu clocks
cycles to 0.
*/
void
start_time(void)
{
GETMYTIME(&start_time_val);
}
void start_time(void) { GETMYTIME(&start_time_val); }
/* Function : stop_time
This function will be called right after ending the timed portion of the
benchmark.
@ -131,11 +127,7 @@ start_time(void)
example code) or other system parameters - e.g. reading the current value of
cpu cycles counter.
*/
void
stop_time(void)
{
GETMYTIME(&stop_time_val);
}
void stop_time(void) { GETMYTIME(&stop_time_val); }
/* Function : get_time
Return an abstract "ticks" number that signifies time on the system.
@ -146,11 +138,9 @@ stop_time(void)
controlled by <TIMER_RES_DIVIDER>
*/
CORE_TICKS
get_time(void)
{
CORE_TICKS elapsed
= (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
return elapsed;
get_time(void) {
CORE_TICKS elapsed = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
return elapsed;
}
/* Function : time_in_secs
Convert the value returned by get_time to seconds.
@ -159,11 +149,9 @@ get_time(void)
floating point. Default implementation implemented by the EE_TICKS_PER_SEC
macro above.
*/
secs_ret
time_in_secs(CORE_TICKS ticks)
{
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
return retval;
secs_ret time_in_secs(CORE_TICKS ticks) {
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
return retval;
}
ee_u32 default_num_contexts = 1;
@ -172,27 +160,18 @@ ee_u32 default_num_contexts = 1;
Target specific initialization code
Test for some common mistakes.
*/
void
portable_init(core_portable *p, int *argc, char *argv[])
{
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
{
ee_printf(
"ERROR! Please define ee_ptr_int to a type that holds a "
"pointer!\n");
}
if (sizeof(ee_u32) != 4)
{
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
}
p->portable_id = 1;
ee_printf("portable_init finished.\n");
void portable_init(core_portable *p, int *argc, char *argv[]) {
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
ee_printf("ERROR! Please define ee_ptr_int to a type that holds a "
"pointer!\n");
}
if (sizeof(ee_u32) != 4) {
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
}
p->portable_id = 1;
ee_printf("portable_init finished.\n");
}
/* Function : portable_fini
Target specific final code
*/
void
portable_fini(core_portable *p)
{
p->portable_id = 0;
}
void portable_fini(core_portable *p) { p->portable_id = 0; }

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,3 @@
dhrystone
/dhrystone.dis
build/

View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.21)
project(dhrystone C)
set(TARGET dhrystone)
set(ITERATIONS 50000)
add_executable(${TARGET} dhry_1.c dhry_2.c dhry_stubs.c)
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_compile_options(${TARGET} PRIVATE -fno-inline -fno-builtin-printf -fno-common -Wno-implicit -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las)
target_compile_definitions(${TARGET} PRIVATE ITERATIONS=${ITERATIONS} HZ=32768 TIME NO_INIT)
set(BOARD "iss" CACHE STRING "Target board")
add_subdirectory(../../bare-metal-bsp bsp)
target_link_libraries(${TARGET} PRIVATE bsp)
target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
COMMENT "Creating disassembly for ${TARGET}")

View File

@ -0,0 +1,118 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "32imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "64imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "iss",
"hidden": true,
"cacheVariables": {
"BOARD": "iss"
}
},
{
"name": "moonlight",
"hidden": true,
"cacheVariables": {
"BOARD": "moonlight"
}
},
{
"name": "tgc_vp",
"hidden": true,
"cacheVariables": {
"BOARD": "tgc_vp"
}
},
{
"name": "rtl",
"hidden": true,
"cacheVariables": {
"BOARD": "rtl"
}
},
{
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ISS_Debug",
"inherits": ["iss", "debug", "32imc"]
},
{
"name": "Moonlight_Debug",
"inherits": ["moonlight", "debug", "32imc"]
},
{
"name": "TGC_VP_Debug",
"inherits": ["tgc_vp", "debug", "32imc"]
},
{
"name": "ISS_Debug_64",
"inherits": ["iss", "debug", "64imc"]
},
{
"name": "Moonlight_Debug_64",
"inherits": ["moonlight", "debug", "64imc"]
},
{
"name": "TGC_VP_Debug_64",
"inherits": ["tgc_vp", "debug", "64imc"]
},
{
"name": "ISS_Release",
"inherits": ["iss", "release", "32imc"]
},
{
"name": "Moonlight_Release",
"inherits": ["moonlight", "release", "32imc"]
},
{
"name": "TGC_VP_Release",
"inherits": ["tgc_vp", "release", "32imc"]
},
{
"name": "ISS_Release_64",
"inherits": ["iss", "release", "64imc"]
},
{
"name": "Moonlight_Release_64",
"inherits": ["moonlight", "release", "64imc"]
},
{
"name": "TGC_VP_Release_64",
"inherits": ["tgc_vp", "release", "64imc"]
}
]
}

View File

@ -9,16 +9,15 @@ HEADERS := dhry.h
BOARD?=iss
LINK_TARGET=link
RISCV_ARCH:=rv32$(ISA)
ifeq ($(ISA),e)
ifneq (,$(findstring e,$(ISA)))
RISCV_ABI:=ilp32e
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))
BSP_BASE = ../../bare-metal-bsp

View File

@ -212,7 +212,7 @@ main ()
printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
printf (" should be: Number_Of_Runs + 10\n");
printf ("Ptr_Glob->\n");
printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
printf (" Ptr_Comp: %d\n", (long) Ptr_Glob->Ptr_Comp);
printf (" should be: (implementation-dependent)\n");
printf (" Discr: %d\n", Ptr_Glob->Discr);
printf (" should be: %d\n", 0);
@ -223,7 +223,7 @@ main ()
printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
printf ("Next_Ptr_Glob->\n");
printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
printf (" Ptr_Comp: %d\n", (long) Next_Ptr_Glob->Ptr_Comp);
printf (" should be: (implementation-dependent), same as above\n");
printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
printf (" should be: %d\n", 0);

View File

@ -1,4 +1,5 @@
#include "platform.h"
#include <unistd.h>
#ifndef ITERATIONS
#define ITERATIONS 20000
#endif
@ -6,20 +7,16 @@
/* The functions in this file are only meant to support Dhrystone on an
* embedded RV32 system and are obviously incorrect in general. */
long time(void)
{
return get_timer_value();
}
long time(void) { return get_timer_value(); }
// set the number of dhrystone iterations
void __wrap_scanf(const char* fmt, int* n)
{
*n = ITERATIONS;
}
void __wrap_scanf(const char *fmt, int *n) { *n = ITERATIONS; }
extern volatile uint32_t tohost;
// extern volatile uint64_t tohost;
void exit(int n){
tohost = 0x1;
for (;;);
void exit(int n) {
// tohost = 0x1;
write_hex(STDERR_FILENO, 1);
for (;;)
;
}

View File

@ -1,2 +1,3 @@
/hello
/hello.dis
build/

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.21)
project(hello-world C)
set(TARGET hello)
add_executable(${TARGET} hello.c)
set(BOARD "iss" CACHE STRING "Target board")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp bsp)
target_link_libraries(${TARGET} PRIVATE bsp)
target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
COMMENT "Creating disassembly for ${TARGET}")

View File

@ -0,0 +1,118 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "32imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "64imc",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "iss",
"hidden": true,
"cacheVariables": {
"BOARD": "iss"
}
},
{
"name": "moonlight",
"hidden": true,
"cacheVariables": {
"BOARD": "moonlight"
}
},
{
"name": "tgc_vp",
"hidden": true,
"cacheVariables": {
"BOARD": "tgc_vp"
}
},
{
"name": "rtl",
"hidden": true,
"cacheVariables": {
"BOARD": "rtl"
}
},
{
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ISS_Debug",
"inherits": ["iss", "debug", "32imc"]
},
{
"name": "Moonlight_Debug",
"inherits": ["moonlight", "debug", "32imc"]
},
{
"name": "TGC_VP_Debug",
"inherits": ["tgc_vp", "debug", "32imc"]
},
{
"name": "ISS_Debug_64",
"inherits": ["iss", "debug", "64imc"]
},
{
"name": "Moonlight_Debug_64",
"inherits": ["moonlight", "debug", "64imc"]
},
{
"name": "TGC_VP_Debug_64",
"inherits": ["tgc_vp", "debug", "64imc"]
},
{
"name": "ISS_Release",
"inherits": ["iss", "release", "32imc"]
},
{
"name": "Moonlight_Release",
"inherits": ["moonlight", "release", "32imc"]
},
{
"name": "TGC_VP_Release",
"inherits": ["tgc_vp", "release", "32imc"]
},
{
"name": "ISS_Release_64",
"inherits": ["iss", "release", "64imc"]
},
{
"name": "Moonlight_Release_64",
"inherits": ["moonlight", "release", "64imc"]
},
{
"name": "TGC_VP_Release_64",
"inherits": ["tgc_vp", "release", "64imc"]
}
]
}

View File

@ -1,4 +1,3 @@
TARGET = hello
ISA?=imc

View File

@ -1,24 +1,21 @@
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "platform.h"
#include "encoding.h"
int factorial(int i){
volatile int result = 1;
for (int ii = 1; ii <= i; ii++) {
result = result * ii;
}
return result;
#include <string.h>
int factorial(int i) {
volatile int result = 1;
for (int ii = 1; ii <= i; ii++) {
result = result * ii;
}
return result;
}
int main()
{
volatile int result = factorial (10);
printf("Factorial is %d\n", result);
printf("End of execution");
return 0;
int main() {
int result = factorial(10);
printf("Factorial is %d", result);
return 0;
}