Rizin
unix-like reverse engineering framework and cli tools
asm_tricore.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "disas-asm.h"

Go to the source code of this file.

Enumerations

enum  {
  TRICORE_GENERIC = 0x00000000 , TRICORE_RIDER_A = 0x00000001 , TRICORE_RIDER_B = 0x00000002 , TRICORE_RIDER_D = TRICORE_RIDER_B ,
  TRICORE_V2 = 0x00000004 , TRICORE_PCP = 0x00000010 , TRICORE_PCP2 = 0x00000020
}
 

Functions

static int cpu_to_mach (char *cpu_type)
 
static int tricore_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
 
static int symbol_at_address (bfd_vma addr, struct disassemble_info *info)
 
static void memory_error_func (int status, bfd_vma memaddr, struct disassemble_info *info)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

static unsigned long Offset = 0
 
static RzStrBufbuf_global = NULL
 
static ut8 bytes [128]
 
RzAsmPlugin rz_asm_plugin_tricore
 
RZ_API RzLibStruct rizin_plugin
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TRICORE_GENERIC 
TRICORE_RIDER_A 
TRICORE_RIDER_B 
TRICORE_RIDER_D 
TRICORE_V2 
TRICORE_PCP 
TRICORE_PCP2 

Definition at line 18 of file asm_tricore.c.

18  {
19  TRICORE_GENERIC = 0x00000000,
20  TRICORE_RIDER_A = 0x00000001,
21  TRICORE_RIDER_B = 0x00000002,
23  TRICORE_V2 = 0x00000004,
24  TRICORE_PCP = 0x00000010,
25  TRICORE_PCP2 = 0x00000020
26 };
@ TRICORE_RIDER_A
Definition: asm_tricore.c:20
@ TRICORE_PCP2
Definition: asm_tricore.c:25
@ TRICORE_RIDER_B
Definition: asm_tricore.c:21
@ TRICORE_V2
Definition: asm_tricore.c:23
@ TRICORE_PCP
Definition: asm_tricore.c:24
@ TRICORE_RIDER_D
Definition: asm_tricore.c:22
@ TRICORE_GENERIC
Definition: asm_tricore.c:19

Function Documentation

◆ cpu_to_mach()

static int cpu_to_mach ( char *  cpu_type)
static

Definition at line 28 of file asm_tricore.c.

28  {
29  if (cpu_type && *cpu_type) {
30  if (!strcmp(cpu_type, "generic")) {
31  return TRICORE_GENERIC;
32  }
33  if (!strcmp(cpu_type, "rider-a")) {
34  return TRICORE_RIDER_A;
35  }
36  if ((!strcmp(cpu_type, "rider-b")) || (!strcmp(cpu_type, "rider-d"))) {
37  return TRICORE_RIDER_B;
38  }
39  if (!strcmp(cpu_type, "v2")) {
40  return TRICORE_V2;
41  }
42  if (!strcmp(cpu_type, "pcp")) {
43  return TRICORE_PCP;
44  }
45  if (!strcmp(cpu_type, "pcp2")) {
46  return TRICORE_PCP2;
47  }
48  }
49  return TRICORE_RIDER_B;
50 }
static int cpu_type
Definition: arc-opc.c:143

References cpu_type, TRICORE_GENERIC, TRICORE_PCP, TRICORE_PCP2, TRICORE_RIDER_A, TRICORE_RIDER_B, and TRICORE_V2.

Referenced by disassemble().

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 71 of file asm_tricore.c.

71  {
72  struct disassemble_info disasm_obj;
73  buf_global = &op->buf_asm;
74  Offset = a->pc;
75  memcpy(bytes, buf, RZ_MIN(len, 8)); // TODO handle thumb
76 
77  /* prepare disassembler */
78  memset(&disasm_obj, '\0', sizeof(struct disassemble_info));
79  disasm_obj.disassembler_options = (a->bits == 64) ? "64" : "";
80  disasm_obj.buffer = bytes;
81  disasm_obj.read_memory_func = &tricore_buffer_read_memory;
82  disasm_obj.symbol_at_address_func = &symbol_at_address;
83  disasm_obj.memory_error_func = &memory_error_func;
84  disasm_obj.print_address_func = &generic_print_address_func;
85  disasm_obj.endian = BFD_ENDIAN_LITTLE;
86  disasm_obj.fprintf_func = &generic_fprintf_func;
87  disasm_obj.stream = stdout;
88 
89  // cpu type
90  disasm_obj.mach = cpu_to_mach(a->cpu);
91 
92  op->size = print_insn_tricore((bfd_vma)Offset, &disasm_obj);
93  if (op->size == -1) {
94  rz_asm_op_set_asm(op, " (data)");
95  }
96  return op->size;
97 }
size_t len
Definition: 6502dis.c:15
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
static ut8 bytes[128]
Definition: asm_tricore.c:17
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info)
Definition: asm_tricore.c:64
static unsigned long Offset
Definition: asm_tricore.c:15
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info)
Definition: asm_tricore.c:60
static RzStrBuf * buf_global
Definition: asm_tricore.c:16
static int cpu_to_mach(char *cpu_type)
Definition: asm_tricore.c:28
static int tricore_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
Definition: asm_tricore.c:52
int print_insn_tricore(bfd_vma memaddr, struct disassemble_info *info)
Definition: tricore-dis.c:1884
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
@ BFD_ENDIAN_LITTLE
Definition: mybfd.h:4618
#define RZ_MIN(x, y)
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, BFD_ENDIAN_LITTLE, buf_global, disassemble_info::buffer, bytes, cpu_to_mach(), disassemble_info::disassembler_options, disassemble_info::endian, disassemble_info::fprintf_func, len, disassemble_info::mach, memcpy(), memory_error_func(), disassemble_info::memory_error_func, memset(), Offset, disassemble_info::print_address_func, print_insn_tricore(), disassemble_info::read_memory_func, rz_asm_op_set_asm(), RZ_MIN, disassemble_info::stream, symbol_at_address(), disassemble_info::symbol_at_address_func, and tricore_buffer_read_memory().

◆ memory_error_func()

static void memory_error_func ( int  status,
bfd_vma  memaddr,
struct disassemble_info info 
)
static

Definition at line 64 of file asm_tricore.c.

64  {
65  //--
66 }

Referenced by disassemble().

◆ symbol_at_address()

static int symbol_at_address ( bfd_vma  addr,
struct disassemble_info info 
)
static

Definition at line 60 of file asm_tricore.c.

60  {
61  return 0;
62 }

Referenced by disassemble().

◆ tricore_buffer_read_memory()

static int tricore_buffer_read_memory ( bfd_vma  memaddr,
bfd_byte myaddr,
ut32  length,
struct disassemble_info info 
)
static

Definition at line 52 of file asm_tricore.c.

52  {
53  int delta = memaddr - Offset;
54  if (delta >= 0 && length + delta < sizeof(bytes)) {
55  memcpy(myaddr, bytes + delta, length);
56  }
57  return 0;
58 }
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 length
Definition: sflib.h:133
static st64 delta
Definition: vmenus.c:2425

References bytes, delta, length, memcpy(), and Offset.

Referenced by disassemble().

Variable Documentation

◆ buf_global

RzStrBuf* buf_global = NULL
static

Definition at line 16 of file asm_tricore.c.

Referenced by disassemble().

◆ bytes

ut8 bytes[128]
static

Definition at line 17 of file asm_tricore.c.

Referenced by disassemble(), and tricore_buffer_read_memory().

◆ Offset

unsigned long Offset = 0
static

Definition at line 15 of file asm_tricore.c.

Referenced by disassemble(), and tricore_buffer_read_memory().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_tricore
Definition: asm_tricore.c:99
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 110 of file asm_tricore.c.

◆ rz_asm_plugin_tricore

RzAsmPlugin rz_asm_plugin_tricore
Initial value:
= {
.name = "tricore",
.arch = "tricore",
.license = "GPL3",
.bits = 32,
.desc = "Siemens TriCore CPU",
.disassemble = &disassemble,
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_tricore.c:71
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 99 of file asm_tricore.c.