- Jump to main performed by eret.
- Nano trap handler added.
- FinishTest refactored to perform SYS_exit, placed in util.h.
- Only SYS_exit with test_result=1 results in a passed test.
- Any other exceptions/syscalls/test_results end program with FAILED test.
- PCR status set to S64/U64 if compiled in 64b.
li x30,0
li x31,0
+#ifdef __riscv64
+ setpcr status, SR_S64
+ setpcr status, SR_U64
+#endif
+
# enable fp
setpcr status, SR_EF
fmv.s.x f31,x0
1:
+ lui a0, %hi(trap_entry)
+ add a0, a0, %lo(trap_entry)
+ mtpcr a0, evec
+
+ lui a0, %hi(main)
+ add a0, a0, %lo(main)
+ mtpcr a0, epc
+
# only allow core 0 to proceed
1:mfpcr a0, hartid
bnez a0, 1b
la sp,stacktop
- jal main
+
+ # jmp to main as a user program
+ eret
+1:b 1b
+
+.align 4
+.globl trap_entry
+trap_entry: # only check for SYS_exit, otherwise crash out
+ li a3, 1337 # magic "bad things" happened error code
+ mfpcr a1, cause
+ li a2, 6 # syscall exception number
+ bne a1, a2, exit_error
+handle_syscall:
+ li a1, 93 # SYS_exit number
+ bne v0, a1, exit_error
+ li a1, 1 # successful exit code
+ move a3, a0
+ bne a3, a1, exit_error
+ mtpcr a1, tohost # exit successfully (tohost == 1)
+1:b 1b
+exit_error:
+ sll a3, a3, 1
+ or a3, a3, 1
+ mtpcr a3, tohost
1:b 1b
.bss
#ifndef __UTIL_H
#define __UTIL_H
+#include <machine/syscall.h>
+
#define rdcycle() ({ unsigned long _c; asm volatile ("rdcycle %0" : "=r"(_c) :: "memory"); _c; })
#define rdinstret() ({ unsigned long _c; asm volatile ("rdinstret %0" : "=r"(_c) :: "memory"); _c; })
__sync_synchronize();
}
-
+
+
+
+
+
+void finishTest(int test_result)
+{
+#if HOST_DEBUG
+ if ( test_result == 1 )
+ printf( "*** PASSED ***\n" );
+ else
+ printf( "*** FAILED *** (tohost = %d)\n", test_result);
+ exit(0);
+#else
+ {
+ // perform exit syscall
+ asm volatile(
+ "move a0,%0 ;"
+ "li a1,0 ;"
+ "li a2,0 ;"
+ "li a3,0 ;"
+ "li v0,%1 ;"
+ "syscall" : : "r"(test_result) , "i"(SYS_exit));
+ }
+#endif
+}
+
#endif //__UTIL_H
// Double-precision general matrix multiplication benchmark
//--------------------------------------------------------------------------
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
#include "dhrystone.h"
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
#include "median.h"
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
#include "multiply.h"
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
// processor simulator itself. You should not change anything except
// the HOST_DEBUG and PREALLOCATE macros for your timing run.
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
// Double-precision general matrix multiplication benchmark
//--------------------------------------------------------------------------
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
// smips processor simulator itself. You should not change anything except
// the HOST_DEBUG and PREALLOCATE macros for your timing run.
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
//--------------------------------------------------------------------------
// Helper functions
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
-
void setStats( int enable )
{
#if ( !HOST_DEBUG && SET_STATS )
// not on the smips processor simulator itself. You should not change
// anything except the HOST_DEBUG and PREALLOCATE macros for your timing
// runs.
-
+
+int ncores = 1;
+#include "util.h"
+
//--------------------------------------------------------------------------
// Macros
}
#endif
-void finishTest( int toHostValue )
-{
-#if HOST_DEBUG
- if ( toHostValue == 1 )
- printf( "*** PASSED ***\n" );
- else
- printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
- exit(0);
-#else
- asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
- while ( 1 ) { }
-#endif
-}
+//void finishTest( int toHostValue )
+//{
+//#if HOST_DEBUG
+// if ( toHostValue == 1 )
+// printf( "*** PASSED ***\n" );
+// else
+// printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
+// exit(0);
+//#else
+// asm( "mtpcr %0, tohost" : : "r" (toHostValue) );
+// while ( 1 ) { }
+//#endif
+//}
void setStats( int enable )
{