-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_api.h
More file actions
95 lines (83 loc) · 3.74 KB
/
sim_api.h
File metadata and controls
95 lines (83 loc) · 3.74 KB
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
//sim_api.h copied from sniper 6.1 codebase for instrumentation purposes
#ifndef __SIM_API
#define __SIM_API
#define SIM_CMD_ROI_TOGGLE 0 // Deprecated, for compatibility with programs compiled long ago
#define SIM_CMD_ROI_START 1
#define SIM_CMD_ROI_END 2
#define SIM_CMD_MHZ_SET 3
#define SIM_CMD_MARKER 4
#define SIM_CMD_USER 5
#define SIM_CMD_INSTRUMENT_MODE 6
#define SIM_CMD_MHZ_GET 7
#define SIM_CMD_IN_SIMULATOR 8
#define SIM_CMD_PROC_ID 9
#define SIM_CMD_THREAD_ID 10
#define SIM_CMD_NUM_PROCS 11
#define SIM_CMD_NUM_THREADS 12
#define SIM_CMD_NAMED_MARKER 13
#define SIM_CMD_SET_THREAD_NAME 14
#define SIM_OPT_INSTRUMENT_DETAILED 0
#define SIM_OPT_INSTRUMENT_WARMUP 1
#define SIM_OPT_INSTRUMENT_FASTFORWARD 2
#if defined(__i386)
#define MAGIC_REG_A "eax"
#define MAGIC_REG_B "edx" // Required for -fPIC support
#define MAGIC_REG_C "ecx"
#else
#define MAGIC_REG_A "rax"
#define MAGIC_REG_B "rbx"
#define MAGIC_REG_C "rcx"
#endif
#define SimMagic0(cmd) ({ \
unsigned long _cmd = (cmd), _res; \
__asm__ __volatile__ ( \
"mov %1, %%" MAGIC_REG_A "\n" \
"\txchg %%bx, %%bx\n" \
: "=a" (_res) /* output */ \
: "g"(_cmd) /* input */ \
); /* clobbered */ \
_res; \
})
#define SimMagic1(cmd, arg0) ({ \
unsigned long _cmd = (cmd), _arg0 = (arg0), _res; \
__asm__ __volatile__ ( \
"mov %1, %%" MAGIC_REG_A "\n" \
"\tmov %2, %%" MAGIC_REG_B "\n" \
"\txchg %%bx, %%bx\n" \
: "=a" (_res) /* output */ \
: "g"(_cmd), \
"g"(_arg0) /* input */ \
: "%" MAGIC_REG_B ); /* clobbered */ \
_res; \
})
#define SimMagic2(cmd, arg0, arg1) ({ \
unsigned long _cmd = (cmd), _arg0 = (arg0), _arg1 = (arg1), _res; \
__asm__ __volatile__ ( \
"mov %1, %%" MAGIC_REG_A "\n" \
"\tmov %2, %%" MAGIC_REG_B "\n" \
"\tmov %3, %%" MAGIC_REG_C "\n" \
"\txchg %%bx, %%bx\n" \
: "=a" (_res) /* output */ \
: "g"(_cmd), \
"g"(_arg0), \
"g"(_arg1) /* input */ \
: "%" MAGIC_REG_B, "%" MAGIC_REG_C ); /* clobbered */ \
_res; \
})
#define SimRoiStart() SimMagic0(SIM_CMD_ROI_START)
#define SimRoiEnd() SimMagic0(SIM_CMD_ROI_END)
#define SimGetProcId() SimMagic0(SIM_CMD_PROC_ID)
#define SimGetThreadId() SimMagic0(SIM_CMD_THREAD_ID)
#define SimSetThreadName(name) SimMagic1(SIM_CMD_SET_THREAD_NAME, (unsigned long)(name))
#define SimGetNumProcs() SimMagic0(SIM_CMD_NUM_PROCS)
#define SimGetNumThreads() SimMagic0(SIM_CMD_NUM_THREADS)
#define SimSetFreqMHz(proc, mhz) SimMagic2(SIM_CMD_MHZ_SET, proc, mhz)
#define SimSetOwnFreqMHz(mhz) SimSetFreqMHz(SimGetProcId(), mhz)
#define SimGetFreqMHz(proc) SimMagic1(SIM_CMD_MHZ_GET, proc)
#define SimGetOwnFreqMHz() SimGetFreqMHz(SimGetProcId())
#define SimMarker(arg0, arg1) SimMagic2(SIM_CMD_MARKER, arg0, arg1)
#define SimNamedMarker(arg0, str) SimMagic2(SIM_CMD_NAMED_MARKER, arg0, (unsigned long)(str))
#define SimUser(cmd, arg) SimMagic2(SIM_CMD_USER, cmd, arg)
#define SimSetInstrumentMode(opt) SimMagic1(SIM_CMD_INSTRUMENT_MODE, opt)
#define SimInSimulator() (SimMagic0(SIM_CMD_IN_SIMULATOR)!=SIM_CMD_IN_SIMULATOR)
#endif /* __SIM_API */