forked from byungwoo733/riscv-ovpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriscvModelCallbacks.h
367 lines (317 loc) · 10.4 KB
/
riscvModelCallbacks.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Copyright (c) 2005-2020 Imperas Software Ltd., www.imperas.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#pragma once
// basic number types
#include "hostapi/impTypes.h"
// VMI header files
#include "vmi/vmiDbg.h"
// model header files
#include "riscvDerivedMorph.h"
#include "riscvExceptionTypes.h"
#include "riscvMode.h"
#include "riscvRegisterTypes.h"
#include "riscvTypes.h"
#include "riscvTypeRefs.h"
#include "riscvVariant.h"
#include "riscvVectorTypes.h"
////////////////////////////////////////////////////////////////////////////////
// IMPLEMENTED BY BASE MODEL
////////////////////////////////////////////////////////////////////////////////
//
// Register extension callback block with the base model
//
#define RISCV_REGISTER_EXT_CB_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvExtCBP extCB, \
Uns32 id \
)
typedef RISCV_REGISTER_EXT_CB_FN((*riscvRegisterExtCBFn));
//
// Return the indexed extension's extCB clientData
//
#define RISCV_GET_EXT_CLIENT_DATA_FN(_NAME) void * _NAME( \
riscvP riscv, \
Uns32 id \
)
typedef RISCV_GET_EXT_CLIENT_DATA_FN((*riscvGetExtClientDataFn));
//
// Return the indexed extension configuration
//
#define RISCV_GET_EXT_CONFIG_FN(_NAME) riscvExtConfigCP _NAME( \
riscvP riscv, \
Uns32 id \
)
typedef RISCV_GET_EXT_CONFIG_FN((*riscvGetExtConfigFn));
//
// Return the current XLEN
//
#define RISCV_GET_XLEN_FN(_NAME) Uns32 _NAME(riscvP riscv)
typedef RISCV_GET_XLEN_FN((*riscvGetXlenFn));
//
// Return the indexed register name
//
#define RISCV_GET_REG_NAME_FN(_NAME) const char *_NAME(Uns32 index)
typedef RISCV_GET_REG_NAME_FN((*riscvGetRegNameFn));
//
// Return true if in transaction mode
// Use at morph time only - assumes instruction checking this could
// abort a transaction so emits end block if in TM
//
#define RISCV_GET_TMODE_FN(_NAME) Bool _NAME(riscvP riscv)
typedef RISCV_GET_TMODE_FN((*riscvGetTModeFn));
//
// Return data endianness in the given processor mode
//
#define RISCV_GET_DATA_ENDIAN_FN(_NAME) memEndian _NAME( \
riscvP riscv, \
riscvMode mode \
)
typedef RISCV_GET_DATA_ENDIAN_FN((*riscvGetDataEndianFn));
//
// Enable or disable transaction mode
//
#define RISCV_SET_TMODE_FN(_NAME) void _NAME(riscvP riscv, Bool enable)
typedef RISCV_SET_TMODE_FN((*riscvSetTModeFn));
//
// Take Illegal Instruction exception
//
#define RISCV_ILLEGAL_INSTRUCTION_FN(_NAME) void _NAME(riscvP riscv)
typedef RISCV_ILLEGAL_INSTRUCTION_FN((*riscvIllegalInstructionFn));
//
// Take processor exception
//
#define RISCV_TAKE_EXCEPTION_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvException exception, \
Uns64 tval \
)
typedef RISCV_TAKE_EXCEPTION_FN((*riscvTakeExceptionFn));
//
// Validate that the instruction is supported and enabled and take an Illegal
// Instruction exception if not
//
#define RISCV_INSTRUCTION_ENABLED_FN(_NAME) Bool _NAME( \
riscvP riscv, \
riscvArchitecture requiredVariant \
)
typedef RISCV_INSTRUCTION_ENABLED_FN((*riscvInstructionEnabledFn));
//
// Return VMI register for the given abstract register
//
#define RISCV_GET_VMI_REG_FN(_NAME) vmiReg _NAME(riscvP riscv, riscvRegDesc r)
typedef RISCV_GET_VMI_REG_FN((*riscvGetVMIRegFn));
//
// Return VMI register for the given abstract register which may require a NaN
// box test if it is floating point
//
#define RISCV_GET_VMI_REG_FS_FN(_NAME) vmiReg _NAME( \
riscvP riscv, \
riscvRegDesc r, \
vmiReg tmp \
)
typedef RISCV_GET_VMI_REG_FS_FN((*riscvGetVMIRegFSFn));
//
// Do actions when a register is written (extending or NaN boxing, if
// required)
//
#define RISCV_WRITE_REG_SIZE_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvRegDesc r, \
Uns32 srcBits, \
Bool signExtend \
)
typedef RISCV_WRITE_REG_SIZE_FN((*riscvWriteRegSizeFn));
//
// Do actions when a register is written (extending or NaN boxing, if
// required) using the derived register size
//
#define RISCV_WRITE_REG_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvRegDesc r, \
Bool signExtend \
)
typedef RISCV_WRITE_REG_FN((*riscvWriteRegFn));
//
// Return VMI register for floating point status flags when written
//
#define RISCV_GET_FP_FLAGS_MT_FN(_NAME) vmiReg _NAME(riscvP riscv)
typedef RISCV_GET_FP_FLAGS_MT_FN((*riscvGetFPFlagsMtFn));
//
// Return data endianness in the current processor mode at morph time
//
#define RISCV_GET_DATA_ENDIAN_MT_FN(_NAME) memEndian _NAME(riscvP riscv)
typedef RISCV_GET_DATA_ENDIAN_MT_FN((*riscvGetDataEndianMtFn));
//
// Validate the given rounding mode is legal and emit an Illegal Instruction
// exception call if not
//
#define RISCV_CHECK_LEGAL_RM_MT_FN(_NAME) Bool _NAME( \
riscvP riscv, \
riscvRMDesc rm \
)
typedef RISCV_CHECK_LEGAL_RM_MT_FN((*riscvCheckLegalRMMtFn));
//
// Emit vector operation from extension library
//
#define RISCV_MORPH_VOP_FN(_NAME) void _NAME( \
riscvP riscv, \
Uns64 thisPC, \
riscvRegDesc r0, \
riscvRegDesc r1, \
riscvRegDesc r2, \
riscvRegDesc mask, \
riscvVShape shape, \
riscvVExternalFn externalCB, \
void *userData \
)
typedef RISCV_MORPH_VOP_FN((*riscvMorphVOpFn));
//
// Register new CSR
//
#define RISCV_NEW_CSR_FN(_NAME) void _NAME(riscvCSRAttrsCP attrs, riscvP riscv)
typedef RISCV_NEW_CSR_FN((*riscvNewCSRFn));
////////////////////////////////////////////////////////////////////////////////
// IMPLEMENTED BY DERIVED MODEL
////////////////////////////////////////////////////////////////////////////////
//
// Notifier called on trap entry or exception return
//
#define RISCV_TRAP_NOTIFIER_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvMode mode, \
void *clientData \
)
typedef RISCV_TRAP_NOTIFIER_FN((*riscvTrapNotifierFn));
//
// Notifier called at reset
//
#define RISCV_RESET_NOTIFIER_FN(_NAME) void _NAME( \
riscvP riscv, \
void *clientData \
)
typedef RISCV_RESET_NOTIFIER_FN((*riscvResetNotifierFn));
//
// Return first exception in the derived model
//
#define RISCV_FIRST_EXCEPTION_FN(_NAME) vmiExceptionInfoCP _NAME( \
riscvP riscv, \
void *clientData \
)
typedef RISCV_FIRST_EXCEPTION_FN((*riscvFirstExceptionFn));
//
// Notifier called on a model context switch. 'state' describes the new state.
//
#define RISCV_IASSWITCH_FN(_NAME) void _NAME( \
riscvP riscv, \
vmiIASRunState state, \
void *clientData \
)
typedef RISCV_IASSWITCH_FN((*riscvIASSwitchFn));
//
// Implement a load that is part of a transaction of the given size in bytes
// from the given virtual address, writing the loaded value to the buffer
//
#define RISCV_TLOAD_FN(_NAME) void _NAME( \
riscvP riscv, \
void *buffer, \
Addr VA, \
Uns32 bytes, \
void *clientData \
)
typedef RISCV_TLOAD_FN((*riscvTLoadFn));
//
// Implement a store that is part of a transaction of the given size in bytes
// to the given virtual address, taking the value from the buffer
//
#define RISCV_TSTORE_FN(_NAME) void _NAME( \
riscvP riscv, \
const void *buffer, \
Addr VA, \
Uns32 bytes, \
void *clientData \
)
typedef RISCV_TSTORE_FN((*riscvTStoreFn));
//
// Implement PMA check for the given address range
//
#define RISCV_PMA_CHECK_FN(_NAME) void _NAME( \
riscvP riscv, \
riscvMode mode, \
memPriv requiredPriv, \
Uns64 lowPA, \
Uns64 highPA, \
void *clientData \
)
typedef RISCV_PMA_CHECK_FN((*riscvPMACheckFn));
//
// Container structure for all callbacks implemented by the base model
//
typedef struct riscvModelCBS {
// from riscvUtils.h
riscvRegisterExtCBFn registerExtCB;
riscvGetExtClientDataFn getExtClientData;
riscvGetExtConfigFn getExtConfig;
riscvGetXlenFn getXlenMode;
riscvGetXlenFn getXlenArch;
riscvGetRegNameFn getXRegName;
riscvGetRegNameFn getFRegName;
riscvGetRegNameFn getVRegName;
riscvSetTModeFn setTMode;
riscvGetTModeFn getTMode;
riscvGetDataEndianFn getDataEndian;
// from riscvExceptions.h
riscvIllegalInstructionFn illegalInstruction;
riscvTakeExceptionFn takeException;
// from riscvMorph.h
riscvInstructionEnabledFn instructionEnabled;
riscvGetVMIRegFn getVMIReg;
riscvGetVMIRegFSFn getVMIRegFS;
riscvWriteRegSizeFn writeRegSize;
riscvWriteRegFn writeReg;
riscvGetFPFlagsMtFn getFPFlagsMt;
riscvGetDataEndianMtFn getDataEndianMt;
riscvCheckLegalRMMtFn checkLegalRMMt;
riscvMorphVOpFn morphVOp;
// from riscvCSR.h
riscvNewCSRFn newCSR;
} riscvModelCB;
//
// Container structure for all callbacks implemented by an extension
//
typedef struct riscvExtCBS {
// link pointer and id (maintained by base model)
riscvExtCBP next;
Uns32 id;
// handle back to client data
void *clientData;
// exception actions
riscvTrapNotifierFn trapNotifier;
riscvTrapNotifierFn ERETNotifier;
riscvResetNotifierFn resetNotifier;
riscvFirstExceptionFn firstException;
// code generation actions
riscvDerivedMorphFn preMorph;
riscvDerivedMorphFn postMorph;
// transaction support actions
riscvIASSwitchFn switchCB;
riscvTLoadFn tLoad;
riscvTStoreFn tStore;
// PMA check actions
riscvPMACheckFn PMACheck;
} riscvExtCB;