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_SMC BIT(5)
27 #define LIGHTREC_NO_INVALIDATE BIT(6)
28 #define LIGHTREC_NO_MASK BIT(7)
30 /* I/O mode for load/store opcodes */
31 #define LIGHTREC_IO_MODE_LSB 8
32 #define LIGHTREC_IO_MODE(x) ((x) << LIGHTREC_IO_MODE_LSB)
33 #define LIGHTREC_IO_UNKNOWN 0x0
34 #define LIGHTREC_IO_DIRECT 0x1
35 #define LIGHTREC_IO_HW 0x2
36 #define LIGHTREC_IO_RAM 0x3
37 #define LIGHTREC_IO_BIOS 0x4
38 #define LIGHTREC_IO_SCRATCH 0x5
39 #define LIGHTREC_IO_MASK LIGHTREC_IO_MODE(0x7)
40 #define LIGHTREC_FLAGS_GET_IO_MODE(x) \
41 (((x) & LIGHTREC_IO_MASK) >> LIGHTREC_IO_MODE_LSB)
43 /* Flags for branches */
44 #define LIGHTREC_EMULATE_BRANCH BIT(5)
45 #define LIGHTREC_LOCAL_BRANCH BIT(6)
47 /* Flags for div/mult opcodes */
48 #define LIGHTREC_NO_LO BIT(5)
49 #define LIGHTREC_NO_HI BIT(6)
50 #define LIGHTREC_NO_DIV_CHECK BIT(7)
54 enum standard_opcodes {
94 enum special_opcodes {
95 OP_SPECIAL_SLL = 0x00,
96 OP_SPECIAL_SRL = 0x02,
97 OP_SPECIAL_SRA = 0x03,
98 OP_SPECIAL_SLLV = 0x04,
99 OP_SPECIAL_SRLV = 0x06,
100 OP_SPECIAL_SRAV = 0x07,
101 OP_SPECIAL_JR = 0x08,
102 OP_SPECIAL_JALR = 0x09,
103 OP_SPECIAL_SYSCALL = 0x0c,
104 OP_SPECIAL_BREAK = 0x0d,
105 OP_SPECIAL_MFHI = 0x10,
106 OP_SPECIAL_MTHI = 0x11,
107 OP_SPECIAL_MFLO = 0x12,
108 OP_SPECIAL_MTLO = 0x13,
109 OP_SPECIAL_MULT = 0x18,
110 OP_SPECIAL_MULTU = 0x19,
111 OP_SPECIAL_DIV = 0x1a,
112 OP_SPECIAL_DIVU = 0x1b,
113 OP_SPECIAL_ADD = 0x20,
114 OP_SPECIAL_ADDU = 0x21,
115 OP_SPECIAL_SUB = 0x22,
116 OP_SPECIAL_SUBU = 0x23,
117 OP_SPECIAL_AND = 0x24,
118 OP_SPECIAL_OR = 0x25,
119 OP_SPECIAL_XOR = 0x26,
120 OP_SPECIAL_NOR = 0x27,
121 OP_SPECIAL_SLT = 0x2a,
122 OP_SPECIAL_SLTU = 0x2b,
125 enum regimm_opcodes {
126 OP_REGIMM_BLTZ = 0x00,
127 OP_REGIMM_BGEZ = 0x01,
128 OP_REGIMM_BLTZAL = 0x10,
129 OP_REGIMM_BGEZAL = 0x11,
144 enum cp2_basic_opcodes {
145 OP_CP2_BASIC_MFC2 = 0x00,
146 OP_CP2_BASIC_CFC2 = 0x02,
147 OP_CP2_BASIC_MTC2 = 0x04,
148 OP_CP2_BASIC_CTC2 = 0x06,
152 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
170 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
184 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
194 /* Keep in sync with struct opcode */
202 /* Keep this union at the first position */
206 /* Keep in sync with union code */
215 void lightrec_print_disassembly(const struct block *block, const u32 *code);
217 #endif /* __DISASSEMBLER_H__ */