00cc9309cb
de6e324bdseparate emu thread10d3daf86Roms List improvements95d202f37Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.fc306967fWow the ROM Header was just completely busted. Game list view works nowbad1691eefuck this shit2b59e5f46game list in progressd26417b83remappable inputs in progressac4af8106inpute72abc240update readme430139dc9Qt6 frontend3080d4d45Fix this small bug too08cd13b85Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.61bb4fb44make idle loop detection a little more specific with where the load goesb037de4c3SAZDFsdff12e81e73eneed to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)204f0e13bidle skipping seems to work!cb8bb634asdkfjlasdf58e5c89c1Fix compilation issue on my machine (no idea)24fb2898eattempting more serious idle skipping214719577Place rsp.Step inside cached interpreter. Gains about 3 more fpsbb97dcc23mmmmm920b77d38wjkhasdfjhkasdf430ccdab4it's a start...4f42a673aCached interpreter plays Mario 64. Start looking into RSP as wellc9a030787idle skipping works!5fbda03cenew idea366637abaIdle skipping... maybe?609fa2fb0Cache instructions implemented but broken lmao. Commented out for nowe140a6d12- Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work68e613057prep cache impl811b4d809fix clang formatfda755f7didkd5024ebbfsmall MI refactor in preparation of (eventually) implementing the RDRAM interface properly694b45341Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'206dcdedfSquashed 'external/SDL/' content from commit 4d17b99d0a4d16e1cb4need to update sdl848b19920Fix compilation errordb61b5299Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'e94a94559Squashed 'external/imgui/' content from commit 02e9b8cac52edb3757need to update imguic1a705e86Emulate weird JALR behaviour4b4c32f4bFix exception for "unusable COP1" in 4 instructions i missed accidentally (again)df5828142Bug putting 0s in the log everywheref8b580048Make isviewer a sink to file8241e9735Fix exception for "unusable COP1" in 4 instructions i missed accidentallyb29715f20small changesd9a620bc1make use of my new small utility library0d1aa938eAdd 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'e64eb40b3Fuck git git-subtree-dir: external/ircolib git-subtree-split:de6e324bde
291 lines
7.1 KiB
C
291 lines
7.1 KiB
C
/* Capstone Disassembly Engine */
|
|
/* By Dmitry Sibirtsev <sibirtsevdl@gmail.com>, 2024 */
|
|
|
|
#ifdef CAPSTONE_HAS_ARC
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <capstone/capstone.h>
|
|
#include <capstone/arc.h>
|
|
|
|
#include "../../Mapping.h"
|
|
#include "../../MCDisassembler.h"
|
|
#include "../../cs_priv.h"
|
|
#include "../../cs_simple_types.h"
|
|
|
|
#include "ARCMapping.h"
|
|
#include "ARCLinkage.h"
|
|
|
|
#define GET_REGINFO_ENUM
|
|
#define GET_REGINFO_MC_DESC
|
|
#include "ARCGenRegisterInfo.inc"
|
|
|
|
#define GET_INSTRINFO_ENUM
|
|
#include "ARCGenInstrInfo.inc"
|
|
|
|
void ARC_init_mri(MCRegisterInfo *MRI)
|
|
{
|
|
MCRegisterInfo_InitMCRegisterInfo(MRI, ARCRegDesc,
|
|
sizeof(ARCRegDesc), 0, 0,
|
|
ARCMCRegisterClasses,
|
|
ARR_SIZE(ARCMCRegisterClasses),
|
|
0, 0, ARCRegDiffLists, 0,
|
|
ARCSubRegIdxLists,
|
|
ARR_SIZE(ARCSubRegIdxLists), 0);
|
|
}
|
|
|
|
const char *ARC_reg_name(csh handle, unsigned int reg)
|
|
{
|
|
return ARC_LLVM_getRegisterName(reg);
|
|
}
|
|
|
|
void ARC_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
|
|
{
|
|
// Not used by ARC. Information is set after disassembly.
|
|
}
|
|
|
|
static const char *const insn_name_maps[] = {
|
|
#include "ARCGenCSMappingInsnName.inc"
|
|
};
|
|
|
|
const char *ARC_insn_name(csh handle, unsigned int id)
|
|
{
|
|
#ifndef CAPSTONE_DIET
|
|
if (id < ARR_SIZE(insn_name_maps))
|
|
return insn_name_maps[id];
|
|
// not found
|
|
return NULL;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
#ifndef CAPSTONE_DIET
|
|
static const name_map group_name_maps[] = {
|
|
{ ARC_GRP_INVALID, NULL },
|
|
|
|
{ ARC_GRP_JUMP, "jump" },
|
|
{ ARC_GRP_CALL, "call" },
|
|
{ ARC_GRP_RET, "return" },
|
|
{ ARC_GRP_BRANCH_RELATIVE, "branch_relative" },
|
|
|
|
};
|
|
#endif
|
|
|
|
const char *ARC_group_name(csh handle, unsigned int id)
|
|
{
|
|
#ifndef CAPSTONE_DIET
|
|
return id2name(group_name_maps, ARR_SIZE(group_name_maps), id);
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
void ARC_reg_access(const cs_insn *insn, cs_regs regs_read,
|
|
uint8_t *regs_read_count, cs_regs regs_write,
|
|
uint8_t *regs_write_count)
|
|
{
|
|
uint8_t i;
|
|
uint8_t read_count, write_count;
|
|
cs_arc *arc = &(insn->detail->arc);
|
|
|
|
read_count = insn->detail->regs_read_count;
|
|
write_count = insn->detail->regs_write_count;
|
|
|
|
// implicit registers
|
|
memcpy(regs_read, insn->detail->regs_read,
|
|
read_count * sizeof(insn->detail->regs_read[0]));
|
|
memcpy(regs_write, insn->detail->regs_write,
|
|
write_count * sizeof(insn->detail->regs_write[0]));
|
|
|
|
// explicit registers
|
|
for (i = 0; i < arc->op_count; i++) {
|
|
cs_arc_op *op = &(arc->operands[i]);
|
|
switch ((int)op->type) {
|
|
case ARC_OP_REG:
|
|
if ((op->access & CS_AC_READ) &&
|
|
!arr_exist(regs_read, read_count, op->reg)) {
|
|
regs_read[read_count] = (uint16_t)op->reg;
|
|
read_count++;
|
|
}
|
|
if ((op->access & CS_AC_WRITE) &&
|
|
!arr_exist(regs_write, write_count, op->reg)) {
|
|
regs_write[write_count] = (uint16_t)op->reg;
|
|
write_count++;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
*regs_read_count = read_count;
|
|
*regs_write_count = write_count;
|
|
}
|
|
|
|
const insn_map arc_insns[] = {
|
|
#include "ARCGenCSMappingInsn.inc"
|
|
};
|
|
|
|
void ARC_set_instr_map_data(MCInst *MI)
|
|
{
|
|
map_cs_id(MI, arc_insns, ARR_SIZE(arc_insns));
|
|
map_implicit_reads(MI, arc_insns);
|
|
map_implicit_writes(MI, arc_insns);
|
|
map_groups(MI, arc_insns);
|
|
}
|
|
|
|
bool ARC_getInstruction(csh handle, const uint8_t *code, size_t code_len,
|
|
MCInst *instr, uint16_t *size, uint64_t address,
|
|
void *info)
|
|
{
|
|
uint64_t temp_size;
|
|
ARC_init_cs_detail(instr);
|
|
DecodeStatus Result = ARC_LLVM_getInstruction(instr, &temp_size, code,
|
|
code_len, address, info);
|
|
ARC_set_instr_map_data(instr);
|
|
*size = temp_size;
|
|
if (Result == MCDisassembler_SoftFail) {
|
|
MCInst_setSoftFail(instr);
|
|
}
|
|
return Result != MCDisassembler_Fail;
|
|
}
|
|
|
|
void ARC_printer(MCInst *MI, SStream *O,
|
|
void * /* MCRegisterInfo* */ info)
|
|
{
|
|
MCRegisterInfo *MRI = (MCRegisterInfo *)info;
|
|
MI->MRI = MRI;
|
|
|
|
ARC_LLVM_printInst(MI, MI->address, "", O);
|
|
}
|
|
|
|
void ARC_setup_op(cs_arc_op *op)
|
|
{
|
|
memset(op, 0, sizeof(cs_arc_op));
|
|
op->type = ARC_OP_INVALID;
|
|
}
|
|
|
|
void ARC_init_cs_detail(MCInst *MI)
|
|
{
|
|
if (!detail_is_set(MI)) {
|
|
return;
|
|
}
|
|
unsigned int i;
|
|
|
|
memset(get_detail(MI), 0,
|
|
offsetof(cs_detail, arc) + sizeof(cs_arc));
|
|
|
|
for (i = 0; i < ARR_SIZE(ARC_get_detail(MI)->operands);
|
|
i++)
|
|
ARC_setup_op(
|
|
&ARC_get_detail(MI)->operands[i]);
|
|
}
|
|
|
|
static const map_insn_ops insn_operands[] = {
|
|
#include "ARCGenCSMappingInsnOp.inc"
|
|
};
|
|
|
|
void ARC_set_detail_op_imm(MCInst *MI, unsigned OpNum,
|
|
arc_op_type ImmType, int64_t Imm)
|
|
{
|
|
if (!detail_is_set(MI))
|
|
return;
|
|
ARC_check_safe_inc(MI);
|
|
CS_ASSERT((map_get_op_type(MI, OpNum) & ~CS_OP_MEM) == CS_OP_IMM);
|
|
CS_ASSERT(ImmType == ARC_OP_IMM);
|
|
|
|
ARC_get_detail_op(MI, 0)->type = ImmType;
|
|
ARC_get_detail_op(MI, 0)->imm = Imm;
|
|
ARC_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
|
|
ARC_inc_op_count(MI);
|
|
}
|
|
|
|
void ARC_set_detail_op_reg(MCInst *MI, unsigned OpNum, arc_reg Reg)
|
|
{
|
|
if (!detail_is_set(MI))
|
|
return;
|
|
ARC_check_safe_inc(MI);
|
|
CS_ASSERT((map_get_op_type(MI, OpNum) & ~CS_OP_MEM) == CS_OP_REG);
|
|
|
|
ARC_get_detail_op(MI, 0)->type = ARC_OP_REG;
|
|
ARC_get_detail_op(MI, 0)->reg = Reg;
|
|
ARC_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
|
|
ARC_inc_op_count(MI);
|
|
}
|
|
|
|
void ARC_add_cs_detail(MCInst *MI, int op_group,
|
|
va_list args)
|
|
{
|
|
if (!detail_is_set(MI))
|
|
return;
|
|
|
|
unsigned OpNum = va_arg(args, unsigned);
|
|
cs_op_type op_type = map_get_op_type(MI, OpNum);
|
|
cs_op_type base_op_type = op_type;
|
|
cs_op_type offset_op_type;
|
|
// Fill cs_detail
|
|
switch (op_group) {
|
|
default:
|
|
printf("ERROR: Operand group %d not handled!\n", op_group);
|
|
CS_ASSERT_RET(0);
|
|
case ARC_OP_GROUP_Operand:
|
|
if (op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else if (op_type == CS_OP_REG) {
|
|
ARC_set_detail_op_reg(MI, OpNum,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else {
|
|
// Expression
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCOperand_getImm(MCInst_getOperand(MI, OpNum)));
|
|
}
|
|
break;
|
|
case ARC_OP_GROUP_PredicateOperand:
|
|
if (op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
break;
|
|
case ARC_OP_GROUP_MemOperandRI:
|
|
if (base_op_type == CS_OP_REG) {
|
|
ARC_set_detail_op_reg(MI, OpNum,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
offset_op_type = map_get_op_type(MI, OpNum+1);
|
|
if (offset_op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum+1, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum+1));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
break;
|
|
case ARC_OP_GROUP_BRCCPredicateOperand:
|
|
if (op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
break;
|
|
case ARC_OP_GROUP_CCOperand:
|
|
if (op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
break;
|
|
case ARC_OP_GROUP_U6:
|
|
if (op_type == CS_OP_IMM) {
|
|
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
|
|
MCInst_getOpVal(MI, OpNum));
|
|
} else
|
|
CS_ASSERT(0 && "Op type not handled.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endif
|