Rizin
unix-like reverse engineering framework and cli tools
common.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_COMMON_H
5 #define RZ_SH_COMMON_H
6 
7 #include "disassembler.h"
8 
13 };
14 
15 typedef struct sh_param_builder_t {
16  // either find the param using param builder or use an already provided param
17  union {
20  };
21  bool is_param;
23 
24 typedef struct sh_op_raw_t {
25  const char *str_mnem;
32 
33 // xxxx used to denote param fields in the opcode
34 #define I f
35 #define N f
36 #define D f
37 #define M f
38 
39 // to form opcode in nibbles
40 #define OPCODE_(a, b, c, d) 0x##a##b##c##d
41 #define OPCODE(a, b, c, d) OPCODE_(a, b, c, d)
42 
43 // nibble position
44 #define NIB0 0
45 #define NIB1 4
46 #define NIB2 8
47 #define NIB3 12
48 
49 // return a param builder struct
50 #define ADDR(nib, addrmode) \
51  { \
52  { .addr = { .start = nib, .bits = -1, .mode = addrmode } }, .is_param = false \
53  }
54 
55 // return a param builder struct with custom bit read length
56 #define ADDRBITS(nib, addrmode, b) \
57  { \
58  { .addr = { .start = nib, .bits = b, .mode = addrmode } }, .is_param = false \
59  }
60 
61 // return a param
62 #define PARAM(reg, addrmode) \
63  { { .param = { .param = { \
64  SH_REG_IND_##reg, \
65  }, \
66  .mode = addrmode } }, \
67  .is_param = true }
68 
69 // opcode for "weird" movl
70 #define MOVL 0x1fff
71 
72 #define NOPARAM ADDR(NIB0, SH_ADDR_INVALID)
73 
74 #endif // RZ_SH_COMMON_H
uint16_t ut16
uint8_t ut8
Definition: lh5801.h:11
struct sh_param_builder_t SHParamBuilder
struct sh_op_raw_t SHOpRaw
#define st8
Definition: rz_types_base.h:16
enum sh_scaling_t SHScaling
enum sh_addr_mode_t SHAddrMode
SHOpMnem
Definition: disassembler.h:152
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
ut16 mask
mask for opcode to mask out param bits
Definition: common.h:28
ut8 start
start bit of the param (assuming little-endian)
Definition: common.h:10
SHAddrMode mode
addressing mode being used
Definition: common.h:12
st8 bits
bits to be read (-1, if you want this to be inferred from mode)
Definition: common.h:11
SHParam param
Definition: common.h:19
struct sh_param_builder_addr_t addr
Definition: common.h:18
bool is_param
whether a param was directly passed
Definition: common.h:21