Rizin
unix-like reverse engineering framework and cli tools
M68KInstPrinter.h File Reference
#include "capstone/capstone.h"
#include "../../MCRegisterInfo.h"
#include "../../MCInst.h"

Go to the source code of this file.

Functions

void M68K_init (MCRegisterInfo *MRI)
 
void M68K_printInst (MCInst *MI, struct SStream *O, void *Info)
 
const char * M68K_reg_name (csh handle, unsigned int reg)
 
void M68K_get_insn_id (cs_struct *h, cs_insn *insn, unsigned int id)
 
const char * M68K_insn_name (csh handle, unsigned int id)
 
const char * M68K_group_name (csh handle, unsigned int id)
 
void M68K_post_printer (csh handle, cs_insn *flat_insn, char *insn_asm, MCInst *mci)
 

Function Documentation

◆ M68K_get_insn_id()

void M68K_get_insn_id ( cs_struct h,
cs_insn *  insn,
unsigned int  id 
)

Definition at line 355 of file M68KInstPrinter.c.

356 {
357  insn->id = id; // These id's matches for 68k
358 }
int id
Definition: op.c:540

References id.

◆ M68K_group_name()

const char* M68K_group_name ( csh  handle,
unsigned int  id 
)

Definition at line 379 of file M68KInstPrinter.c.

380 {
381 #ifndef CAPSTONE_DIET
383 #else
384  return NULL;
385 #endif
386 }
static name_map group_name_maps[]
#define NULL
Definition: cris-opc.c:27
#define ARR_SIZE(a)
Definition: ocaml.c:13
const char * id2name(const name_map *map, int max, const unsigned int id)
Definition: utils.c:56

References ARR_SIZE, group_name_maps, id2name(), and NULL.

◆ M68K_init()

void M68K_init ( MCRegisterInfo MRI)

◆ M68K_insn_name()

const char* M68K_insn_name ( csh  handle,
unsigned int  id 
)

Definition at line 360 of file M68KInstPrinter.c.

361 {
362 #ifdef CAPSTONE_DIET
363  return NULL;
364 #else
365  return s_instruction_names[id];
366 #endif
367 }
static const char * s_instruction_names[]

References id, NULL, and s_instruction_names.

◆ M68K_post_printer()

void M68K_post_printer ( csh  handle,
cs_insn *  flat_insn,
char *  insn_asm,
MCInst mci 
)

◆ M68K_printInst()

void M68K_printInst ( MCInst MI,
struct SStream O,
void *  Info 
)

Definition at line 262 of file M68KInstPrinter.c.

263 {
264 #ifndef CAPSTONE_DIET
265  m68k_info *info = (m68k_info *)PrinterInfo;
266  cs_m68k *ext = &info->extension;
267  cs_detail *detail = NULL;
268  int i = 0;
269 
270  detail = MI->flat_insn->detail;
271  if (detail) {
272  int regs_read_count = m68k_min(m68k_sizeof_array(detail->regs_read), info->regs_read_count);
273  int regs_write_count = m68k_min(m68k_sizeof_array(detail->regs_write), info->regs_write_count);
274  int groups_count = m68k_min(m68k_sizeof_array(detail->groups), info->groups_count);
275 
276  memcpy(&detail->m68k, ext, sizeof(cs_m68k));
277 
278  memcpy(&detail->regs_read, &info->regs_read, regs_read_count * sizeof(uint16_t));
279  detail->regs_read_count = regs_read_count;
280 
281  memcpy(&detail->regs_write, &info->regs_write, regs_write_count * sizeof(uint16_t));
282  detail->regs_write_count = regs_write_count;
283 
284  memcpy(&detail->groups, &info->groups, groups_count);
285  detail->groups_count = groups_count;
286  }
287 
288  if (MI->Opcode == M68K_INS_INVALID) {
289  if (ext->op_count)
290  SStream_concat(O, "dc.w $%x", ext->operands[0].imm);
291  else
292  SStream_concat(O, "dc.w $<unknown>");
293  return;
294  }
295 
297 
298  switch (ext->op_size.type) {
300  break;
301 
302  case M68K_SIZE_TYPE_CPU :
303  switch (ext->op_size.cpu_size) {
304  case M68K_CPU_SIZE_BYTE: SStream_concat0(O, ".b"); break;
305  case M68K_CPU_SIZE_WORD: SStream_concat0(O, ".w"); break;
306  case M68K_CPU_SIZE_LONG: SStream_concat0(O, ".l"); break;
307  case M68K_CPU_SIZE_NONE: break;
308  }
309  break;
310 
311  case M68K_SIZE_TYPE_FPU :
312  switch (ext->op_size.fpu_size) {
313  case M68K_FPU_SIZE_SINGLE: SStream_concat0(O, ".s"); break;
314  case M68K_FPU_SIZE_DOUBLE: SStream_concat0(O, ".d"); break;
315  case M68K_FPU_SIZE_EXTENDED: SStream_concat0(O, ".x"); break;
316  case M68K_FPU_SIZE_NONE: break;
317  }
318  break;
319  }
320 
321  SStream_concat0(O, " ");
322 
323  // this one is a bit spacial so we do special things
324 
325  if (MI->Opcode == M68K_INS_CAS2) {
326  int reg_value_0, reg_value_1;
327  printAddressingMode(O, info->pc, ext, &ext->operands[0]); SStream_concat0(O, ",");
328  printAddressingMode(O, info->pc, ext, &ext->operands[1]); SStream_concat0(O, ",");
329  reg_value_0 = ext->operands[2].register_bits >> 4;
330  reg_value_1 = ext->operands[2].register_bits & 0xf;
331  SStream_concat(O, "(%s):(%s)", s_reg_names[M68K_REG_D0 + reg_value_0], s_reg_names[M68K_REG_D0 + reg_value_1]);
332  return;
333  }
334 
335  for (i = 0; i < ext->op_count; ++i) {
336  printAddressingMode(O, info->pc, ext, &ext->operands[i]);
337  if ((i + 1) != ext->op_count)
338  SStream_concat(O, ",%s", s_spacing);
339  }
340 #endif
341 }
#define m68k_min(a, b)
static const char * s_reg_names[]
static const char * s_spacing
#define m68k_sizeof_array(array)
static void printAddressingMode(SStream *O, unsigned int pc, const cs_m68k *inst, const cs_m68k_op *op)
void SStream_concat(SStream *ss, const char *fmt,...)
Definition: SStream.c:45
void SStream_concat0(SStream *ss, const char *s)
Definition: SStream.c:31
lzma_index ** i
Definition: index.h:629
static const char ext[]
Definition: apprentice.c:1981
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
@ M68K_CPU_SIZE_LONG
4 bytes in size
Definition: m68k.h:181
@ M68K_CPU_SIZE_WORD
2 bytes in size
Definition: m68k.h:180
@ M68K_CPU_SIZE_BYTE
1 byte in size
Definition: m68k.h:179
@ M68K_CPU_SIZE_NONE
unsized or unspecified
Definition: m68k.h:178
@ M68K_SIZE_TYPE_INVALID
Definition: m68k.h:194
@ M68K_SIZE_TYPE_CPU
Definition: m68k.h:196
@ M68K_SIZE_TYPE_FPU
Definition: m68k.h:197
@ M68K_FPU_SIZE_SINGLE
4 byte in size (single float)
Definition: m68k.h:187
@ M68K_FPU_SIZE_NONE
unsized like fsave/frestore
Definition: m68k.h:186
@ M68K_FPU_SIZE_DOUBLE
8 byte in size (double)
Definition: m68k.h:188
@ M68K_FPU_SIZE_EXTENDED
12 byte in size (extended real format)
Definition: m68k.h:189
@ M68K_INS_INVALID
Definition: m68k.h:219
@ M68K_INS_CAS2
Definition: m68k.h:264
@ M68K_REG_D0
Definition: m68k.h:23
#define O
Definition: rcond.c:14
unsigned short uint16_t
Definition: sftypes.h:30
cs_insn * flat_insn
Definition: MCInst.h:95
unsigned Opcode
Definition: MCInst.h:93
The M68K instruction and it's operands.
Definition: m68k.h:210

References ext, MCInst::flat_insn, i, info(), M68K_CPU_SIZE_BYTE, M68K_CPU_SIZE_LONG, M68K_CPU_SIZE_NONE, M68K_CPU_SIZE_WORD, M68K_FPU_SIZE_DOUBLE, M68K_FPU_SIZE_EXTENDED, M68K_FPU_SIZE_NONE, M68K_FPU_SIZE_SINGLE, M68K_INS_CAS2, M68K_INS_INVALID, m68k_min, M68K_REG_D0, M68K_SIZE_TYPE_CPU, M68K_SIZE_TYPE_FPU, M68K_SIZE_TYPE_INVALID, m68k_sizeof_array, memcpy(), NULL, O, MCInst::Opcode, printAddressingMode(), s_instruction_names, s_reg_names, s_spacing, SStream_concat(), and SStream_concat0().

Referenced by M68K_getInstruction().

◆ M68K_reg_name()

const char* M68K_reg_name ( csh  handle,
unsigned int  reg 
)

Definition at line 343 of file M68KInstPrinter.c.

344 {
345 #ifdef CAPSTONE_DIET
346  return NULL;
347 #else
348  if (reg >= ARR_SIZE(s_reg_names)) {
349  return NULL;
350  }
351  return s_reg_names[(int)reg];
352 #endif
353 }
#define reg(n)
static int
Definition: sfsocketcall.h:114

References ARR_SIZE, int, NULL, reg, and s_reg_names.