1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * Copyright (C) 2014-2021 Paul Cercueil <paul@crapouillou.net>
6 #ifndef __DISASSEMBLER_H__
7 #define __DISASSEMBLER_H__
13 #define __packed __attribute__((packed))
16 #define BIT(x) (1ULL << (x))
18 /* Flags for all opcodes */
19 #define LIGHTREC_NO_DS BIT(0)
20 #define LIGHTREC_UNLOAD_RS BIT(1)
21 #define LIGHTREC_UNLOAD_RT BIT(2)
22 #define LIGHTREC_UNLOAD_RD BIT(3)
23 #define LIGHTREC_SYNC BIT(4)
25 /* Flags for load/store opcodes */
26 #define LIGHTREC_DIRECT_IO BIT(5)
27 #define LIGHTREC_HW_IO BIT(6)
28 #define LIGHTREC_SMC BIT(7)
29 #define LIGHTREC_NO_INVALIDATE BIT(8)
31 /* Flags for branches */
32 #define LIGHTREC_EMULATE_BRANCH BIT(5)
33 #define LIGHTREC_LOCAL_BRANCH BIT(6)
35 /* Flags for div/mult opcodes */
36 #define LIGHTREC_NO_LO BIT(5)
37 #define LIGHTREC_NO_HI BIT(6)
38 #define LIGHTREC_NO_DIV_CHECK BIT(7)
42 enum standard_opcodes {
82 enum special_opcodes {
83 OP_SPECIAL_SLL = 0x00,
84 OP_SPECIAL_SRL = 0x02,
85 OP_SPECIAL_SRA = 0x03,
86 OP_SPECIAL_SLLV = 0x04,
87 OP_SPECIAL_SRLV = 0x06,
88 OP_SPECIAL_SRAV = 0x07,
90 OP_SPECIAL_JALR = 0x09,
91 OP_SPECIAL_SYSCALL = 0x0c,
92 OP_SPECIAL_BREAK = 0x0d,
93 OP_SPECIAL_MFHI = 0x10,
94 OP_SPECIAL_MTHI = 0x11,
95 OP_SPECIAL_MFLO = 0x12,
96 OP_SPECIAL_MTLO = 0x13,
97 OP_SPECIAL_MULT = 0x18,
98 OP_SPECIAL_MULTU = 0x19,
99 OP_SPECIAL_DIV = 0x1a,
100 OP_SPECIAL_DIVU = 0x1b,
101 OP_SPECIAL_ADD = 0x20,
102 OP_SPECIAL_ADDU = 0x21,
103 OP_SPECIAL_SUB = 0x22,
104 OP_SPECIAL_SUBU = 0x23,
105 OP_SPECIAL_AND = 0x24,
106 OP_SPECIAL_OR = 0x25,
107 OP_SPECIAL_XOR = 0x26,
108 OP_SPECIAL_NOR = 0x27,
109 OP_SPECIAL_SLT = 0x2a,
110 OP_SPECIAL_SLTU = 0x2b,
113 enum regimm_opcodes {
114 OP_REGIMM_BLTZ = 0x00,
115 OP_REGIMM_BGEZ = 0x01,
116 OP_REGIMM_BLTZAL = 0x10,
117 OP_REGIMM_BGEZAL = 0x11,
132 enum cp2_basic_opcodes {
133 OP_CP2_BASIC_MFC2 = 0x00,
134 OP_CP2_BASIC_CFC2 = 0x02,
135 OP_CP2_BASIC_MTC2 = 0x04,
136 OP_CP2_BASIC_CTC2 = 0x06,
140 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
158 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
172 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
182 /* Keep in sync with struct opcode */
190 /* Keep this union at the first position */
194 /* Keep in sync with union code */
203 void lightrec_print_disassembly(const struct block *block, const u32 *code);
205 #endif /* __DISASSEMBLER_H__ */