Rizin
unix-like reverse engineering framework and cli tools
asm_hppa_gnu.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.

Functions

static int hppa_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 unsigned char bytes [4]
 
RzAsmPlugin rz_asm_plugin_hppa_gnu
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

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

Definition at line 52 of file asm_hppa_gnu.c.

52  {
53  struct disassemble_info disasm_obj;
54  if (len < 4) {
55  return -1;
56  }
57  buf_global = &op->buf_asm;
58  Offset = a->pc;
59  memcpy(bytes, buf, 4); // TODO handle thumb
60 
61  /* prepare disassembler */
62  memset(&disasm_obj, '\0', sizeof(struct disassemble_info));
63  disasm_obj.disassembler_options = (a->bits == 64) ? "64" : "";
64  disasm_obj.buffer = bytes;
65  disasm_obj.read_memory_func = &hppa_buffer_read_memory;
66  disasm_obj.symbol_at_address_func = &symbol_at_address;
67  disasm_obj.memory_error_func = &memory_error_func;
68  disasm_obj.print_address_func = &generic_print_address_func;
69  disasm_obj.endian = BFD_ENDIAN_BIG;
70  disasm_obj.fprintf_func = &generic_fprintf_func;
71  disasm_obj.stream = stdout;
72 
73  op->size = print_insn_hppa((bfd_vma)Offset, &disasm_obj);
74  if (op->size == -1) {
75  rz_strbuf_set(&op->buf_asm, "(data)");
76  }
77  return op->size;
78 }
size_t len
Definition: 6502dis.c:15
static int hppa_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
Definition: asm_hppa_gnu.c:19
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info)
Definition: asm_hppa_gnu.c:45
static unsigned long Offset
Definition: asm_hppa_gnu.c:15
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info)
Definition: asm_hppa_gnu.c:41
static RzStrBuf * buf_global
Definition: asm_hppa_gnu.c:16
static unsigned char bytes[4]
Definition: asm_hppa_gnu.c:17
int print_insn_hppa(bfd_vma memaddr, disassemble_info *info)
Definition: hppa-dis.c:361
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_BIG
Definition: mybfd.h:4617
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, BFD_ENDIAN_BIG, buf_global, disassemble_info::buffer, bytes, disassemble_info::disassembler_options, disassemble_info::endian, disassemble_info::fprintf_func, hppa_buffer_read_memory(), len, memcpy(), memory_error_func(), disassemble_info::memory_error_func, memset(), Offset, disassemble_info::print_address_func, print_insn_hppa(), disassemble_info::read_memory_func, rz_strbuf_set(), disassemble_info::stream, symbol_at_address(), and disassemble_info::symbol_at_address_func.

◆ hppa_buffer_read_memory()

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

Definition at line 19 of file asm_hppa_gnu.c.

19  {
20 #if 0 // XXX rewrite needed
21  if (length == 4) {
22  // swap
23  myaddr[0] = bytes[3];
24  myaddr[1] = bytes[2];
25  myaddr[2] = bytes[1];
26  myaddr[3] = bytes[0];
27  return 0;
28  }
29 #endif
30  int delta = (memaddr - Offset);
31  if (delta < 0) {
32  return -1; // disable backward reads
33  }
34  if ((delta + length) > 4) {
35  return -1;
36  }
37  memcpy(myaddr, bytes + delta, length);
38  return 0;
39 }
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().

◆ memory_error_func()

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

Definition at line 45 of file asm_hppa_gnu.c.

45  {
46  //--
47 }

Referenced by disassemble().

◆ symbol_at_address()

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

Definition at line 41 of file asm_hppa_gnu.c.

41  {
42  return 0;
43 }

Referenced by disassemble().

Variable Documentation

◆ buf_global

RzStrBuf* buf_global = NULL
static

Definition at line 16 of file asm_hppa_gnu.c.

Referenced by disassemble().

◆ bytes

unsigned char bytes[4]
static

Definition at line 17 of file asm_hppa_gnu.c.

Referenced by disassemble(), and hppa_buffer_read_memory().

◆ Offset

unsigned long Offset = 0
static

Definition at line 15 of file asm_hppa_gnu.c.

Referenced by disassemble(), and hppa_buffer_read_memory().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_hppa_gnu
Definition: asm_hppa_gnu.c:80
@ 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 91 of file asm_hppa_gnu.c.

◆ rz_asm_plugin_hppa_gnu

RzAsmPlugin rz_asm_plugin_hppa_gnu
Initial value:
= {
.name = "hppa",
.arch = "hppa",
.license = "GPL3",
.bits = 32,
.endian = RZ_SYS_ENDIAN_BIG,
.desc = "HP PA-RISC",
.disassemble = &disassemble
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_hppa_gnu.c:52
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527

Definition at line 80 of file asm_hppa_gnu.c.