-
Notifications
You must be signed in to change notification settings - Fork 1
/
nanorv_example.c
73 lines (65 loc) · 1.48 KB
/
nanorv_example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include "nanorv.h"
VOID
RvTest(
VOID
)
{
RV_SIZE_T i;
RV_PROCESSOR Vp;
RV_UINT32 VpMemory[ 1024 ] =
{
0x93000001, 0x93901000, 0x13010010, 0x23201100,
0xb7100000, 0xf32200c0, 0x13010010, 0x63441100,
0x6f00c000, 0x93012000, 0x6f008000, 0x93011000,
0x33c23000, 0x732300c0, 0x73001000, 0x00000000,
};
//
// Set up initial processor context.
//
Vp = ( RV_PROCESSOR ) {
/* Flat span of host memory to pass to the guest. */
.MmuVaSpanHostBase = VpMemory,
.MmuVaSpanSize = sizeof( VpMemory ),
/* Begin the flat span of memory at guest effective address 0. */
.MmuVaSpanGuestBase = 0,
/* Begin executing at guest effective address 0. */
.Pc = 0
};
//
// Execute ticks.
//
while( RV_TRUE ) {
//
// Execute a tick; Fetches, decodes, and executes an instruction.
//
RvpTickExecute( &Vp );
//
// Print exception information.
//
if( Vp.ExceptionPending ) {
printf( "RV exception %i @ PC=0x%llx\n", ( RV_INT )Vp.ExceptionIndex, ( RV_UINT64 )Vp.Pc );
break;
}
//
// Terminate execution upon EBREAK.
//
if( Vp.EBreakPending ) {
break;
}
}
//
// Dump all general-purpose registers.
//
for( i = 0; i < RV_COUNTOF( Vp.Xr ); i++ ) {
printf( "x%i = 0x%llx\n", ( RV_INT )i, ( RV_UINT64 )Vp.Xr[ i ] );
}
//
// Dump program-counter register.
//
printf( "pc = 0x%llx\n", ( RV_UINT64 )Vp.Pc );
//
// Dump test value written to memory.
//
printf( "VpMemory[0x40] = 0x%x\n", VpMemory[ 0x40 ] );
}