2 * Copyright (C) 2014-2020 Paul Cercueil <paul@crapouillou.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 #ifndef __DISASSEMBLER_H__
16 #define __DISASSEMBLER_H__
22 #define __packed __attribute__((packed))
25 #define LIGHTREC_DIRECT_IO (1 << 0)
26 #define LIGHTREC_NO_INVALIDATE (1 << 1)
27 #define LIGHTREC_NO_DS (1 << 2)
28 #define LIGHTREC_SMC (1 << 3)
29 #define LIGHTREC_EMULATE_BRANCH (1 << 4)
30 #define LIGHTREC_LOCAL_BRANCH (1 << 5)
31 #define LIGHTREC_HW_IO (1 << 6)
32 #define LIGHTREC_MULT32 (1 << 7)
36 enum standard_opcodes {
70 OP_META_REG_UNLOAD = 0x11,
79 enum special_opcodes {
80 OP_SPECIAL_SLL = 0x00,
81 OP_SPECIAL_SRL = 0x02,
82 OP_SPECIAL_SRA = 0x03,
83 OP_SPECIAL_SLLV = 0x04,
84 OP_SPECIAL_SRLV = 0x06,
85 OP_SPECIAL_SRAV = 0x07,
87 OP_SPECIAL_JALR = 0x09,
88 OP_SPECIAL_SYSCALL = 0x0c,
89 OP_SPECIAL_BREAK = 0x0d,
90 OP_SPECIAL_MFHI = 0x10,
91 OP_SPECIAL_MTHI = 0x11,
92 OP_SPECIAL_MFLO = 0x12,
93 OP_SPECIAL_MTLO = 0x13,
94 OP_SPECIAL_MULT = 0x18,
95 OP_SPECIAL_MULTU = 0x19,
96 OP_SPECIAL_DIV = 0x1a,
97 OP_SPECIAL_DIVU = 0x1b,
98 OP_SPECIAL_ADD = 0x20,
99 OP_SPECIAL_ADDU = 0x21,
100 OP_SPECIAL_SUB = 0x22,
101 OP_SPECIAL_SUBU = 0x23,
102 OP_SPECIAL_AND = 0x24,
103 OP_SPECIAL_OR = 0x25,
104 OP_SPECIAL_XOR = 0x26,
105 OP_SPECIAL_NOR = 0x27,
106 OP_SPECIAL_SLT = 0x2a,
107 OP_SPECIAL_SLTU = 0x2b,
110 enum regimm_opcodes {
111 OP_REGIMM_BLTZ = 0x00,
112 OP_REGIMM_BGEZ = 0x01,
113 OP_REGIMM_BLTZAL = 0x10,
114 OP_REGIMM_BGEZAL = 0x11,
129 enum cp2_basic_opcodes {
130 OP_CP2_BASIC_MFC2 = 0x00,
131 OP_CP2_BASIC_CFC2 = 0x02,
132 OP_CP2_BASIC_MTC2 = 0x04,
133 OP_CP2_BASIC_CTC2 = 0x06,
137 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
155 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
169 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
179 /* Keep in sync with struct opcode */
187 /* Keep this union at the first position */
191 /* Keep in sync with union code */
202 struct opcode * lightrec_disassemble(struct lightrec_state *state,
203 const u32 *src, unsigned int *len);
204 void lightrec_free_opcode_list(struct lightrec_state *state,
205 struct opcode *list);
207 unsigned int lightrec_cycles_of_opcode(union code code);
209 void lightrec_print_disassembly(const struct block *block,
210 const u32 *code, unsigned int length);
212 #endif /* __DISASSEMBLER_H__ */