Rizin
unix-like reverse engineering framework and cli tools
disassembler.c File Reference
#include "disassembler.h"
#include "common.h"

Go to the source code of this file.

Classes

struct  avr_decoder_t
 

Typedefs

typedef ut32(* Decode) (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
typedef struct avr_decoder_t AvrInstruction
 

Functions

static ut32 avr_unique (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rdddddrrrr (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_KKddKKKK (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_KKKKddddKKKK (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcbbb (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_kkkkkkkccc (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_kkkkkccck (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_AAAAAbbb (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_KKKKcccc (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_z (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_zp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddcrrr (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_AAdddddAAAA (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_x (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_xp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_xm (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_y (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_yp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_ym (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_qcqqcdddddcqqq_y (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_zm (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_qcqqcdddddcqqq_z (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_load32 (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_kkkddddkkkk_load16 (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_ddddrrrr (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_ddddrrrr_2x (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_AArrrrrAAAA (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_kkkkkkkkkkkk (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcbbb (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_ddddcccc (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_spmz (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_x (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_xp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_xm (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_y (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_yp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_ym (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_qcqqcrrrrrcqqq_y (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_z (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_zp (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_rrrrrcccc_zm (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_qcqqcrrrrrcqqq_z (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_dddddcccc_store32 (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
static ut32 avr_kkkddddkkkk_store16 (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)
 
ut32 avr_disassembler (const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp *aop, RzStrBuf *sb)
 

Variables

static const AvrInstruction instructions []
 

Detailed Description

Disassembles AVR instructions Each instruction is decoded comparing the applied bitmask result with constants bits Legend for function decoders names:

  • r = Rr
  • d = Rd
  • K, k = immediate value
  • b = bit offset
  • A = i/o address
  • c = constant value (see cbits)
  • x, xp, xm = X, X+, -X
  • y, yp, ym = Y, Y+, -Y
  • z, zp, zm = Z, Z+, -Z
  • q = displacement const

Definition in file disassembler.c.

Typedef Documentation

◆ AvrInstruction

typedef struct avr_decoder_t AvrInstruction

◆ Decode

typedef ut32(* Decode) (cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb)

Definition at line 23 of file disassembler.c.

Function Documentation

◆ avr_AAAAAbbb()

static ut32 avr_AAAAAbbb ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 164 of file disassembler.c.

164  {
165  ut16 b = data[0] & 0x0007;
166  ut16 A = ((data[0] & 0x00F8) >> 3);
167 
168  aop->mnemonic = id;
169  aop->param[0] = A;
170  aop->param[1] = b;
171  rz_strbuf_setf(sb, "%s 0x%02x, %u", name, A, b);
172  return 2;
173 }
#define A(x)
Definition: arc.h:165
static SblHeader sb
Definition: bin_mbn.c:26
uint16_t ut16
int id
Definition: op.c:540
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define b(i)
Definition: sha256.c:42
ut16 param[4]
Definition: disassembler.h:131
AVROpMnem mnemonic
Definition: disassembler.h:129
Definition: z80asm.h:102

References A, b, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_AAdddddAAAA()

static ut32 avr_AAdddddAAAA ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 222 of file disassembler.c.

222  {
223  ut16 A = data[0] & 0x000F;
224  ut16 Rd = ((data[0] & 0x01F0) >> 4);
225  A |= ((data[0] & 0x0600) >> 5);
226 
227  aop->mnemonic = id;
228  aop->param[0] = Rd;
229  aop->param[1] = A;
230  rz_strbuf_setf(sb, "%s r%u, 0x%02x", name, Rd, A);
231  return 2;
232 }

References A, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_AArrrrrAAAA()

static ut32 avr_AArrrrrAAAA ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 405 of file disassembler.c.

405  {
406  ut16 A = data[0] & 0x000F;
407  ut16 Rr = ((data[0] & 0x01F0) >> 4);
408  A |= ((data[0] & 0x0600) >> 5);
409 
410  aop->mnemonic = id;
411  aop->param[0] = A;
412  aop->param[1] = Rr;
413  rz_strbuf_setf(sb, "%s 0x%02x, r%u", name, A, Rr);
414  return 2;
415 }

References A, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddcrrr()

static ut32 avr_dddcrrr ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 210 of file disassembler.c.

210  {
211  ut16 Rr = 16 + (data[0] & 0x0007);
212  ut16 Rd = 16 + ((data[0] & 0x0070) >> 4);
213 
214  aop->mnemonic = id;
215  aop->param[0] = Rd;
216  aop->param[1] = Rr;
217  rz_strbuf_setf(sb, "%s r%u, r%u", name, Rd, Rr);
218  return 2;
219 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_ddddcccc()

static ut32 avr_ddddcccc ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 450 of file disassembler.c.

450  {
451  ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4);
452 
453  aop->mnemonic = id;
454  aop->param[0] = Rd;
455  rz_strbuf_setf(sb, "%s r%u", name, Rd);
456  return 2;
457 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcbbb()

static ut32 avr_dddddcbbb ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 118 of file disassembler.c.

118  {
119  ut16 b = data[0] & 0x0007;
120  ut16 Rd = ((data[0] & 0x01F0) >> 4);
121 
122  aop->mnemonic = id;
123  aop->param[0] = Rd;
124  aop->param[1] = b;
125  rz_strbuf_setf(sb, "%s r%u, %u", name, Rd, b);
126  return 2;
127 }

References b, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc()

static ut32 avr_dddddcccc ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 108 of file disassembler.c.

108  {
109  ut16 Rd = ((data[0] & 0x01F0) >> 4);
110 
111  aop->mnemonic = id;
112  aop->param[0] = Rd;
113  rz_strbuf_setf(sb, "%s r%u", name, Rd);
114  return 2;
115 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_load32()

static ut32 avr_dddddcccc_load32 ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 354 of file disassembler.c.

354  {
355  ut16 Rd = ((data[0] & 0x01F0) >> 4);
356  aop->mnemonic = id;
357  aop->param[0] = Rd;
358  aop->param[1] = data[1];
359  rz_strbuf_setf(sb, "%s r%u, 0x%02x", name, Rd, data[1]);
360  return 4;
361 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_store32()

static ut32 avr_dddddcccc_store32 ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 612 of file disassembler.c.

612  {
613  ut16 Rd = ((data[0] & 0x01F0) >> 4);
614 
615  aop->mnemonic = id;
616  aop->param[0] = data[1];
617  aop->param[1] = Rd;
618  rz_strbuf_setf(sb, "%s 0x%02x, r%u", name, data[1], Rd);
619  return 4;
620 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_x()

static ut32 avr_dddddcccc_x ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 235 of file disassembler.c.

235  {
236  ut16 Rd = ((data[0] & 0x01F0) >> 4);
237 
238  aop->mnemonic = id;
239  aop->param[0] = Rd;
240  aop->param[1] = 'X';
241  rz_strbuf_setf(sb, "%s r%u, X", name, Rd);
242  return 2;
243 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_xm()

static ut32 avr_dddddcccc_xm ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 259 of file disassembler.c.

259  {
260  ut16 Rd = ((data[0] & 0x01F0) >> 4);
261 
262  aop->mnemonic = id;
263  aop->param[0] = Rd;
264  aop->param[1] = 'X';
265  aop->param[2] = '-';
266  aop->param[3] = 1;
267  rz_strbuf_setf(sb, "%s r%u, -X", name, Rd);
268  return 2;
269 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_xp()

static ut32 avr_dddddcccc_xp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 246 of file disassembler.c.

246  {
247  ut16 Rd = ((data[0] & 0x01F0) >> 4);
248 
249  aop->mnemonic = id;
250  aop->param[0] = Rd;
251  aop->param[1] = 'X';
252  aop->param[2] = '+';
253  aop->param[3] = 1;
254  rz_strbuf_setf(sb, "%s r%u, X+", name, Rd);
255  return 2;
256 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_y()

static ut32 avr_dddddcccc_y ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 272 of file disassembler.c.

272  {
273  ut16 Rd = ((data[0] & 0x01F0) >> 4);
274 
275  aop->mnemonic = id;
276  aop->param[0] = Rd;
277  aop->param[1] = 'Y';
278  rz_strbuf_setf(sb, "%s r%u, Y", name, Rd);
279  return 2;
280 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_ym()

static ut32 avr_dddddcccc_ym ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 296 of file disassembler.c.

296  {
297  ut16 Rd = ((data[0] & 0x01F0) >> 4);
298 
299  aop->mnemonic = id;
300  aop->param[0] = Rd;
301  aop->param[1] = 'Y';
302  aop->param[2] = '-';
303  aop->param[3] = 1;
304  rz_strbuf_setf(sb, "%s r%u, -Y", name, Rd);
305  return 2;
306 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_yp()

static ut32 avr_dddddcccc_yp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 283 of file disassembler.c.

283  {
284  ut16 Rd = ((data[0] & 0x01F0) >> 4);
285 
286  aop->mnemonic = id;
287  aop->param[0] = Rd;
288  aop->param[1] = 'Y';
289  aop->param[2] = '+';
290  aop->param[3] = 1;
291  rz_strbuf_setf(sb, "%s r%u, Y+", name, Rd);
292  return 2;
293 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_z()

static ut32 avr_dddddcccc_z ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 186 of file disassembler.c.

186  {
187  ut16 Rd = ((data[0] & 0x01F0) >> 4);
188 
189  aop->mnemonic = id;
190  aop->param[0] = Rd;
191  aop->param[1] = 'Z';
192  rz_strbuf_setf(sb, "%s r%u, Z", name, Rd);
193  return 2;
194 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_zm()

static ut32 avr_dddddcccc_zm ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 325 of file disassembler.c.

325  {
326  ut16 Rd = ((data[0] & 0x01F0) >> 4);
327 
328  aop->mnemonic = id;
329  aop->param[0] = Rd;
330  aop->param[1] = 'Z';
331  aop->param[2] = '-';
332  aop->param[3] = 1;
333  rz_strbuf_setf(sb, "%s r%u, -Z", name, Rd);
334  return 2;
335 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_dddddcccc_zp()

static ut32 avr_dddddcccc_zp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 197 of file disassembler.c.

197  {
198  ut16 Rd = ((data[0] & 0x01F0) >> 4);
199 
200  aop->mnemonic = id;
201  aop->param[0] = Rd;
202  aop->param[1] = 'Z';
203  aop->param[2] = '+';
204  aop->param[3] = 1;
205  rz_strbuf_setf(sb, "%s r%u, Z+", name, Rd);
206  return 2;
207 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_ddddrrrr()

static ut32 avr_ddddrrrr ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 376 of file disassembler.c.

376  {
377  ut16 Rr = data[0] & 0x000F;
378  ut16 Rd = ((data[0] & 0x00F0) >> 4);
379 
380  Rr *= 2;
381  Rd *= 2;
382 
383  aop->mnemonic = id;
384  aop->param[0] = Rd;
385  aop->param[1] = Rr;
386  rz_strbuf_setf(sb, "%s r%u, r%u", name, Rd, Rr);
387  return 2;
388 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_ddddrrrr_2x()

static ut32 avr_ddddrrrr_2x ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 391 of file disassembler.c.

391  {
392  ut16 Rr = data[0] & 0x000F;
393  ut16 Rd = ((data[0] & 0x00F0) >> 4);
394  Rr += 16;
395  Rd += 16;
396 
397  aop->mnemonic = id;
398  aop->param[0] = Rd;
399  aop->param[1] = Rr;
400  rz_strbuf_setf(sb, "%s r%u, r%u", name, Rd, Rr);
401  return 2;
402 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ 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
AVROpMnem
Definition: disassembler.h:9
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

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().

◆ avr_KKddKKKK()

static ut32 avr_KKddKKKK ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 75 of file disassembler.c.

75  {
76  ut16 K = data[0] & 0x000F;
77  ut16 Rd = 24 + ((data[0] & 0x0030) >> 3);
78  K |= ((data[0] & 0x00C0) >> 2);
79 
80  aop->mnemonic = id;
81  aop->param[0] = Rd + 1;
82  aop->param[1] = Rd;
83  aop->param[2] = K;
84  rz_strbuf_setf(sb, "%s r%u:r%u, 0x%02x", name, Rd + 1, Rd, K);
85  return 2;
86 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_kkkddddkkkk_load16()

static ut32 avr_kkkddddkkkk_load16 ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 364 of file disassembler.c.

364  {
365  ut16 k = data[0] & 0x000F;
366  ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4);
367  k |= ((data[0] & 0x0700) >> 4);
368  aop->mnemonic = id;
369  aop->param[0] = Rd;
370  aop->param[1] = k;
371  rz_strbuf_setf(sb, "%s r%u, 0x%02x", name, Rd, k);
372  return 2;
373 }
const char * k
Definition: dsignal.c:11

References id, k, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_kkkddddkkkk_store16()

static ut32 avr_kkkddddkkkk_store16 ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 623 of file disassembler.c.

623  {
624  ut16 k = data[0] & 0x000F;
625  ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4);
626  k |= ((data[0] & 0x0700) >> 4);
627 
628  aop->mnemonic = id;
629  aop->param[0] = k;
630  aop->param[1] = Rd;
631  rz_strbuf_setf(sb, "%s 0x%02x, r%u", name, k, Rd);
632  return 2;
633 }

References id, k, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_KKKKcccc()

static ut32 avr_KKKKcccc ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 176 of file disassembler.c.

176  {
177  ut16 K = ((data[0] & 0x00F0) >> 4);
178 
179  aop->mnemonic = id;
180  aop->param[0] = K;
181  rz_strbuf_setf(sb, "%s 0x%02x", name, K);
182  return 2;
183 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_KKKKddddKKKK()

static ut32 avr_KKKKddddKKKK ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 89 of file disassembler.c.

89  {
90  ut16 K = data[0] & 0x000F;
91  ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4);
92  K |= ((data[0] & 0x0F00) >> 4);
93 
94  aop->param[0] = Rd;
95  if (K == 0xFF && !strncmp(name, "ldi", 3)) {
96  aop->mnemonic = AVR_OP_SER;
97  rz_strbuf_setf(sb, "ser r%u", Rd);
98  } else {
99  aop->mnemonic = id;
100  aop->param[1] = K;
101  rz_strbuf_setf(sb, "%s r%u, 0x%02x", name, Rd, K);
102  }
103 
104  return 2;
105 }
@ AVR_OP_SER
Definition: disassembler.h:108

References AVR_OP_SER, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_kkkkkccck()

static ut32 avr_kkkkkccck ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 149 of file disassembler.c.

149  {
150  st32 k = data[0] & 0x0001;
151  k |= ((data[0] & 0x01F0) >> 3);
152  k <<= 16;
153  k |= data[1];
154  k *= 2;
155 
156  aop->mnemonic = id;
157  aop->param[0] = (k >> 16) & 0xFFFF;
158  aop->param[1] = k & 0xFFFF;
159  rz_strbuf_setf(sb, "%s 0x%x", name, k);
160  return 4;
161 }
#define st32
Definition: rz_types_base.h:12

References id, k, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), sb, and st32.

◆ avr_kkkkkkkccc()

static ut32 avr_kkkkkkkccc ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 130 of file disassembler.c.

130  {
131  st16 k = (data[0] & 0x03F8) >> 3;
132  k *= 2;
133  if (k & 0x0080) {
134  // manually extend signed value
135  k |= 0xFF00;
136  k = -(~k) + 1;
137  } else {
138  k += 2;
139  }
140  pc += k;
141 
142  aop->mnemonic = id;
143  aop->param[0] = pc;
144  rz_strbuf_setf(sb, "%s 0x%" PFMT64x, name, pc);
145  return 2;
146 }
#define PFMT64x
Definition: rz_types.h:393
#define st16
Definition: rz_types_base.h:14

References id, k, avr_opcode_t::mnemonic, avr_opcode_t::param, pc, PFMT64x, rz_strbuf_setf(), sb, and st16.

◆ avr_kkkkkkkkkkkk()

static ut32 avr_kkkkkkkkkkkk ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 418 of file disassembler.c.

418  {
419  st16 k = data[0] & 0x0FFF;
420  k *= 2;
421  if (k & 0x1000) {
422  // manually extend signed value
423  k |= 0xF000;
424  k = -(~k) + 1;
425  } else {
426  k += 2;
427  }
428 
429  pc += k;
430 
431  aop->mnemonic = id;
432  aop->param[0] = pc;
433  rz_strbuf_setf(sb, "%s 0x%" PFMT64x, name, pc);
434  return 2;
435 }

References id, k, avr_opcode_t::mnemonic, avr_opcode_t::param, pc, PFMT64x, rz_strbuf_setf(), sb, and st16.

◆ avr_qcqqcdddddcqqq_y()

static ut32 avr_qcqqcdddddcqqq_y ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 309 of file disassembler.c.

309  {
310  ut16 q = data[0] & 0x0007;
311  ut16 Rd = ((data[0] & 0x01F0) >> 4);
312  q |= ((data[0] & 0x0C00) >> 7);
313  q |= ((data[0] & 0x2000) >> 8);
314 
315  aop->mnemonic = id;
316  aop->param[0] = Rd;
317  aop->param[1] = 'Y';
318  aop->param[2] = '+';
319  aop->param[3] = q;
320  rz_strbuf_setf(sb, "%s r%u, Y+%u", name, Rd, q);
321  return 2;
322 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_qcqqcdddddcqqq_z()

static ut32 avr_qcqqcdddddcqqq_z ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 338 of file disassembler.c.

338  {
339  ut16 q = data[0] & 0x0007;
340  ut16 Rd = ((data[0] & 0x01F0) >> 4);
341  q |= ((data[0] & 0x0C00) >> 7);
342  q |= ((data[0] & 0x2000) >> 8);
343 
344  aop->mnemonic = id;
345  aop->param[0] = Rd;
346  aop->param[1] = 'Z';
347  aop->param[2] = '+';
348  aop->param[3] = q;
349  rz_strbuf_setf(sb, "%s r%u, Z+%u", name, Rd, q);
350  return 2;
351 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_qcqqcrrrrrcqqq_y()

static ut32 avr_qcqqcrrrrrcqqq_y ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 543 of file disassembler.c.

543  {
544  ut16 q = data[0] & 0x0007;
545  ut16 Rr = ((data[0] & 0x01F0) >> 4);
546  q |= ((data[0] & 0x0C00) >> 7);
547  q |= ((data[0] & 0x2000) >> 8);
548 
549  aop->mnemonic = id;
550  aop->param[0] = Rr;
551  aop->param[1] = 'Y';
552  aop->param[2] = '+';
553  aop->param[3] = q;
554  rz_strbuf_setf(sb, "%s Y+%u, r%u", name, q, Rr);
555  return 2;
556 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_qcqqcrrrrrcqqq_z()

static ut32 avr_qcqqcrrrrrcqqq_z ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 596 of file disassembler.c.

596  {
597  ut16 q = data[0] & 0x0007;
598  ut16 Rr = ((data[0] & 0x01F0) >> 4);
599  q |= ((data[0] & 0x0C00) >> 7);
600  q |= ((data[0] & 0x2000) >> 8);
601 
602  aop->mnemonic = id;
603  aop->param[0] = Rr;
604  aop->param[1] = 'Z';
605  aop->param[2] = '+';
606  aop->param[3] = q;
607  rz_strbuf_setf(sb, "%s Z+%u, r%u", name, q, Rr);
608  return 2;
609 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rdddddrrrr()

static ut32 avr_rdddddrrrr ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 41 of file disassembler.c.

41  {
42  ut16 Rr = data[0] & 0x000F;
43  ut16 Rd = ((data[0] & 0x01F0) >> 4);
44  Rr |= ((data[0] & 0x0200) >> 5);
45 
46  aop->param[0] = Rd;
47  aop->param[1] = Rr;
48  if (Rd == Rr) {
49  aop->param[0] = Rd;
50  if (!strncmp(name, "adc", 3)) {
51  aop->mnemonic = AVR_OP_ROL;
52  rz_strbuf_setf(sb, "rol r%u", Rd);
53  } else if (!strncmp(name, "add", 3)) {
54  aop->mnemonic = AVR_OP_LSL;
55  rz_strbuf_setf(sb, "lsl r%u", Rd);
56  } else if (!strncmp(name, "and", 3)) {
57  aop->mnemonic = AVR_OP_TST;
58  rz_strbuf_setf(sb, "tst r%u", Rd);
59  } else if (!strncmp(name, "eor", 3)) {
60  aop->mnemonic = AVR_OP_CLR;
61  rz_strbuf_setf(sb, "clr r%u", Rd);
62  } else {
63  aop->mnemonic = id;
64  rz_strbuf_setf(sb, "%s r%u, r%u", name, Rd, Rr);
65  }
66  } else {
67  aop->mnemonic = id;
68  rz_strbuf_setf(sb, "%s r%u, r%u", name, Rd, Rr);
69  }
70 
71  return 2;
72 }
@ AVR_OP_LSL
Definition: disassembler.h:76
@ AVR_OP_ROL
Definition: disassembler.h:94
@ AVR_OP_TST
Definition: disassembler.h:121
@ AVR_OP_CLR
Definition: disassembler.h:44

References AVR_OP_CLR, AVR_OP_LSL, AVR_OP_ROL, AVR_OP_TST, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcbbb()

static ut32 avr_rrrrrcbbb ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 438 of file disassembler.c.

438  {
439  ut16 b = data[0] & 0x0007;
440  ut16 Rr = ((data[0] & 0x01F0) >> 4);
441 
442  aop->mnemonic = id;
443  aop->param[0] = Rr;
444  aop->param[1] = b;
445  rz_strbuf_setf(sb, "%s r%u, %u", name, Rr, b);
446  return 2;
447 }

References b, id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_x()

static ut32 avr_rrrrrcccc_x ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 469 of file disassembler.c.

469  {
470  ut16 Rr = ((data[0] & 0x01F0) >> 4);
471 
472  aop->mnemonic = id;
473  aop->param[0] = Rr;
474  aop->param[1] = 'X';
475  rz_strbuf_setf(sb, "%s X, r%u", name, Rr);
476  return 2;
477 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_xm()

static ut32 avr_rrrrrcccc_xm ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 493 of file disassembler.c.

493  {
494  ut16 Rr = ((data[0] & 0x01F0) >> 4);
495 
496  aop->mnemonic = id;
497  aop->param[0] = Rr;
498  aop->param[1] = 'X';
499  aop->param[2] = '-';
500  aop->param[3] = 1;
501  rz_strbuf_setf(sb, "%s -X, r%u", name, Rr);
502  return 2;
503 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_xp()

static ut32 avr_rrrrrcccc_xp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 480 of file disassembler.c.

480  {
481  ut16 Rr = ((data[0] & 0x01F0) >> 4);
482 
483  aop->mnemonic = id;
484  aop->param[0] = Rr;
485  aop->param[1] = 'X';
486  aop->param[2] = '+';
487  aop->param[3] = 1;
488  rz_strbuf_setf(sb, "%s X+1, r%u", name, Rr);
489  return 2;
490 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_y()

static ut32 avr_rrrrrcccc_y ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 506 of file disassembler.c.

506  {
507  ut16 Rr = ((data[0] & 0x01F0) >> 4);
508 
509  aop->mnemonic = id;
510  aop->param[0] = Rr;
511  aop->param[1] = 'Y';
512  rz_strbuf_setf(sb, "%s Y, r%u", name, Rr);
513  return 2;
514 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_ym()

static ut32 avr_rrrrrcccc_ym ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 530 of file disassembler.c.

530  {
531  ut16 Rr = ((data[0] & 0x01F0) >> 4);
532 
533  aop->mnemonic = id;
534  aop->param[0] = Rr;
535  aop->param[1] = 'Y';
536  aop->param[2] = '-';
537  aop->param[3] = 1;
538  rz_strbuf_setf(sb, "%s -Y, r%u", name, Rr);
539  return 2;
540 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_yp()

static ut32 avr_rrrrrcccc_yp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 517 of file disassembler.c.

517  {
518  ut16 Rr = ((data[0] & 0x01F0) >> 4);
519 
520  aop->mnemonic = id;
521  aop->param[0] = Rr;
522  aop->param[1] = 'Y';
523  aop->param[2] = '+';
524  aop->param[3] = 1;
525  rz_strbuf_setf(sb, "%s Y+1, r%u", name, Rr);
526  return 2;
527 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_z()

static ut32 avr_rrrrrcccc_z ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 559 of file disassembler.c.

559  {
560  ut16 Rr = ((data[0] & 0x01F0) >> 4);
561 
562  aop->mnemonic = id;
563  aop->param[0] = Rr;
564  aop->param[1] = 'Z';
565  rz_strbuf_setf(sb, "%s Z, r%u", name, Rr);
566  return 2;
567 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_zm()

static ut32 avr_rrrrrcccc_zm ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 583 of file disassembler.c.

583  {
584  ut16 Rr = ((data[0] & 0x01F0) >> 4);
585 
586  aop->mnemonic = id;
587  aop->param[0] = Rr;
588  aop->param[1] = 'Z';
589  aop->param[2] = '-';
590  aop->param[3] = 1;
591  rz_strbuf_setf(sb, "%s -Z, r%u", name, Rr);
592  return 2;
593 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_rrrrrcccc_zp()

static ut32 avr_rrrrrcccc_zp ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 570 of file disassembler.c.

570  {
571  ut16 Rr = ((data[0] & 0x01F0) >> 4);
572 
573  aop->mnemonic = id;
574  aop->param[0] = Rr;
575  aop->param[1] = 'Z';
576  aop->param[2] = '+';
577  aop->param[3] = 1;
578  rz_strbuf_setf(sb, "%s Z+1, r%u", name, Rr);
579  return 2;
580 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_spmz()

static ut32 avr_spmz ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 460 of file disassembler.c.

460  {
461  aop->mnemonic = id;
462  aop->param[0] = 'Z';
463  aop->param[1] = '+';
464  rz_strbuf_setf(sb, "%s Z+", name);
465  return 2;
466 }

References id, avr_opcode_t::mnemonic, avr_opcode_t::param, rz_strbuf_setf(), and sb.

◆ avr_unique()

static ut32 avr_unique ( cchar name,
AVROpMnem  id,
ut16  data[2],
ut64  pc,
AVROp aop,
RzStrBuf sb 
)
static

Definition at line 35 of file disassembler.c.

35  {
36  aop->mnemonic = id;
38  return 2;
39 }
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153

References id, avr_opcode_t::mnemonic, rz_strbuf_set(), and sb.

Variable Documentation

◆ instructions

const AvrInstruction instructions[]
static

Definition at line 636 of file disassembler.c.

Referenced by avr_disassembler().