Rizin
unix-like reverse engineering framework and cli tools
disassembler.h File Reference
#include <rz_types.h>
#include <rz_util.h>

Go to the source code of this file.

Classes

struct  sh_param_t
 
struct  sh_opcode_t
 

Macros

#define BITS_PER_BYTE   8
 
#define SH_REG_SIZE   4 * BITS_PER_BYTE
 
#define SH_ADDR_SIZE   4 * BITS_PER_BYTE
 
#define SH_INSTR_SIZE   2 * BITS_PER_BYTE
 
#define SH_GPR_COUNT   16
 
#define SH_BANKED_REG_COUNT   8
 
#define SH_REG_COUNT   61
 
#define SH_SR_T_BIT   1u << 0
 
#define SH_SR_T   "sr_t"
 SR.T: True/False condition or carry/borrow bit. More...
 
#define SH_SR_S_BIT   1u << 1
 
#define SH_SR_S   "sr_s"
 SR.S: Specifies a saturation operation for a MAC instruction. More...
 
#define SH_SR_I_BIT   1u << 4
 
#define SH_SR_I   "sr_i"
 SR.I: Interrupt mask level: External interrupts of a lower level than IMASK are masked. More...
 
#define SH_SR_Q_BIT   1u << 8
 
#define SH_SR_Q   "sr_q"
 SR.Q: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions) More...
 
#define SH_SR_M_BIT   1u << 9
 
#define SH_SR_M   "sr_m"
 SR.M: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions) More...
 
#define SH_SR_F_BIT   1u << 15
 
#define SH_SR_F   "sr_f"
 SR.FD: FPU disable bit (cleared to 0 by a reset) More...
 
#define SH_SR_B_BIT   1u << 28
 
#define SH_SR_B   "sr_b"
 SR.BL: Exception/interrupt block bit (set to 1 by a reset, exception, or interrupt) More...
 
#define SH_SR_R_BIT   1u << 29
 
#define SH_SR_R   "sr_r"
 SR.RB: General register bank specifier in privileged mode (set to 1 by a reset, exception or interrupt) More...
 
#define SH_SR_D_BIT   1u << 30
 
#define SH_SR_D   "sr_d"
 SR.MD: Processor mode. More...
 

Typedefs

typedef enum sh_addr_mode_t SHAddrMode
 
typedef enum sh_scaling_t SHScaling
 
typedef enum sh_register_index_t SHRegisterIndex
 
typedef struct sh_param_t SHParam
 
typedef struct sh_opcode_t SHOp
 

Enumerations

enum  sh_addr_mode_t {
  SH_ADDR_INVALID = 0 , SH_REG_DIRECT , SH_REG_INDIRECT , SH_REG_INDIRECT_I ,
  SH_REG_INDIRECT_D , SH_REG_INDIRECT_DISP , SH_REG_INDIRECT_INDEXED , SH_GBR_INDIRECT_DISP ,
  SH_GBR_INDIRECT_INDEXED , SH_PC_RELATIVE_DISP , SH_PC_RELATIVE8 , SH_PC_RELATIVE12 ,
  SH_PC_RELATIVE_REG , SH_IMM_U , SH_IMM_S
}
 
enum  sh_scaling_t {
  SH_SCALING_INVALID = 0 , SH_SCALING_B , SH_SCALING_W , SH_SCALING_L ,
  SH_SCALING_Q
}
 
enum  sh_register_index_t {
  SH_REG_IND_R0 = 0 , SH_REG_IND_R1 , SH_REG_IND_R2 , SH_REG_IND_R3 ,
  SH_REG_IND_R4 , SH_REG_IND_R5 , SH_REG_IND_R6 , SH_REG_IND_R7 ,
  SH_REG_IND_R8 , SH_REG_IND_R9 , SH_REG_IND_R10 , SH_REG_IND_R11 ,
  SH_REG_IND_R12 , SH_REG_IND_R13 , SH_REG_IND_R14 , SH_REG_IND_R15 ,
  SH_REG_IND_PC , SH_REG_IND_SR , SH_REG_IND_GBR , SH_REG_IND_SSR ,
  SH_REG_IND_SPC , SH_REG_IND_SGR , SH_REG_IND_DBR , SH_REG_IND_VBR ,
  SH_REG_IND_MACH , SH_REG_IND_MACL , SH_REG_IND_PR , SH_REG_IND_FPUL ,
  SH_REG_IND_FPSCR , SH_REG_IND_FR0 , SH_REG_IND_FR1 , SH_REG_IND_FR2 ,
  SH_REG_IND_FR3 , SH_REG_IND_FR4 , SH_REG_IND_FR5 , SH_REG_IND_FR6 ,
  SH_REG_IND_FR7 , SH_REG_IND_FR8 , SH_REG_IND_FR9 , SH_REG_IND_FR10 ,
  SH_REG_IND_FR11 , SH_REG_IND_FR12 , SH_REG_IND_FR13 , SH_REG_IND_FR14 ,
  SH_REG_IND_FR15 , SH_REG_IND_XF0 , SH_REG_IND_XF1 , SH_REG_IND_XF2 ,
  SH_REG_IND_XF3 , SH_REG_IND_XF4 , SH_REG_IND_XF5 , SH_REG_IND_XF6 ,
  SH_REG_IND_XF7 , SH_REG_IND_XF8 , SH_REG_IND_XF9 , SH_REG_IND_XF10 ,
  SH_REG_IND_XF11 , SH_REG_IND_XF12 , SH_REG_IND_XF13 , SH_REG_IND_XF14 ,
  SH_REG_IND_XF15 , SH_REG_IND_R0B , SH_REG_IND_R1B , SH_REG_IND_R2B ,
  SH_REG_IND_R3B , SH_REG_IND_R4B , SH_REG_IND_R5B , SH_REG_IND_R6B ,
  SH_REG_IND_R7B , SH_REG_IND_SIZE
}
 
enum  SHOpMnem {
  SH_OP_INVALID = 0 , SH_OP_MOV , SH_OP_MOVT , SH_OP_SWAP ,
  SH_OP_XTRCT , SH_OP_ADD , SH_OP_ADDC , SH_OP_ADDV ,
  SH_OP_CMP_EQ , SH_OP_CMP_HS , SH_OP_CMP_GE , SH_OP_CMP_HI ,
  SH_OP_CMP_GT , SH_OP_CMP_PZ , SH_OP_CMP_PL , SH_OP_CMP_STR ,
  SH_OP_DIV1 , SH_OP_DIV0S , SH_OP_DIV0U , SH_OP_DMULS ,
  SH_OP_DMULU , SH_OP_DT , SH_OP_EXTS , SH_OP_EXTU ,
  SH_OP_MAC , SH_OP_MUL , SH_OP_MULS , SH_OP_MULU ,
  SH_OP_NEG , SH_OP_NEGC , SH_OP_SUB , SH_OP_SUBC ,
  SH_OP_SUBV , SH_OP_AND , SH_OP_NOT , SH_OP_OR ,
  SH_OP_TAS , SH_OP_TST , SH_OP_XOR , SH_OP_ROTL ,
  SH_OP_ROTR , SH_OP_ROTCL , SH_OP_ROTCR , SH_OP_SHAD ,
  SH_OP_SHAL , SH_OP_SHAR , SH_OP_SHLD , SH_OP_SHLL ,
  SH_OP_SHLR , SH_OP_SHLL2 , SH_OP_SHLR2 , SH_OP_SHLL8 ,
  SH_OP_SHLR8 , SH_OP_SHLL16 , SH_OP_SHLR16 , SH_OP_BF ,
  SH_OP_BFS , SH_OP_BT , SH_OP_BTS , SH_OP_BRA ,
  SH_OP_BRAF , SH_OP_BSR , SH_OP_BSRF , SH_OP_JMP ,
  SH_OP_JSR , SH_OP_RTS , SH_OP_CLRMAC , SH_OP_CLRS ,
  SH_OP_CLRT , SH_OP_LDC , SH_OP_LDS , SH_OP_MOVCA ,
  SH_OP_NOP , SH_OP_RTE , SH_OP_SETS , SH_OP_SETT ,
  SH_OP_SLEEP , SH_OP_STC , SH_OP_STS , SH_OP_UNIMPL ,
  SH_OP_SIZE
}
 

Functions

RZ_IPI RZ_OWN SHOpsh_disassembler (ut16 opcode)
 Disassemble opcode and return a SHOp. More...
 
RZ_IPI RZ_OWN char * sh_op_param_to_str (SHParam param, SHScaling scaling, ut64 pc)
 Return string representation of disassembled param. More...
 
RZ_IPI RZ_OWN char * sh_op_to_str (RZ_NONNULL const SHOp *op, ut64 pc)
 Return string representation of disassembled op. More...
 

Variables

static const ut8 sh_scaling_size [] = { -1, 1, 2, 4, 8 }
 

Macro Definition Documentation

◆ BITS_PER_BYTE

#define BITS_PER_BYTE   8

Definition at line 9 of file disassembler.h.

◆ SH_ADDR_SIZE

#define SH_ADDR_SIZE   4 * BITS_PER_BYTE

Definition at line 11 of file disassembler.h.

◆ SH_BANKED_REG_COUNT

#define SH_BANKED_REG_COUNT   8

Definition at line 14 of file disassembler.h.

◆ SH_GPR_COUNT

#define SH_GPR_COUNT   16

Definition at line 13 of file disassembler.h.

◆ SH_INSTR_SIZE

#define SH_INSTR_SIZE   2 * BITS_PER_BYTE

Definition at line 12 of file disassembler.h.

◆ SH_REG_COUNT

#define SH_REG_COUNT   61

Definition at line 15 of file disassembler.h.

◆ SH_REG_SIZE

#define SH_REG_SIZE   4 * BITS_PER_BYTE

Definition at line 10 of file disassembler.h.

◆ SH_SR_B

#define SH_SR_B   "sr_b"

SR.BL: Exception/interrupt block bit (set to 1 by a reset, exception, or interrupt)

Definition at line 61 of file disassembler.h.

◆ SH_SR_B_BIT

#define SH_SR_B_BIT   1u << 28

Definition at line 60 of file disassembler.h.

◆ SH_SR_D

#define SH_SR_D   "sr_d"

SR.MD: Processor mode.

Definition at line 65 of file disassembler.h.

◆ SH_SR_D_BIT

#define SH_SR_D_BIT   1u << 30

Definition at line 64 of file disassembler.h.

◆ SH_SR_F

#define SH_SR_F   "sr_f"

SR.FD: FPU disable bit (cleared to 0 by a reset)

Definition at line 59 of file disassembler.h.

◆ SH_SR_F_BIT

#define SH_SR_F_BIT   1u << 15

Definition at line 58 of file disassembler.h.

◆ SH_SR_I

#define SH_SR_I   "sr_i"

SR.I: Interrupt mask level: External interrupts of a lower level than IMASK are masked.

Definition at line 53 of file disassembler.h.

◆ SH_SR_I_BIT

#define SH_SR_I_BIT   1u << 4

Definition at line 52 of file disassembler.h.

◆ SH_SR_M

#define SH_SR_M   "sr_m"

SR.M: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)

Definition at line 57 of file disassembler.h.

◆ SH_SR_M_BIT

#define SH_SR_M_BIT   1u << 9

Definition at line 56 of file disassembler.h.

◆ SH_SR_Q

#define SH_SR_Q   "sr_q"

SR.Q: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)

Definition at line 55 of file disassembler.h.

◆ SH_SR_Q_BIT

#define SH_SR_Q_BIT   1u << 8

Definition at line 54 of file disassembler.h.

◆ SH_SR_R

#define SH_SR_R   "sr_r"

SR.RB: General register bank specifier in privileged mode (set to 1 by a reset, exception or interrupt)

Definition at line 63 of file disassembler.h.

◆ SH_SR_R_BIT

#define SH_SR_R_BIT   1u << 29

Definition at line 62 of file disassembler.h.

◆ SH_SR_S

#define SH_SR_S   "sr_s"

SR.S: Specifies a saturation operation for a MAC instruction.

Definition at line 51 of file disassembler.h.

◆ SH_SR_S_BIT

#define SH_SR_S_BIT   1u << 1

Definition at line 50 of file disassembler.h.

◆ SH_SR_T

#define SH_SR_T   "sr_t"

SR.T: True/False condition or carry/borrow bit.

Definition at line 49 of file disassembler.h.

◆ SH_SR_T_BIT

#define SH_SR_T_BIT   1u << 0

Definition at line 48 of file disassembler.h.

Typedef Documentation

◆ SHAddrMode

typedef enum sh_addr_mode_t SHAddrMode

◆ SHOp

typedef struct sh_opcode_t SHOp

◆ SHParam

typedef struct sh_param_t SHParam

◆ SHRegisterIndex

Enum for register indexes

◆ SHScaling

typedef enum sh_scaling_t SHScaling

Enumeration Type Documentation

◆ sh_addr_mode_t

Enumerator
SH_ADDR_INVALID 
SH_REG_DIRECT 
SH_REG_INDIRECT 
SH_REG_INDIRECT_I 

register indirect with post-increment

SH_REG_INDIRECT_D 

register indirect with pre-decrement

SH_REG_INDIRECT_DISP 

register indirect with displacement

SH_REG_INDIRECT_INDEXED 

indexed register indirect

SH_GBR_INDIRECT_DISP 
SH_GBR_INDIRECT_INDEXED 
SH_PC_RELATIVE_DISP 
SH_PC_RELATIVE8 
SH_PC_RELATIVE12 
SH_PC_RELATIVE_REG 
SH_IMM_U 

8-bit immediate value (zero-extended)

SH_IMM_S 

8-bit immediate value (sign-extended)

Definition at line 17 of file disassembler.h.

17  {
18  SH_ADDR_INVALID = 0,
31  SH_IMM_U,
32  SH_IMM_S,
33 } SHAddrMode;
enum sh_addr_mode_t SHAddrMode
@ 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

◆ sh_register_index_t

Enum for register indexes

Enumerator
SH_REG_IND_R0 
SH_REG_IND_R1 
SH_REG_IND_R2 
SH_REG_IND_R3 
SH_REG_IND_R4 
SH_REG_IND_R5 
SH_REG_IND_R6 
SH_REG_IND_R7 
SH_REG_IND_R8 
SH_REG_IND_R9 
SH_REG_IND_R10 
SH_REG_IND_R11 
SH_REG_IND_R12 
SH_REG_IND_R13 
SH_REG_IND_R14 
SH_REG_IND_R15 
SH_REG_IND_PC 
SH_REG_IND_SR 
SH_REG_IND_GBR 
SH_REG_IND_SSR 
SH_REG_IND_SPC 
SH_REG_IND_SGR 
SH_REG_IND_DBR 
SH_REG_IND_VBR 
SH_REG_IND_MACH 
SH_REG_IND_MACL 
SH_REG_IND_PR 
SH_REG_IND_FPUL 
SH_REG_IND_FPSCR 
SH_REG_IND_FR0 
SH_REG_IND_FR1 
SH_REG_IND_FR2 
SH_REG_IND_FR3 
SH_REG_IND_FR4 
SH_REG_IND_FR5 
SH_REG_IND_FR6 
SH_REG_IND_FR7 
SH_REG_IND_FR8 
SH_REG_IND_FR9 
SH_REG_IND_FR10 
SH_REG_IND_FR11 
SH_REG_IND_FR12 
SH_REG_IND_FR13 
SH_REG_IND_FR14 
SH_REG_IND_FR15 
SH_REG_IND_XF0 
SH_REG_IND_XF1 
SH_REG_IND_XF2 
SH_REG_IND_XF3 
SH_REG_IND_XF4 
SH_REG_IND_XF5 
SH_REG_IND_XF6 
SH_REG_IND_XF7 
SH_REG_IND_XF8 
SH_REG_IND_XF9 
SH_REG_IND_XF10 
SH_REG_IND_XF11 
SH_REG_IND_XF12 
SH_REG_IND_XF13 
SH_REG_IND_XF14 
SH_REG_IND_XF15 
SH_REG_IND_R0B 
SH_REG_IND_R1B 
SH_REG_IND_R2B 
SH_REG_IND_R3B 
SH_REG_IND_R4B 
SH_REG_IND_R5B 
SH_REG_IND_R6B 
SH_REG_IND_R7B 
SH_REG_IND_SIZE 

Definition at line 70 of file disassembler.h.

70  {
71  // General purpose registers
72  SH_REG_IND_R0 = 0,
88 
89  // System registers
101 
102  // Floating point registers
137 
138  // Banked registers
147 
148  // Size
enum sh_register_index_t SHRegisterIndex
@ 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

◆ sh_scaling_t

Enumerator
SH_SCALING_INVALID 
SH_SCALING_B 

byte

SH_SCALING_W 

word

SH_SCALING_L 

long word

SH_SCALING_Q 

quad word

Definition at line 35 of file disassembler.h.

35  {
37  SH_SCALING_B,
38  SH_SCALING_W,
39  SH_SCALING_L,
41 } SHScaling;
enum sh_scaling_t SHScaling
@ 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

◆ SHOpMnem

enum SHOpMnem
Enumerator
SH_OP_INVALID 
SH_OP_MOV 
SH_OP_MOVT 
SH_OP_SWAP 
SH_OP_XTRCT 
SH_OP_ADD 
SH_OP_ADDC 
SH_OP_ADDV 
SH_OP_CMP_EQ 
SH_OP_CMP_HS 
SH_OP_CMP_GE 
SH_OP_CMP_HI 
SH_OP_CMP_GT 
SH_OP_CMP_PZ 
SH_OP_CMP_PL 
SH_OP_CMP_STR 
SH_OP_DIV1 
SH_OP_DIV0S 
SH_OP_DIV0U 
SH_OP_DMULS 
SH_OP_DMULU 
SH_OP_DT 
SH_OP_EXTS 
SH_OP_EXTU 
SH_OP_MAC 
SH_OP_MUL 
SH_OP_MULS 
SH_OP_MULU 
SH_OP_NEG 
SH_OP_NEGC 
SH_OP_SUB 
SH_OP_SUBC 
SH_OP_SUBV 
SH_OP_AND 
SH_OP_NOT 
SH_OP_OR 
SH_OP_TAS 
SH_OP_TST 
SH_OP_XOR 
SH_OP_ROTL 
SH_OP_ROTR 
SH_OP_ROTCL 
SH_OP_ROTCR 
SH_OP_SHAD 
SH_OP_SHAL 
SH_OP_SHAR 
SH_OP_SHLD 
SH_OP_SHLL 
SH_OP_SHLR 
SH_OP_SHLL2 
SH_OP_SHLR2 
SH_OP_SHLL8 
SH_OP_SHLR8 
SH_OP_SHLL16 
SH_OP_SHLR16 
SH_OP_BF 
SH_OP_BFS 
SH_OP_BT 
SH_OP_BTS 
SH_OP_BRA 
SH_OP_BRAF 
SH_OP_BSR 
SH_OP_BSRF 
SH_OP_JMP 
SH_OP_JSR 
SH_OP_RTS 
SH_OP_CLRMAC 
SH_OP_CLRS 
SH_OP_CLRT 
SH_OP_LDC 
SH_OP_LDS 
SH_OP_MOVCA 
SH_OP_NOP 
SH_OP_RTE 
SH_OP_SETS 
SH_OP_SETT 
SH_OP_SLEEP 
SH_OP_STC 
SH_OP_STS 
SH_OP_UNIMPL 
SH_OP_SIZE 

Definition at line 152 of file disassembler.h.

152  {
153  SH_OP_INVALID = 0,
154  SH_OP_MOV,
155  SH_OP_MOVT,
156  SH_OP_SWAP,
157  SH_OP_XTRCT,
158  SH_OP_ADD,
159  SH_OP_ADDC,
160  SH_OP_ADDV,
161  SH_OP_CMP_EQ,
162  SH_OP_CMP_HS,
163  SH_OP_CMP_GE,
164  SH_OP_CMP_HI,
165  SH_OP_CMP_GT,
166  SH_OP_CMP_PZ,
167  SH_OP_CMP_PL,
169  SH_OP_DIV1,
170  SH_OP_DIV0S,
171  SH_OP_DIV0U,
172  SH_OP_DMULS,
173  SH_OP_DMULU,
174  SH_OP_DT,
175  SH_OP_EXTS,
176  SH_OP_EXTU,
177  SH_OP_MAC,
178  SH_OP_MUL,
179  SH_OP_MULS,
180  SH_OP_MULU,
181  SH_OP_NEG,
182  SH_OP_NEGC,
183  SH_OP_SUB,
184  SH_OP_SUBC,
185  SH_OP_SUBV,
186  SH_OP_AND,
187  SH_OP_NOT,
188  SH_OP_OR,
189  SH_OP_TAS,
190  SH_OP_TST,
191  SH_OP_XOR,
192  SH_OP_ROTL,
193  SH_OP_ROTR,
194  SH_OP_ROTCL,
195  SH_OP_ROTCR,
196  SH_OP_SHAD,
197  SH_OP_SHAL,
198  SH_OP_SHAR,
199  SH_OP_SHLD,
200  SH_OP_SHLL,
201  SH_OP_SHLR,
202  SH_OP_SHLL2,
203  SH_OP_SHLR2,
204  SH_OP_SHLL8,
205  SH_OP_SHLR8,
206  SH_OP_SHLL16,
207  SH_OP_SHLR16,
208  SH_OP_BF,
209  SH_OP_BFS,
210  SH_OP_BT,
211  SH_OP_BTS,
212  SH_OP_BRA,
213  SH_OP_BRAF,
214  SH_OP_BSR,
215  SH_OP_BSRF,
216  SH_OP_JMP,
217  SH_OP_JSR,
218  SH_OP_RTS,
219  SH_OP_CLRMAC,
220  SH_OP_CLRS,
221  SH_OP_CLRT,
222  SH_OP_LDC,
223  SH_OP_LDS,
224  SH_OP_MOVCA,
225  SH_OP_NOP,
226  SH_OP_RTE,
227  SH_OP_SETS,
228  SH_OP_SETT,
229  SH_OP_SLEEP,
230  SH_OP_STC,
231  SH_OP_STS,
232  SH_OP_UNIMPL,
233  /* end */
234  SH_OP_SIZE
235 } SHOpMnem;
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

Function Documentation

◆ sh_disassembler()

RZ_IPI RZ_OWN SHOp* sh_disassembler ( ut16  opcode)

Disassemble opcode and return a SHOp.

Parameters
opcode16 bit wide opcode
Returns
SHOp object corresponding to the opcode

Definition at line 130 of file disassembler.c.

130  {
131  for (ut16 i = 0; i < OPCODE_NUM; i++) {
132  if ((opcode | sh_op_lookup[i].mask) != sh_op_lookup[i].opcode) {
133  continue;
134  }
135 
136  SHOpRaw raw = sh_op_lookup[i];
137  SHOp *op = RZ_NEW(SHOp);
138  op->opcode = opcode;
139  op->mnemonic = raw.mnemonic;
140  op->scaling = raw.scaling;
141  op->str_mnem = raw.str_mnem;
142  // check for "weird" mov.l
143  if (raw.opcode == MOVL) {
144  op->param[0] = sh_op_get_param_movl(opcode, true);
145  op->param[1] = sh_op_get_param_movl(opcode, false);
146  return op;
147  }
148  op->param[0] = sh_op_get_param(opcode, raw.param_builder[0]);
149  op->param[1] = sh_op_get_param(opcode, raw.param_builder[1]);
150  return op;
151  }
152 
153  RZ_LOG_DEBUG("SuperH: Invalid opcode encountered by disassembler: 0x%06x\n", opcode);
154  return NULL;
155 }
ut8 op
Definition: 6502dis.c:13
#define mask()
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
uint16_t ut16
#define MOVL
Definition: common.h:70
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
#define RZ_NEW(x)
Definition: rz_types.h:285
static SHParam sh_op_get_param(ut16 opcode, SHParamBuilder shb)
Get SHParam from opcode Make sure the opcode is passed in little-endian form.
Definition: disassembler.c:18
const SHOpRaw sh_op_lookup[]
Definition: lookup.c:7
static SHParam sh_op_get_param_movl(ut16 opcode, bool m)
Get params for mov.l instruction (0001NMD) A special function is required because the nibbles for the...
Definition: disassembler.c:110
const ut32 OPCODE_NUM
Definition: lookup.c:195
const char * str_mnem
string mnemonic
Definition: common.h:25
SHScaling scaling
scaling for the opcode
Definition: common.h:29
SHOpMnem mnemonic
enum mnemonic
Definition: common.h:26
SHParamBuilder param_builder[2]
param builders for the params
Definition: common.h:30
ut16 opcode
opcode
Definition: common.h:27
Definition: dis.c:32

References i, mask, sh_op_raw_t::mnemonic, MOVL, NULL, op, sh_op_raw_t::opcode, OPCODE_NUM, sh_op_raw_t::param_builder, RZ_LOG_DEBUG, RZ_NEW, sh_op_raw_t::scaling, sh_op_get_param(), sh_op_get_param_movl(), sh_op_lookup, and sh_op_raw_t::str_mnem.

Referenced by disassemble(), and sh_op().

◆ sh_op_param_to_str()

RZ_IPI RZ_OWN char* sh_op_param_to_str ( SHParam  param,
SHScaling  scaling,
ut64  pc 
)

Return string representation of disassembled param.

Parameters
SHParamto be disassembled
SHScalingof the instruction associated with the param
Returns
char *, owned by the caller

Definition at line 166 of file disassembler.c.

166  {
167  if (param.mode == SH_ADDR_INVALID) {
168  return NULL;
169  }
170 
172  switch (param.mode) {
173  case SH_REG_DIRECT:
174  rz_strbuf_appendf(buf, "%s", sh_registers[param.param[0]]);
175  break;
176  case SH_REG_INDIRECT:
177  rz_strbuf_appendf(buf, "@%s", sh_registers[param.param[0]]);
178  break;
179  case SH_REG_INDIRECT_I:
180  rz_strbuf_appendf(buf, "@%s+", sh_registers[param.param[0]]);
181  break;
182  case SH_REG_INDIRECT_D:
183  rz_strbuf_appendf(buf, "@-%s", sh_registers[param.param[0]]);
184  break;
186  rz_strbuf_appendf(buf, "@(0x%02x,%s)", param.param[1] * sh_scaling_size[scaling], sh_registers[param.param[0]]);
187  break;
189  rz_strbuf_appendf(buf, "@(r0,%s)", sh_registers[param.param[0]]);
190  break;
192  rz_strbuf_appendf(buf, "@(0x%03x,gbr)", param.param[0] * sh_scaling_size[scaling]);
193  break;
195  rz_strbuf_append(buf, "@(r0,gbr)");
196  break;
197  case SH_PC_RELATIVE_DISP:
198  rz_strbuf_appendf(buf, "@(0x%03x,pc)", param.param[0] * sh_scaling_size[scaling]);
199  break;
200  case SH_PC_RELATIVE8:
201  case SH_PC_RELATIVE12:
202  rz_strbuf_appendf(buf, "0x%08x", (ut32)pc + 4 + (st32)((st8)param.param[0]) * 2);
203  break;
204  case SH_PC_RELATIVE_REG:
205  rz_strbuf_appendf(buf, "%s", sh_registers[param.param[0]]);
206  break;
207  case SH_IMM_U:
208  case SH_IMM_S:
209  rz_strbuf_appendf(buf, "0x%02x", param.param[0]);
210  break;
211  default:
213  }
214 
215  return rz_strbuf_drain(buf);
216 }
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
static const char * sh_registers[]
Definition: regs.h:10
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define st8
Definition: rz_types_base.h:16
#define st32
Definition: rz_types_base.h:12
static const ut8 sh_scaling_size[]
Definition: disassembler.h:43
ut16 param[2]
Definition: disassembler.h:238
SHAddrMode mode
Definition: disassembler.h:239

References sh_param_t::mode, NULL, sh_param_t::param, pc, rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), rz_warn_if_reached, SH_ADDR_INVALID, SH_GBR_INDIRECT_DISP, SH_GBR_INDIRECT_INDEXED, SH_IMM_S, SH_IMM_U, SH_PC_RELATIVE12, SH_PC_RELATIVE8, SH_PC_RELATIVE_DISP, SH_PC_RELATIVE_REG, SH_REG_DIRECT, SH_REG_INDIRECT, SH_REG_INDIRECT_D, SH_REG_INDIRECT_DISP, SH_REG_INDIRECT_I, SH_REG_INDIRECT_INDEXED, sh_registers, sh_scaling_size, st32, and st8.

Referenced by sh_op_to_str().

◆ sh_op_to_str()

RZ_IPI RZ_OWN char* sh_op_to_str ( RZ_NONNULL const SHOp op,
ut64  pc 
)

Return string representation of disassembled op.

Parameters
SHOpto be disassembled
Returns
char *, owned by the caller

Definition at line 224 of file disassembler.c.

224  {
226  if (!op->str_mnem) {
227  return NULL;
228  }
229  RzStrBuf *buf = rz_strbuf_new(op->str_mnem);
230 
231  char *param = NULL;
232  if ((param = sh_op_param_to_str(op->param[0], op->scaling, pc))) {
233  rz_strbuf_appendf(buf, " %s", param);
234  free(param);
235  if ((param = sh_op_param_to_str(op->param[1], op->scaling, pc))) {
236  rz_strbuf_appendf(buf, ", %s", param);
237  free(param);
238  }
239  }
240 
241  return rz_strbuf_drain(buf);
242 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
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

References free(), NULL, pc, rz_return_val_if_fail, rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), and sh_op_param_to_str().

Referenced by disassemble().

Variable Documentation

◆ sh_scaling_size

const ut8 sh_scaling_size[] = { -1, 1, 2, 4, 8 }
static