Rizin
unix-like reverse engineering framework and cli tools
disassembler.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 Dhruv Maroo <dhruvmaru007@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef RZ_SH_DISASSEMBLER_H
5 #define RZ_SH_DISASSEMBLER_H
6 #include <rz_types.h>
7 #include <rz_util.h>
8 
9 #define BITS_PER_BYTE 8
10 #define SH_REG_SIZE 4 * BITS_PER_BYTE
11 #define SH_ADDR_SIZE 4 * BITS_PER_BYTE
12 #define SH_INSTR_SIZE 2 * BITS_PER_BYTE
13 #define SH_GPR_COUNT 16
14 #define SH_BANKED_REG_COUNT 8
15 #define SH_REG_COUNT 61
16 
17 typedef enum sh_addr_mode_t {
34 
35 typedef enum sh_scaling_t {
42 
43 static const ut8 sh_scaling_size[] = { -1, 1, 2, 4, 8 };
44 
45 // SR register in SH
46 // SR = x|D|R|B|xxxxxxxxxxxx|F|xxxxx|M|Q|IIII|xx|S|T
47 // x are the reserved bits
48 #define SH_SR_T_BIT 1u << 0
49 #define SH_SR_T "sr_t"
50 #define SH_SR_S_BIT 1u << 1
51 #define SH_SR_S "sr_s"
52 #define SH_SR_I_BIT 1u << 4
53 #define SH_SR_I "sr_i"
54 #define SH_SR_Q_BIT 1u << 8
55 #define SH_SR_Q "sr_q"
56 #define SH_SR_M_BIT 1u << 9
57 #define SH_SR_M "sr_m"
58 #define SH_SR_F_BIT 1u << 15
59 #define SH_SR_F "sr_f"
60 #define SH_SR_B_BIT 1u << 28
61 #define SH_SR_B "sr_b"
62 #define SH_SR_R_BIT 1u << 29
63 #define SH_SR_R "sr_r"
64 #define SH_SR_D_BIT 1u << 30
65 #define SH_SR_D "sr_d"
66 
70 typedef enum sh_register_index_t {
71  // General purpose registers
88 
89  // System registers
101 
102  // Floating point registers
137 
138  // Banked registers
147 
148  // Size
151 
152 typedef enum {
233  /* end */
234  SH_OP_SIZE
236 
237 typedef struct sh_param_t {
241 
242 typedef struct sh_opcode_t {
244  const char *str_mnem;
249 
251 
252 RZ_IPI RZ_OWN char *sh_op_param_to_str(SHParam param, SHScaling scaling, ut64 pc);
254 
255 #endif /* RZ_SH_DISASSEMBLER_H */
#define RZ_IPI
Definition: analysis_wasm.c:11
uint16_t ut16
uint8_t ut8
Definition: lh5801.h:11
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
enum sh_scaling_t SHScaling
RZ_IPI RZ_OWN SHOp * sh_disassembler(ut16 opcode)
Disassemble opcode and return a SHOp.
Definition: disassembler.c:130
RZ_IPI RZ_OWN char * sh_op_param_to_str(SHParam param, SHScaling scaling, ut64 pc)
Return string representation of disassembled param.
Definition: disassembler.c:166
sh_scaling_t
Definition: disassembler.h:35
@ SH_SCALING_L
long word
Definition: disassembler.h:39
@ SH_SCALING_INVALID
Definition: disassembler.h:36
@ SH_SCALING_W
word
Definition: disassembler.h:38
@ SH_SCALING_Q
quad word
Definition: disassembler.h:40
@ SH_SCALING_B
byte
Definition: disassembler.h:37
struct sh_param_t SHParam
enum sh_addr_mode_t SHAddrMode
enum sh_register_index_t SHRegisterIndex
struct sh_opcode_t SHOp
SHOpMnem
Definition: disassembler.h:152
@ SH_OP_DIV0S
Definition: disassembler.h:170
@ SH_OP_CMP_PL
Definition: disassembler.h:167
@ SH_OP_SHLL8
Definition: disassembler.h:204
@ SH_OP_LDS
Definition: disassembler.h:223
@ SH_OP_MOV
Definition: disassembler.h:154
@ SH_OP_BRA
Definition: disassembler.h:212
@ SH_OP_ADDV
Definition: disassembler.h:160
@ SH_OP_CMP_STR
Definition: disassembler.h:168
@ SH_OP_SHLL2
Definition: disassembler.h:202
@ SH_OP_UNIMPL
Definition: disassembler.h:232
@ SH_OP_AND
Definition: disassembler.h:186
@ SH_OP_TST
Definition: disassembler.h:190
@ SH_OP_SHLL
Definition: disassembler.h:200
@ SH_OP_BT
Definition: disassembler.h:210
@ SH_OP_CMP_GT
Definition: disassembler.h:165
@ SH_OP_XOR
Definition: disassembler.h:191
@ SH_OP_ROTR
Definition: disassembler.h:193
@ SH_OP_BTS
Definition: disassembler.h:211
@ SH_OP_BSRF
Definition: disassembler.h:215
@ SH_OP_CMP_HI
Definition: disassembler.h:164
@ SH_OP_NOP
Definition: disassembler.h:225
@ SH_OP_OR
Definition: disassembler.h:188
@ SH_OP_XTRCT
Definition: disassembler.h:157
@ SH_OP_MULU
Definition: disassembler.h:180
@ SH_OP_EXTU
Definition: disassembler.h:176
@ SH_OP_BRAF
Definition: disassembler.h:213
@ SH_OP_MULS
Definition: disassembler.h:179
@ SH_OP_ADDC
Definition: disassembler.h:159
@ SH_OP_TAS
Definition: disassembler.h:189
@ SH_OP_INVALID
Definition: disassembler.h:153
@ SH_OP_SETS
Definition: disassembler.h:227
@ SH_OP_SHLR16
Definition: disassembler.h:207
@ SH_OP_NEGC
Definition: disassembler.h:182
@ SH_OP_SWAP
Definition: disassembler.h:156
@ SH_OP_SETT
Definition: disassembler.h:228
@ SH_OP_SLEEP
Definition: disassembler.h:229
@ SH_OP_SHLR
Definition: disassembler.h:201
@ SH_OP_SHLL16
Definition: disassembler.h:206
@ SH_OP_STS
Definition: disassembler.h:231
@ SH_OP_ADD
Definition: disassembler.h:158
@ SH_OP_SUB
Definition: disassembler.h:183
@ SH_OP_NEG
Definition: disassembler.h:181
@ SH_OP_CLRS
Definition: disassembler.h:220
@ SH_OP_DIV0U
Definition: disassembler.h:171
@ SH_OP_ROTL
Definition: disassembler.h:192
@ SH_OP_STC
Definition: disassembler.h:230
@ SH_OP_BFS
Definition: disassembler.h:209
@ SH_OP_DMULS
Definition: disassembler.h:172
@ SH_OP_CMP_GE
Definition: disassembler.h:163
@ SH_OP_CLRT
Definition: disassembler.h:221
@ SH_OP_MUL
Definition: disassembler.h:178
@ SH_OP_MAC
Definition: disassembler.h:177
@ SH_OP_SHLD
Definition: disassembler.h:199
@ SH_OP_ROTCR
Definition: disassembler.h:195
@ SH_OP_DT
Definition: disassembler.h:174
@ SH_OP_NOT
Definition: disassembler.h:187
@ SH_OP_DMULU
Definition: disassembler.h:173
@ SH_OP_BF
Definition: disassembler.h:208
@ SH_OP_SHAR
Definition: disassembler.h:198
@ SH_OP_DIV1
Definition: disassembler.h:169
@ SH_OP_MOVT
Definition: disassembler.h:155
@ SH_OP_ROTCL
Definition: disassembler.h:194
@ SH_OP_CMP_PZ
Definition: disassembler.h:166
@ SH_OP_SIZE
Definition: disassembler.h:234
@ SH_OP_SUBC
Definition: disassembler.h:184
@ SH_OP_RTE
Definition: disassembler.h:226
@ SH_OP_CLRMAC
Definition: disassembler.h:219
@ SH_OP_EXTS
Definition: disassembler.h:175
@ SH_OP_RTS
Definition: disassembler.h:218
@ SH_OP_LDC
Definition: disassembler.h:222
@ SH_OP_CMP_EQ
Definition: disassembler.h:161
@ SH_OP_SHLR8
Definition: disassembler.h:205
@ SH_OP_BSR
Definition: disassembler.h:214
@ SH_OP_JMP
Definition: disassembler.h:216
@ SH_OP_MOVCA
Definition: disassembler.h:224
@ SH_OP_SHAD
Definition: disassembler.h:196
@ SH_OP_JSR
Definition: disassembler.h:217
@ SH_OP_SUBV
Definition: disassembler.h:185
@ SH_OP_CMP_HS
Definition: disassembler.h:162
@ SH_OP_SHAL
Definition: disassembler.h:197
@ SH_OP_SHLR2
Definition: disassembler.h:203
static const ut8 sh_scaling_size[]
Definition: disassembler.h:43
sh_register_index_t
Definition: disassembler.h:70
@ SH_REG_IND_XF5
Definition: disassembler.h:126
@ SH_REG_IND_R6
Definition: disassembler.h:78
@ SH_REG_IND_FPUL
Definition: disassembler.h:103
@ SH_REG_IND_FR7
Definition: disassembler.h:112
@ SH_REG_IND_R2B
Definition: disassembler.h:141
@ SH_REG_IND_R14
Definition: disassembler.h:86
@ SH_REG_IND_MACH
Definition: disassembler.h:98
@ SH_REG_IND_XF1
Definition: disassembler.h:122
@ SH_REG_IND_FR14
Definition: disassembler.h:119
@ SH_REG_IND_FPSCR
Definition: disassembler.h:104
@ SH_REG_IND_XF15
Definition: disassembler.h:136
@ SH_REG_IND_R3
Definition: disassembler.h:75
@ SH_REG_IND_R10
Definition: disassembler.h:82
@ SH_REG_IND_R9
Definition: disassembler.h:81
@ SH_REG_IND_FR13
Definition: disassembler.h:118
@ SH_REG_IND_XF11
Definition: disassembler.h:132
@ SH_REG_IND_R6B
Definition: disassembler.h:145
@ SH_REG_IND_FR6
Definition: disassembler.h:111
@ SH_REG_IND_R7B
Definition: disassembler.h:146
@ SH_REG_IND_FR2
Definition: disassembler.h:107
@ SH_REG_IND_XF6
Definition: disassembler.h:127
@ SH_REG_IND_GBR
Definition: disassembler.h:92
@ SH_REG_IND_FR0
Definition: disassembler.h:105
@ SH_REG_IND_R7
Definition: disassembler.h:79
@ SH_REG_IND_XF10
Definition: disassembler.h:131
@ SH_REG_IND_FR11
Definition: disassembler.h:116
@ SH_REG_IND_XF2
Definition: disassembler.h:123
@ SH_REG_IND_XF14
Definition: disassembler.h:135
@ SH_REG_IND_FR1
Definition: disassembler.h:106
@ SH_REG_IND_R3B
Definition: disassembler.h:142
@ SH_REG_IND_XF7
Definition: disassembler.h:128
@ SH_REG_IND_FR12
Definition: disassembler.h:117
@ SH_REG_IND_FR15
Definition: disassembler.h:120
@ SH_REG_IND_R12
Definition: disassembler.h:84
@ SH_REG_IND_PC
Definition: disassembler.h:90
@ SH_REG_IND_PR
Definition: disassembler.h:100
@ SH_REG_IND_XF13
Definition: disassembler.h:134
@ SH_REG_IND_VBR
Definition: disassembler.h:97
@ SH_REG_IND_R15
Definition: disassembler.h:87
@ SH_REG_IND_DBR
Definition: disassembler.h:96
@ SH_REG_IND_R11
Definition: disassembler.h:83
@ SH_REG_IND_XF0
Definition: disassembler.h:121
@ SH_REG_IND_R2
Definition: disassembler.h:74
@ SH_REG_IND_XF4
Definition: disassembler.h:125
@ SH_REG_IND_R5
Definition: disassembler.h:77
@ SH_REG_IND_MACL
Definition: disassembler.h:99
@ SH_REG_IND_SIZE
Definition: disassembler.h:149
@ SH_REG_IND_SSR
Definition: disassembler.h:93
@ SH_REG_IND_XF9
Definition: disassembler.h:130
@ SH_REG_IND_SR
Definition: disassembler.h:91
@ SH_REG_IND_R0B
Definition: disassembler.h:139
@ SH_REG_IND_R5B
Definition: disassembler.h:144
@ SH_REG_IND_FR10
Definition: disassembler.h:115
@ SH_REG_IND_FR9
Definition: disassembler.h:114
@ SH_REG_IND_SPC
Definition: disassembler.h:94
@ SH_REG_IND_FR5
Definition: disassembler.h:110
@ SH_REG_IND_XF8
Definition: disassembler.h:129
@ SH_REG_IND_FR8
Definition: disassembler.h:113
@ SH_REG_IND_R4B
Definition: disassembler.h:143
@ SH_REG_IND_R0
Definition: disassembler.h:72
@ SH_REG_IND_R4
Definition: disassembler.h:76
@ SH_REG_IND_XF12
Definition: disassembler.h:133
@ SH_REG_IND_FR3
Definition: disassembler.h:108
@ SH_REG_IND_XF3
Definition: disassembler.h:124
@ SH_REG_IND_R8
Definition: disassembler.h:80
@ SH_REG_IND_R1
Definition: disassembler.h:73
@ SH_REG_IND_R13
Definition: disassembler.h:85
@ SH_REG_IND_FR4
Definition: disassembler.h:109
@ SH_REG_IND_SGR
Definition: disassembler.h:95
@ SH_REG_IND_R1B
Definition: disassembler.h:140
RZ_IPI RZ_OWN char * sh_op_to_str(RZ_NONNULL const SHOp *op, ut64 pc)
Return string representation of disassembled op.
Definition: disassembler.c:224
sh_addr_mode_t
Definition: disassembler.h:17
@ SH_PC_RELATIVE8
Definition: disassembler.h:28
@ SH_IMM_S
8-bit immediate value (sign-extended)
Definition: disassembler.h:32
@ SH_REG_INDIRECT_DISP
register indirect with displacement
Definition: disassembler.h:23
@ SH_PC_RELATIVE_DISP
Definition: disassembler.h:27
@ SH_REG_DIRECT
Definition: disassembler.h:19
@ SH_PC_RELATIVE_REG
Definition: disassembler.h:30
@ SH_PC_RELATIVE12
Definition: disassembler.h:29
@ SH_REG_INDIRECT_INDEXED
indexed register indirect
Definition: disassembler.h:24
@ SH_ADDR_INVALID
Definition: disassembler.h:18
@ SH_REG_INDIRECT_I
register indirect with post-increment
Definition: disassembler.h:21
@ SH_REG_INDIRECT
Definition: disassembler.h:20
@ SH_IMM_U
8-bit immediate value (zero-extended)
Definition: disassembler.h:31
@ SH_REG_INDIRECT_D
register indirect with pre-decrement
Definition: disassembler.h:22
@ SH_GBR_INDIRECT_DISP
Definition: disassembler.h:25
@ SH_GBR_INDIRECT_INDEXED
Definition: disassembler.h:26
SHParam param[2]
Definition: disassembler.h:246
SHScaling scaling
Definition: disassembler.h:247
SHOpMnem mnemonic
Definition: disassembler.h:245
const char * str_mnem
Definition: disassembler.h:244
ut16 param[2]
Definition: disassembler.h:238
SHAddrMode mode
Definition: disassembler.h:239
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()