-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemul.h
103 lines (67 loc) · 2.04 KB
/
emul.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Risc-V 32 IM emulator
Copyright (c) 2024, Michał Kubecki - qubeck78@wp.pl
Supplied under BSD-3 Clause license ( see LICENSE file )
Note: While not enforced by the license, I kindly request that any application
using this software includes "Michal Kubecki - qubeck78@wp.pl" in its about
or credits section as a token of appreciation for the open-source contribution.
*/
#ifndef _EMUL_H
#define _EMUL_H
#include "gfTypes.h"
#define _RVEMUL_OK 0
#define _RVEMUL_UNDEFINED_INSTRUCTION 1
#define _RVEMUL_EBREAK 256
#define _RV_CSR_MSTATUS 0x300
#define _RV_CSR_MISA 0x301
#define _RV_CSR_MIE 0x304
#define _RV_CSR_MTVEC 0x305
#define _RV_CSR_MSTATUSH 0x310
#define _RV_CSR_MSCRATCH 0x340
#define _RV_CSR_MEPC 0x341
#define _RV_CSR_MCAUSE 0x342
#define _RV_CSR_MTVAL 0x343
#define _RV_CSR_MIP 0x344
#define _RV_CSR_MHARTID 0xf14
typedef struct _emContext_t
{
//memory interface callback functions
//addr
uint32_t ( *fetchInstruction )( uint32_t );
//addr
uint32_t ( *fetchData )( uint32_t );
//addr mask data
uint32_t ( *storeData )( uint32_t, uint8_t, uint32_t );
uint32_t pc;
uint32_t regs[32];
int32_t *sregs;
//instruction counter;
uint32_t instrCounter;
//instruction decoder
uint32_t instruction;
//csr regs
//0x300
uint32_t mstatus;
//0x304
uint32_t mie;
//0x305
uint32_t mtvec;
//0x310
uint32_t mstatush;
//0x340
uint32_t mscratch;
//0x341
uint32_t mepc;
//0x342
uint32_t mcause;
//0x343
uint32_t mtval;
//0x344
uint32_t mip;
}emContext_t;
uint32_t rvReadCSR( emContext_t *ctx, uint32_t csr );
uint32_t rvWriteCSR( emContext_t *ctx, uint32_t csr, uint32_t value );
uint32_t rvReset( emContext_t *ctx );
uint32_t rvStep( emContext_t *ctx );
uint32_t rvTriggerMtimeIRQ( emContext_t *ctx );
#endif