Rizin
unix-like reverse engineering framework and cli tools
asm_nios2.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014-2018 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <string.h>
7 
8 #include <rz_types.h>
9 #include <rz_lib.h>
10 #include <rz_util.h>
11 #include <rz_asm.h>
12 
13 #include "disas-asm.h"
14 
17 static unsigned long Offset = 0;
19 static unsigned char bytes[4];
20 
21 static int nios2_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
22  memcpy(myaddr, bytes, length);
23  return 0;
24 }
25 
27  return 0;
28 }
29 
30 static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
31  //--
32 }
33 
36 
37 static int disassemble(RzAsm *a, struct rz_asm_op_t *op, const ut8 *buf, int len) {
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;
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 }
68 
70  .name = "nios2",
71  .arch = "nios2",
72  .license = "GPL3",
73  .bits = 32,
75  .desc = "NIOS II Embedded Processor",
76  .disassemble = &disassemble
77 };
78 
79 #ifndef RZ_PLUGIN_INCORE
82  .data = &rz_asm_plugin_nios2,
84 };
85 #endif
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
RZ_API RzLibStruct rizin_plugin
Definition: asm_nios2.c:80
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
RzAsmPlugin rz_asm_plugin_nios2
Definition: asm_nios2.c:69
static int disassemble(RzAsm *a, struct rz_asm_op_t *op, const ut8 *buf, int len)
Definition: asm_nios2.c:37
int print_insn_big_nios2(bfd_vma address, disassemble_info *info)
Definition: nios2-dis.c:422
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
#define RZ_API
#define NULL
Definition: cris-opc.c:27
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
uint32_t ut32
#define DECLARE_GENERIC_FPRINTF_FUNC()
Definition: disas-asm.h:422
#define DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
Definition: disas-asm.h:435
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define const
Definition: ansidecl.h:240
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
unsigned char bfd_byte
Definition: mybfd.h:176
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
@ BFD_ENDIAN_BIG
Definition: mybfd.h:4617
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
fprintf_ftype fprintf_func
Definition: disas-asm.h:69
char * disassembler_options
Definition: disas-asm.h:214
enum bfd_endian endian
Definition: disas-asm.h:83
void(* memory_error_func)(int status, bfd_vma memaddr, struct disassemble_info *dinfo)
Definition: disas-asm.h:140
void(* print_address_func)(bfd_vma addr, struct disassemble_info *dinfo)
Definition: disas-asm.h:143
int(* symbol_at_address_func)(bfd_vma addr, struct disassemble_info *dinfo)
Definition: disas-asm.h:152
int(* read_memory_func)(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *dinfo)
Definition: disas-asm.h:133
bfd_byte * buffer
Definition: disas-asm.h:160
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32
static int addr
Definition: z80asm.c:58