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

int print_insn_big_nios2 (bfd_vma address, disassemble_info *info)
 
int print_insn_little_nios2 (bfd_vma address, disassemble_info *info)
 
static int nios2_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, struct rz_asm_op_t *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_nios2
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

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

Definition at line 37 of file asm_nios2.c.

37  {
38  struct disassemble_info disasm_obj;
39  if (len < 4) {
40  return -1;
41  }
42  buf_global = &op->buf_asm;
43  Offset = a->pc;
44  memcpy(bytes, buf, 4); // TODO handle thumb
45 
46  /* prepare disassembler */
47  memset(&disasm_obj, '\0', sizeof(struct disassemble_info));
48  disasm_obj.disassembler_options = "";
49  disasm_obj.buffer = bytes;
50  disasm_obj.read_memory_func = &nios2_buffer_read_memory;
51  disasm_obj.symbol_at_address_func = &symbol_at_address;
52  disasm_obj.memory_error_func = &memory_error_func;
53  disasm_obj.print_address_func = &generic_print_address_func;
54  disasm_obj.endian = !a->big_endian;
55  disasm_obj.fprintf_func = &generic_fprintf_func;
56  disasm_obj.stream = stdout;
57 
58  if (disasm_obj.endian == BFD_ENDIAN_BIG) {
59  op->size = print_insn_big_nios2((bfd_vma)Offset, &disasm_obj);
60  } else {
61  op->size = print_insn_little_nios2((bfd_vma)Offset, &disasm_obj);
62  }
63  if (op->size == -1) {
64  rz_asm_op_set_asm(op, "(data)");
65  }
66  return op->size;
67 }
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 void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info)
Definition: asm_nios2.c:30
static unsigned long Offset
Definition: asm_nios2.c:17
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info)
Definition: asm_nios2.c:26
static RzStrBuf * buf_global
Definition: asm_nios2.c:18
static unsigned char bytes[4]
Definition: asm_nios2.c:19
static int nios2_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
Definition: asm_nios2.c:21
int print_insn_little_nios2(bfd_vma address, disassemble_info *info)
Definition: nios2-dis.c:428
int print_insn_big_nios2(bfd_vma address, disassemble_info *info)
Definition: nios2-dis.c:422
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
#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, len, memcpy(), memory_error_func(), disassemble_info::memory_error_func, memset(), nios2_buffer_read_memory(), Offset, disassemble_info::print_address_func, print_insn_big_nios2(), print_insn_little_nios2(), disassemble_info::read_memory_func, rz_asm_op_set_asm(), disassemble_info::stream, symbol_at_address(), and disassemble_info::symbol_at_address_func.

◆ memory_error_func()

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

Definition at line 30 of file asm_nios2.c.

30  {
31  //--
32 }

Referenced by disassemble().

◆ nios2_buffer_read_memory()

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

Definition at line 21 of file asm_nios2.c.

21  {
22  memcpy(myaddr, bytes, length);
23  return 0;
24 }
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

References bytes, length, and memcpy().

Referenced by disassemble().

◆ print_insn_big_nios2()

int print_insn_big_nios2 ( bfd_vma  address,
disassemble_info info 
)

Definition at line 422 of file nios2-dis.c.

423 {
424  return print_insn_nios2 (address, info, BFD_ENDIAN_BIG);
425 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static int print_insn_nios2(bfd_vma address, disassemble_info *info, enum bfd_endian endianness)
Definition: nios2-dis.c:394

Referenced by disassemble().

◆ print_insn_little_nios2()

int print_insn_little_nios2 ( bfd_vma  address,
disassemble_info info 
)

Definition at line 428 of file nios2-dis.c.

429 {
430  return print_insn_nios2 (address, info, BFD_ENDIAN_LITTLE);
431 }
@ BFD_ENDIAN_LITTLE
Definition: mybfd.h:4618

Referenced by disassemble().

◆ symbol_at_address()

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

Definition at line 26 of file asm_nios2.c.

26  {
27  return 0;
28 }

Referenced by disassemble().

Variable Documentation

◆ buf_global

RzStrBuf* buf_global = NULL
static

Definition at line 18 of file asm_nios2.c.

Referenced by disassemble().

◆ bytes

unsigned char bytes[4]
static

Definition at line 19 of file asm_nios2.c.

Referenced by disassemble(), and nios2_buffer_read_memory().

◆ Offset

unsigned long Offset = 0
static

Definition at line 17 of file asm_nios2.c.

Referenced by disassemble().

◆ rizin_plugin

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

◆ rz_asm_plugin_nios2

RzAsmPlugin rz_asm_plugin_nios2
Initial value:
= {
.name = "nios2",
.arch = "nios2",
.license = "GPL3",
.bits = 32,
.desc = "NIOS II Embedded Processor",
.disassemble = &disassemble
}
static int disassemble(RzAsm *a, struct rz_asm_op_t *op, const ut8 *buf, int len)
Definition: asm_nios2.c:37
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 69 of file asm_nios2.c.