Rizin
unix-like reverse engineering framework and cli tools
spc700dis.c File Reference
#include <rz_types.h>
#include <rz_asm.h>
#include <stdio.h>
#include <string.h>
#include "spc700_opcode_table.h"

Go to the source code of this file.

Functions

static ut64 spc700_op_size (Spc700ArgType arg)
 
static ut64 spc700_resolve_relative (ut64 pc, ut8 r)
 
static size_t spc700_disas (RzStrBuf *out, ut64 pc, const ut8 *buf, size_t bufsz)
 

Function Documentation

◆ spc700_disas()

static size_t spc700_disas ( RzStrBuf out,
ut64  pc,
const ut8 buf,
size_t  bufsz 
)
static

Definition at line 36 of file spc700dis.c.

36  {
37  if (!bufsz) {
38  return 0;
39  }
40  const Spc700Op *sop = &spc700_op_table[buf[0]];
41  ut64 opsz = spc700_op_size(sop->arg);
42  if (bufsz < (ut64)opsz) {
43  return 0;
44  }
45  if (!out) {
46  return opsz;
47  }
48  switch (sop->arg) {
49  case SPC700_ARG_NONE:
50  rz_strbuf_set(out, sop->name);
51  break;
52  case SPC700_ARG_IMM8:
53  case SPC700_ARG_ABS8:
54  case SPC700_ARG_UPPER8:
55  rz_strbuf_setf(out, sop->name, (unsigned int)buf[1]);
56  break;
58  rz_strbuf_setf(out, sop->name,
59  (unsigned int)buf[1],
60  (unsigned int)spc700_resolve_relative(pc + 3, buf[2]));
61  break;
62  case SPC700_ARG_ABS16:
63  rz_strbuf_setf(out, sop->name, (unsigned int)buf[1] | ((unsigned int)buf[2] << 8));
64  break;
66  rz_strbuf_setf(out, sop->name,
67  (unsigned int)((ut16)buf[1] | ((ut16)(buf[2] & 0x1f) << 8)),
68  (unsigned int)(buf[2] >> 5));
69  break;
70  case SPC700_ARG_REL8:
71  rz_strbuf_setf(out, sop->name,
72  (unsigned int)spc700_resolve_relative(pc + 2, buf[1]));
73  break;
76  rz_strbuf_setf(out, sop->name, (unsigned int)buf[2], (unsigned int)buf[1]);
77  break;
78  default:
79  rz_strbuf_set(out, "invalid");
80  break;
81  }
82  return opsz;
83 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
uint16_t ut16
voidpf void * buf
Definition: ioapi.h:138
unsigned long sop
Definition: regex2.h:62
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
static const Spc700Op spc700_op_table[]
@ SPC700_ARG_ABS8
@ SPC700_ARG_ABS8_REL8
@ SPC700_ARG_IMM8_ABS8
@ SPC700_ARG_REL8
@ SPC700_ARG_NONE
@ SPC700_ARG_IMM8
@ SPC700_ARG_ABS16
@ SPC700_ARG_ABS13_BIT3
@ SPC700_ARG_ABS8_ABS8
@ SPC700_ARG_UPPER8
static ut64 spc700_op_size(Spc700ArgType arg)
Definition: spc700dis.c:10
static ut64 spc700_resolve_relative(ut64 pc, ut8 r)
Definition: spc700dis.c:29
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References out, pc, rz_strbuf_set(), rz_strbuf_setf(), SPC700_ARG_ABS13_BIT3, SPC700_ARG_ABS16, SPC700_ARG_ABS8, SPC700_ARG_ABS8_ABS8, SPC700_ARG_ABS8_REL8, SPC700_ARG_IMM8, SPC700_ARG_IMM8_ABS8, SPC700_ARG_NONE, SPC700_ARG_REL8, SPC700_ARG_UPPER8, spc700_op_size(), spc700_op_table, spc700_resolve_relative(), and ut64().

Referenced by disassemble(), and op().

◆ spc700_op_size()

static ut64 spc700_op_size ( Spc700ArgType  arg)
static

Definition at line 10 of file spc700dis.c.

10  {
11  switch (arg) {
12  case SPC700_ARG_NONE:
13  return 1;
14  case SPC700_ARG_IMM8:
15  case SPC700_ARG_ABS8:
16  case SPC700_ARG_REL8:
17  case SPC700_ARG_UPPER8:
18  return 2;
21  case SPC700_ARG_ABS16:
24  return 3;
25  }
26  return 0;
27 }

References SPC700_ARG_ABS13_BIT3, SPC700_ARG_ABS16, SPC700_ARG_ABS8, SPC700_ARG_ABS8_ABS8, SPC700_ARG_ABS8_REL8, SPC700_ARG_IMM8, SPC700_ARG_IMM8_ABS8, SPC700_ARG_NONE, SPC700_ARG_REL8, and SPC700_ARG_UPPER8.

Referenced by spc700_disas().

◆ spc700_resolve_relative()

static ut64 spc700_resolve_relative ( ut64  pc,
ut8  r 
)
static

Definition at line 29 of file spc700dis.c.

29  {
30  ut16 spc = (ut16)pc;
31  ut16 relpc = (ut16)(st16)(st8)r;
32  spc += relpc;
33  return (ut64)spc;
34 }
#define r
Definition: crypto_rc6.c:12
#define st8
Definition: rz_types_base.h:16
#define st16
Definition: rz_types_base.h:14

References pc, r, st16, st8, and ut64().

Referenced by spc700_disas().