N64FlashcartMenu
Loading...
Searching...
No Matches
vr4300_asm.h
1#ifndef VR4300_ASM_H__
2#define VR4300_ASM_H__
3
4#include <stdint.h>
5
6typedef union {
7 uint32_t raw;
8
9 struct {
10 uint32_t op : 6;
11 uint32_t rs : 5;
12 uint32_t rt : 5;
13 uint32_t imm : 16;
14 } i_type;
15
16 struct {
17 uint32_t op : 6;
18 uint32_t target : 26;
19 } j_type;
20
21 struct {
22 uint32_t op : 6;
23 uint32_t rs : 5;
24 uint32_t rt : 5;
25 uint32_t rd : 5;
26 uint32_t sa : 5;
27 uint32_t funct : 6;
28 } r_type;
29
30 struct {
31 uint32_t op : 6;
32 uint32_t co : 1;
33 uint32_t funct : 25;
34 } c_type;
36
37typedef enum {
38 OP_SPECIAL,
39 OP_REGIMM,
40 OP_J,
41 OP_JAL,
42 OP_BEQ,
43 OP_BNE,
44 OP_BLEZ,
45 OP_BGTZ,
46 OP_ADDI,
47 OP_ADDIU,
48 OP_SLTI,
49 OP_SLTIU,
50 OP_ANDI,
51 OP_ORI,
52 OP_XORI,
53 OP_LUI,
54 OP_COP0,
55 OP_COP1,
56 OP_COP2,
57 __OP_RESERVED_19,
58 OP_BEQL,
59 OP_BNEL,
60 OP_BLEZL,
61 OP_BGTZL,
62 OP_DADDI,
63 OP_DADDIU,
64 OP_LDL,
65 OP_LDR,
66 __OP_RESERVED_28,
67 __OP_RESERVED_29,
68 __OP_RESERVED_30,
69 __OP_RESERVED_31,
70 OP_LB,
71 OP_LH,
72 OP_LWL,
73 OP_LW,
74 OP_LBU,
75 OP_LHU,
76 OP_LWR,
77 OP_LWU,
78 OP_SB,
79 OP_SH,
80 OP_SWL,
81 OP_SW,
82 OP_SDL,
83 OP_SDR,
84 OP_SWR,
85 OP_CACHE,
86 OP_LL,
87 OP_LWC1,
88 OP_LWC2,
89 __OP_RESERVED_51,
90 OP_LLD,
91 OP_LDC1,
92 OP_LDC2,
93 OP_LD,
94 OP_SC,
95 OP_SWC1,
96 OP_SWC2,
97 __OP_RESERVED_59,
98 OP_SCD,
99 OP_SDC1,
100 OP_SDC2,
101 OP_SD,
102} vr4300_op_t;
103
104typedef enum {
105 FUNCT_SSL,
106 __FUNCT_RESERVED_1,
107 FUNCT_SRL,
108 FUNCT_SRA,
109 FUNCT_SLLV,
110 __FUNCT_RESERVED_5,
111 FUNCT_SRLV,
112 FUNCT_SRAV,
113 FUNCT_JR,
114 FUNCT_JALR,
115 __FUNCT_RESERVED_10,
116 __FUNCT_RESERVED_11,
117 FUNCT_SYSCALL,
118 FUNCT_BREAK,
119 __FUNCT_RESERVED_14,
120 FUNCT_SYNC,
121 FUNCT_MFHI,
122 FUNCT_MTHI,
123 FUNCT_MFLO,
124 FUNCT_MTLO,
125 FUNCT_DSLLV,
126 __FUNCT_RESERVED_21,
127 FUNCT_DSRLV,
128 FUNCT_DSRAV,
129 FUNCT_MULT,
130 FUNCT_MULTU,
131 FUNCT_DIV,
132 FUNCT_DIVU,
133 FUNCT_DMULT,
134 FUNCT_DMULTU,
135 FUNCT_DDIV,
136 FUNCT_DDIVU,
137 FUNCT_ADD,
138 FUNCT_ADDU,
139 FUNCT_SUB,
140 FUNCT_SUBU,
141 FUNCT_AND,
142 FUNCT_OR,
143 FUNCT_XOR,
144 FUNCT_NOR,
145 __FUNCT_RESERVED_40,
146 __FUNCT_RESERVED_41,
147 FUNCT_SLT,
148 FUNCT_SLTU,
149 FUNCT_DADD,
150 FUNCT_DADDU,
151 FUNCT_DSUB,
152 FUNCT_DSUBU,
153 FUNCT_TGE,
154 FUNCT_TGEU,
155 FUNCT_TLT,
156 FUNCT_TLTU,
157 FUNCT_TEQ,
158 __FUNCT_RESERVED_53,
159 FUNCT_TNE,
160 __FUNCT_RESERVED_55,
161 FUNCT_DSLL,
162 __FUNCT_RESERVED_57,
163 FUNCT_DSRL,
164 FUNCT_DSRA,
165 FUNCT_DSLL32,
166 __FUNCT_RESERVED_61,
167 FUNCT_DSRL32,
168 FUNCT_DSRA32,
169} vr4300_funct_t;
170
171typedef enum {
172 REGIMM_BLTZ,
173 REGIMM_BGEZ,
174 REGIMM_BLTZL,
175 REGIMM_BGEZL,
176 __REGIMM_RESERVED_4,
177 __REGIMM_RESERVED_5,
178 __REGIMM_RESERVED_6,
179 __REGIMM_RESERVED_7,
180 REGIMM_TGEI,
181 REGIMM_TGEIU,
182 REGIMM_TLTI,
183 REGIMM_TLTIU,
184 REGIMM_TEQI,
185 __REGIMM_RESERVED_13,
186 REGIMM_TNEI,
187 __REGIMM_RESERVED_15,
188 REGIMM_BLTZAL,
189 REGIMM_BGEZAL,
190 REGIMM_BLTZALL,
191 REGIMM_BGEZALL,
192 __REGIMM_RESERVED_20,
193 __REGIMM_RESERVED_21,
194 __REGIMM_RESERVED_22,
195 __REGIMM_RESERVED_23,
196 __REGIMM_RESERVED_24,
197 __REGIMM_RESERVED_25,
198 __REGIMM_RESERVED_26,
199 __REGIMM_RESERVED_27,
200 __REGIMM_RESERVED_28,
201 __REGIMM_RESERVED_29,
202 __REGIMM_RESERVED_30,
203 __REGIMM_RESERVED_31,
204} vr4300_regimm_t;
205
206typedef enum {
207 REG_ZERO,
208 REG_AT,
209 REG_V0,
210 REG_V1,
211 REG_A0,
212 REG_A1,
213 REG_A2,
214 REG_A3,
215 REG_T0,
216 REG_T1,
217 REG_T2,
218 REG_T3,
219 REG_T4,
220 REG_T5,
221 REG_T6,
222 REG_T7,
223 REG_S0,
224 REG_S1,
225 REG_S2,
226 REG_S3,
227 REG_S4,
228 REG_S5,
229 REG_S6,
230 REG_S7,
231 REG_T8,
232 REG_T9,
233 REG_K0,
234 REG_K1,
235 REG_GP,
236 REG_SP,
237 REG_FP,
238 REG_RA,
239} vr4300_reg_t;
240
241typedef enum {
242 C0_REG_INDEX,
243 C0_REG_RANDOM,
244 C0_REG_ENTRY_LO_0,
245 C0_REG_ENTRY_LO_1,
246 C0_REG_CONTEXT,
247 C0_REG_PAGE_MASK,
248 C0_REG_WIRED,
249 __C0_REG_RESERVED_7,
250 C0_REG_BAD_V_ADDR,
251 C0_REG_COUNT,
252 C0_REG_ENTRY_HI,
253 C0_REG_COMPARE,
254 C0_REG_STATUS,
255 C0_REG_CAUSE,
256 C0_REG_EPC,
257 C0_REG_PR_ID,
258 C0_REG_CONFIG,
259 C0_REG_LL_ADDR,
260 C0_REG_WATCH_LO,
261 C0_REG_WATCH_HI,
262 C0_REG_X_CONTEXT,
263 __C0_REG_RESERVED_21,
264 __C0_REG_RESERVED_22,
265 __C0_REG_RESERVED_23,
266 __C0_REG_RESERVED_24,
267 __C0_REG_RESERVED_25,
268 C0_REG_PARITY_ERROR,
269 C0_REG_CACHE_ERROR,
270 C0_REG_TAG_LO,
271 C0_REG_TAG_HI,
272 C0_REG_ERROR_EPC,
273 __C0_REG_RESERVED_31,
274} vr4300_c0_reg_t;
275
276typedef enum {
277 COPZ_RS_MF,
278 COPZ_RS_DMF,
279 COPZ_RS_CF,
280 __COPZ_RS_RESERVED_3,
281 COPZ_RS_MT,
282 COPZ_RS_DMT,
283 COPZ_RS_CT,
284 __COPZ_RS_RESERVED_7,
285 COPZ_RS_BC,
286 __COPZ_RS_RESERVED_9,
287 __COPZ_RS_RESERVED_10,
288 __COPZ_RS_RESERVED_11,
289 __COPZ_RS_RESERVED_12,
290 __COPZ_RS_RESERVED_13,
291 __COPZ_RS_RESERVED_14,
292 __COPZ_RS_RESERVED_15,
293} vr4300_copz_rs_t;
294
295typedef enum {
296 __C0_FUNCT_RESERVED_0,
297 C0_FUNCT_TLBR,
298 C0_FUNCT_TLBWI,
299 __C0_FUNCT_RESERVED_3,
300 __C0_FUNCT_RESERVED_4,
301 __C0_FUNCT_RESERVED_5,
302 C0_FUNCT_TLBWR,
303 __C0_FUNCT_RESERVED_7,
304 C0_FUNCT_TLBP,
305 __C0_FUNCT_RESERVED_9,
306 __C0_FUNCT_RESERVED_10,
307 __C0_FUNCT_RESERVED_11,
308 __C0_FUNCT_RESERVED_12,
309 __C0_FUNCT_RESERVED_13,
310 __C0_FUNCT_RESERVED_14,
311 __C0_FUNCT_RESERVED_15,
312 __C0_FUNCT_RESERVED_16,
313 __C0_FUNCT_RESERVED_17,
314 __C0_FUNCT_RESERVED_18,
315 __C0_FUNCT_RESERVED_19,
316 __C0_FUNCT_RESERVED_20,
317 __C0_FUNCT_RESERVED_21,
318 __C0_FUNCT_RESERVED_22,
319 __C0_FUNCT_RESERVED_23,
320 C0_FUNCT_ERET,
321 __C0_FUNCT_RESERVED_25,
322 __C0_FUNCT_RESERVED_26,
323 __C0_FUNCT_RESERVED_27,
324 __C0_FUNCT_RESERVED_28,
325 __C0_FUNCT_RESERVED_29,
326 __C0_FUNCT_RESERVED_30,
327 __C0_FUNCT_RESERVED_31,
328 __C0_FUNCT_RESERVED_32,
329 __C0_FUNCT_RESERVED_33,
330 __C0_FUNCT_RESERVED_34,
331 __C0_FUNCT_RESERVED_35,
332 __C0_FUNCT_RESERVED_36,
333 __C0_FUNCT_RESERVED_37,
334 __C0_FUNCT_RESERVED_38,
335 __C0_FUNCT_RESERVED_39,
336 __C0_FUNCT_RESERVED_40,
337 __C0_FUNCT_RESERVED_41,
338 __C0_FUNCT_RESERVED_42,
339 __C0_FUNCT_RESERVED_43,
340 __C0_FUNCT_RESERVED_44,
341 __C0_FUNCT_RESERVED_45,
342 __C0_FUNCT_RESERVED_46,
343 __C0_FUNCT_RESERVED_47,
344 __C0_FUNCT_RESERVED_48,
345 __C0_FUNCT_RESERVED_49,
346 __C0_FUNCT_RESERVED_50,
347 __C0_FUNCT_RESERVED_51,
348 __C0_FUNCT_RESERVED_52,
349 __C0_FUNCT_RESERVED_53,
350 __C0_FUNCT_RESERVED_54,
351 __C0_FUNCT_RESERVED_55,
352 __C0_FUNCT_RESERVED_56,
353 __C0_FUNCT_RESERVED_57,
354 __C0_FUNCT_RESERVED_58,
355 __C0_FUNCT_RESERVED_59,
356 __C0_FUNCT_RESERVED_60,
357 __C0_FUNCT_RESERVED_61,
358 __C0_FUNCT_RESERVED_62,
359 __C0_FUNCT_RESERVED_63,
360} vr4300_c0_funct;
361
362#define __ASM_I_INST(o, s, t, i) \
363 (((vr4300_instruction_t){.i_type = {.op = (o), .rs = (s), .rt = (t), .imm = (i)&0xFFFF}}).raw)
364#define __ASM_J_INST(o, t) (((vr4300_instruction_t){.j_type = {.op = (o), .target = (t)&0x3FFFFFF}}).raw)
365#define __ASM_R_INST(o, s, t, d, a, f) \
366 (((vr4300_instruction_t){.r_type = {.op = (o), .rs = (s), .rt = (t), .rd = (d), .sa = (a), .funct = (f)}}).raw)
367#define __ASM_C_INST(o, c, f) (((vr4300_instruction_t){.c_type = {.op = (o), .co = (c), .funct = (f)}}).raw)
368
369#define A_OFFSET(a) ((int16_t)((a)&0xFFFF))
370#define A_BASE(a) ((uint16_t)((((a) >> 16) & 0xFFFF) + (A_OFFSET(a) < 0 ? 1 : 0)))
371
372#define I_ADDIU(rt, rs, immediate) __ASM_I_INST(OP_ADDIU, rs, rt, immediate)
373#define I_AND(rd, rs, rt) __ASM_R_INST(OP_SPECIAL, rs, rt, rd, 0, FUNCT_AND)
374#define I_ANDI(rt, rs, immediate) __ASM_I_INST(OP_ANDI, rs, rt, immediate)
375#define I_BEQ(rs, rt, offset) __ASM_I_INST(OP_BEQ, rs, rt, offset)
376#define I_BGTZ(rs, offset) __ASM_I_INST(OP_BGTZ, rs, 0, offset)
377#define I_BNE(rs, rt, offset) __ASM_I_INST(OP_BNE, rs, rt, offset)
378#define I_BNEL(rs, rt, offset) __ASM_I_INST(OP_BNEL, rs, rt, offset)
379#define I_CACHE(op, offset, base) __ASM_I_INST(OP_CACHE, base, op, offset)
380#define I_ERET() __ASM_C_INST(OP_COP0, 1, C0_FUNCT_ERET)
381#define I_J(target) __ASM_J_INST(OP_J, (target >> 2))
382#define I_JR(rs) __ASM_R_INST(OP_SPECIAL, rs, REG_ZERO, REG_ZERO, 0, FUNCT_JR)
383#define I_LBU(rt, offset, base) __ASM_I_INST(OP_LBU, base, rt, offset)
384#define I_LHU(rt, offset, base) __ASM_I_INST(OP_LHU, base, rt, offset)
385#define I_LUI(rt, immediate) __ASM_I_INST(OP_LUI, 0, rt, immediate)
386#define I_LW(rt, offset, base) __ASM_I_INST(OP_LW, base, rt, offset)
387#define I_MFC0(rt, rd) __ASM_R_INST(OP_COP0, COPZ_RS_MF, rt, rd, 0, 0)
388#define I_MTC0(rt, rd) __ASM_R_INST(OP_COP0, COPZ_RS_MT, rt, rd, 0, 0)
389#define I_NOP() __ASM_R_INST(OP_SPECIAL, REG_ZERO, REG_ZERO, REG_ZERO, 0, FUNCT_SSL)
390#define I_OR(rd, rs, rt) __ASM_R_INST(OP_SPECIAL, rs, rt, rd, 0, FUNCT_OR)
391#define I_ORI(rt, rs, immediate) __ASM_I_INST(OP_ORI, rs, rt, immediate)
392#define I_SB(rt, offset, base) __ASM_I_INST(OP_SB, base, rt, offset)
393#define I_SH(rt, offset, base) __ASM_I_INST(OP_SH, base, rt, offset)
394#define I_SRL(rd, rt, sa) __ASM_R_INST(OP_SPECIAL, 0, rt, rd, sa, FUNCT_SRL)
395#define I_SW(rt, offset, base) __ASM_I_INST(OP_SW, base, rt, offset)
396
397#endif
Definition: vr4300_asm.h:6