Rizin
unix-like reverse engineering framework and cli tools
or1k_disas.h File Reference
#include <rz_lib.h>

Go to the source code of this file.

Classes

struct  insn_oper_descr_t
 
struct  insn_type_descr_t
 
struct  insn_extra_t
 
struct  insn_t
 

Macros

#define INSN_OPCODE_MASK   (0x3fULL * 0x4000000)
 
#define INSN_OPCODE_SHIFT   26
 
#define INSN_EMPTY_SHIFT   0
 
#define INSN_EMPTY_MASK   0
 
#define INSN_N_MASK   0x3ffffff
 
#define INSN_D_SHIFT   21
 
#define INSN_D_MASK   (0x1f * 0x200000)
 
#define INSN_K_MASK   0xffff
 
#define INSN_B_SHIFT   11
 
#define INSN_B_MASK   (0x1f * 0x800)
 
#define INSN_A_SHIFT   16
 
#define INSN_A_MASK   (0x1f * 0x10000)
 
#define INSN_I_MASK   0xffff
 
#define INSN_L_MASK   0x3f
 
#define INSN_K1_SHIFT   21
 
#define INSN_K1_MASK   (0x1f * 0x200000)
 
#define INSN_K2_MASK   0x7ff
 

Typedefs

typedef enum insn_type insn_type_t
 

Enumerations

enum  insn_type {
  INSN_END = 0 , INSN_INVAL = 0 , INSN_X , INSN_N ,
  INSN_DN , INSN_K , INSN_DK , INSN_D ,
  INSN_B , INSN_AI , INSN_DAI , INSN_DAK ,
  INSN_DAL , INSN_KABK , INSN_AB , INSN_DA ,
  INSN_DAB , INSN_IABI , INSN_SIZE
}
 
enum  insn_oper_t {
  INSN_OPER_K1 , INSN_OPER_K2 , INSN_OPER_A , INSN_OPER_B ,
  INSN_OPER_N , INSN_OPER_K , INSN_OPER_D , INSN_OPER_I ,
  INSN_OPER_L , INSN_OPER_SIZE
}
 

Functions

insn_extra_tfind_extra_descriptor (insn_extra_t *extra_descr, ut32 insn)
 
ut32 sign_extend (ut32 number, ut32 mask)
 Performs sign extension of number. More...
 
static ut32 get_operand_mask (insn_type_descr_t *type_descr, insn_oper_t operand)
 
static ut32 get_operand_shift (insn_type_descr_t *type_descr, insn_oper_t operand)
 
static ut32 get_operand_value (ut32 insn, insn_type_descr_t *type_descr, insn_oper_t operand)
 
static int has_type_descriptor (insn_type_t type)
 
static int is_type_descriptor_defined (insn_type_t type)
 
static insn_type_t type_of_opcode (insn_t *descr, insn_extra_t *extra_descr)
 

Variables

insn_type_descr_t types []
 
size_t types_count
 
insn_extra_t extra_0x5 []
 
insn_extra_t extra_0x6 []
 
insn_extra_t extra_0x8 []
 
insn_extra_t extra_0x2e []
 
insn_extra_t extra_0x2f []
 
insn_extra_t extra_0x31 []
 
insn_extra_t extra_0x32 []
 
insn_extra_t extra_0x38 []
 
insn_extra_t extra_0x39 []
 
insn_t or1k_insns []
 
size_t insns_count
 

Macro Definition Documentation

◆ INSN_A_MASK

#define INSN_A_MASK   (0x1f * 0x10000)

Mask for A operand

Definition at line 36 of file or1k_disas.h.

◆ INSN_A_SHIFT

#define INSN_A_SHIFT   16

Shift for A operand

Definition at line 34 of file or1k_disas.h.

◆ INSN_B_MASK

#define INSN_B_MASK   (0x1f * 0x800)

Mask for B operand

Definition at line 31 of file or1k_disas.h.

◆ INSN_B_SHIFT

#define INSN_B_SHIFT   11

Shift for B operand

Definition at line 29 of file or1k_disas.h.

◆ INSN_D_MASK

#define INSN_D_MASK   (0x1f * 0x200000)

Mask for D operand

Definition at line 23 of file or1k_disas.h.

◆ INSN_D_SHIFT

#define INSN_D_SHIFT   21

Shift for D operand

Definition at line 21 of file or1k_disas.h.

◆ INSN_EMPTY_MASK

#define INSN_EMPTY_MASK   0

Definition at line 15 of file or1k_disas.h.

◆ INSN_EMPTY_SHIFT

#define INSN_EMPTY_SHIFT   0

Empty mask for unused operands

Definition at line 14 of file or1k_disas.h.

◆ INSN_I_MASK

#define INSN_I_MASK   0xffff

Mask for I operand

Definition at line 39 of file or1k_disas.h.

◆ INSN_K1_MASK

#define INSN_K1_MASK   (0x1f * 0x200000)

Mask for first K operand

Definition at line 47 of file or1k_disas.h.

◆ INSN_K1_SHIFT

#define INSN_K1_SHIFT   21

Shift for first K operand

Definition at line 45 of file or1k_disas.h.

◆ INSN_K2_MASK

#define INSN_K2_MASK   0x7ff

Mask for second K operand

Definition at line 50 of file or1k_disas.h.

◆ INSN_K_MASK

#define INSN_K_MASK   0xffff

Mask for K operand

Definition at line 26 of file or1k_disas.h.

◆ INSN_L_MASK

#define INSN_L_MASK   0x3f

Mask for L operand

Definition at line 42 of file or1k_disas.h.

◆ INSN_N_MASK

#define INSN_N_MASK   0x3ffffff

Mask for N operand

Definition at line 18 of file or1k_disas.h.

◆ INSN_OPCODE_MASK

#define INSN_OPCODE_MASK   (0x3fULL * 0x4000000)

Default mask for opcode

Definition at line 10 of file or1k_disas.h.

◆ INSN_OPCODE_SHIFT

#define INSN_OPCODE_SHIFT   26

Definition at line 11 of file or1k_disas.h.

Typedef Documentation

◆ insn_type_t

typedef enum insn_type insn_type_t

Enumeration Type Documentation

◆ insn_oper_t

Enumerator
INSN_OPER_K1 

5-bit MSBs of immediate

INSN_OPER_K2 

11-bit LSBs of immediate

INSN_OPER_A 

5-bit source register

INSN_OPER_B 

5-bit source register

INSN_OPER_N 

26-bit immediate

INSN_OPER_K 

16-bit immediate

INSN_OPER_D 

5-bit destination register

INSN_OPER_I 

16-bit immediate

INSN_OPER_L 

6-bit immediate

INSN_OPER_SIZE 

number of operand types

Definition at line 80 of file or1k_disas.h.

80  {
81  INSN_OPER_K1,
82  INSN_OPER_K2,
83  INSN_OPER_A,
84  INSN_OPER_B,
85  INSN_OPER_N,
86  INSN_OPER_K,
87  INSN_OPER_D,
88  INSN_OPER_I,
89  INSN_OPER_L,
91 } insn_oper_t;
insn_oper_t
Definition: or1k_disas.h:80
@ INSN_OPER_A
Definition: or1k_disas.h:83
@ INSN_OPER_B
Definition: or1k_disas.h:84
@ INSN_OPER_I
Definition: or1k_disas.h:88
@ INSN_OPER_N
Definition: or1k_disas.h:85
@ INSN_OPER_K
Definition: or1k_disas.h:86
@ INSN_OPER_D
Definition: or1k_disas.h:87
@ INSN_OPER_L
Definition: or1k_disas.h:89
@ INSN_OPER_K2
Definition: or1k_disas.h:82
@ INSN_OPER_SIZE
Definition: or1k_disas.h:90
@ INSN_OPER_K1
Definition: or1k_disas.h:81

◆ insn_type

enum insn_type
Enumerator
INSN_END 

end of array indicator

INSN_INVAL 

invalid opcode

INSN_X 

no operands

INSN_N 

26-bit immediate

INSN_DN 

5-bit destination register, then 26-bit immediate

INSN_K 

16-bit immediate

INSN_DK 

5-bit destination register, then 16-bit immediate

INSN_D 

5-bit destination register

INSN_B 

5-bit source register

INSN_AI 

5-bit source register, then 16-bit immediate

INSN_DAI 

5-bit destination register, 5-bit source register, then 16-bit immediate

INSN_DAK 

5-bit destination register, 5-bit source register, then 16-bit immediate

INSN_DAL 

5-bit destination register, 5-bit source register, then 6-bit immediate

INSN_KABK 

5-bit MSB of immediate, 5-bit source register, 5-bit source register, then 11-bit rest of immediate

INSN_AB 

5-bit source register, then 5-bit source register

INSN_DA 

5-bit destination register, then 5-bit source register

INSN_DAB 

5-bit destination register, 5-bit source register, then 5-bit source register

INSN_IABI 

5-bit MSB of immediate, 5-bit source register, 5-bit source register, then 11-bit rest of immediate

INSN_SIZE 

number of types

Definition at line 52 of file or1k_disas.h.

52  {
53  INSN_END = 0,
54  INSN_INVAL = 0,
55  INSN_X,
56  INSN_N,
57  INSN_DN,
58  INSN_K,
59  INSN_DK,
60  INSN_D,
61  INSN_B,
62  INSN_AI,
63  INSN_DAI,
65  INSN_DAK,
67  INSN_DAL,
69  INSN_KABK,
71  INSN_AB,
72  INSN_DA,
73  INSN_DAB,
75  INSN_IABI,
77  INSN_SIZE,
78 } insn_type_t;
@ INSN_D
Definition: or1k_disas.h:60
@ INSN_DAB
Definition: or1k_disas.h:73
@ INSN_KABK
Definition: or1k_disas.h:69
@ INSN_DA
Definition: or1k_disas.h:72
@ INSN_X
Definition: or1k_disas.h:55
@ INSN_AI
Definition: or1k_disas.h:62
@ INSN_N
Definition: or1k_disas.h:56
@ INSN_END
Definition: or1k_disas.h:53
@ INSN_B
Definition: or1k_disas.h:61
@ INSN_DN
Definition: or1k_disas.h:57
@ INSN_DAL
Definition: or1k_disas.h:67
@ INSN_IABI
Definition: or1k_disas.h:75
@ INSN_K
Definition: or1k_disas.h:58
@ INSN_DAI
Definition: or1k_disas.h:63
@ INSN_AB
Definition: or1k_disas.h:71
@ INSN_DK
Definition: or1k_disas.h:59
@ INSN_SIZE
Definition: or1k_disas.h:77
@ INSN_INVAL
Definition: or1k_disas.h:54
@ INSN_DAK
Definition: or1k_disas.h:65
enum insn_type insn_type_t

Function Documentation

◆ find_extra_descriptor()

insn_extra_t* find_extra_descriptor ( insn_extra_t extra_descr,
ut32  insn 
)

Definition at line 288 of file or1k_disas.c.

288  {
289  ut32 opcode;
290  while (extra_descr->type != INSN_END) {
291  opcode = (insn & extra_descr->opcode_mask);
292  if (extra_descr->opcode == opcode) {
293  break;
294  }
295  extra_descr++;
296  }
297  if (extra_descr->type != INSN_END) {
298  return extra_descr;
299  } else {
300  return NULL;
301  }
302 }
#define NULL
Definition: cris-opc.c:27
uint32_t ut32

References INSN_END, NULL, insn_extra_t::opcode, insn_extra_t::opcode_mask, and insn_extra_t::type.

Referenced by disassemble(), and or1k_op().

◆ get_operand_mask()

static ut32 get_operand_mask ( insn_type_descr_t type_descr,
insn_oper_t  operand 
)
inlinestatic

Definition at line 152 of file or1k_disas.h.

152  {
153  return type_descr->operands[operand].mask;
154 }
operand
Definition: arc-opc.c:39
insn_oper_descr_t operands[INSN_OPER_SIZE]
Definition: or1k_disas.h:102

References insn_oper_descr_t::mask, and insn_type_descr_t::operands.

Referenced by get_operand_value(), insn_to_op(), and insn_to_str().

◆ get_operand_shift()

static ut32 get_operand_shift ( insn_type_descr_t type_descr,
insn_oper_t  operand 
)
inlinestatic

Definition at line 156 of file or1k_disas.h.

156  {
157  return type_descr->operands[operand].shift;
158 }

References insn_type_descr_t::operands, and insn_oper_descr_t::shift.

Referenced by get_operand_value().

◆ get_operand_value()

static ut32 get_operand_value ( ut32  insn,
insn_type_descr_t type_descr,
insn_oper_t  operand 
)
inlinestatic

Definition at line 160 of file or1k_disas.h.

160  {
161  return (insn & get_operand_mask(type_descr, operand)) >> get_operand_shift(type_descr, operand);
162 }
static ut32 get_operand_mask(insn_type_descr_t *type_descr, insn_oper_t operand)
Definition: or1k_disas.h:152
static ut32 get_operand_shift(insn_type_descr_t *type_descr, insn_oper_t operand)
Definition: or1k_disas.h:156

References get_operand_mask(), and get_operand_shift().

Referenced by insn_to_op(), and insn_to_str().

◆ has_type_descriptor()

static int has_type_descriptor ( insn_type_t  type)
inlinestatic

Definition at line 164 of file or1k_disas.h.

164  {
165  return types + types_count > &types[type];
166 }
int type
Definition: mipsasm.c:17
insn_type_descr_t types[]
Definition: or1k_disas.c:7
size_t types_count
Definition: or1k_disas.c:76

References type, types, and types_count.

Referenced by insn_to_op(), and insn_to_str().

◆ is_type_descriptor_defined()

static int is_type_descriptor_defined ( insn_type_t  type)
inlinestatic

Definition at line 168 of file or1k_disas.h.

168  {
169  return types[type].type == type;
170 }

References type, insn_type_descr_t::type, and types.

Referenced by insn_to_op(), and insn_to_str().

◆ sign_extend()

ut32 sign_extend ( ut32  number,
ut32  mask 
)

Performs sign extension of number.

Parameters
numbernumber to extend
maskmask under which number is placed
Returns
sign-extended number

If mask does not begin on the lsb, space on the right will also be filled with ones

Definition at line 304 of file or1k_disas.c.

304  {
305  /* xor of mask with itself shifted left detects msb of mask and msb of space
306  * on the right. And discards the latter */
307  ut32 first_bit = (mask ^ (mask >> 1)) & mask;
308  /* if first bit is set */
309  if (number & first_bit) {
310  /* set every bit outside mask */
311  number |= ~mask;
312  }
313  return number;
314 }
#define mask()

References mask.

◆ type_of_opcode()

static insn_type_t type_of_opcode ( insn_t descr,
insn_extra_t extra_descr 
)
inlinestatic

Definition at line 172 of file or1k_disas.h.

172  {
174 
175  if (extra_descr == NULL) {
176  return descr->type;
177  } else {
178  return extra_descr->type;
179  }
180 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
int type
Definition: or1k_disas.h:116

References INSN_END, NULL, rz_return_val_if_fail, insn_extra_t::type, and insn_t::type.

Referenced by insn_to_op(), and insn_to_str().

Variable Documentation

◆ extra_0x2e

insn_extra_t extra_0x2e[]
extern

Definition at line 98 of file or1k_disas.c.

◆ extra_0x2f

insn_extra_t extra_0x2f[]
extern

Definition at line 106 of file or1k_disas.c.

◆ extra_0x31

insn_extra_t extra_0x31[]
extern

Definition at line 120 of file or1k_disas.c.

◆ extra_0x32

insn_extra_t extra_0x32[]
extern

Definition at line 128 of file or1k_disas.c.

◆ extra_0x38

insn_extra_t extra_0x38[]
extern

Definition at line 176 of file or1k_disas.c.

◆ extra_0x39

insn_extra_t extra_0x39[]
extern

Definition at line 205 of file or1k_disas.c.

◆ extra_0x5

insn_extra_t extra_0x5[]
extern

Definition at line 78 of file or1k_disas.c.

◆ extra_0x6

insn_extra_t extra_0x6[]
extern

Definition at line 83 of file or1k_disas.c.

◆ extra_0x8

insn_extra_t extra_0x8[]
extern

Definition at line 89 of file or1k_disas.c.

◆ insns_count

size_t insns_count
extern

Definition at line 286 of file or1k_disas.c.

Referenced by disassemble(), and or1k_op().

◆ or1k_insns

insn_t or1k_insns[]
extern

Definition at line 219 of file or1k_disas.c.

Referenced by disassemble(), and or1k_op().

◆ types

◆ types_count

size_t types_count
extern

Definition at line 76 of file or1k_disas.c.

Referenced by has_type_descriptor().