GekkoDisassembler.h 4.1 KB

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