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

Go to the source code of this file.

Classes

struct  avr_decoder_t
 

Macros

#define MAX_TOKENS   6
 
#define IS_INDIRECT_ADDRESS_REGISTER(x)   ((x)=='x'||(x)=='y'||(x)=='z')
 
#define throw_error(msg, ...)
 
#define return_error_if_empty_input(a, b)
 
#define expected_const_or_error(a, exp)
 
#define parse_register_or_error_limit(rn, rs, min, max)
 
#define parse_register_or_error(rn, rs)
 
#define parse_register_pair_or_error(rn, rs)
 Parse things like "r25:r24" or just "r24". Result would be 24 in both cases. More...
 
#define parse_unsigned_or_error(rn, rs, limit)
 
#define parse_address_or_error(rn, rs, pc, llow, lhigh)
 
#define parse_signed_or_error(rn, rs, min, max)
 
#define auto_write16(buf, val, be)
 

Typedefs

typedef ut32(* Encode) (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
typedef struct avr_decoder_t AvrInstruction
 

Functions

static ut32 avr_unique (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_rdddddrrrr (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_KKddKKKK (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_KKKKddddKKKK (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_cbr (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_dddddcccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_dddddcbbb (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_kkkkkkkccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_kkkkkccck (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_AAAAAbbb (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_dddddddddd (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_KKKKcccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_elpm (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_dddcrrr (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_AAdddddAAAA (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_rrrrrcccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ld (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ldd (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_lds (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_lpm (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_kkkkkkkkkkkk (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ddddrrrr (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ddddrrrr_2x (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_AArrrrrAAAA (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_rrrrrcbbb (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ddddcccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_spm (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_st (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_std (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_sts (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_ssscccc (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static ut32 avr_kkkkkkksss (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)
 
static char * strdup_limit (cchar *begin, cchar *end)
 
static void sanitize_input (char *cinput, st32 input_size)
 
static char ** tokens_new (cchar *input, st32 input_size, ut32 *ntokens)
 
static void tokens_free (char **tokens)
 
ut32 avr_assembler (const char *input, st32 input_size, ut8 *output, st32 output_size, ut64 pc, bool be)
 

Variables

static const AvrInstruction instructions []
 

Macro Definition Documentation

◆ auto_write16

#define auto_write16 (   buf,
  val,
  be 
)
Value:
do { \
if (be) { \
rz_write_be16(buf, val); \
} else { \
rz_write_le16(buf, val); \
} \
} while (0)
ut16 val
Definition: armass64_const.h:6
voidpf void * buf
Definition: ioapi.h:138

Definition at line 163 of file assembler.c.

◆ expected_const_or_error

#define expected_const_or_error (   a,
  exp 
)
Value:
do { \
if (RZ_STR_ISEMPTY((a)) || strcmp((a),(exp))) { \
RZ_LOG_ERROR("[!] avr_assembler: expected '%s' but got '%s'.\n", (exp), (a)); \
return AVR_INVALID_SIZE; \
} \
} while (0)
#define AVR_INVALID_SIZE
Definition: common.h:7
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
#define a(i)
Definition: sha256.c:41

Definition at line 24 of file assembler.c.

◆ IS_INDIRECT_ADDRESS_REGISTER

#define IS_INDIRECT_ADDRESS_REGISTER (   x)    ((x)=='x'||(x)=='y'||(x)=='z')

Definition at line 8 of file assembler.c.

◆ MAX_TOKENS

#define MAX_TOKENS   6

Definition at line 7 of file assembler.c.

◆ parse_address_or_error

#define parse_address_or_error (   rn,
  rs,
  pc,
  llow,
  lhigh 
)
Value:
do { \
cchar *tmp = (rs); \
if (RZ_STR_ISEMPTY(tmp)) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid address '%s'.\n", (rs)); \
return AVR_INVALID_SIZE; \
} \
if (tmp[0] == '.') { \
(rn) = (st64)strtoull(tmp + 1, NULL, 0); \
} else { \
st64 abs = strtoull(tmp, NULL, 0); \
(rn) = abs - pc; \
} \
if ((rn) < 0) { \
(rn) = ~(-((rn) - 1)); \
} else { \
(rn) -= 2; \
} \
(rn) /= 2; \
if (((rn) < (llow) || (rn) > (lhigh))) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid address -64 <= addr <= 63 (parsed %d).\n", (rn)); \
return AVR_INVALID_SIZE; \
} \
} while (0)
#define rs()
#define NULL
Definition: cris-opc.c:27
#define st64
Definition: rz_types_base.h:10

Definition at line 120 of file assembler.c.

◆ parse_register_or_error

#define parse_register_or_error (   rn,
  rs 
)
Value:
do { \
cchar *tmp = (rs); \
if (*tmp == 'r') { \
tmp++; \
} \
if (RZ_STR_ISEMPTY(tmp)) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid register '%s'.\n", (rs)); \
return AVR_INVALID_SIZE; \
} \
(rn) = strtoll(tmp, NULL, 0); \
if ((rn) > 31) { \
RZ_LOG_ERROR("[!] avr_assembler: expected register 0 <= reg <= 31 (parsed %u).\n", (rn)); \
return AVR_INVALID_SIZE; \
} \
} while (0)

Definition at line 49 of file assembler.c.

◆ parse_register_or_error_limit

#define parse_register_or_error_limit (   rn,
  rs,
  min,
  max 
)
Value:
do { \
cchar *tmp = (rs); \
if (*tmp == 'r') { \
tmp++; \
} \
if (RZ_STR_ISEMPTY(tmp)) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid register '%s'.\n", (rs)); \
return AVR_INVALID_SIZE; \
} \
(rn) = strtoll(tmp, NULL, 0); \
if ((rn) < (min) || (rn) > (max)) { \
RZ_LOG_ERROR("[!] avr_assembler: expected register %u <= reg <= 31 (parsed %u).\n", (min), (rn)); \
return AVR_INVALID_SIZE; \
} \
} while (0)
int max
Definition: enough.c:225
#define min(a, b)
Definition: qsort.h:83

Definition at line 32 of file assembler.c.

◆ parse_register_pair_or_error

#define parse_register_pair_or_error (   rn,
  rs 
)

Parse things like "r25:r24" or just "r24". Result would be 24 in both cases.

Definition at line 67 of file assembler.c.

◆ parse_signed_or_error

#define parse_signed_or_error (   rn,
  rs,
  min,
  max 
)
Value:
do { \
cchar *tmp = (rs); \
if (RZ_STR_ISEMPTY(tmp)) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid unsigned number '%s'.\n", (rs)); \
return AVR_INVALID_SIZE; \
} \
(rn) = atoi(tmp); \
if ((rn) < (min)) { \
RZ_LOG_ERROR("[!] avr_assembler: signed number '%s' < %u.\n", (rs), min); \
return AVR_INVALID_SIZE; \
} \
if ((rn) > (max)) { \
RZ_LOG_ERROR("[!] avr_assembler: signed number '%s' > %u.\n", (rs), max); \
return AVR_INVALID_SIZE; \
} \
} while (0)

Definition at line 145 of file assembler.c.

◆ parse_unsigned_or_error

#define parse_unsigned_or_error (   rn,
  rs,
  limit 
)
Value:
do { \
cchar *tmp = (rs); \
ut32 base = 0; \
if (tmp[0] == '$') { \
tmp++; \
base = 16; \
} \
if (RZ_STR_ISEMPTY(tmp)) { \
RZ_LOG_ERROR("[!] avr_assembler: invalid unsigned number '%s'.\n", (rs)); \
return AVR_INVALID_SIZE; \
} \
(rn) = strtoull(tmp, NULL, base); \
if ((rn) > (limit)) { \
RZ_LOG_ERROR("[!] avr_assembler: unsigned number '%s' >= %u.\n", (rs), limit); \
return AVR_INVALID_SIZE; \
} \
} while (0)
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45

Definition at line 101 of file assembler.c.

◆ return_error_if_empty_input

#define return_error_if_empty_input (   a,
  b 
)
Value:
do { \
if (RZ_STR_ISEMPTY(a) || b < 1) { \
RZ_LOG_ERROR("[!] avr_assembler: the input is empty.\n"); \
return AVR_INVALID_SIZE; \
} \
} while (0)
#define b(i)
Definition: sha256.c:42

Definition at line 16 of file assembler.c.

◆ throw_error

#define throw_error (   msg,
  ... 
)
Value:
do { \
RZ_LOG_ERROR("[!] avr_assembler: " msg, ##__VA_ARGS__); \
return AVR_INVALID_SIZE; \
} while (0)
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119

Definition at line 10 of file assembler.c.

Typedef Documentation

◆ AvrInstruction

typedef struct avr_decoder_t AvrInstruction

◆ Encode

typedef ut32(* Encode) (ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be)

Definition at line 172 of file assembler.c.

Function Documentation

◆ avr_AAAAAbbb()

static ut32 avr_AAAAAbbb ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 317 of file assembler.c.

317  {
318  // CBI A,b | 0 <= A <= 31 | 0 <= b <= 7
319  ut16 A, b;
320  parse_unsigned_or_error(A, tokens[1], 31);
321  parse_unsigned_or_error(b, tokens[2], 7);
322 
323 
324  cbins |= (b & 0x0007);
325  cbins |= ((A << 3) & 0x00F8);
326 
327  auto_write16(data, cbins, be);
328  return 2;
329 }
#define A(x)
Definition: arc.h:165
#define parse_unsigned_or_error(rn, rs, limit)
Definition: assembler.c:101
#define auto_write16(buf, val, be)
Definition: assembler.c:163
uint16_t ut16

References A, auto_write16, b, and parse_unsigned_or_error.

◆ avr_AAdddddAAAA()

static ut32 avr_AAdddddAAAA ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 407 of file assembler.c.

407  {
408  /* <opcode> Rd, A | 0 <= d <= 31, 0 <= A <= 63 */
409  ut16 Rd, A;
410  parse_register_or_error(Rd, tokens[1]);
411  parse_unsigned_or_error(A, tokens[2], 63);
412 
413  cbins |= (A & 0x000F);
414  cbins |= ((A << 5) & 0x0600);
415  cbins |= ((Rd << 4) & 0x01F0);
416 
417  auto_write16(data, cbins, be);
418  return 2;
419 }
#define parse_register_or_error(rn, rs)
Definition: assembler.c:49

References A, auto_write16, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_AArrrrrAAAA()

static ut32 avr_AArrrrrAAAA ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 640 of file assembler.c.

640  {
641  /* <opcode> Rd, A | 0 <= d <= 31, 0 <= A <= 63 */
642  ut16 Rd, A;
643  parse_unsigned_or_error(A, tokens[1], 63);
644  parse_register_or_error(Rd, tokens[2]);
645 
646  cbins |= (A & 0x000F);
647  cbins |= ((A << 5) & 0x0600);
648  cbins |= ((Rd << 4) & 0x01F0);
649 
650  auto_write16(data, cbins, be);
651  return 2;
652 }

References A, auto_write16, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_assembler()

ut32 avr_assembler ( const char *  input,
st32  input_size,
ut8 output,
st32  output_size,
ut64  pc,
bool  be 
)

Definition at line 1084 of file assembler.c.

1084  {
1085  return_error_if_empty_input(input, input_size);
1086 
1087  ut32 written = AVR_INVALID_SIZE;
1088  ut32 ntokens = 0;
1089  char** tokens = tokens_new(input, input_size, &ntokens);
1090  if (!tokens || ntokens < 1) {
1091  RZ_LOG_ERROR("[!] avr_assembler: invalid assembly.\n");
1092  goto avr_assembler_end;
1093  }
1094 
1095 
1096  for (ut32 i = 0; i < RZ_ARRAY_SIZE(instructions); ++i) {
1097  if (!rz_str_casecmp(tokens[0], instructions[i].opcode)) {
1098  ut16 mintoks = instructions[i].mintoks;
1099  ut16 maxtoks = instructions[i].maxtoks;
1100  if (ntokens < mintoks || ntokens > maxtoks) {
1101  RZ_LOG_ERROR("[!] avr_assembler: '%s' requires %u <= ntokens <= %u, but %u tokens was provided.\n", tokens[0], mintoks, maxtoks, ntokens);
1102  goto avr_assembler_end;
1103  }
1104  written = instructions[i].encode(instructions[i].cbits, (cchar**)tokens, ntokens, output, pc, be);
1105  break;
1106  }
1107  }
1108 
1109 avr_assembler_end:
1110  tokens_free(tokens);
1111  return written;
1112 }
lzma_index ** i
Definition: index.h:629
static const AvrInstruction instructions[]
Definition: assembler.c:880
static void tokens_free(char **tokens)
Definition: assembler.c:1073
#define return_error_if_empty_input(a, b)
Definition: assembler.c:16
static char ** tokens_new(cchar *input, st32 input_size, ut32 *ntokens)
Definition: assembler.c:1024
uint32_t ut32
const char cchar
Definition: common.h:9
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
Definition: str.c:121
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
Encode encode
Definition: assembler.c:179
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)
diff_output_t output
Definition: zipcmp.c:237

References AVR_INVALID_SIZE, avr_decoder_t::encode, i, input(), instructions, avr_decoder_t::maxtoks, avr_decoder_t::mintoks, output, pc, return_error_if_empty_input, RZ_ARRAY_SIZE, RZ_LOG_ERROR, rz_str_casecmp(), tokens_free(), and tokens_new().

Referenced by assemble().

◆ avr_cbr()

static ut32 avr_cbr ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 244 of file assembler.c.

244  {
245  /* <opcode> Rd, K | 16 <= d <= 31, 0 <= K <= 255 */
246  ut16 Rd, K;
247  parse_register_or_error_limit(Rd, tokens[1], 16, 31);
248  parse_unsigned_or_error(K, tokens[2], 255);
249 
250  Rd -= 16;
251  K = 0xFF - K;
252 
253  cbins |= (K & 0x000F);
254  cbins |= ((K << 4) & 0x0F00);
255  cbins |= ((Rd << 4) & 0x00F0);
256 
257  auto_write16(data, cbins, be);
258  return 2;
259 }
#define parse_register_or_error_limit(rn, rs, min, max)
Definition: assembler.c:32

References auto_write16, parse_register_or_error_limit, and parse_unsigned_or_error.

◆ avr_dddcrrr()

static ut32 avr_dddcrrr ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 390 of file assembler.c.

390  {
391  /* <opcode> Rd,Rr | 16 <= d <= 23 | 16 <= r <= 23 */
392  ut16 Rd, Rr;
393  parse_register_or_error_limit(Rd, tokens[1], 16, 23);
394  parse_register_or_error_limit(Rr, tokens[2], 16, 23);
395 
396  Rd -= 16;
397  Rr -= 16;
398 
399  cbins |= (Rr & 0x0007);
400  cbins |= ((Rd << 4) & 0x0070);
401 
402  auto_write16(data, cbins, be);
403  return 2;
404 }

References auto_write16, and parse_register_or_error_limit.

◆ avr_ddddcccc()

static ut32 avr_ddddcccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 668 of file assembler.c.

668  {
669  /* <opcode> Rd | 16 <= d <= 31 */
670  ut16 Rd;
671  parse_register_or_error_limit(Rd, tokens[1], 16, 31);
672 
673  Rd -= 16;
674  cbins |= ((Rd << 4) & 0x00F0);
675 
676  auto_write16(data, cbins, be);
677  return 2;
678 }

References auto_write16, and parse_register_or_error_limit.

◆ avr_dddddcbbb()

static ut32 avr_dddddcbbb ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 273 of file assembler.c.

273  {
274  /* <opcode> Rd, b | 0 <= d <= 31, 0 <= b <= 7 */
275 
276  ut16 Rd, b;
277  parse_register_or_error(Rd, tokens[1]);
278  parse_unsigned_or_error(b, tokens[2], 7);
279 
280  cbins |= (b & 0x0007);
281  cbins |= ((Rd << 4) & 0x01F0);
282 
283  auto_write16(data, cbins, be);
284  return 2;
285 }

References auto_write16, b, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_dddddcccc()

static ut32 avr_dddddcccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 262 of file assembler.c.

262  {
263  /* <opcode> Rd | 0 <= d <= 31 */
264  ut16 Rd;
265  parse_register_or_error(Rd, tokens[1]);
266  cbins |= ((Rd << 4) & 0x01F0);
267 
268  auto_write16(data, cbins, be);
269  return 2;
270 }

References auto_write16, and parse_register_or_error.

◆ avr_dddddddddd()

static ut32 avr_dddddddddd ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 332 of file assembler.c.

332  {
333  /* <opcode> Rd | 0 <= d <= 31 */
334  ut16 Rd;
335  parse_register_or_error(Rd, tokens[1]);
336 
337  cbins |= (Rd & 0x000F);
338  cbins |= ((Rd << 5) & 0x0200);
339  cbins |= ((Rd << 4) & 0x01F0);
340 
341  auto_write16(data, cbins, be);
342  return 2;
343 }

References auto_write16, and parse_register_or_error.

◆ avr_ddddrrrr()

static ut32 avr_ddddrrrr ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 602 of file assembler.c.

602  {
603  /* <opcode> Rd, Rr | d = {0,2,...,30} | r = {0,2,...,30} */
604  ut16 Rd, Rr;
605  parse_register_or_error(Rd, tokens[1]);
606  parse_register_or_error(Rr, tokens[2]);
607 
608  if (Rd & 1) {
609  throw_error("register must be even, Rd = {0,2,...,30} (parsed r%u)\n", Rd);
610  } else if (Rr & 1) {
611  throw_error("register must be even, Rr = {0,2,...,30} (parsed r%u)\n", Rr);
612  }
613 
614  Rr /= 2;
615  Rd /= 2;
616  cbins |= Rr & 0x000F;
617  cbins |= ((Rd << 4) & 0x00F0);
618 
619  auto_write16(data, cbins, be);
620  return 2;
621 }
#define throw_error(msg,...)
Definition: assembler.c:10

References auto_write16, parse_register_or_error, and throw_error.

◆ avr_ddddrrrr_2x()

static ut32 avr_ddddrrrr_2x ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 624 of file assembler.c.

624  {
625  /* <opcode> Rd, Rr | 16 <= d <= 31 | 16 <= r <= 31 */
626  ut16 Rd, Rr;
627  parse_register_or_error_limit(Rd, tokens[1], 16, 31);
628  parse_register_or_error_limit(Rr, tokens[2], 16, 31);
629 
630  Rr -= 16;
631  Rd -= 16;
632  cbins |= Rr & 0x000F;
633  cbins |= ((Rd << 4) & 0x00F0);
634 
635  auto_write16(data, cbins, be);
636  return 2;
637 }

References auto_write16, and parse_register_or_error_limit.

◆ avr_elpm()

static ut32 avr_elpm ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 358 of file assembler.c.

358  {
359  if (ntokens == 1) {
360  /* elpm */
361  /* 1001010111011000 */
362  cbins = 0x95D8;
363  } else if (ntokens == 3) {
364  /* elpm Rd, Z | 0 <= Rd <= 31 */
365  ut16 Rd;
366  parse_register_or_error(Rd, tokens[1]);
367  expected_const_or_error(tokens[2], "z");
368 
369  /* 1001000ddddd0110 */
370  cbins = 0x9006;
371  cbins |= ((Rd << 4) & 0x01F0);
372  } else if (ntokens == 4) {
373  /* elpm Rd, Z+ | 0 <= Rd <= 31 */
374  ut16 Rd;
375  parse_register_or_error(Rd, tokens[1]);
376  expected_const_or_error(tokens[2], "z");
377  expected_const_or_error(tokens[3], "+");
378 
379  /* 1001000ddddd0111 */
380  cbins = 0x9007;
381  cbins |= ((Rd << 4) & 0x01F0);
382  } else {
383  throw_error("expected 'elpm' or 'elpm Rd, M' | 0 <= d <= 31 | M = {Z,Z+}\n");
384  }
385 
386  auto_write16(data, cbins, be);
387  return 2;
388 }
#define expected_const_or_error(a, exp)
Definition: assembler.c:24

References auto_write16, expected_const_or_error, parse_register_or_error, and throw_error.

◆ avr_KKddKKKK()

static ut32 avr_KKddKKKK ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 205 of file assembler.c.

205  {
206  /* <opcode> Rd, K | d = {24,26,28,30}, 0 <= K <= 63 */
207  ut16 Rd, K;
208  parse_register_pair_or_error(Rd, tokens[1]);
209  parse_unsigned_or_error(K, tokens[2], 63);
210 
211  if (Rd < 24 || Rd & 1) {
212  throw_error("register must be Rd = {24,26,28,30} (parsed r%u)\n", Rd);
213  }
214 
215  Rd -= 24;
216  Rd >>= 1;
217 
218  cbins |= (K & 0x000F);
219  cbins |= ((K << 2) & 0x00C0);
220  cbins |= ((Rd << 4) & 0x0030);
221 
222  auto_write16(data, cbins, be);
223  return 2;
224 }
#define parse_register_pair_or_error(rn, rs)
Parse things like "r25:r24" or just "r24". Result would be 24 in both cases.
Definition: assembler.c:67

References auto_write16, parse_register_pair_or_error, parse_unsigned_or_error, and throw_error.

◆ avr_KKKKcccc()

static ut32 avr_KKKKcccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 346 of file assembler.c.

346  {
347  /* <opcode> K | 0 <= K <= 0xF */
348  ut16 K;
349  parse_unsigned_or_error(K, tokens[1], 0xF);
350 
351  cbins |= ((K << 4) & 0x00F0);
352 
353  auto_write16(data, cbins, be);
354  return 2;
355 }

References auto_write16, and parse_unsigned_or_error.

◆ avr_KKKKddddKKKK()

static ut32 avr_KKKKddddKKKK ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 227 of file assembler.c.

227  {
228  /* <opcode> Rd, K | 16 <= d <= 31, 0 <= K <= 255 */
229  ut16 Rd, K;
230  parse_register_or_error_limit(Rd, tokens[1], 16, 31);
231  parse_unsigned_or_error(K, tokens[2], 255);
232 
233  Rd -= 16;
234 
235  cbins |= (K & 0x000F);
236  cbins |= ((K << 4) & 0x0F00);
237  cbins |= ((Rd << 4) & 0x00F0);
238 
239  auto_write16(data, cbins, be);
240  return 2;
241 }

References auto_write16, parse_register_or_error_limit, and parse_unsigned_or_error.

◆ avr_kkkkkccck()

static ut32 avr_kkkkkccck ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 298 of file assembler.c.

298  {
299  // <opcode> k | 0 <= k < 0x7ffffe
300  ut32 k;
301  parse_unsigned_or_error(k, tokens[1], 0x7ffffe);
302 
303  k /= 2;
304 
305  ut16 kh = k >> 16;
306  ut16 kl = k & 0xFFFF;
307 
308  cbins |= (kh & 0x0001);
309  cbins |= ((kh << 3) & 0x01F0);
310 
311  auto_write16(data, cbins, be);
312  auto_write16(data + 2, kl, be);
313  return 4;
314 }
const char * k
Definition: dsignal.c:11

References auto_write16, k, and parse_unsigned_or_error.

◆ avr_kkkkkkkccc()

static ut32 avr_kkkkkkkccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 288 of file assembler.c.

288  {
289  /* <opcode> k | -64 <= k <= 63 */
290  st16 k;
291  parse_address_or_error(k, tokens[1], pc, -64, 63);
292  cbins |= ((k << 3) & 0x03F8);
293  auto_write16(data, cbins, be);
294  return 2;
295 }
#define parse_address_or_error(rn, rs, pc, llow, lhigh)
Definition: assembler.c:120
#define st16
Definition: rz_types_base.h:14

References auto_write16, k, parse_address_or_error, pc, and st16.

◆ avr_kkkkkkkkkkkk()

static ut32 avr_kkkkkkkkkkkk ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 591 of file assembler.c.

591  {
592  /* <opcode> k | -4096 <= k <= 4096 */
593  st16 k;
594  parse_address_or_error(k, tokens[1], pc, -4096, 4096);
595  cbins |= (k & 0x0FFF);
596 
597  auto_write16(data, cbins, be);
598  return 2;
599 }

References auto_write16, k, parse_address_or_error, pc, and st16.

◆ avr_kkkkkkksss()

static ut32 avr_kkkkkkksss ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 866 of file assembler.c.

866  {
867  /* <opcode> b, k | -64 <= k <= 63 | 0 <= b <= 7 */
868  ut16 b;
869  st16 k;
870  parse_unsigned_or_error(b, tokens[1], 7);
871  parse_address_or_error(k, tokens[2], pc, -64, 63);
872 
873  cbins |= (b & 0x0007);
874  cbins |= ((k << 3) & 0x03F8);
875  auto_write16(data, cbins, be);
876  return 2;
877 }

References auto_write16, b, k, parse_address_or_error, parse_unsigned_or_error, pc, and st16.

◆ avr_ld()

static ut32 avr_ld ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 434 of file assembler.c.

434  {
435  /* ld Rd, M | 0 <= d <= 31 | M = {X,Y,Z,X+,Y+,Z+,-X,-Y,-Z} */
436  ut16 Rd;
437  parse_register_or_error(Rd, tokens[1]);
438 
439  if (ntokens == 3) {
440  if (!strcmp(tokens[2], "x")) {
441  /* ld Rd, X */
442  /* 1001000ddddd1100 */
443  cbins = 0x900C;
444  } else if (!strcmp(tokens[2], "y")) {
445  /* ld Rd, Y */
446  /* 1000000ddddd1000 */
447  cbins = 0x8008;
448  } else if (!strcmp(tokens[2], "z")) {
449  /* ld Rd, Z */
450  /* 1001000ddddd0000 */
451  cbins = 0x8000;
452  } else if (!strcmp(tokens[2], "-x")) {
453  /* ld Rd, -X */
454  /* 1001000ddddd1110 */
455  cbins = 0x900E;
456  } else if (!strcmp(tokens[2], "-y")) {
457  /* ld Rd, -Y */
458  /* 1001000ddddd1010 */
459  cbins = 0x900A;
460  } else if (!strcmp(tokens[2], "-z")) {
461  /* ld Rd, -Z */
462  /* 1001000ddddd0010 */
463  cbins = 0x9002;
464  } else {
465  throw_error("expected 'X' or 'Y' or 'Z' or '-X' or '-Y' or '-Z', but got '%s'\n", tokens[2]);
466  }
467  } else if (ntokens == 4 && !strcmp(tokens[3], "+")) {
468  if (!strcmp(tokens[2], "x")) {
469  /* ld Rd, X+ */
470  /* 1001000ddddd1101 */
471  cbins = 0x900D;
472  } else if (!strcmp(tokens[2], "y")) {
473  /* ld Rd, Y+ */
474  /* 1001000ddddd1001 */
475  cbins = 0x9009;
476  } else if (!strcmp(tokens[2], "z")) {
477  /* ld Rd, Z+ */
478  /* 1001000ddddd0001 */
479  cbins = 0x9001;
480  } else {
481  throw_error("expected 'X+' or 'Y+' or 'Z+', but got '%s+'\n", tokens[2]);
482  }
483  } else {
484  throw_error("expected ld Rd, M | 0 <= d <= 31 | M = {X,Y,Z,X+,Y+,Z+,-X,-Y,-Z}\n");
485  }
486 
487  cbins |= ((Rd << 4) & 0x01F0);
488  auto_write16(data, cbins, be);
489  return 2;
490 }

References auto_write16, parse_register_or_error, and throw_error.

◆ avr_ldd()

static ut32 avr_ldd ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 493 of file assembler.c.

493  {
494  /* ldd Rd, M + q | 0 <= d <= 31 | M = {Y,Z} | 0 <= q <= 63*/
495  ut16 Rd, q;
496  parse_register_or_error(Rd, tokens[1]);
497  parse_unsigned_or_error(q, tokens[4], 63);
498 
499  if (!strcmp(tokens[3], "+")) {
500  if (!strcmp(tokens[2], "y")) {
501  /* ldd Rd, Y+q */
502  /* 10q0qq0ddddd1qqq */
503  cbins = 0x8008;
504  } else if (!strcmp(tokens[2], "z")) {
505  /* ldd Rd, Z+q */
506  /* 10q0qq0ddddd0qqq */
507  cbins = 0x8000;
508  } else {
509  throw_error("expected 'Y+' or 'Z+', but got '%s+'\n", tokens[2]);
510  }
511  } else {
512  throw_error("expected ldd Rd, M + q | 0 <= d <= 31 | M = {Y,Z} | 0 <= q <= 63\n");
513  }
514 
515  cbins |= q & 0x0007;
516  cbins |= ((q << 7) & 0x0C00);
517  cbins |= ((q << 8) & 0x2000);
518  cbins |= ((Rd << 4) & 0x01F0);
519  auto_write16(data, cbins, be);
520  return 2;
521 }

References auto_write16, parse_register_or_error, parse_unsigned_or_error, and throw_error.

◆ avr_lds()

static ut32 avr_lds ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 524 of file assembler.c.

524  {
525  ut16 Rd;
526  ut32 k;
527  parse_register_or_error(Rd, tokens[1]);
528  parse_unsigned_or_error(k, tokens[2], 0xFFFF);
529 
530 #if 0
531  // The STS (16-bit) and LDS (16-bit) instructions only exist in the reduced AVR cores.
532  // This includes only the ATtiny4/5/9/10 family, and the ATtiny20/40 family.
533  // They also lack some features like the lack of CPU registers R0 to R15.
534  // On rizin these platforms are not supported, therefore this code is commented, but works as intended.
535  if (k <= 127 && Rd >= 16) {
536  /* lds Rd, k | 16 <= d <= 31 | 0 <= k <= 127 */
537  /* 10100kkkddddkkkk */
538  cbins = 0xA000;
539  Rd -= 16;
540  cbins |= k & 0x000F;
541  cbins |= ((k << 4) & 0x0700);
542  cbins |= ((Rd << 4) & 0x00F0);
543 
544  auto_write16(data, cbins, be);
545  return 2;
546  }
547 #endif
548  /* lds Rd, k | 0 <= d <= 31 | 0 <= k <= 0xFFFF */
549  /* 1001000ddddd0000 kkkkkkkkkkkkkkkk */
550  cbins = 0x9000;
551  cbins |= ((Rd << 4) & 0x01F0);
552  auto_write16(data, cbins, be);
553  auto_write16(data + 2, k, be);
554  return 4;
555 }

References auto_write16, k, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_lpm()

static ut32 avr_lpm ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 558 of file assembler.c.

558  {
559  if (ntokens == 1) {
560  /* lpm */
561  /* 1001010111001000 */
562  cbins = 0x95C8;
563  } else if (ntokens == 3) {
564  /* lpm Rd, Z | 0 <= Rd <= 31 */
565  ut16 Rd;
566  parse_register_or_error(Rd, tokens[1]);
567  expected_const_or_error(tokens[2], "z");
568 
569  /* 1001000ddddd0100 */
570  cbins = 0x9004;
571  cbins |= ((Rd << 4) & 0x01F0);
572  } else if (ntokens == 4) {
573  /* lpm Rd, Z+ | 0 <= Rd <= 31 */
574  ut16 Rd;
575  parse_register_or_error(Rd, tokens[1]);
576  expected_const_or_error(tokens[2], "z");
577  expected_const_or_error(tokens[3], "+");
578 
579  /* 1001000ddddd0101 */
580  cbins = 0x9005;
581  cbins |= ((Rd << 4) & 0x01F0);
582  } else {
583  throw_error("expected 'lpm' or 'lpm Rd, M' | 0 <= d <= 31 | M = {Z,Z+}\n");
584  }
585 
586  auto_write16(data, cbins, be);
587  return 2;
588 }

References auto_write16, expected_const_or_error, parse_register_or_error, and throw_error.

◆ avr_rdddddrrrr()

static ut32 avr_rdddddrrrr ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 189 of file assembler.c.

189  {
190  /* <opcode> Rd,Rr | 0 <= d <= 31 | 0 <= r <= 31 */
191  ut16 Rd, Rr;
192  parse_register_or_error(Rd, tokens[1]);
193  parse_register_or_error(Rr, tokens[2]);
194 
195 
196  cbins |= (Rr & 0x000F);
197  cbins |= ((Rr << 5) & 0x0200);
198  cbins |= ((Rd << 4) & 0x01F0);
199 
200  auto_write16(data, cbins, be);
201  return 2;
202 }

References auto_write16, and parse_register_or_error.

◆ avr_rrrrrcbbb()

static ut32 avr_rrrrrcbbb ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 655 of file assembler.c.

655  {
656  /* <opcode> Rr, b | 0 <= d <= 31, 0 <= b <= 7 */
657  ut16 Rr, b;
658  parse_register_or_error(Rr, tokens[1]);
659  parse_unsigned_or_error(b, tokens[2], 63);
660 
661  cbins |= (b & 0x0007);
662  cbins |= ((Rr << 4) & 0x01F0);
663 
664  auto_write16(data, cbins, be);
665  return 2;
666 }

References auto_write16, b, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_rrrrrcccc()

static ut32 avr_rrrrrcccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 421 of file assembler.c.

421  {
422  /* <opcode> Rd | 0 <= d <= 31 */
423  ut16 Rd;
424  expected_const_or_error(tokens[1], "z");
425  parse_register_or_error(Rd, tokens[2]);
426  cbins |= ((Rd << 4) & 0x01F0);
427 
428  auto_write16(data, cbins, be);
429  return 2;
430 }

References auto_write16, expected_const_or_error, and parse_register_or_error.

◆ avr_spm()

static ut32 avr_spm ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 681 of file assembler.c.

681  {
682  if (ntokens == 1) {
683  /* spm */
684  /* 1001010111101000 */
685  cbins = 0x95E8;
686  } else if (ntokens == 3) {
687  /* spm Z+ | 0 <= Rd <= 31 */
688  expected_const_or_error(tokens[1], "z");
689  expected_const_or_error(tokens[2], "+");
690 
691  /* 1001010111111000 */
692  cbins = 0x95F8;
693  } else {
694  throw_error("expected 'spm' or 'spm Z+'\n");
695  }
696 
697  auto_write16(data, cbins, be);
698  return 2;
699 }

References auto_write16, expected_const_or_error, and throw_error.

◆ avr_ssscccc()

static ut32 avr_ssscccc ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 855 of file assembler.c.

855  {
856  /* <opcode> b | 0 <= b <= 7 */
857  ut16 b;
858  parse_unsigned_or_error(b, tokens[1], 7);
859 
860  cbins |= ((b << 4) & 0x0070);
861  auto_write16(data, cbins, be);
862  return 2;
863 }

References auto_write16, b, and parse_unsigned_or_error.

◆ avr_st()

static ut32 avr_st ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 702 of file assembler.c.

702  {
703  /* st M, Rr | 0 <= r <= 31 | M = {X,Y,Z,-X,-Y,-Z} */
704  ut16 Rr;
705  parse_register_or_error(Rr, tokens[2]);
706 
707  if (ntokens == 3) {
708  if (!strcmp(tokens[1], "x")) {
709  /* st X, Rr */
710  /* 1001001rrrrr1100 */
711  cbins = 0x920C;
712  } else if (!strcmp(tokens[1], "y")) {
713  /* st Y, Rr */
714  /* 1000001rrrrr1000 */
715  cbins = 0x8208;
716  } else if (!strcmp(tokens[1], "z")) {
717  /* st Z, Rr */
718  /* 1000001rrrrr0000 */
719  cbins = 0x8200;
720  } else if (!strcmp(tokens[1], "-x")) {
721  /* st -X, Rr */
722  /* 1001001rrrrr1110 */
723  cbins = 0x920E;
724  } else if (!strcmp(tokens[1], "-y")) {
725  /* st -Y, Rr */
726  /* 1001001rrrrr1010 */
727  cbins = 0x920A;
728  } else if (!strcmp(tokens[1], "-z")) {
729  /* st -Z, Rr */
730  /* 1001001rrrrr0010 */
731  cbins = 0x9202;
732  } else {
733  throw_error("expected 'X' or 'Y' or 'Z' or '-X' or '-Y' or '-Z', but got '%s'\n", tokens[1]);
734  }
735  } else if (ntokens == 5 && !strcmp(tokens[2], "+") && !strcmp(tokens[3], "1")) {
736  if (!strcmp(tokens[1], "x")) {
737  /* st X+1, Rr */
738  /* 1001001rrrrr1101 */
739  cbins = 0x920D;
740  } else if (!strcmp(tokens[1], "y")) {
741  /* st Y+1, Rr */
742  /* 1001001rrrrr1001 */
743  cbins = 0x9209;
744  } else if (!strcmp(tokens[1], "z")) {
745  /* st Z+1, Rr */
746  /* 1001001rrrrr0001 */
747  cbins = 0x9201;
748  } else {
749  throw_error("expected 'X+' or 'Y+' or 'Z+', but got '%s+'\n", tokens[2]);
750  }
751  } else {
752  throw_error("expected st M, Rr | 0 <= r <= 31 | M = {X,Y,Z,-X,-Y,-Z}\n");
753  }
754 
755  cbins |= ((Rr << 4) & 0x01F0);
756  auto_write16(data, cbins, be);
757  return 2;
758 }

References auto_write16, parse_register_or_error, and throw_error.

◆ avr_std()

static ut32 avr_std ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 761 of file assembler.c.

761  {
762  if (ntokens == 4) {
763  /* std M, Rr | 0 <= r <= 31 | M = {X+,Y+,Z+} */
764  ut16 Rr;
765  expected_const_or_error(tokens[2], "+");
766  parse_register_or_error(Rr, tokens[3]);
767 
768  if (!strcmp(tokens[1], "x")) {
769  /* std X+, Rr */
770  /* 1001001rrrrr1101 */
771  cbins = 0x900D;
772  } else if (!strcmp(tokens[1], "y")) {
773  /* std Y+, Rr */
774  /* 1001001rrrrr1001 */
775  cbins = 0x9009;
776  } else if (!strcmp(tokens[1], "z")) {
777  /* std Z+, Rr */
778  /* 1001001rrrrr0001 */
779  cbins = 0x9001;
780  } else {
781  throw_error("expected 'X+' or 'Y+' or 'Z+', but got '%s+'\n", tokens[1]);
782  }
783  cbins |= ((Rr << 4) & 0x01F0);
784 
785  auto_write16(data, cbins, be);
786  return 2;
787  } else if (ntokens == 5) {
788  /* std M + q, Rr | 0 <= r <= 31 | M = {Y,Z} | 0 <= q <= 63*/
789  ut16 Rr, q;
790  expected_const_or_error(tokens[2], "+");
791  parse_unsigned_or_error(q, tokens[3], 63);
792  parse_register_or_error(Rr, tokens[4]);
793 
794  if (!strcmp(tokens[1], "y")) {
795  /* std Y+q, Rr */
796  /* 10q0qq1rrrrr1qqq */
797  cbins = 0x8208;
798  } else if (!strcmp(tokens[1], "z")) {
799  /* std Z+q, Rr */
800  /* 10q0qq1rrrrr0qqq */
801  cbins = 0x8200;
802  } else {
803  throw_error("expected 'Y' or 'Z', but got '%s'\n", tokens[1]);
804  }
805 
806  cbins |= q & 0x0007;
807  cbins |= ((q << 7) & 0x0C00);
808  cbins |= ((q << 8) & 0x2000);
809  cbins |= ((Rr << 4) & 0x01F0);
810 
811  auto_write16(data, cbins, be);
812  return 2;
813  }
814 
815  throw_error("expected std Rr, M + q | 0 <= d <= 31 | M = {Y,Z} | 0 <= q <= 63\n");
816 }

References auto_write16, expected_const_or_error, parse_register_or_error, parse_unsigned_or_error, and throw_error.

◆ avr_sts()

static ut32 avr_sts ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 820 of file assembler.c.

820  {
821  /* sts k, Rr | 0 <= r <= 31, 0 <= k <= 0xFFFF */
822  ut16 Rr;
823  ut32 k;
824  parse_unsigned_or_error(k, tokens[1], 0xFFFF);
825  parse_register_or_error(Rr, tokens[2]);
826 
827 #if 0
828  // The STS (16-bit) and LDS (16-bit) instructions only exist in the reduced AVR cores.
829  // This includes only the ATtiny4/5/9/10 family, and the ATtiny20/40 family.
830  // They also lack some features like the lack of CPU registers R0 to R15.
831  // On rizin these platforms are not supported, therefore this code is commented, but works as intended.
832  if (k <= 127 && Rr >= 16) {
833  /* sts k, Rr | 16 <= d <= 31 | 0 <= k <= 127 */
834  /* 10101kkkddddkkkk */
835  cbins = 0xA800;
836  Rr -= 16;
837  cbins |= k & 0x000F;
838  cbins |= ((k << 4) & 0x0700);
839  cbins |= ((Rr << 4) & 0x00F0);
840 
841  auto_write16(data, cbins, be);
842  return 2;
843  }
844 #endif
845  /* sts k, Rr | 0 <= d <= 31 | 0 <= k <= 0xFFFF */
846  /* 1001001ddddd0000 kkkkkkkkkkkkkkkk */
847  cbins = 0x9200;
848  cbins |= ((Rr << 4) & 0x01F0);
849  auto_write16(data, cbins, be);
850  auto_write16(data + 2, k, be);
851  return 4;
852 }

References auto_write16, k, parse_register_or_error, and parse_unsigned_or_error.

◆ avr_unique()

static ut32 avr_unique ( ut16  cbins,
cchar **  tokens,
ut32  ntokens,
ut8 data,
ut64  pc,
bool  be 
)
static

Definition at line 183 of file assembler.c.

183  {
184  auto_write16(data, cbins, be);
185  return 2;
186 }

References auto_write16.

◆ sanitize_input()

static void sanitize_input ( char *  cinput,
st32  input_size 
)
static

Definition at line 1016 of file assembler.c.

1016  {
1017  for (st32 i = 0; i < input_size; ++i) {
1018  if (cinput[i] == ',') {
1019  cinput[i] = ' ';
1020  }
1021  }
1022 }
#define st32
Definition: rz_types_base.h:12

References i, and st32.

Referenced by tokens_new().

◆ strdup_limit()

static char* strdup_limit ( cchar begin,
cchar end 
)
static

Definition at line 1002 of file assembler.c.

1002  {
1003  ssize_t size = end - begin;
1004  if (size < 1) {
1005  return NULL;
1006  }
1007  char* str = malloc(size + 1);
1008  if (!str) {
1009  return NULL;
1010  }
1011  memcpy(str, begin, size);
1012  str[size] = 0;
1013  return str;
1014 }
voidpf void uLong size
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
int ssize_t
Definition: sftypes.h:39

References test_evm::end, malloc(), memcpy(), NULL, and cmd_descs_generate::str.

Referenced by tokens_new().

◆ tokens_free()

static void tokens_free ( char **  tokens)
static

Definition at line 1073 of file assembler.c.

1073  {
1074  if (!tokens) {
1075  return;
1076  }
1077  for (ut32 i = 0; i < MAX_TOKENS; ++i) {
1078  free(tokens[i]);
1079  }
1080  free(tokens);
1081 }
#define MAX_TOKENS
Definition: assembler.c:7
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), i, and MAX_TOKENS.

Referenced by avr_assembler().

◆ tokens_new()

static char** tokens_new ( cchar input,
st32  input_size,
ut32 ntokens 
)
static

Definition at line 1024 of file assembler.c.

1024  {
1025 
1026  char* cinput = strdup(input);
1027  if (!cinput) {
1029  return NULL;
1030  }
1031 
1032  sanitize_input(cinput, input_size);
1033 
1034  char **tokens = RZ_NEWS0(char*, MAX_TOKENS);
1035  if (!tokens) {
1036  free(cinput);
1038  return NULL;
1039  }
1040 
1041  ut32 count;
1042  cchar *start, *end;
1043  char* copy;
1044 
1045  start = rz_str_trim_head_ro(cinput);
1046  for (count = 0; *start && count < MAX_TOKENS; count++) {
1048 
1049  for (ut32 i = 0; i < end - start; ++i) {
1050  if (start[i] == '+') {
1051  end = start + 1;
1052  break;
1053  }
1054  }
1055 
1056  copy = strdup_limit(start, end);
1057  if (!copy) {
1059  break;
1060  }
1061 
1062  tokens[count] = copy;
1064  }
1065 
1067 
1068  *ntokens = count;
1069  free(cinput);
1070  return tokens;
1071 }
static void sanitize_input(char *cinput, st32 input_size)
Definition: assembler.c:1016
static char * strdup_limit(cchar *begin, cchar *end)
Definition: assembler.c:1002
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35
RZ_API const char * rz_str_trim_head_wp(const char *str)
Definition: str_trim.c:95
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282

References count, test_evm::end, free(), i, input(), MAX_TOKENS, NULL, RZ_NEWS0, rz_str_trim_head_ro(), rz_str_trim_head_wp(), rz_warn_if_fail, rz_warn_if_reached, sanitize_input(), start, strdup(), and strdup_limit().

Referenced by avr_assembler().

Variable Documentation

◆ instructions