adds extern to tohost/fromhost to avoid error during BSS initialization

This commit is contained in:
Hongyu Liu 2025-03-14 14:20:53 +01:00
parent 884d445cb9
commit 686d01ab3e

View File

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