Rizin
unix-like reverse engineering framework and cli tools
arc-ext.h File Reference

Go to the source code of this file.

Macros

#define IGNORE_FIRST_OPD   1
 
#define UNMANGLED
 

Enumerations

enum  ExtOperType {
  EXT_INSTRUCTION = 0 , EXT_CORE_REGISTER = 1 , EXT_AUX_REGISTER = 2 , EXT_COND_CODE = 3 ,
  EXT_INSTRUCTION32 = 4 , EXT_AC_INSTRUCTION = 4 , EXT_REMOVE_CORE_REG = 5 , EXT_LONG_CORE_REGISTER = 6 ,
  EXT_AUX_REGISTER_EXTENDED = 7 , EXT_INSTRUCTION32_EXTENDED = 8 , EXT_CORE_REGISTER_CLASS = 9
}
 
enum  ExtReadWrite { REG_INVALID , REG_READ , REG_WRITE , REG_READWRITE }
 

Functions

void build_ARC_extmap (void *text_bfd)
 
enum ExtReadWrite arcExtMap_coreReadWrite (int regnum)
 
const char * arcExtMap_coreRegName (int regnum)
 
const char * arcExtMap_auxRegName (long regnum)
 
const char * arcExtMap_condCodeName (int code)
 
const char * arcExtMap_instName (int opcode, int insn, int *flags)
 
void dump_ARC_extmap (void)
 

Macro Definition Documentation

◆ IGNORE_FIRST_OPD

#define IGNORE_FIRST_OPD   1

Definition at line 50 of file arc-ext.h.

◆ UNMANGLED

#define UNMANGLED

Definition at line 54 of file arc-ext.h.

Enumeration Type Documentation

◆ ExtOperType

Enumerator
EXT_INSTRUCTION 
EXT_CORE_REGISTER 
EXT_AUX_REGISTER 
EXT_COND_CODE 
EXT_INSTRUCTION32 
EXT_AC_INSTRUCTION 
EXT_REMOVE_CORE_REG 
EXT_LONG_CORE_REGISTER 
EXT_AUX_REGISTER_EXTENDED 
EXT_INSTRUCTION32_EXTENDED 
EXT_CORE_REGISTER_CLASS 

Definition at line 60 of file arc-ext.h.

61 {
62  EXT_INSTRUCTION = 0,
64  EXT_AUX_REGISTER = 2,
65  EXT_COND_CODE = 3,
66  EXT_INSTRUCTION32 = 4, /* why are there */
67  EXT_AC_INSTRUCTION = 4, /* two with value 4? */
73 };
@ EXT_LONG_CORE_REGISTER
Definition: arc-ext.h:69
@ EXT_CORE_REGISTER_CLASS
Definition: arc-ext.h:72
@ EXT_AUX_REGISTER_EXTENDED
Definition: arc-ext.h:70
@ EXT_AUX_REGISTER
Definition: arc-ext.h:64
@ EXT_INSTRUCTION32_EXTENDED
Definition: arc-ext.h:71
@ EXT_COND_CODE
Definition: arc-ext.h:65
@ EXT_INSTRUCTION
Definition: arc-ext.h:62
@ EXT_INSTRUCTION32
Definition: arc-ext.h:66
@ EXT_CORE_REGISTER
Definition: arc-ext.h:63
@ EXT_AC_INSTRUCTION
Definition: arc-ext.h:67
@ EXT_REMOVE_CORE_REG
Definition: arc-ext.h:68

◆ ExtReadWrite

Enumerator
REG_INVALID 
REG_READ 
REG_WRITE 
REG_READWRITE 

Definition at line 76 of file arc-ext.h.

77 {
79  REG_READ,
80  REG_WRITE,
82 };
@ REG_WRITE
Definition: arc-ext.h:80
@ REG_READWRITE
Definition: arc-ext.h:81
@ REG_READ
Definition: arc-ext.h:79
@ REG_INVALID
Definition: arc-ext.h:78

Function Documentation

◆ arcExtMap_auxRegName()

const char* arcExtMap_auxRegName ( long  regnum)

Definition at line 435 of file arc-ext.c.

436 {
437  /* Walk the list of auxiliary register names and find the name. */
438  struct ExtAuxRegister *r;
439 
440  for (r = arc_extension_map.auxRegisters; r; r = r->next)
441  {
442  if (r->address == address) {
443  return (const char *)r->name;
444  }
445  }
446  return NULL;
447 }
static struct arcExtMap arc_extension_map
Definition: arc-ext.c:108
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
long address
Definition: arc-ext.c:82
struct ExtAuxRegister * auxRegisters
Definition: arc-ext.c:96

References ExtAuxRegister::address, arc_extension_map, arcExtMap::auxRegisters, NULL, and r.

Referenced by _auxRegName().

◆ arcExtMap_condCodeName()

const char* arcExtMap_condCodeName ( int  code)

Definition at line 424 of file arc-ext.c.

425 {
427  return NULL;
428  }
430 }
#define FIRST_EXTENSION_CONDITION_CODE
Definition: arc-ext.c:55
#define LAST_EXTENSION_CONDITION_CODE
Definition: arc-ext.c:56
char * condCodes[NUM_EXT_COND]
Definition: arc-ext.c:99
Definition: inftree9.h:24

References arc_extension_map, arcExtMap::condCodes, FIRST_EXTENSION_CONDITION_CODE, LAST_EXTENSION_CONDITION_CODE, and NULL.

Referenced by _condCodeName().

◆ arcExtMap_coreReadWrite()

enum ExtReadWrite arcExtMap_coreReadWrite ( int  regnum)

Definition at line 402 of file arc-ext.c.

414 {
415  if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER) {
416  return REG_INVALID;
417  }
419 }
#define LAST_EXTENSION_CORE_REGISTER
Definition: arc-ext.c:54
#define FIRST_EXTENSION_CORE_REGISTER
Definition: arc-ext.c:53
enum ExtReadWrite rw
Definition: arc-ext.c:90
struct ExtCoreRegister coreRegisters[NUM_EXT_CORE]
Definition: arc-ext.c:98

References arc_extension_map, arcExtMap::coreRegisters, FIRST_EXTENSION_CORE_REGISTER, LAST_EXTENSION_CORE_REGISTER, ExtCoreRegister::name, and NULL.

◆ arcExtMap_coreRegName()

const char* arcExtMap_coreRegName ( int  regnum)

Definition at line 402 of file arc-ext.c.

403 {
404  if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER) {
405  return NULL;
406  }
408 }
char * name
Definition: arc-ext.c:91

Referenced by _coreRegName().

◆ arcExtMap_instName()

const char* arcExtMap_instName ( int  opcode,
int  insn,
int flags 
)

Definition at line 300 of file arc-ext.c.

301 {
302  /* Here the following tasks need to be done. First of all, the opcode
303  stored in the Extension Map is the real opcode. However, the subopcode
304  stored in the instruction to be disassembled is mangled. We pass (in
305  minor opcode), the instruction word. Here we will un-mangle it and get
306  the real subopcode which we can look for in the Extension Map. This
307  function is used both for the ARCTangent and the ARCompact, so we would
308  also need some sort of a way to distinguish between the two
309  architectures. This is because the ARCTangent does not do any of this
310  mangling so we have no issues there. */
311 
312  /* If P[22:23] is 0 or 2 then un-mangle using iiiiiI. If it is 1 then use
313  iiiiIi. Now, if P is 3 then check M[5:5] and if it is 0 then un-mangle
314  using iiiiiI else iiiiii. */
315 
316  unsigned char minor;
317  struct ExtInstruction *temp;
318 
319  if (*flags != E_ARC_MACH_A4) /* ARCompact extension instructions. */
320  {
321  /* 16-bit instructions. */
322  if (0x08 <= opcode && opcode <= 0x0b)
323  {
324  /* I - set but not used */
325  unsigned char /* I, */ b, c, i;
326 
327  /* I = (insn & 0xf800) >> 11; */
328  b = (insn & 0x0700) >> 8;
329  c = (insn & 0x00e0) >> 5;
330  i = (insn & 0x001f);
331 
332  if (i) {
333  minor = i;
334  } else {
335  minor = (c == 0x07) ? b : c;
336  }
337  }
338  /* 32-bit instructions. */
339  else
340  {
341  /* P, M - set but not used */
342  unsigned char /* P, M, */ I, A, B;
343 
344  /* P = (insn & 0x00c00000) >> 22; */
345  /* M = (insn & 0x00000020); */
346  I = (insn & 0x003f0000) >> 16;
347  A = (insn & 0x0000003f);
348  B = ((insn & 0x07000000) >> 24) | ((insn & 0x00007000) >> 9);
349 
350  if (I != 0x2f)
351  {
352 #ifndef UNMANGLED
353  switch (P)
354  {
355  case 3:
356  if (M)
357  {
358  minor = I;
359  break;
360  }
361  case 0:
362  case 2:
363  minor = (I >> 1) | ((I & 0x1) << 5);
364  break;
365  case 1:
366  minor = (I >> 1) | (I & 0x1) | ((I & 0x2) << 4);
367  }
368 #else
369  minor = I;
370 #endif
371  }
372  else
373  {
374  if (A != 0x3f) {
375  minor = A;
376  } else {
377  minor = B;
378  }
379  }
380  }
381  } else { /* ARCTangent extension instructions. */
382  minor = insn;
383  }
384 
385  temp = arc_extension_map.instructions[INST_HASH (opcode, minor)];
386  while (temp)
387  {
388  if ((temp->major == opcode) && (temp->minor == minor))
389  {
390  *flags = temp->flags;
391  return temp->name;
392  }
393  temp = temp->next;
394  }
395 
396  return NULL;
397 }
lzma_index ** i
Definition: index.h:629
#define INST_HASH(MAJOR, MINOR)
Definition: arc-ext.c:116
#define A(x)
Definition: arc.h:165
#define I(x)
Definition: arc.h:164
#define E_ARC_MACH_A4
Definition: arc.h:47
#define B(x)
Definition: arc.h:166
#define P
#define minor(dev)
Definition: fsmagic.c:57
#define M
Definition: common.h:37
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define b(i)
Definition: sha256.c:42
#define c(i)
Definition: sha256.c:43
char minor
Definition: arc-ext.c:74
char flags
Definition: arc-ext.c:75
char * name
Definition: arc-ext.c:76
struct ExtInstruction * next
Definition: arc-ext.c:77
char major
Definition: arc-ext.c:73
struct ExtInstruction * instructions[INST_HASH_SIZE]
Definition: arc-ext.c:97

References A, arc_extension_map, b, B, c, E_ARC_MACH_A4, ExtInstruction::flags, flags, I, i, INST_HASH, arcExtMap::instructions, M, ExtInstruction::major, ExtInstruction::minor, minor, ExtInstruction::name, ExtInstruction::next, NULL, and P.

Referenced by _instName().

◆ build_ARC_extmap()

void build_ARC_extmap ( void *  text_bfd)

Definition at line 453 of file arc-ext.c.

454 {
455 #if 0
456  asection *sect;
457 
458  /* the map is built each time gdb loads an executable file - so free any
459  * existing map, as the map defined by the new file may differ from the old
460  */
461  destroy_map();
462 
463  for (sect = text_bfd->sections; sect != NULL; sect = sect->next)
464  if (!strncmp (sect->name,
465  ".gnu.linkonce.arcextmap.",
466  sizeof (".gnu.linkonce.arcextmap.") - 1)
467  || !strcmp (sect->name,".arcextmap"))
468  {
470  unsigned char* buffer = xmalloc (count);
471 
472  if (buffer)
473  {
474  if (bfd_get_section_contents (text_bfd, sect, buffer, 0, count))
475  create_map(buffer, count);
476  free (buffer);
477  }
478  }
479 #endif
480 }
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
#define xmalloc
Definition: disas-asm.h:43
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
BFD_HOST_U_64_BIT bfd_size_type
Definition: mybfd.h:113
bfd_boolean bfd_get_section_contents(bfd *abfd, asection *section, void *location, file_ptr offset, bfd_size_type count)
#define bfd_get_section_size(ptr)
Definition: mybfd.h:316
struct bfd_section * next
Definition: mybfd.h:1016
const char * name
Definition: mybfd.h:1007
Definition: buffer.h:15

References bfd_get_section_contents(), bfd_get_section_size, count, free(), bfd_section::name, bfd_section::next, NULL, and xmalloc.

◆ dump_ARC_extmap()

void dump_ARC_extmap ( void  )

Definition at line 483 of file arc-ext.c.

484 {
485  struct ExtAuxRegister* r;
486  int i;
487 
489 
490  while (r)
491  {
492  printf("AUX : %s %ld\n", r->name, r->address);
493  r = r->next;
494  }
495 
496  for (i = 0; i < INST_HASH_SIZE; i++)
497  {
498  struct ExtInstruction *insn;
499 
500  for (insn = arc_extension_map.instructions[i]; insn != NULL; insn = insn->next) {
501  printf ("INST: %d %d %x %s\n", insn->major, insn->minor, insn->flags, insn->name);
502  }
503  }
504 
505  for (i = 0; i < NUM_EXT_CORE; i++)
506  {
508 
509  if (reg.name) {
510  printf ("CORE: %s %d %s\n", reg.name, reg.number, ExtReadWrite_image (reg.rw));
511  }
512  }
513 
514  for (i = 0; i < NUM_EXT_COND; i++) {
516  printf ("COND: %s\n", arc_extension_map.condCodes[i]);
517  }
518  }
519 }
#define INST_HASH_SIZE
Definition: arc-ext.c:61
static const char * ExtReadWrite_image(enum ExtReadWrite val)
Definition: arc-ext.c:280
#define NUM_EXT_CORE
Definition: arc-ext.c:58
#define NUM_EXT_COND
Definition: arc-ext.c:59
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define reg(n)

References arc_extension_map, arcExtMap::auxRegisters, arcExtMap::condCodes, arcExtMap::coreRegisters, ExtReadWrite_image(), ExtInstruction::flags, i, INST_HASH_SIZE, arcExtMap::instructions, ExtInstruction::major, ExtInstruction::minor, ExtInstruction::name, ExtInstruction::next, NULL, NUM_EXT_COND, NUM_EXT_CORE, printf(), r, and reg.