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  avr_opcode_t
 

Typedefs

typedef struct avr_opcode_t AVROp
 

Enumerations

enum  AVROpMnem {
  AVR_OP_INVALID = 0 , AVR_OP_ADC , AVR_OP_ADD , AVR_OP_ADIW ,
  AVR_OP_AND , AVR_OP_ANDI , AVR_OP_ASR , AVR_OP_BLD ,
  AVR_OP_BRCC , AVR_OP_BRCS , AVR_OP_BREAK , AVR_OP_BREQ ,
  AVR_OP_BRGE , AVR_OP_BRHC , AVR_OP_BRHS , AVR_OP_BRID ,
  AVR_OP_BRIE , AVR_OP_BRLO , AVR_OP_BRLT , AVR_OP_BRMI ,
  AVR_OP_BRNE , AVR_OP_BRPL , AVR_OP_BRSH , AVR_OP_BRTC ,
  AVR_OP_BRTS , AVR_OP_BRVC , AVR_OP_BRVS , AVR_OP_BST ,
  AVR_OP_CALL , AVR_OP_CBI , AVR_OP_CLC , AVR_OP_CLH ,
  AVR_OP_CLI , AVR_OP_CLN , AVR_OP_CLR , AVR_OP_CLS ,
  AVR_OP_CLT , AVR_OP_CLV , AVR_OP_CLZ , AVR_OP_COM ,
  AVR_OP_CP , AVR_OP_CPC , AVR_OP_CPI , AVR_OP_CPSE ,
  AVR_OP_DEC , AVR_OP_DES , AVR_OP_EICALL , AVR_OP_EIJMP ,
  AVR_OP_ELPM , AVR_OP_EOR , AVR_OP_FMUL , AVR_OP_FMULS ,
  AVR_OP_FMULSU , AVR_OP_ICALL , AVR_OP_IJMP , AVR_OP_IN ,
  AVR_OP_INC , AVR_OP_JMP , AVR_OP_LAC , AVR_OP_LAS ,
  AVR_OP_LAT , AVR_OP_LD , AVR_OP_LDD , AVR_OP_LDI ,
  AVR_OP_LDS , AVR_OP_LPM , AVR_OP_LSL , AVR_OP_LSR ,
  AVR_OP_MOV , AVR_OP_MOVW , AVR_OP_MUL , AVR_OP_MULS ,
  AVR_OP_MULSU , AVR_OP_NEG , AVR_OP_NOP , AVR_OP_OR ,
  AVR_OP_ORI , AVR_OP_OUT , AVR_OP_POP , AVR_OP_PUSH ,
  AVR_OP_RCALL , AVR_OP_RET , AVR_OP_RETI , AVR_OP_RJMP ,
  AVR_OP_ROL , AVR_OP_ROR , AVR_OP_SBC , AVR_OP_SBCI ,
  AVR_OP_SBI , AVR_OP_SBIC , AVR_OP_SBIS , AVR_OP_SBIW ,
  AVR_OP_SBRC , AVR_OP_SBRS , AVR_OP_SEC , AVR_OP_SEH ,
  AVR_OP_SEI , AVR_OP_SEN , AVR_OP_SER , AVR_OP_SES ,
  AVR_OP_SET , AVR_OP_SEV , AVR_OP_SEZ , AVR_OP_SLEEP ,
  AVR_OP_SPM , AVR_OP_ST , AVR_OP_STD , AVR_OP_STS ,
  AVR_OP_SUB , AVR_OP_SUBI , AVR_OP_SWAP , AVR_OP_TST ,
  AVR_OP_WDR , AVR_OP_XCH , AVR_OP_SIZE
}
 

Functions

ut32 avr_disassembler (const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp *aop, RzStrBuf *sb)
 

Typedef Documentation

◆ AVROp

typedef struct avr_opcode_t AVROp

Enumeration Type Documentation

◆ AVROpMnem

enum AVROpMnem
Enumerator
AVR_OP_INVALID 
AVR_OP_ADC 
AVR_OP_ADD 
AVR_OP_ADIW 
AVR_OP_AND 
AVR_OP_ANDI 
AVR_OP_ASR 
AVR_OP_BLD 
AVR_OP_BRCC 
AVR_OP_BRCS 
AVR_OP_BREAK 
AVR_OP_BREQ 
AVR_OP_BRGE 
AVR_OP_BRHC 
AVR_OP_BRHS 
AVR_OP_BRID 
AVR_OP_BRIE 
AVR_OP_BRLO 
AVR_OP_BRLT 
AVR_OP_BRMI 
AVR_OP_BRNE 
AVR_OP_BRPL 
AVR_OP_BRSH 
AVR_OP_BRTC 
AVR_OP_BRTS 
AVR_OP_BRVC 
AVR_OP_BRVS 
AVR_OP_BST 
AVR_OP_CALL 
AVR_OP_CBI 
AVR_OP_CLC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definition at line 9 of file disassembler.h.

9  {
10  AVR_OP_INVALID = 0,
11  AVR_OP_ADC,
12  AVR_OP_ADD,
14  AVR_OP_AND,
16  AVR_OP_ASR,
17  AVR_OP_BLD,
37  AVR_OP_BST,
39  AVR_OP_CBI,
40  AVR_OP_CLC,
41  AVR_OP_CLH,
42  AVR_OP_CLI,
43  AVR_OP_CLN,
44  AVR_OP_CLR,
45  AVR_OP_CLS,
46  AVR_OP_CLT,
47  AVR_OP_CLV,
48  AVR_OP_CLZ,
49  AVR_OP_COM,
50  AVR_OP_CP,
51  AVR_OP_CPC,
52  AVR_OP_CPI,
54  AVR_OP_DEC,
55  AVR_OP_DES,
59  AVR_OP_EOR,
65  AVR_OP_IN,
66  AVR_OP_INC,
67  AVR_OP_JMP,
68  AVR_OP_LAC,
69  AVR_OP_LAS,
70  AVR_OP_LAT,
71  AVR_OP_LD,
72  AVR_OP_LDD,
73  AVR_OP_LDI,
74  AVR_OP_LDS,
75  AVR_OP_LPM,
76  AVR_OP_LSL,
77  AVR_OP_LSR,
78  AVR_OP_MOV,
80  AVR_OP_MUL,
83  AVR_OP_NEG,
84  AVR_OP_NOP,
85  AVR_OP_OR,
86  AVR_OP_ORI,
87  AVR_OP_OUT,
88  AVR_OP_POP,
91  AVR_OP_RET,
94  AVR_OP_ROL,
95  AVR_OP_ROR,
96  AVR_OP_SBC,
98  AVR_OP_SBI,
100  AVR_OP_SBIS,
101  AVR_OP_SBIW,
102  AVR_OP_SBRC,
103  AVR_OP_SBRS,
104  AVR_OP_SEC,
105  AVR_OP_SEH,
106  AVR_OP_SEI,
107  AVR_OP_SEN,
108  AVR_OP_SER,
109  AVR_OP_SES,
110  AVR_OP_SET,
111  AVR_OP_SEV,
112  AVR_OP_SEZ,
113  AVR_OP_SLEEP,
114  AVR_OP_SPM,
115  AVR_OP_ST,
116  AVR_OP_STD,
117  AVR_OP_STS,
118  AVR_OP_SUB,
119  AVR_OP_SUBI,
120  AVR_OP_SWAP,
121  AVR_OP_TST,
122  AVR_OP_WDR,
123  AVR_OP_XCH,
124  /* end */
126 } AVROpMnem;
AVROpMnem
Definition: disassembler.h:9
@ AVR_OP_AND
Definition: disassembler.h:14
@ AVR_OP_INC
Definition: disassembler.h:66
@ AVR_OP_BREAK
Definition: disassembler.h:20
@ AVR_OP_DEC
Definition: disassembler.h:54
@ AVR_OP_BRNE
Definition: disassembler.h:30
@ AVR_OP_MUL
Definition: disassembler.h:80
@ AVR_OP_CP
Definition: disassembler.h:50
@ AVR_OP_CPC
Definition: disassembler.h:51
@ AVR_OP_SPM
Definition: disassembler.h:114
@ AVR_OP_INVALID
Definition: disassembler.h:10
@ AVR_OP_IJMP
Definition: disassembler.h:64
@ AVR_OP_LDD
Definition: disassembler.h:72
@ AVR_OP_FMULSU
Definition: disassembler.h:62
@ AVR_OP_LAT
Definition: disassembler.h:70
@ AVR_OP_BRSH
Definition: disassembler.h:32
@ AVR_OP_SWAP
Definition: disassembler.h:120
@ AVR_OP_CBI
Definition: disassembler.h:39
@ AVR_OP_LSR
Definition: disassembler.h:77
@ AVR_OP_SBCI
Definition: disassembler.h:97
@ AVR_OP_BRGE
Definition: disassembler.h:22
@ AVR_OP_ADIW
Definition: disassembler.h:13
@ AVR_OP_CPSE
Definition: disassembler.h:53
@ AVR_OP_SBRC
Definition: disassembler.h:102
@ AVR_OP_ASR
Definition: disassembler.h:16
@ AVR_OP_CLH
Definition: disassembler.h:41
@ AVR_OP_CLZ
Definition: disassembler.h:48
@ AVR_OP_SEN
Definition: disassembler.h:107
@ AVR_OP_ADC
Definition: disassembler.h:11
@ AVR_OP_BRPL
Definition: disassembler.h:31
@ AVR_OP_BRLT
Definition: disassembler.h:28
@ AVR_OP_MOVW
Definition: disassembler.h:79
@ AVR_OP_CLT
Definition: disassembler.h:46
@ AVR_OP_NOP
Definition: disassembler.h:84
@ AVR_OP_BRCS
Definition: disassembler.h:19
@ AVR_OP_MOV
Definition: disassembler.h:78
@ AVR_OP_EOR
Definition: disassembler.h:59
@ AVR_OP_SEI
Definition: disassembler.h:106
@ AVR_OP_SES
Definition: disassembler.h:109
@ AVR_OP_BRTS
Definition: disassembler.h:34
@ AVR_OP_LSL
Definition: disassembler.h:76
@ AVR_OP_SEV
Definition: disassembler.h:111
@ AVR_OP_LDI
Definition: disassembler.h:73
@ AVR_OP_SUB
Definition: disassembler.h:118
@ AVR_OP_ROL
Definition: disassembler.h:94
@ AVR_OP_SER
Definition: disassembler.h:108
@ AVR_OP_COM
Definition: disassembler.h:49
@ AVR_OP_ORI
Definition: disassembler.h:86
@ AVR_OP_BRCC
Definition: disassembler.h:18
@ AVR_OP_LDS
Definition: disassembler.h:74
@ AVR_OP_LPM
Definition: disassembler.h:75
@ AVR_OP_RJMP
Definition: disassembler.h:93
@ AVR_OP_STS
Definition: disassembler.h:117
@ AVR_OP_LAS
Definition: disassembler.h:69
@ AVR_OP_SEH
Definition: disassembler.h:105
@ AVR_OP_XCH
Definition: disassembler.h:123
@ AVR_OP_LAC
Definition: disassembler.h:68
@ AVR_OP_ADD
Definition: disassembler.h:12
@ AVR_OP_BRLO
Definition: disassembler.h:27
@ AVR_OP_SBIC
Definition: disassembler.h:99
@ AVR_OP_BRIE
Definition: disassembler.h:26
@ AVR_OP_ST
Definition: disassembler.h:115
@ AVR_OP_BRTC
Definition: disassembler.h:33
@ AVR_OP_ICALL
Definition: disassembler.h:63
@ AVR_OP_SBIW
Definition: disassembler.h:101
@ AVR_OP_FMUL
Definition: disassembler.h:60
@ AVR_OP_CLV
Definition: disassembler.h:47
@ AVR_OP_OUT
Definition: disassembler.h:87
@ AVR_OP_CLN
Definition: disassembler.h:43
@ AVR_OP_CLI
Definition: disassembler.h:42
@ AVR_OP_RETI
Definition: disassembler.h:92
@ AVR_OP_CLS
Definition: disassembler.h:45
@ AVR_OP_SET
Definition: disassembler.h:110
@ AVR_OP_SIZE
Definition: disassembler.h:125
@ AVR_OP_BREQ
Definition: disassembler.h:21
@ AVR_OP_MULS
Definition: disassembler.h:81
@ AVR_OP_ANDI
Definition: disassembler.h:15
@ AVR_OP_BRMI
Definition: disassembler.h:29
@ AVR_OP_SEZ
Definition: disassembler.h:112
@ AVR_OP_ROR
Definition: disassembler.h:95
@ AVR_OP_POP
Definition: disassembler.h:88
@ AVR_OP_BRHS
Definition: disassembler.h:24
@ AVR_OP_SEC
Definition: disassembler.h:104
@ AVR_OP_EIJMP
Definition: disassembler.h:57
@ AVR_OP_OR
Definition: disassembler.h:85
@ AVR_OP_FMULS
Definition: disassembler.h:61
@ AVR_OP_BRHC
Definition: disassembler.h:23
@ AVR_OP_SBIS
Definition: disassembler.h:100
@ AVR_OP_CPI
Definition: disassembler.h:52
@ AVR_OP_TST
Definition: disassembler.h:121
@ AVR_OP_SBI
Definition: disassembler.h:98
@ AVR_OP_RET
Definition: disassembler.h:91
@ AVR_OP_BRVS
Definition: disassembler.h:36
@ AVR_OP_PUSH
Definition: disassembler.h:89
@ AVR_OP_BRID
Definition: disassembler.h:25
@ AVR_OP_SBC
Definition: disassembler.h:96
@ AVR_OP_LD
Definition: disassembler.h:71
@ AVR_OP_CLR
Definition: disassembler.h:44
@ AVR_OP_SBRS
Definition: disassembler.h:103
@ AVR_OP_EICALL
Definition: disassembler.h:56
@ AVR_OP_BRVC
Definition: disassembler.h:35
@ AVR_OP_STD
Definition: disassembler.h:116
@ AVR_OP_ELPM
Definition: disassembler.h:58
@ AVR_OP_DES
Definition: disassembler.h:55
@ AVR_OP_BST
Definition: disassembler.h:37
@ AVR_OP_IN
Definition: disassembler.h:65
@ AVR_OP_NEG
Definition: disassembler.h:83
@ AVR_OP_BLD
Definition: disassembler.h:17
@ AVR_OP_CALL
Definition: disassembler.h:38
@ AVR_OP_WDR
Definition: disassembler.h:122
@ AVR_OP_SUBI
Definition: disassembler.h:119
@ AVR_OP_CLC
Definition: disassembler.h:40
@ AVR_OP_SLEEP
Definition: disassembler.h:113
@ AVR_OP_MULSU
Definition: disassembler.h:82
@ AVR_OP_RCALL
Definition: disassembler.h:90
@ AVR_OP_JMP
Definition: disassembler.h:67

Function Documentation

◆ avr_disassembler()

ut32 avr_disassembler ( const ut8 buffer,
const ut32  size,
ut64  pc,
bool  be,
AVROp aop,
RzStrBuf sb 
)

Definition at line 773 of file disassembler.c.

773  {
774  rz_return_val_if_fail(buffer && size && aop && sb, false);
775  if (size < 2) {
776  return AVR_INVALID_SIZE;
777  }
778 
779  ut16 masked;
780  ut16 data[2] = {0};
781 
782  data[0] = rz_read_ble16(buffer, be);
783 
784  memset(aop, 0, sizeof(AVROp));
785  for (ut32 i = 0; i < RZ_ARRAY_SIZE(instructions); ++i) {
786  masked = data[0] & instructions[i].mbits;
787  if (masked == instructions[i].cbits) {
788  if (instructions[i].opsize > 2) {
789  if (size < instructions[i].opsize) {
790  return AVR_INVALID_SIZE;
791  }
792  data[1] = be ? rz_read_at_be16(buffer, 2) : rz_read_at_le16(buffer, 2);
793  }
794  const char *name = instructions[i].name;
795  AVROpMnem id = instructions[i].id;
796  aop->size = instructions[i].decode(name, id, data, pc, aop, sb);
797  aop->mask = instructions[i].mbits;
798  return aop->size;
799  }
800  }
801  return AVR_INVALID_SIZE;
802 }
lzma_index ** i
Definition: index.h:629
static const AvrInstruction instructions[]
Definition: disassembler.c:636
static SblHeader sb
Definition: bin_mbn.c:26
uint16_t ut16
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
return memset(p, 0, total)
#define AVR_INVALID_SIZE
Definition: common.h:7
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static ut16 rz_read_at_le16(const void *src, size_t offset)
Definition: rz_endian.h:214
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
static ut16 rz_read_at_be16(const void *src, size_t offset)
Definition: rz_endian.h:55
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
cchar * name
Definition: disassembler.c:26
AVROpMnem id
Definition: disassembler.c:27
Definition: buffer.h:15
Definition: z80asm.h:102

References AVR_INVALID_SIZE, avr_decoder_t::decode, i, avr_decoder_t::id, instructions, avr_opcode_t::mask, avr_decoder_t::mbits, memset(), avr_decoder_t::name, pc, RZ_ARRAY_SIZE, rz_read_at_be16(), rz_read_at_le16(), rz_read_ble16(), rz_return_val_if_fail, sb, and avr_opcode_t::size.

Referenced by analysis_mask_avr(), avr_op(), disassemble(), and handle_skip_next_instruction().