Rizin
unix-like reverse engineering framework and cli tools
or1k_disas.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2019 v3l0c1r4pt0r <v3l0c1r4pt0r@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_lib.h>
5 
6 #ifndef OR1K_DISAS_H
7 #define OR1K_DISAS_H
8 
10 #define INSN_OPCODE_MASK (0x3fULL * 0x4000000)
11 #define INSN_OPCODE_SHIFT 26
12 
14 #define INSN_EMPTY_SHIFT 0
15 #define INSN_EMPTY_MASK 0
16 
18 #define INSN_N_MASK 0x3ffffff
19 
21 #define INSN_D_SHIFT 21
23 #define INSN_D_MASK (0x1f * 0x200000)
24 
26 #define INSN_K_MASK 0xffff
27 
29 #define INSN_B_SHIFT 11
31 #define INSN_B_MASK (0x1f * 0x800)
32 
34 #define INSN_A_SHIFT 16
36 #define INSN_A_MASK (0x1f * 0x10000)
37 
39 #define INSN_I_MASK 0xffff
40 
42 #define INSN_L_MASK 0x3f
43 
45 #define INSN_K1_SHIFT 21
47 #define INSN_K1_MASK (0x1f * 0x200000)
48 
50 #define INSN_K2_MASK 0x7ff
51 
52 typedef enum insn_type {
53  INSN_END = 0,
54  INSN_INVAL = 0,
63  INSN_DAI,
65  INSN_DAK,
67  INSN_DAL,
69  INSN_KABK,
73  INSN_DAB,
75  INSN_IABI,
79 
80 typedef enum {
92 
93 typedef struct {
94  int oper;
98 
99 typedef struct {
100  int type;
101  char *format;
104 
105 typedef struct {
107  char *name;
108  int type;
110  int insn_type;
111 } insn_extra_t;
112 
113 typedef struct {
115  char *name;
116  int type;
117  int insn_type;
119 } insn_t;
120 
121 extern insn_type_descr_t types[];
122 extern size_t types_count;
123 
124 extern insn_extra_t extra_0x5[];
125 extern insn_extra_t extra_0x6[];
126 extern insn_extra_t extra_0x8[];
127 extern insn_extra_t extra_0x2e[];
128 extern insn_extra_t extra_0x2f[];
129 extern insn_extra_t extra_0x31[];
130 extern insn_extra_t extra_0x32[];
131 extern insn_extra_t extra_0x38[];
132 extern insn_extra_t extra_0x39[];
133 
134 extern insn_t or1k_insns[];
135 extern size_t insns_count;
136 
138 
150 ut32 sign_extend(ut32 number, ut32 mask);
151 
153  return type_descr->operands[operand].mask;
154 }
155 
157  return type_descr->operands[operand].shift;
158 }
159 
160 static inline ut32 get_operand_value(ut32 insn, insn_type_descr_t *type_descr, insn_oper_t operand) {
161  return (insn & get_operand_mask(type_descr, operand)) >> get_operand_shift(type_descr, operand);
162 }
163 
165  return types + types_count > &types[type];
166 }
167 
169  return types[type].type == type;
170 }
171 
172 static inline insn_type_t type_of_opcode(insn_t *descr, insn_extra_t *extra_descr) {
174 
175  if (extra_descr == NULL) {
176  return descr->type;
177  } else {
178  return extra_descr->type;
179  }
180 }
181 
182 #endif /* OR1K_DISAS_H */
#define mask()
operand
Definition: arc-opc.c:39
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
int type
Definition: mipsasm.c:17
ut32 sign_extend(ut32 number, ut32 mask)
Performs sign extension of number.
Definition: or1k_disas.c:304
insn_extra_t extra_0x32[]
Definition: or1k_disas.c:128
insn_extra_t extra_0x39[]
Definition: or1k_disas.c:205
insn_extra_t extra_0x5[]
Definition: or1k_disas.c:78
insn_t or1k_insns[]
Definition: or1k_disas.c:219
insn_extra_t extra_0x2f[]
Definition: or1k_disas.c:106
insn_extra_t extra_0x31[]
Definition: or1k_disas.c:120
insn_type_descr_t types[]
Definition: or1k_disas.c:7
insn_extra_t extra_0x6[]
Definition: or1k_disas.c:83
insn_extra_t extra_0x8[]
Definition: or1k_disas.c:89
static ut32 get_operand_mask(insn_type_descr_t *type_descr, insn_oper_t operand)
Definition: or1k_disas.h:152
insn_extra_t extra_0x2e[]
Definition: or1k_disas.c:98
size_t types_count
Definition: or1k_disas.c:76
static int is_type_descriptor_defined(insn_type_t type)
Definition: or1k_disas.h:168
static int has_type_descriptor(insn_type_t type)
Definition: or1k_disas.h:164
insn_type
Definition: or1k_disas.h:52
@ 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
size_t insns_count
Definition: or1k_disas.c:286
static ut32 get_operand_shift(insn_type_descr_t *type_descr, insn_oper_t operand)
Definition: or1k_disas.h:156
static ut32 get_operand_value(ut32 insn, insn_type_descr_t *type_descr, insn_oper_t operand)
Definition: or1k_disas.h:160
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
static insn_type_t type_of_opcode(insn_t *descr, insn_extra_t *extra_descr)
Definition: or1k_disas.h:172
insn_extra_t extra_0x38[]
Definition: or1k_disas.c:176
insn_extra_t * find_extra_descriptor(insn_extra_t *extra_descr, ut32 insn)
Definition: or1k_disas.c:288
enum insn_type insn_type_t
uint64_t insn_t
Definition: riscv.h:31
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
char * name
Definition: or1k_disas.h:107
ut32 opcode
Definition: or1k_disas.h:114
insn_extra_t * extra
Definition: or1k_disas.h:118
char * name
Definition: or1k_disas.h:115
int type
Definition: or1k_disas.h:116
int insn_type
Definition: or1k_disas.h:117
insn_oper_descr_t operands[INSN_OPER_SIZE]
Definition: or1k_disas.h:102