Debian Codegraph @

Source/Core/Common/GekkoDisassembler.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 /* $VER: ppc_disasm.h V1.6 (09.12.2011)
5 *
6 * Disassembler module for the PowerPC microprocessor family
7 * Copyright (c) 1998-2001,2009,2011 Frank Wille
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 // Modified for use with Dolphin
33
34 #pragma once
35
36 #include <string>
37 #include <string_view>
38
39 #include "Common/CommonTypes.h"
40
41 namespace Common
42 {
43 class GekkoDisassembler final
44 {
45 public:
46 static std::string Disassemble(u32 opcode, u32 current_instruction_address,
47 bool big_endian = true);
48 static const char* GetGPRName(u32 index);
49 static const char* GetFPRName(u32 index);
50
51 private:
52 GekkoDisassembler() = delete;
53
54 static void ill(u32 in);
55 static std::string imm(u32 in, int uimm, int type, bool hex);
56
57 static std::string ra_rb(u32 in);
58 static std::string rd_ra_rb(u32 in, int mask);
59 static std::string fd_ra_rb(u32 in);
60
61 static void trapi(u32 in, unsigned char dmode);
62 static void cmpi(u32 in, int uimm);
63 static void addi(u32 in, std::string_view ext);
64 static size_t branch(u32 in, std::string_view bname, int aform, int bdisp);
65 static void bc(u32 in);
66 static void bli(u32 in);
67 static void mcrf(u32 in, std::string_view suffix);
68 static void crop(u32 in, std::string_view n1, std::string_view n2);
69 static void nooper(u32 in, std::string_view name);
70 static void rlw(u32 in, std::string_view name, int i);
71 static void ori(u32 in, std::string_view name);
72 static void rld(u32 in, std::string_view name, int i);
73 static void cmp(u32 in);
74 static void trap(u32 in, unsigned char dmode);
75 static void dab(u32 in, std::string_view name, int mask, int smode, int chkoe, int chkrc);
76 static void rrn(u32 in, std::string_view name, int smode, int chkoe, int chkrc);
77 static void mtcr(u32 in);
78 static void msr(u32 in, int smode);
79 static void mspr(u32 in, int smode);
80 static void mtb(u32 in);
81 static void sradi(u32 in);
82 static void ldst(u32 in, std::string_view name, char reg);
83 static void fdabc(u32 in, std::string_view name, int mask);
84 static void fmr(u32 in);
85 static void fdab(u32 in, std::string_view name);
86 static void fcmp(u32 in, char c);
87 static void mtfsb(u32 in, int n);
88 static void ps(u32 inst);
89 static void ps_mem(u32 inst);
90
91 static u32* DoDisassembly(bool big_endian);
92
93 enum Flags
94 {
95 PPCF_ILLEGAL = (1 << 0), // Illegal PowerPC instruction
96 PPCF_UNSIGNED = (1 << 1), // Unsigned immediate instruction
97 PPCF_SUPER = (1 << 2), // Supervisor level instruction
98 PPCF_64 = (1 << 3), // 64-bit only instruction
99 };
100
101 static u32* m_instr; // Pointer to instruction to disassemble
102 static u32* m_iaddr; // Instruction.address., usually the same as instr
103 static std::string m_opcode; // Buffer for opcode, min. 10 chars.
104 static std::string m_operands; // Operand buffer, min. 24 chars.
105 };
106 } // namespace Common