Rizin
unix-like reverse engineering framework and cli tools
amd29k.h File Reference
#include <stdint.h>
#include <rz_types.h>

Go to the source code of this file.

Classes

struct  amd29k_instr_s
 

Macros

#define CPU_29000   "29000"
 
#define CPU_29050   "29050"
 

Typedefs

typedef struct amd29k_instr_s amd29k_instr_t
 

Functions

bool amd29k_instr_decode (const ut8 *buffer, const ut32 buffer_size, amd29k_instr_t *instruction, const char *cpu)
 
void amd29k_instr_print (char *string, int string_size, ut64 address, amd29k_instr_t *instruction)
 
bool amd29k_instr_is_ret (amd29k_instr_t *instruction)
 
ut64 amd29k_instr_jump (ut64 address, amd29k_instr_t *instruction)
 

Macro Definition Documentation

◆ CPU_29000

#define CPU_29000   "29000"

Definition at line 13 of file amd29k.h.

◆ CPU_29050

#define CPU_29050   "29050"

Definition at line 14 of file amd29k.h.

Typedef Documentation

◆ amd29k_instr_t

Function Documentation

◆ amd29k_instr_decode()

bool amd29k_instr_decode ( const ut8 buffer,
const ut32  buffer_size,
amd29k_instr_t instruction,
const char *  cpu 
)

Definition at line 435 of file amd29k.c.

435  {
436  if (!buffer || buffer_size < 4 || !instruction || (cpu && strlen(cpu) < 5)) {
437  return false;
438  }
439  if (!cpu) {
440  cpu = CPU_29000;
441  }
442  if (buffer[0] == 0x70 && buffer[1] == 0x40 && buffer[2] == 0x01 && buffer[3] == 0x01) {
444  instruction->mnemonic = "nop";
446  return true;
447  }
448  int i;
449  for (i = 0; i < N_AMD29K_INSTRUCTIONS; i++) {
451  if (in->cpu[0] == '*' && in->mask == buffer[0]) {
452  in->decode(instruction, buffer);
453  instruction->mnemonic = in->mnemonic;
454  instruction->op_type = in->op_type;
455  return true;
456  } else if (in->cpu[0] != '*' && in->mask == buffer[0] && is_cpu(cpu, in)) {
457  in->decode(instruction, buffer);
458  instruction->mnemonic = in->mnemonic;
459  instruction->op_type = in->op_type;
460  return true;
461  }
462  }
463  return false;
464 }
static void decode_none(amd29k_instr_t *instruction, const ut8 *buffer)
Definition: amd29k.c:207
const amd29k_instruction_t amd29k_instructions[N_AMD29K_INSTRUCTIONS]
Definition: amd29k.c:217
#define N_AMD29K_INSTRUCTIONS
Definition: amd29k.c:11
static bool is_cpu(const char *cpu, const amd29k_instruction_t *in)
Definition: amd29k.c:427
#define CPU_29000
Definition: amd29k.h:13
static ut32 cpu[32]
Definition: analysis_or1k.c:21
lzma_index ** i
Definition: index.h:629
const lzma_allocator const uint8_t * in
Definition: block.h:527
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
Definition: buffer.h:15
#define buffer_size(buffer)

References amd29k_instructions, buffer_size, cpu, CPU_29000, decode_none(), i, in, is_cpu(), N_AMD29K_INSTRUCTIONS, and RZ_ANALYSIS_OP_TYPE_NOP.

Referenced by analop(), and disassemble().

◆ amd29k_instr_is_ret()

bool amd29k_instr_is_ret ( amd29k_instr_t instruction)

Definition at line 473 of file amd29k.c.

473  {
474  if (instruction && !strcmp(instruction->mnemonic, "calli") && instruction->operands[0] == 128 && instruction->operands[1] == 128) {
475  return true;
476  }
477  return false;
478 }

Referenced by analop().

◆ amd29k_instr_jump()

ut64 amd29k_instr_jump ( ut64  address,
amd29k_instr_t instruction 
)

Definition at line 480 of file amd29k.c.

480  {
481  if (!instruction) {
482  return UT64_MAX;
483  }
484  int t0 = AMD29K_GET_TYPE(instruction, 0);
485  int t1 = AMD29K_GET_TYPE(instruction, 1);
486  int t2 = AMD29K_GET_TYPE(instruction, 2);
487  int t3 = AMD29K_GET_TYPE(instruction, 3);
488  int t4 = AMD29K_GET_TYPE(instruction, 4);
489  int t5 = AMD29K_GET_TYPE(instruction, 5);
490 
491  int v0 = AMD29K_GET_VALUE(instruction, 0);
492  int v1 = AMD29K_GET_VALUE(instruction, 1);
494  return address + ((int)v0);
496  return address + ((int)v1);
497  }
498  return UT64_MAX;
499 }
#define AMD29K_IS_2(a, b)
Definition: amd29k.c:468
#define AMD29K_GET_VALUE(x, i)
Definition: amd29k.c:14
#define AMD29K_IS_1(a)
Definition: amd29k.c:467
#define AMD29K_GET_TYPE(x, i)
Definition: amd29k.c:13
@ AMD29K_TYPE_JMP
@ AMD29K_TYPE_REG
@ v0
Definition: lanai.h:84
@ v1
Definition: lanai.h:85
#define UT64_MAX
Definition: rz_types_base.h:86
static int
Definition: sfsocketcall.h:114

References AMD29K_GET_TYPE, AMD29K_GET_VALUE, AMD29K_IS_1, AMD29K_IS_2, AMD29K_TYPE_JMP, AMD29K_TYPE_REG, int, benchmark::t1, UT64_MAX, v0, and v1.

Referenced by analop().

◆ amd29k_instr_print()

void amd29k_instr_print ( char *  string,
int  string_size,
ut64  address,
amd29k_instr_t instruction 
)

Definition at line 501 of file amd29k.c.

501  {
502  if (!string || string_size < 0 || !instruction) {
503  return;
504  }
505  int t0 = AMD29K_GET_TYPE(instruction, 0);
506  int t1 = AMD29K_GET_TYPE(instruction, 1);
507  int t2 = AMD29K_GET_TYPE(instruction, 2);
508  int t3 = AMD29K_GET_TYPE(instruction, 3);
509  int t4 = AMD29K_GET_TYPE(instruction, 4);
510  int t5 = AMD29K_GET_TYPE(instruction, 5);
511 
512  int v0 = AMD29K_GET_VALUE(instruction, 0);
513  int v1 = AMD29K_GET_VALUE(instruction, 1);
514  int v2 = AMD29K_GET_VALUE(instruction, 2);
515  int v3 = AMD29K_GET_VALUE(instruction, 3);
516  int v4 = AMD29K_GET_VALUE(instruction, 4);
517  int v5 = AMD29K_GET_VALUE(instruction, 5);
518 
520  const char *p0 = AMD29K_REGNAME(v0);
521  snprintf(string, string_size, "%s %s%d", instruction->mnemonic, p0, AMD29K_LR(v0));
522 
523  } else if (AMD29K_IS_1(AMD29K_TYPE_IMM)) {
524  if (v0 >= 0) {
525  snprintf(string, string_size, "%s 0x%x", instruction->mnemonic, v0);
526  } else {
527  v0 = 0 - v0;
528  snprintf(string, string_size, "%s -0x%x", instruction->mnemonic, v0);
529  }
530 
531  } else if (AMD29K_IS_1(AMD29K_TYPE_JMP)) {
532  ut64 ptr = address + ((int)v0);
533  snprintf(string, string_size, "%s 0x%" PFMT64x, instruction->mnemonic, ptr);
534 
536  const char *p0 = AMD29K_REGNAME(v0);
537  const char *p1 = AMD29K_REGNAME(v1);
538  snprintf(string, string_size, "%s %s%d %s%d", instruction->mnemonic, p0, AMD29K_LR(v0), p1, AMD29K_LR(v1));
539 
541  const char *p0 = AMD29K_REGNAME(v0);
542  if (v1 >= 0) {
543  snprintf(string, string_size, "%s %s%d 0x%x", instruction->mnemonic, p0, AMD29K_LR(v0), v1);
544  } else {
545  v1 = 0 - v1;
546  snprintf(string, string_size, "%s %s%d -0x%x", instruction->mnemonic, p0, AMD29K_LR(v0), v1);
547  }
548 
550  const char *p0 = AMD29K_REGNAME(v0);
551  ut64 ptr = address + ((int)v1);
552  snprintf(string, string_size, "%s %s%d 0x%" PFMT64x, instruction->mnemonic, p0, AMD29K_LR(v0), ptr);
553 
555  const char *p0 = AMD29K_REGNAME(v0);
556  const char *p1 = AMD29K_REGNAME(v1);
557  const char *p2 = AMD29K_REGNAME(v2);
558  snprintf(string, string_size, "%s %s%d %s%d %s%d", instruction->mnemonic, p0, AMD29K_LR(v0), p1, AMD29K_LR(v1), p2, AMD29K_LR(v2));
559 
561  const char *p0 = AMD29K_REGNAME(v0);
562  const char *p1 = AMD29K_REGNAME(v1);
563  if (v2 >= 0) {
564  snprintf(string, string_size, "%s %s%d %s%d 0x%x", instruction->mnemonic, p0, AMD29K_LR(v0), p1, AMD29K_LR(v1), v2);
565  } else {
566  v2 = 0 - v2;
567  snprintf(string, string_size, "%s %s%d %s%d -0x%x", instruction->mnemonic, p0, AMD29K_LR(v0), p1, AMD29K_LR(v1), v2);
568  }
569 
571  const char *p2 = AMD29K_REGNAME(v2);
572  const char *p3 = AMD29K_REGNAME(v3);
573  snprintf(string, string_size, "%s %d %d %s%d %s%d", instruction->mnemonic, v0, v1, p2, AMD29K_LR(v2), p3, AMD29K_LR(v3));
574 
576  const char *p0 = AMD29K_REGNAME(v0);
577  const char *p1 = AMD29K_REGNAME(v1);
578  snprintf(string, string_size, "%s %s%d %s%d %d %d %d %d", instruction->mnemonic, p0, AMD29K_LR(v0), p1, AMD29K_LR(v1), v2, v3, v4, v5);
579 
580  } else {
581  snprintf(string, string_size, "%s", instruction->mnemonic);
582  }
583  return;
584 }
#define AMD29K_IS_4(a, b, c, d)
Definition: amd29k.c:470
#define AMD29K_LR(x)
Definition: amd29k.c:25
#define AMD29K_IS_3(a, b, c)
Definition: amd29k.c:469
#define AMD29K_REGNAME(x)
Definition: amd29k.c:24
#define AMD29K_IS_6(a, b, c, d, e, f)
Definition: amd29k.c:466
@ AMD29K_TYPE_IMM
snprintf
Definition: kernel.h:364
#define PFMT64x
Definition: rz_types.h:393
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References AMD29K_GET_TYPE, AMD29K_GET_VALUE, AMD29K_IS_1, AMD29K_IS_2, AMD29K_IS_3, AMD29K_IS_4, AMD29K_IS_6, AMD29K_LR, AMD29K_REGNAME, AMD29K_TYPE_IMM, AMD29K_TYPE_JMP, AMD29K_TYPE_REG, int, PFMT64x, snprintf, benchmark::t1, ut64(), v0, and v1.

Referenced by disassemble().