Rizin
unix-like reverse engineering framework and cli tools
spc700dis.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 condret <condr3t@protonmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_types.h>
5 #include <rz_asm.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include "spc700_opcode_table.h"
9 
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 }
28 
30  ut16 spc = (ut16)pc;
31  ut16 relpc = (ut16)(st16)(st8)r;
32  spc += relpc;
33  return (ut64)spc;
34 }
35 
36 static size_t spc700_disas(RzStrBuf *out, ut64 pc, const ut8 *buf, size_t bufsz) {
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
#define r
Definition: crypto_rc6.c:12
uint16_t ut16
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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
#define st8
Definition: rz_types_base.h:16
#define st16
Definition: rz_types_base.h:14
static const Spc700Op spc700_op_table[]
Spc700ArgType
@ 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
static size_t spc700_disas(RzStrBuf *out, ut64 pc, const ut8 *buf, size_t bufsz)
Definition: spc700dis.c:36
ut64(WINAPI *w32_GetEnabledXStateFeatures)()