Files
kaizen/external/capstone/arch/SystemZ/SystemZDisassembler.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

415 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 */
//===-- SystemZDisassembler.cpp - Disassembler for SystemZ ------*- C++ -*-===//
//
// 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <capstone/platform.h>
#include "../../MCInst.h"
#include "../../MathExtras.h"
#include "../../MCInstPrinter.h"
#include "../../MCDisassembler.h"
#include "../../MCFixedLenDisassembler.h"
#include "../../cs_priv.h"
#include "../../utils.h"
#include "SystemZMCTargetDesc.h"
#include "SystemZDisassemblerExtension.h"
#define CONCAT(a, b) CONCAT_(a, b)
#define CONCAT_(a, b) a##_##b
#define DEBUG_TYPE "systemz-disassembler"
static DecodeStatus getInstruction(MCInst *Instr, uint16_t *Size, const uint8_t *Bytes,
size_t BytesLen, uint64_t Address,
SStream *CStream);
/// tryAddingSymbolicOperand - trys to add a symbolic operand in place of the
/// immediate Value in the MCInst.
///
/// @param Value - The immediate Value, has had any PC adjustment made by
/// the caller.
/// @param isBranch - If the instruction is a branch instruction
/// @param Address - The starting address of the instruction
/// @param Offset - The byte offset to this immediate in the instruction
/// @param Width - The byte width of this immediate in the instruction
///
/// If the getOpInfo() function was set when setupForSymbolicDisassembly() was
/// called then that function is called to get any symbolic information for the
/// immediate in the instruction using the Address, Offset and Width. If that
/// returns non-zero then the symbolic information it returns is used to create
/// an MCExpr and that is added as an operand to the MCInst. If getOpInfo()
/// returns zero and isBranch is true then a symbol look up for immediate Value
/// is done and if a symbol is found an MCExpr is created with that, else
/// an MCExpr with the immediate Value is created. This function returns true
/// if it adds an operand to the MCInst and false otherwise.
static bool tryAddingSymbolicOperand(int64_t Value, bool IsBranch,
uint64_t Address, uint64_t Offset,
uint64_t Width, MCInst *MI,
const void *Decoder)
{
// return Decoder->tryAddingSymbolicOperand(MI, Value, Address, IsBranch,
// Offset, Width, /*InstSize=*/0);
return false;
}
static DecodeStatus decodeRegisterClass(MCInst *Inst, uint64_t RegNo,
const unsigned *Regs, unsigned Size,
bool IsAddr)
{
CS_ASSERT((RegNo < Size && "Invalid register"));
if (IsAddr && RegNo == 0) {
RegNo = SystemZ_NoRegister;
} else {
RegNo = Regs[RegNo];
if (RegNo == 0)
return MCDisassembler_Fail;
}
MCOperand_CreateReg0(Inst, (RegNo));
return MCDisassembler_Success;
}
static DecodeStatus DecodeGR32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GR32Regs, 16, false);
}
static DecodeStatus DecodeGRH32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GRH32Regs, 16, false);
}
static DecodeStatus DecodeGR64BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GR64Regs, 16, false);
}
static DecodeStatus DecodeGR128BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GR128Regs, 16, false);
}
static DecodeStatus DecodeADDR32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GR32Regs, 16, true);
}
static DecodeStatus DecodeADDR64BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_GR64Regs, 16, true);
}
static DecodeStatus DecodeFP32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_FP32Regs, 16, false);
}
static DecodeStatus DecodeFP64BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_FP64Regs, 16, false);
}
static DecodeStatus DecodeFP128BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_FP128Regs, 16, false);
}
static DecodeStatus DecodeVR32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_VR32Regs, 32, false);
}
static DecodeStatus DecodeVR64BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_VR64Regs, 32, false);
}
static DecodeStatus DecodeVR128BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_VR128Regs, 32, false);
}
static DecodeStatus DecodeAR32BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_AR32Regs, 16, false);
}
static DecodeStatus DecodeCR64BitRegisterClass(MCInst *Inst, uint64_t RegNo,
uint64_t Address,
const void *Decoder)
{
return decodeRegisterClass(Inst, RegNo, SystemZMC_CR64Regs, 16, false);
}
#define DEFINE_decodeUImmOperand(N) \
static DecodeStatus CONCAT(decodeUImmOperand, N)(MCInst * Inst, \
uint64_t Imm) \
{ \
if (!isUIntN(N, Imm)) \
return MCDisassembler_Fail; \
MCOperand_CreateImm0(Inst, (Imm)); \
return MCDisassembler_Success; \
}
DEFINE_decodeUImmOperand(1);
DEFINE_decodeUImmOperand(2);
DEFINE_decodeUImmOperand(3);
DEFINE_decodeUImmOperand(4);
DEFINE_decodeUImmOperand(8);
DEFINE_decodeUImmOperand(12);
DEFINE_decodeUImmOperand(16);
DEFINE_decodeUImmOperand(32);
#define DEFINE_decodeSImmOperand(N) \
static DecodeStatus CONCAT(decodeSImmOperand, N)(MCInst * Inst, \
uint64_t Imm) \
{ \
if (!isUIntN(N, Imm)) \
return MCDisassembler_Fail; \
MCOperand_CreateImm0(Inst, (SignExtend64((Imm), N))); \
return MCDisassembler_Success; \
}
DEFINE_decodeSImmOperand(8);
DEFINE_decodeSImmOperand(16);
DEFINE_decodeSImmOperand(20);
DEFINE_decodeSImmOperand(32);
static DecodeStatus decodeU1ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 1)(Inst, Imm);
}
static DecodeStatus decodeU2ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 2)(Inst, Imm);
}
static DecodeStatus decodeU3ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 3)(Inst, Imm);
}
static DecodeStatus decodeU4ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 4)(Inst, Imm);
}
static DecodeStatus decodeU8ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 8)(Inst, Imm);
}
static DecodeStatus decodeU12ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 12)(Inst, Imm);
}
static DecodeStatus decodeU16ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 16)(Inst, Imm);
}
static DecodeStatus decodeU32ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeUImmOperand, 32)(Inst, Imm);
}
static DecodeStatus decodeS8ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeSImmOperand, 8)(Inst, Imm);
}
static DecodeStatus decodeS16ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeSImmOperand, 16)(Inst, Imm);
}
static DecodeStatus decodeS20ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeSImmOperand, 20)(Inst, Imm);
}
static DecodeStatus decodeS32ImmOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodeSImmOperand, 32)(Inst, Imm);
}
#define DEFINE_decodeLenOperand(N) \
static DecodeStatus CONCAT(decodeLenOperand, \
N)(MCInst * Inst, uint64_t Imm, \
uint64_t Address, const void *Decoder) \
{ \
if (!isUIntN(N, Imm)) \
return MCDisassembler_Fail; \
MCOperand_CreateImm0(Inst, (Imm + 1)); \
return MCDisassembler_Success; \
}
DEFINE_decodeLenOperand(8);
DEFINE_decodeLenOperand(4);
#define DEFINE_decodePCDBLOperand(N) \
static DecodeStatus CONCAT(decodePCDBLOperand, N)( \
MCInst * Inst, uint64_t Imm, uint64_t Address, bool isBranch, \
const void *Decoder) \
{ \
CS_ASSERT((isUIntN(N, Imm) && "Invalid PC-relative offset")); \
uint64_t Value = SignExtend64((Imm), N) * 2 + Address; \
\
if (!tryAddingSymbolicOperand(Value, isBranch, Address, 2, \
N / 8, Inst, Decoder)) \
MCOperand_CreateImm0(Inst, (Value)); \
\
return MCDisassembler_Success; \
}
DEFINE_decodePCDBLOperand(12);
DEFINE_decodePCDBLOperand(16);
DEFINE_decodePCDBLOperand(24);
DEFINE_decodePCDBLOperand(32);
static DecodeStatus decodePC12DBLBranchOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address,
const void *Decoder)
{
return CONCAT(decodePCDBLOperand, 12)(Inst, Imm, Address, true,
Decoder);
}
static DecodeStatus decodePC16DBLBranchOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address,
const void *Decoder)
{
return CONCAT(decodePCDBLOperand, 16)(Inst, Imm, Address, true,
Decoder);
}
static DecodeStatus decodePC24DBLBranchOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address,
const void *Decoder)
{
return CONCAT(decodePCDBLOperand, 24)(Inst, Imm, Address, true,
Decoder);
}
static DecodeStatus decodePC32DBLBranchOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address,
const void *Decoder)
{
return CONCAT(decodePCDBLOperand, 32)(Inst, Imm, Address, true,
Decoder);
}
static DecodeStatus decodePC32DBLOperand(MCInst *Inst, uint64_t Imm,
uint64_t Address, const void *Decoder)
{
return CONCAT(decodePCDBLOperand, 32)(Inst, Imm, Address, false,
Decoder);
}
#include "SystemZGenDisassemblerTables.inc"
static DecodeStatus getInstruction(MCInst *MI, uint16_t *Size, const uint8_t *Bytes,
size_t BytesLen, uint64_t Address, SStream *CS)
{
// Get the first two bytes of the instruction.
*Size = 0;
if (BytesLen < 2)
return MCDisassembler_Fail;
// The top 2 bits of the first byte specify the size.
const uint8_t *Table;
uint64_t Inst = 0;
if (Bytes[0] < 0x40) {
*Size = 2;
Table = DecoderTable16;
Inst = readBytes16(MI, Bytes);
} else if (Bytes[0] < 0xc0) {
if (BytesLen < 4) {
return MCDisassembler_Fail;
}
*Size = 4;
Table = DecoderTable32;
Inst = readBytes32(MI, Bytes);
} else {
if (BytesLen < 6) {
return MCDisassembler_Fail;
}
*Size = 6;
Table = DecoderTable48;
Inst = readBytes48(MI, Bytes);
}
// Read any remaining bytes.
if (BytesLen < *Size) {
*Size = BytesLen;
return MCDisassembler_Fail;
}
return decodeInstruction_8(Table, MI, Inst, Address, NULL);
}
DecodeStatus SystemZ_LLVM_getInstruction(csh handle, const uint8_t *Bytes,
size_t BytesLen, MCInst *MI,
uint16_t *Size, uint64_t Address,
void *Info)
{
return getInstruction(MI, Size, Bytes, BytesLen, MI->address, NULL);
}