rizin/librz/arch/p/asm/asm_sh.c
مصطفي محمود كمال الدين 29b04fa460
librz/debug: native debugger plugin for RISC-V (#5966)
* added breakpoints and stepping

* add link register to allow single-stepping a ret instruction, fix stacktraces
* refactor to avoid passing the IO layer structs to the breakpoint function
* add tests, refine the stacktrace to not include non-function
* add register information for core file parsing
* core file generation for RISC-V
* make tests run under riscv-64
* make tests run under riscv-32
2026-04-26 16:28:07 +08:00

57 lines
1.6 KiB
C

// SPDX-FileCopyrightText: 2010-2011 eloi <limited-entropy.com>
// SPDX-FileCopyrightText: 2022 Dhruv Maroo <dhruvmaru007@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "sh/disassembler.h"
#include "sh/assembler.h"
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
SHOp *dis_op = sh_disassembler(rz_read_ble16(buf, a->big_endian));
op->size = 2;
if (!dis_op) {
rz_strbuf_set(&op->buf_asm, "invalid");
} else {
char *disasm = sh_op_to_str(dis_op, a->pc);
rz_strbuf_set(&op->buf_asm, disasm);
free(disasm);
}
RZ_FREE(dis_op);
return op->size;
}
static int assemble(const RzAsm *a, RzAsmOp *ao, const char *str) {
bool success;
ut16 opcode = sh_assembler(str, a->pc, &success);
if (!success) {
return -1;
}
ut8 buffer[2];
rz_write_ble16(buffer, opcode, a->big_endian);
rz_strbuf_setbin(&ao->buf, buffer, 2);
return 2;
}
static bool sh_sw_breakpoint(const RzAsm *a, ut64 addr, const RzAsmOp *original, RzAsmOp *breakpoint) {
// { 32, 2, 1, "\xc3\x20" }, // Big endian
// { 32, 2, 0, "\x20\xc3" }, // Little endian
rz_asm_op_set_buf(breakpoint, a->big_endian ? (const ut8 *)"\xc3\x20" : (const ut8 *)"\x20\xc3", 2);
return true;
}
RzAsmPlugin rz_asm_plugin_sh = {
.name = "sh",
.arch = "sh",
.author = "DMaroo",
.license = "LGPL3",
.bits = 32,
.endian = RZ_SYS_ENDIAN_LITTLE | RZ_SYS_ENDIAN_BIG,
.desc = "Hitachi/Renesas SuperH-4 disassembler",
.disassemble = &disassemble,
.assemble = &assemble,
.sw_breakpoint = sh_sw_breakpoint,
};