Files
kaizen/external/capstone/arch/SystemZ/SystemZInstPrinter.c
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need 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)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

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);
}