switch to capstone on master

This commit is contained in:
Simone Coco
2022-09-21 11:21:41 +02:00
parent 7f4352003e
commit de1f287197
5 changed files with 30 additions and 10 deletions

1
.gitmodules vendored
View File

@@ -1,7 +1,6 @@
[submodule "external/capstone"] [submodule "external/capstone"]
path = external/capstone path = external/capstone
url = https://github.com/capstone-engine/capstone/ url = https://github.com/capstone-engine/capstone/
branch = next
[submodule "external/nativefiledialog-extended"] [submodule "external/nativefiledialog-extended"]
path = external/nativefiledialog-extended path = external/nativefiledialog-extended
url = https://github.com/btzy/nativefiledialog-extended/ url = https://github.com/btzy/nativefiledialog-extended/

View File

@@ -88,6 +88,27 @@ inline void HandleInterrupt(Registers& regs) {
} }
} }
inline void Cpu::disassembly(u32 instr) const {
size_t count;
cs_insn *insn;
u8 code[4];
//u32 temp = bswap_32(instr);
memcpy(code, &instr, 4);
count = cs_disasm(handle, code, 4, regs.pc, 0, &insn);
if (count > 0) {
size_t j;
for (j = 0; j < count; j++) {
fmt::print("0x{:016X}:\t{}\t\t{}\n", insn[j].address, insn[j].mnemonic, insn[j].op_str);
}
cs_free(insn, count);
} else
printf("ERROR: Failed to disassemble given code!\n");
}
void Cpu::Step(Mem& mem) { void Cpu::Step(Mem& mem) {
regs.gpr[0] = 0; regs.gpr[0] = 0;
@@ -96,6 +117,8 @@ void Cpu::Step(Mem& mem) {
u32 instruction = mem.Read32(regs, regs.pc, regs.pc); u32 instruction = mem.Read32(regs, regs.pc, regs.pc);
disassembly(instruction);
regs.oldPC = regs.pc; regs.oldPC = regs.pc;
regs.pc = regs.nextPC; regs.pc = regs.nextPC;
regs.nextPC += 4; regs.nextPC += 4;

View File

@@ -7,23 +7,21 @@
namespace n64 { namespace n64 {
struct Cpu { struct Cpu {
Cpu() { Cpu() {
//log = fopen("disasm.txt", "w"); if(cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64, &handle) != CS_ERR_OK) {
//if(cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64, &handle) != CS_ERR_OK) { util::panic("Could not initialize capstone!\n");
// util::panic("Could not initialize capstone!\n"); }
//}
Reset(); Reset();
} }
~Cpu() { ~Cpu() {
//fclose(log); cs_close(&handle);
//cs_close(&handle);
} }
void Reset(); void Reset();
void Step(Mem&); void Step(Mem&);
Registers regs; Registers regs;
private: private:
csh handle; csh handle;
FILE* log; void disassembly(u32 instr) const;
friend struct Cop1; friend struct Cop1;
void special(Mem&, u32); void special(Mem&, u32);