sh2 drc: cleanup, fix for drc crash, for mips code emitter

This commit is contained in:
kub 2019-12-11 20:16:14 +01:00
parent 9760505eaf
commit 90b1c9db91
12 changed files with 151 additions and 120 deletions

View file

@ -435,7 +435,7 @@ static int software_interrupt(unsigned int pc, unsigned int insn, char *buf, siz
return 1;
}
int disarm(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, uintptr_t *addr)
int disarm(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, unsigned long *addr)
{
*addr = 0;
@ -467,7 +467,7 @@ int disarm(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, uintptr_t *ad
return block_data_transfer(pc, insn, buf, buf_len);
if ((insn & 0x0e000000) == 0x0a000000) {
*addr = (long)pc + 8 + ((long)(insn << 8) >> 6);
*addr = (unsigned long)pc+8 + ((unsigned long)(insn << 8) >> 6);
return branch(pc, insn, buf, buf_len);
}

View file

@ -23,6 +23,6 @@
#ifndef DISARM_H
#define DISARM_H
int disarm(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, uintptr_t *sym);
int disarm(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, unsigned long *sym);
#endif /* DISARM_H */

View file

@ -6,8 +6,9 @@
* See COPYING file in the top-level directory.
*/
// XXX unimplemented: SYSCALL, BREAK, SYNC, SDBBP, T*, CACHE, PREF,
// MOVF/MOVT, LWC*/LDC*, SWC*/SDC*, COP*.
// unimplemented insns: MOV[FT], SYSCALL, BREAK, SYNC, SYNCI, T*, SDBBP, RDHWR,
// CACHE, PREF, LWC*/LDC*, SWC*/SDC*, and all of COP* (fpu, mmu, irq, exc, ...)
// unimplemented variants of insns: EHB, SSNOP (both SLL zero), JALR.HB, JR.HB
// however, it's certainly good enough for anything picodrive DRC throws at it.
#include <stdio.h>
@ -79,6 +80,7 @@ struct insn {
#define OP_SPECIAL 0x00
static const struct insn special_insns[] = {
{0x00, S_IMM_DT, "sll"},
// {0x01, , "movf\0movt"},
{0x02, S_IMM_DT|SR_BIT, "srl\0rotr"},
{0x03, S_IMM_DT, "sra"},
{0x04, REG_DTS, "sllv"},
@ -146,6 +148,7 @@ static const struct insn special2_insns[] = {
{0x21, REG_DS, "clo" },
{0x24, REG_DS, "dclz" },
{0x25, REG_DS, "dclo" },
// {0x37, , "sdbbp" },
};
// instructions with opcode SPECIAL3 (R-type)
@ -159,6 +162,7 @@ static const struct insn special3_insns[] = {
{0x05, F_IMM_TS, "dinsm" },
{0x06, F_IMM_TS, "dinsu" },
{0x07, F_IMM_TS, "dins" },
// {0x3b, , "rdhwr" },
};
// instruction with opcode SPECIAL3 and function *BSHFL
@ -192,6 +196,7 @@ static const struct insn regimm_insns[] = {
{0x12, B_IMM_S, "bltzall"},
{0x13, B_IMM_S, "bgezall"},
{0x13, B_IMM_S, "bgezall"},
// {0x1f, , "synci" },
};
// instructions with other opcodes (I-type)
@ -316,7 +321,7 @@ static unsigned long j_target(unsigned long pc, uint32_t insn)
}
// main disassembler function
int dismips(uintptr_t pc, uint32_t insn, char *buf, size_t buflen, uintptr_t *sym)
int dismips(uintptr_t pc, uint32_t insn, char *buf, size_t buflen, unsigned long *sym)
{
const struct insn *pi = decode_insn(insn);
char *rs = register_names[(insn >> 21) & 0x1f];

View file

@ -1,6 +1,6 @@
#ifndef DISMIPS_H
#define DISMIPS_H
int dismips(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, uintptr_t *sym);
int dismips(uintptr_t pc, uint32_t insn, char *buf, size_t buf_len, unsigned long *sym);
#endif /* DISMIPS_H */

View file

@ -37,14 +37,14 @@ void host_dasm(void *addr, int len)
void *end = (char *)addr + len;
const char *name;
char buf[64];
long insn, symaddr;
unsigned long insn, symaddr;
while (addr < end) {
name = lookup_name(addr);
if (name != NULL)
printf("%s:\n", name);
insn = *(long *)addr;
insn = *(unsigned long *)addr;
printf(" %08lx %08lx ", (long)addr, insn);
if(disasm((unsigned)addr, insn, buf, sizeof(buf), &symaddr))
{