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
384 lines
12 KiB
C
384 lines
12 KiB
C
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
|
|
/* Rot127 <unisono@quyllur.org> 2022-2023 */
|
|
/* Automatically translated source file from LLVM. */
|
|
|
|
/* LLVM-commit: <commit> */
|
|
/* LLVM-tag: <tag> */
|
|
|
|
/* Only small edits allowed. */
|
|
/* For multiple similar edits, please create a Patch for the translator. */
|
|
|
|
/* Capstone's C++ file translator: */
|
|
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
|
|
|
|
//===- SystemZInstPrinter.cpp - Convert SystemZ MCInst to assembly syntax -===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <ctype.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <capstone/platform.h>
|
|
|
|
#include "../../MathExtras.h"
|
|
#include "../../MCAsmInfo.h"
|
|
|
|
#include "SystemZMapping.h"
|
|
#include "SystemZInstPrinter.h"
|
|
|
|
#define CONCAT(a, b) CONCAT_(a, b)
|
|
#define CONCAT_(a, b) a##_##b
|
|
|
|
static void printAddress(const MCAsmInfo *MAI, MCRegister Base,
|
|
const MCOperand *DispMO, MCRegister Index, SStream *O);
|
|
static void printMCOperandMAI(const MCOperand *MO, const MCAsmInfo *MAI,
|
|
SStream *O);
|
|
static void printRegName(const MCInst *MI, SStream *O, MCRegister Reg);
|
|
static void printInst(MCInst *MI, uint64_t Address, const char *Annot, SStream *O);
|
|
static void printOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU1ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU2ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU3ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU12ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printU48ImmOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printBDRAddrOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printBDVAddrOperand(MCInst *MI, int OpNum, SStream *O);
|
|
static void printPCRelOperand(MCInst *MI, uint64_t Address, int OpNum, SStream *O);
|
|
static void printPCRelTLSOperand(MCInst *MI, uint64_t Address, int OpNum, SStream *O);
|
|
// This forms part of the instruction name rather than the operand list.
|
|
// Print the mnemonic for a condition-code mask ("ne", "lh", etc.)
|
|
static void printCond4Operand(MCInst *MI, int OpNum, SStream *O);
|
|
|
|
#include "SystemZGenAsmWriter.inc"
|
|
|
|
#define DECLARE_printUImmOperand(N) \
|
|
static void CONCAT(printUImmOperand, N)(MCInst * MI, int OpNum, SStream *O);
|
|
DECLARE_printUImmOperand(1);
|
|
DECLARE_printUImmOperand(2);
|
|
DECLARE_printUImmOperand(3);
|
|
DECLARE_printUImmOperand(4);
|
|
DECLARE_printUImmOperand(8);
|
|
DECLARE_printUImmOperand(12);
|
|
DECLARE_printUImmOperand(16);
|
|
DECLARE_printUImmOperand(32);
|
|
DECLARE_printUImmOperand(48);
|
|
|
|
#define DECLARE_printSImmOperand(N) \
|
|
static void CONCAT(printSImmOperand, N)(MCInst * MI, int OpNum, SStream *O);
|
|
DECLARE_printSImmOperand(8);
|
|
DECLARE_printSImmOperand(16);
|
|
DECLARE_printSImmOperand(32);
|
|
|
|
static void printAddress(const MCAsmInfo *MAI, MCRegister Base,
|
|
const MCOperand *DispMO, MCRegister Index, SStream *O)
|
|
{
|
|
printMCOperandMAI(DispMO, MAI, O);
|
|
if (Base || Index) {
|
|
SStream_concat0(O, "(");
|
|
|
|
if (Index) {
|
|
printFormattedRegName(MAI, Index, O);
|
|
SStream_concat0(O, ",");
|
|
}
|
|
if (Base)
|
|
printFormattedRegName(MAI, Base, O);
|
|
else
|
|
SStream_concat0(O, "0");
|
|
|
|
SStream_concat0(O, ")");
|
|
}
|
|
}
|
|
|
|
static void printMCOperandMAI(const MCOperand *MO, const MCAsmInfo *MAI,
|
|
SStream *O) {
|
|
if (MCOperand_isReg(MO)) {
|
|
if (!MCOperand_getReg(MO))
|
|
SStream_concat1(O, '0');
|
|
else
|
|
printFormattedRegName(MAI, MCOperand_getReg(MO), O);
|
|
}
|
|
else if (MCOperand_isImm(MO))
|
|
printInt64(markup_OS(O, Markup_Immediate), MCOperand_getImm(MO));
|
|
else if (MCOperand_isExpr(MO))
|
|
printExpr(O, MCOperand_getExpr(MO));
|
|
else
|
|
CS_ASSERT(0 && "Invalid operand");
|
|
}
|
|
|
|
static void printMCOperand(const MCInst *MI, const MCOperand *MO, SStream *O)
|
|
{
|
|
if (MCOperand_isReg(MO)) {
|
|
if (!MCOperand_getReg(MO))
|
|
SStream_concat0(O, "0");
|
|
|
|
else
|
|
printFormattedRegName(&MI->MAI, MCOperand_getReg(MO), O);
|
|
} else if (MCOperand_isImm(MO))
|
|
printInt64(markup_OS(O, Markup_Immediate),
|
|
MCOperand_getImm(MO));
|
|
else if (MCOperand_isExpr(MO))
|
|
printExpr(O, MCOperand_getExpr(MO)); \
|
|
else
|
|
CS_ASSERT_RET(0 && "Invalid operand");
|
|
}
|
|
|
|
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg, SStream *O)
|
|
{
|
|
const char *RegName = getRegisterName(Reg);
|
|
if (MAI->assemblerDialect == SYSTEMZASMDIALECT_AD_ATT) {
|
|
// Skip register prefix so that only register number is left
|
|
CS_ASSERT((isalpha(RegName[0]) && isdigit(RegName[1])));
|
|
SStream_concat0(markup_OS(O, Markup_Register), (RegName + 1));
|
|
} else
|
|
SStream_concat1(markup_OS(O, Markup_Register), '%');
|
|
SStream_concat0(markup_OS(O, Markup_Register), RegName);
|
|
}
|
|
|
|
static void printRegName(const MCInst *MI, SStream *O, MCRegister Reg)
|
|
{
|
|
printFormattedRegName(&MI->MAI, Reg, O);
|
|
}
|
|
|
|
static void printInst(MCInst *MI, uint64_t Address, const char *Annot, SStream *O)
|
|
{
|
|
printInstruction(MI, Address, O);
|
|
}
|
|
|
|
#define DEFINE_printUImmOperand(N) \
|
|
void CONCAT(printUImmOperand, N)(MCInst * MI, int OpNum, SStream *O) \
|
|
{ \
|
|
MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
|
|
if (MCOperand_isExpr(MO)) { \
|
|
printExpr(O, MCOperand_getExpr(MO)); \
|
|
return; \
|
|
} \
|
|
uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
|
|
CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
|
|
printUInt64(markup_OS(O, Markup_Immediate), Value); \
|
|
}
|
|
DEFINE_printUImmOperand(1);
|
|
DEFINE_printUImmOperand(2);
|
|
DEFINE_printUImmOperand(3);
|
|
DEFINE_printUImmOperand(4);
|
|
DEFINE_printUImmOperand(8);
|
|
DEFINE_printUImmOperand(12);
|
|
DEFINE_printUImmOperand(16);
|
|
DEFINE_printUImmOperand(32);
|
|
DEFINE_printUImmOperand(48);
|
|
|
|
#define DEFINE_printSImmOperand(N) \
|
|
void CONCAT(printSImmOperand, N)(MCInst * MI, int OpNum, SStream *O) \
|
|
{ \
|
|
MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
|
|
if (MCOperand_isExpr(MO)) { \
|
|
printExpr(O, MCOperand_getExpr(MO)); \
|
|
return; \
|
|
} \
|
|
int64_t Value = \
|
|
MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
|
|
if (N == 8) \
|
|
printInt8(markup_OS(O, Markup_Immediate), Value); \
|
|
else if (N == 16) \
|
|
printInt16(markup_OS(O, Markup_Immediate), Value); \
|
|
else if (N == 32) \
|
|
printInt32(markup_OS(O, Markup_Immediate), Value); \
|
|
else \
|
|
CS_ASSERT(0 && "Unreachable"); \
|
|
}
|
|
DEFINE_printSImmOperand(8);
|
|
DEFINE_printSImmOperand(16);
|
|
DEFINE_printSImmOperand(32);
|
|
|
|
static void printU1ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U1ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 1)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU2ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U2ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 2)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU3ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U3ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 3)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U4ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 4)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_S8ImmOperand, OpNum);
|
|
CONCAT(printSImmOperand, 8)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U8ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 8)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU12ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U12ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 12)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_S16ImmOperand, OpNum);
|
|
CONCAT(printSImmOperand, 16)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U16ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 16)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_S32ImmOperand, OpNum);
|
|
CONCAT(printSImmOperand, 32)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U32ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 32)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printU48ImmOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_U48ImmOperand, OpNum);
|
|
CONCAT(printUImmOperand, 48)(MI, OpNum, O);
|
|
}
|
|
|
|
static void printPCRelOperand(MCInst *MI, uint64_t Address, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_PCRelOperand, OpNum);
|
|
MCOperand *MO = MCInst_getOperand(MI, (OpNum));
|
|
if (MCOperand_isImm(MO)) {
|
|
printInt64(O, MCOperand_getImm(MO));
|
|
} else
|
|
printExpr(O, MCOperand_getExpr(MO));
|
|
}
|
|
|
|
static void printPCRelTLSOperand(MCInst *MI, uint64_t Address, int OpNum, SStream *O)
|
|
{
|
|
// Output the PC-relative operand.
|
|
printPCRelOperand(MI, MI->address, OpNum, O);
|
|
|
|
// Output the TLS marker if present.
|
|
if ((unsigned)OpNum + 1 < MCInst_getNumOperands(MI)) {
|
|
// Expressions not supported
|
|
}
|
|
}
|
|
|
|
static void printOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_Operand, OpNum);
|
|
printMCOperand(MI, MCInst_getOperand(MI, (OpNum)), O);
|
|
}
|
|
|
|
static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_BDAddrOperand, OpNum);
|
|
printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
|
|
MCInst_getOperand(MI, (OpNum + 1)), 0, O);
|
|
}
|
|
|
|
static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_BDXAddrOperand, OpNum);
|
|
printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
|
|
MCInst_getOperand(MI, (OpNum + 1)),
|
|
MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O);
|
|
}
|
|
|
|
static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_BDLAddrOperand, OpNum);
|
|
unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
|
|
MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1));
|
|
uint64_t Length = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 2)));
|
|
printMCOperandMAI(DispMO, &MI->MAI, O);
|
|
SStream_concat1(O, '(');
|
|
printUInt64(O, Length);
|
|
if (Base) {
|
|
SStream_concat0(O, ",");
|
|
printRegName(MI, O, Base);
|
|
}
|
|
SStream_concat0(O, ")");
|
|
}
|
|
|
|
static void printBDRAddrOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_BDRAddrOperand, OpNum);
|
|
unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
|
|
MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1));
|
|
unsigned Length = MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2)));
|
|
printMCOperandMAI(DispMO, &MI->MAI, O);
|
|
SStream_concat0(O, "(");
|
|
printRegName(MI, O, Length);
|
|
if (Base) {
|
|
SStream_concat0(O, ",");
|
|
printRegName(MI, O, Base);
|
|
}
|
|
SStream_concat0(O, ")");
|
|
}
|
|
|
|
static void printBDVAddrOperand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_BDVAddrOperand, OpNum);
|
|
printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
|
|
MCInst_getOperand(MI, (OpNum + 1)),
|
|
MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O);
|
|
}
|
|
|
|
static void printCond4Operand(MCInst *MI, int OpNum, SStream *O)
|
|
{
|
|
add_cs_detail(MI, SystemZ_OP_GROUP_Cond4Operand, OpNum);
|
|
static const char *const CondNames[] = { "o", "h", "nle", "l",
|
|
"nhe", "lh", "ne", "e",
|
|
"nlh", "he", "nl", "le",
|
|
"nh", "no" };
|
|
uint64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
|
|
CS_ASSERT((Imm > 0 && Imm < 15 && "Invalid condition"));
|
|
SStream_concat0(O, CondNames[Imm - 1]);
|
|
}
|
|
|
|
const char *SystemZ_LLVM_getRegisterName(unsigned RegNo)
|
|
{
|
|
return getRegisterName(RegNo);
|
|
}
|
|
|
|
void SystemZ_LLVM_printInstruction(MCInst *MI, const char *Annotation, SStream *O)
|
|
{
|
|
printInst(MI, MI->address, Annotation, O);
|
|
}
|