Compare commits

...

22 Commits

Author SHA1 Message Date
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
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
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
15 changed files with 906 additions and 728 deletions

View File

@ -1,11 +0,0 @@
if (NOT DEFINED BOARD)
set(BOARD iss)
endif()
if (NOT DEFINED ISA)
set(ISA imc)
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} && make -C benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA} && make -C benchmarks/coremark BOARD=${BOARD} ISA=${ISA}
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

@ -1 +1 @@
Subproject commit 87dc0ec2304adcb94a25b397a357aadae1304867
Subproject commit 540397494a48b07b1e8282b6059689246b622564

View File

@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.21)
project(coremark C)
set(TARGET coremark)
#set(CMAKE_BUILD_TYPE Release)
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
if(HAVE_NO_INIT_FINI)
#if HAVE_NO_INIT_FINI is ON
add_definitions(-DHAVE_NO_INIT_FINI)
endif()
# 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 -Wl,-Map=${TARGET}.map)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
#message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
#message(STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
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,70 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_64",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
}
]
}

View File

@ -15,37 +15,40 @@ limitations under the License.
Original Author: Shay Gal-on
*/
#include "coremark.h"
#include "core_portme.h"
#include "coremark.h"
#include <unistd.h>
// Read cycle CSR
unsigned long long _read_cycle()
{
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"
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
: "=r"(upper1), "=r"(lower),
"=r"(upper2) // Outputs : temp variable for load result
:
:
);
:);
*(unsigned long *)(&result) = lower;
*((unsigned long *)(&result) + 1) = upper1;
return result;
}
volatile int tohost;
volatile int fromhost;
// extern volatile int tohost;
// extern volatile int fromhost;
void write_hex(int fd, uint32_t hex);
void exit(int n) {
tohost = 0x1;
for (;;);
write_hex(STDERR_FILENO, 1);
// tohost = 0x1;
for (;;)
;
}
void __libc_init_array(void) {
@ -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.
@ -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,10 +138,8 @@ 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));
get_time(void) {
CORE_TICKS elapsed = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
return elapsed;
}
/* Function : time_in_secs
@ -159,9 +149,7 @@ 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 time_in_secs(CORE_TICKS ticks) {
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
return retval;
}
@ -172,17 +160,12 @@ 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 "
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)
{
if (sizeof(ee_u32) != 4) {
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
}
p->portable_id = 1;
@ -191,8 +174,4 @@ portable_init(core_portable *p, int *argc, char *argv[])
/* 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; }

View File

@ -16,6 +16,7 @@ limitations under the License.
#include <coremark.h>
#include <stdarg.h>
#include <unistd.h>
#define ZEROPAD (1 << 0) /* Pad with zero */
#define SIGN (1 << 1) /* Unsigned/signed long */
@ -31,27 +32,22 @@ static char * digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static ee_size_t strnlen(const char *s, ee_size_t count);
static ee_size_t
strnlen(const char *s, ee_size_t count)
{
static ee_size_t strnlen(const char *s, ee_size_t count) {
const char *sc;
for (sc = s; *sc != '\0' && count--; ++sc)
;
return sc - s;
}
static int
skip_atoi(const char **s)
{
static int skip_atoi(const char **s) {
int i = 0;
while (is_digit(**s))
i = i * 10 + *((*s)++) - '0';
return i;
}
static char *
number(char *str, long num, int base, int size, int precision, int type)
{
static char *number(char *str, long num, int base, int size, int precision,
int type) {
char c, sign, tmp[66];
char *dig = digits;
int i;
@ -65,28 +61,21 @@ number(char *str, long num, int base, int size, int precision, int type)
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN)
{
if (num < 0)
{
if (type & SIGN) {
if (num < 0) {
sign = '-';
num = -num;
size--;
}
else if (type & PLUS)
{
} else if (type & PLUS) {
sign = '+';
size--;
}
else if (type & SPACE)
{
} else if (type & SPACE) {
sign = ' ';
size--;
}
}
if (type & HEX_PREP)
{
if (type & HEX_PREP) {
if (base == 16)
size -= 2;
else if (base == 8)
@ -97,10 +86,8 @@ number(char *str, long num, int base, int size, int precision, int type)
if (num == 0)
tmp[i++] = '0';
else
{
while (num != 0)
{
else {
while (num != 0) {
tmp[i++] = dig[((unsigned long)num) % (unsigned)base];
num = ((unsigned long)num) / (unsigned)base;
}
@ -115,12 +102,10 @@ number(char *str, long num, int base, int size, int precision, int type)
if (sign)
*str++ = sign;
if (type & HEX_PREP)
{
if (type & HEX_PREP) {
if (base == 8)
*str++ = '0';
else if (base == 16)
{
else if (base == 16) {
*str++ = '0';
*str++ = digits[33];
}
@ -139,9 +124,8 @@ number(char *str, long num, int base, int size, int precision, int type)
return str;
}
static char *
eaddr(char *str, unsigned char *addr, int size, int precision, int type)
{
static char *eaddr(char *str, unsigned char *addr, int size, int precision,
int type) {
char tmp[24];
char *dig = digits;
int i, len;
@ -149,8 +133,7 @@ eaddr(char *str, unsigned char *addr, int size, int precision, int type)
if (type & UPPERCASE)
dig = upper_digits;
len = 0;
for (i = 0; i < 6; i++)
{
for (i = 0; i < 6; i++) {
if (i != 0)
tmp[len++] = ':';
tmp[len++] = dig[addr[i] >> 4];
@ -168,32 +151,26 @@ eaddr(char *str, unsigned char *addr, int size, int precision, int type)
return str;
}
static char *
iaddr(char *str, unsigned char *addr, int size, int precision, int type)
{
static char *iaddr(char *str, unsigned char *addr, int size, int precision,
int type) {
char tmp[24];
int i, n, len;
len = 0;
for (i = 0; i < 4; i++)
{
for (i = 0; i < 4; i++) {
if (i != 0)
tmp[len++] = '.';
n = addr[i];
if (n == 0)
tmp[len++] = digits[0];
else
{
if (n >= 100)
{
else {
if (n >= 100) {
tmp[len++] = digits[n / 100];
n = n % 100;
tmp[len++] = digits[n / 10];
n = n % 10;
}
else if (n >= 10)
{
} else if (n >= 10) {
tmp[len++] = digits[n / 10];
n = n % 10;
}
@ -219,47 +196,37 @@ char * ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
static void ee_bufcpy(char *d, char *s, int count);
void
ee_bufcpy(char *pd, char *ps, int count)
{
void ee_bufcpy(char *pd, char *ps, int count) {
char *pe = ps + count;
while (ps != pe)
*pd++ = *ps++;
}
static void
parse_float(double value, char *buffer, char fmt, int precision)
{
static void parse_float(double value, char *buffer, char fmt, int precision) {
int decpt, sign, exp, pos;
char *digits = NULL;
char cvtbuf[80];
int capexp = 0;
int magnitude;
if (fmt == 'G' || fmt == 'E')
{
if (fmt == 'G' || fmt == 'E') {
capexp = 1;
fmt += 'a' - 'A';
}
if (fmt == 'g')
{
if (fmt == 'g') {
digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf);
magnitude = decpt - 1;
if (magnitude < -4 || magnitude > precision - 1)
{
if (magnitude < -4 || magnitude > precision - 1) {
fmt = 'e';
precision -= 1;
}
else
{
} else {
fmt = 'f';
precision -= decpt;
}
}
if (fmt == 'e')
{
if (fmt == 'e') {
digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf);
if (sign)
@ -271,22 +238,18 @@ parse_float(double value, char *buffer, char fmt, int precision)
buffer += precision;
*buffer++ = capexp ? 'E' : 'e';
if (decpt == 0)
{
if (decpt == 0) {
if (value == 0.0)
exp = 0;
else
exp = -1;
}
else
} else
exp = decpt - 1;
if (exp < 0)
{
if (exp < 0) {
*buffer++ = '-';
exp = -exp;
}
else
} else
*buffer++ = '+';
buffer[2] = (exp % 10) + '0';
@ -295,39 +258,29 @@ parse_float(double value, char *buffer, char fmt, int precision)
exp = exp / 10;
buffer[0] = (exp % 10) + '0';
buffer += 3;
}
else if (fmt == 'f')
{
} else if (fmt == 'f') {
digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf);
if (sign)
*buffer++ = '-';
if (*digits)
{
if (decpt <= 0)
{
if (*digits) {
if (decpt <= 0) {
*buffer++ = '0';
*buffer++ = '.';
for (pos = 0; pos < -decpt; pos++)
*buffer++ = '0';
while (*digits)
*buffer++ = *digits++;
}
else
{
} else {
pos = 0;
while (*digits)
{
while (*digits) {
if (pos++ == decpt)
*buffer++ = '.';
*buffer++ = *digits++;
}
}
}
else
{
} else {
*buffer++ = '0';
if (precision > 0)
{
if (precision > 0) {
*buffer++ = '.';
for (pos = 0; pos < precision; pos++)
*buffer++ = '0';
@ -338,11 +291,8 @@ parse_float(double value, char *buffer, char fmt, int precision)
*buffer = '\0';
}
static void
decimal_point(char *buffer)
{
while (*buffer)
{
static void decimal_point(char *buffer) {
while (*buffer) {
if (*buffer == '.')
return;
if (*buffer == 'e' || *buffer == 'E')
@ -350,33 +300,26 @@ decimal_point(char *buffer)
buffer++;
}
if (*buffer)
{
if (*buffer) {
int n = strnlen(buffer, 256);
while (n > 0)
{
while (n > 0) {
buffer[n + 1] = buffer[n];
n--;
}
*buffer = '.';
}
else
{
} else {
*buffer++ = '.';
*buffer = '\0';
}
}
static void
cropzeros(char *buffer)
{
static void cropzeros(char *buffer) {
char *stop;
while (*buffer && *buffer != '.')
buffer++;
if (*buffer++)
{
if (*buffer++) {
while (*buffer && *buffer != 'e' && *buffer != 'E')
buffer++;
stop = buffer--;
@ -389,9 +332,8 @@ cropzeros(char *buffer)
}
}
static char *
flt(char *str, double num, int size, int precision, char fmt, int flags)
{
static char *flt(char *str, double num, int size, int precision, char fmt,
int flags) {
char tmp[80];
char c, sign;
int n, i;
@ -403,21 +345,15 @@ flt(char *str, double num, int size, int precision, char fmt, int flags)
// Determine padding and sign char
c = (flags & ZEROPAD) ? '0' : ' ';
sign = 0;
if (flags & SIGN)
{
if (num < 0.0)
{
if (flags & SIGN) {
if (num < 0.0) {
sign = '-';
num = -num;
size--;
}
else if (flags & PLUS)
{
} else if (flags & PLUS) {
sign = '+';
size--;
}
else if (flags & SPACE)
{
} else if (flags & SPACE) {
sign = ' ';
size--;
}
@ -457,9 +393,7 @@ flt(char *str, double num, int size, int precision, char fmt, int flags)
#endif
static int
ee_vsprintf(char *buf, const char *fmt, va_list args)
{
static int ee_vsprintf(char *buf, const char *fmt, va_list args) {
int len;
unsigned long num;
int i, base;
@ -473,10 +407,8 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
// from string
int qualifier; // 'h', 'l', or 'L' for integer fields
for (str = buf; *fmt; fmt++)
{
if (*fmt != '%')
{
for (str = buf; *fmt; fmt++) {
if (*fmt != '%') {
*str++ = *fmt;
continue;
}
@ -485,8 +417,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
flags = 0;
repeat:
fmt++; // This also skips first '%'
switch (*fmt)
{
switch (*fmt) {
case '-':
flags |= LEFT;
goto repeat;
@ -508,12 +439,10 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
field_width = -1;
if (is_digit(*fmt))
field_width = skip_atoi(&fmt);
else if (*fmt == '*')
{
else if (*fmt == '*') {
fmt++;
field_width = va_arg(args, int);
if (field_width < 0)
{
if (field_width < 0) {
field_width = -field_width;
flags |= LEFT;
}
@ -521,13 +450,11 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
// Get the precision
precision = -1;
if (*fmt == '.')
{
if (*fmt == '.') {
++fmt;
if (is_digit(*fmt))
precision = skip_atoi(&fmt);
else if (*fmt == '*')
{
else if (*fmt == '*') {
++fmt;
precision = va_arg(args, int);
}
@ -537,8 +464,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
// Get the conversion qualifier
qualifier = -1;
if (*fmt == 'l' || *fmt == 'L')
{
if (*fmt == 'l' || *fmt == 'L') {
qualifier = *fmt;
fmt++;
}
@ -546,8 +472,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
// Default base
base = 10;
switch (*fmt)
{
switch (*fmt) {
case 'c':
if (!(flags & LEFT))
while (--field_width > 0)
@ -572,17 +497,12 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
continue;
case 'p':
if (field_width == -1)
{
if (field_width == -1) {
field_width = 2 * sizeof(void *);
flags |= ZEROPAD;
}
str = number(str,
(unsigned long)va_arg(args, void *),
16,
field_width,
precision,
flags);
str = number(str, (unsigned long)va_arg(args, void *), 16, field_width,
precision, flags);
continue;
case 'A':
@ -590,16 +510,10 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
case 'a':
if (qualifier == 'l')
str = eaddr(str,
va_arg(args, unsigned char *),
field_width,
precision,
str = eaddr(str, va_arg(args, unsigned char *), field_width, precision,
flags);
else
str = iaddr(str,
va_arg(args, unsigned char *),
field_width,
precision,
str = iaddr(str, va_arg(args, unsigned char *), field_width, precision,
flags);
continue;
@ -625,11 +539,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
#if HAS_FLOAT
case 'f':
str = flt(str,
va_arg(args, double),
field_width,
precision,
*fmt,
str = flt(str, va_arg(args, double), field_width, precision, *fmt,
flags | SIGN);
continue;
@ -661,31 +571,9 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
#include <platform.h>
void
uart_send_char(char c)
{
#if defined(BOARD_ehrenberg)
while (get_uart_rx_tx_reg_tx_free(uart)==0) ;
uart_write(uart, c);
if (c == '\n') {
while (get_uart_rx_tx_reg_tx_free(uart)==0) ;
uart_write(uart, '\r');
}
#elif defined(BOARD_iss)
*((uint32_t*) 0xFFFF0000) = c;
#else
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
UART0_REG(UART_REG_TXFIFO) = c;
if (c == '\n') {
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
UART0_REG(UART_REG_TXFIFO) = '\r';
}
#endif
}
void uart_send_char(char c) { write(STDOUT_FILENO, &c, 1); }
int
ee_printf(const char *fmt, ...)
{
int ee_printf(const char *fmt, ...) {
char buf[1024], *p;
va_list args;
int n = 0;
@ -694,8 +582,7 @@ ee_printf(const char *fmt, ...)
ee_vsprintf(buf, fmt, args);
va_end(args);
p = buf;
while (*p)
{
while (*p) {
uart_send_char(*p);
n++;
p++;

View File

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

View File

@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.21)
project(dhrystone C)
set(TARGET dhrystone)
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
if(HAVE_NO_INIT_FINI)
#if HAVE_NO_INIT_FINI is ON
add_definitions(-DHAVE_NO_INIT_FINI)
endif()
set(ITERATIONS 50000) # 20000 for TGC
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:--wrap=scanf)
#target_link_options(${TARGET} PRIVATE LINKER:--wrap=scanf -Wl,--no-gc-sections)
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
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,70 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_64",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
}
]
}

View File

@ -17,6 +17,7 @@ endif
# '-lgcc -lm' are needed to add softfloat routines
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 := -Wl,--wrap=scanf
TOOL_DIR=$(dir $(compiler))

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 (;;);
// tohost = 0x1;
write_hex(STDERR_FILENO, 1);
for (;;)
;
}

View File

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

View File

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.21)
project(hello-world C)
set(TARGET hello)
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
if(HAVE_NO_INIT_FINI)
#if HAVE_NO_INIT_FINI is ON
add_definitions(-DHAVE_NO_INIT_FINI)
endif()
add_executable(${TARGET} hello.c)
set(BOARD "iss" CACHE STRING "Target board")
message(" BOARD = ${BOARD}")
add_subdirectory(../bare-metal-bsp bsp)
target_link_libraries(${TARGET} PRIVATE bsp)
target_link_options(${TARGET} PRIVATE -Wl,-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,70 @@
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 24,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
},
{
"name": "debug_64",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_moon",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "moonlight",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "debug_64_tgc",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BOARD": "tgc_vp",
"HAVE_NO_INIT_FINI": "ON",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
}
},
{
"name": "release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
}
}
]
}

View File

@ -1,9 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "platform.h"
#include "encoding.h"
#include "platform.h"
#include <string.h>
int factorial(int i) {
@ -12,13 +14,24 @@ int factorial(int i){
result = result * ii;
}
return result;
}
extern volatile uintptr_t tohost;
void write_tohost(char *string) {
volatile uint64_t payload[4] = {64, 0, (uintptr_t)string,
(strlen(string) + 1)};
tohost = (uintptr_t)payload;
}
int main()
{
volatile int result = factorial (10);
printf("Factorial is %d\n", result);
printf("End of execution");
int main() {
char string[] = "hello world with write in hello";
write_tohost(string);
write(STDOUT_FILENO, string, sizeof(string));
int result = factorial(10);
printf("Factorial is %d", result);
return 0;
}