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 #include "blockcache.h"
17 #include "disassembler.h"
19 #include "optimizer.h"
22 #include <lightning.h>
26 typedef void (*lightrec_rec_func_t)(const struct block *,
27 const struct opcode *, u32);
29 /* Forward declarations */
30 static void rec_SPECIAL(const struct block *block,
31 const struct opcode *op, u32 pc);
32 static void rec_REGIMM(const struct block *block,
33 const struct opcode *op, u32 pc);
34 static void rec_CP0(const struct block *block, const struct opcode *op, u32 pc);
35 static void rec_CP2(const struct block *block, const struct opcode *op, u32 pc);
38 static void unknown_opcode(const struct block *block,
39 const struct opcode *op, u32 pc)
41 pr_warn("Unknown opcode: 0x%08x at PC 0x%08x\n", op->opcode, pc);
44 static void lightrec_emit_end_of_block(const struct block *block,
45 const struct opcode *op, u32 pc,
46 s8 reg_new_pc, u32 imm, u8 ra_reg,
47 u32 link, bool update_cycles)
49 struct lightrec_state *state = block->state;
50 struct regcache *reg_cache = state->reg_cache;
51 u32 cycles = state->cycles;
52 jit_state_t *_jit = block->_jit;
54 jit_note(__FILE__, __LINE__);
57 /* Update the $ra register */
58 u8 link_reg = lightrec_alloc_reg_out(reg_cache, _jit, ra_reg);
59 jit_movi(link_reg, link);
60 lightrec_free_reg(reg_cache, link_reg);
64 reg_new_pc = lightrec_alloc_reg(reg_cache, _jit, JIT_V0);
65 lightrec_lock_reg(reg_cache, _jit, reg_new_pc);
67 jit_movi(reg_new_pc, imm);
70 if (has_delay_slot(op->c) &&
71 !(op->flags & (LIGHTREC_NO_DS | LIGHTREC_LOCAL_BRANCH))) {
72 cycles += lightrec_cycles_of_opcode(op->next->c);
74 /* Recompile the delay slot */
75 if (op->next->c.opcode)
76 lightrec_rec_opcode(block, op->next, pc + 4);
79 /* Store back remaining registers */
80 lightrec_storeback_regs(reg_cache, _jit);
82 jit_movr(JIT_V0, reg_new_pc);
84 if (cycles && update_cycles) {
85 jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE, cycles);
86 pr_debug("EOB: %u cycles\n", cycles);
89 if (op->next && ((op->flags & LIGHTREC_NO_DS) || op->next->next))
90 state->branches[state->nb_branches++] = jit_jmpi();
93 void lightrec_emit_eob(const struct block *block,
94 const struct opcode *op, u32 pc)
96 struct lightrec_state *state = block->state;
97 struct regcache *reg_cache = state->reg_cache;
98 jit_state_t *_jit = block->_jit;
100 lightrec_storeback_regs(reg_cache, _jit);
102 jit_movi(JIT_V0, pc);
103 jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE,
104 state->cycles - lightrec_cycles_of_opcode(op->c));
106 state->branches[state->nb_branches++] = jit_jmpi();
109 static void rec_special_JR(const struct block *block,
110 const struct opcode *op, u32 pc)
112 struct regcache *reg_cache = block->state->reg_cache;
113 jit_state_t *_jit = block->_jit;
114 u8 rs = lightrec_request_reg_in(reg_cache, _jit, op->r.rs, JIT_V0);
116 _jit_name(block->_jit, __func__);
117 lightrec_lock_reg(reg_cache, _jit, rs);
118 lightrec_emit_end_of_block(block, op, pc, rs, 0, 31, 0, true);
121 static void rec_special_JALR(const struct block *block,
122 const struct opcode *op, u32 pc)
124 struct regcache *reg_cache = block->state->reg_cache;
125 jit_state_t *_jit = block->_jit;
126 u8 rs = lightrec_request_reg_in(reg_cache, _jit, op->r.rs, JIT_V0);
128 _jit_name(block->_jit, __func__);
129 lightrec_lock_reg(reg_cache, _jit, rs);
130 lightrec_emit_end_of_block(block, op, pc, rs, 0, op->r.rd, pc + 8, true);
133 static void rec_J(const struct block *block, const struct opcode *op, u32 pc)
135 _jit_name(block->_jit, __func__);
136 lightrec_emit_end_of_block(block, op, pc, -1,
137 (pc & 0xf0000000) | (op->j.imm << 2), 31, 0, true);
140 static void rec_JAL(const struct block *block, const struct opcode *op, u32 pc)
142 _jit_name(block->_jit, __func__);
143 lightrec_emit_end_of_block(block, op, pc, -1,
144 (pc & 0xf0000000) | (op->j.imm << 2),
148 static void rec_b(const struct block *block, const struct opcode *op, u32 pc,
149 jit_code_t code, u32 link, bool unconditional, bool bz)
151 struct regcache *reg_cache = block->state->reg_cache;
152 struct native_register *regs_backup;
153 jit_state_t *_jit = block->_jit;
154 struct lightrec_branch *branch;
157 u32 offset, cycles = block->state->cycles;
158 bool is_forward = (s16)op->i.imm >= -1;
160 jit_note(__FILE__, __LINE__);
162 if (!(op->flags & LIGHTREC_NO_DS))
163 cycles += lightrec_cycles_of_opcode(op->next->c);
165 block->state->cycles = 0;
168 jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE, cycles);
170 if (!unconditional) {
171 u8 rs = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->i.rs),
172 rt = bz ? 0 : lightrec_alloc_reg_in_ext(reg_cache,
175 /* Generate the branch opcode */
176 addr = jit_new_node_pww(code, NULL, rs, rt);
178 lightrec_free_regs(reg_cache);
179 regs_backup = lightrec_regcache_enter_branch(reg_cache);
182 if (op->flags & LIGHTREC_LOCAL_BRANCH) {
183 if (op->next && !(op->flags & LIGHTREC_NO_DS)) {
184 /* Recompile the delay slot */
185 if (op->next->opcode)
186 lightrec_rec_opcode(block, op->next, pc + 4);
190 /* Update the $ra register */
191 link_reg = lightrec_alloc_reg_out(reg_cache, _jit, 31);
192 jit_movi(link_reg, link);
193 lightrec_free_reg(reg_cache, link_reg);
196 /* Store back remaining registers */
197 lightrec_storeback_regs(reg_cache, _jit);
199 offset = op->offset + 1 + (s16)op->i.imm;
200 pr_debug("Adding local branch to offset 0x%x\n", offset << 2);
201 branch = &block->state->local_branches[
202 block->state->nb_local_branches++];
204 branch->target = offset;
206 branch->branch = jit_jmpi();
208 branch->branch = jit_bgti(LIGHTREC_REG_CYCLE, 0);
211 if (!(op->flags & LIGHTREC_LOCAL_BRANCH) || !is_forward) {
212 lightrec_emit_end_of_block(block, op, pc, -1,
213 pc + 4 + ((s16)op->i.imm << 2),
217 if (!unconditional) {
219 lightrec_regcache_leave_branch(reg_cache, regs_backup);
222 /* Update the $ra register */
223 link_reg = lightrec_alloc_reg_out_ext(reg_cache,
225 jit_movi(link_reg, (s32)link);
226 lightrec_free_reg(reg_cache, link_reg);
229 if (!(op->flags & LIGHTREC_NO_DS) && op->next->opcode)
230 lightrec_rec_opcode(block, op->next, pc + 4);
234 static void rec_BNE(const struct block *block, const struct opcode *op, u32 pc)
236 _jit_name(block->_jit, __func__);
237 rec_b(block, op, pc, jit_code_beqr, 0, false, false);
240 static void rec_BEQ(const struct block *block, const struct opcode *op, u32 pc)
242 _jit_name(block->_jit, __func__);
243 rec_b(block, op, pc, jit_code_bner, 0,
244 op->i.rs == op->i.rt, false);
247 static void rec_BLEZ(const struct block *block, const struct opcode *op, u32 pc)
249 _jit_name(block->_jit, __func__);
250 rec_b(block, op, pc, jit_code_bgti, 0, op->i.rs == 0, true);
253 static void rec_BGTZ(const struct block *block, const struct opcode *op, u32 pc)
255 _jit_name(block->_jit, __func__);
256 rec_b(block, op, pc, jit_code_blei, 0, false, true);
259 static void rec_regimm_BLTZ(const struct block *block,
260 const struct opcode *op, u32 pc)
262 _jit_name(block->_jit, __func__);
263 rec_b(block, op, pc, jit_code_bgei, 0, false, true);
266 static void rec_regimm_BLTZAL(const struct block *block,
267 const struct opcode *op, u32 pc)
269 _jit_name(block->_jit, __func__);
270 rec_b(block, op, pc, jit_code_bgei, pc + 8, false, true);
273 static void rec_regimm_BGEZ(const struct block *block,
274 const struct opcode *op, u32 pc)
276 _jit_name(block->_jit, __func__);
277 rec_b(block, op, pc, jit_code_blti, 0, !op->i.rs, true);
280 static void rec_regimm_BGEZAL(const struct block *block,
281 const struct opcode *op, u32 pc)
283 _jit_name(block->_jit, __func__);
284 rec_b(block, op, pc, jit_code_blti, pc + 8, !op->i.rs, true);
287 static void rec_alu_imm(const struct block *block, const struct opcode *op,
288 jit_code_t code, bool sign_extend)
290 struct regcache *reg_cache = block->state->reg_cache;
291 jit_state_t *_jit = block->_jit;
294 jit_note(__FILE__, __LINE__);
295 rs = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->i.rs);
296 rt = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->i.rt);
299 jit_new_node_www(code, rt, rs, (s32)(s16) op->i.imm);
301 jit_new_node_www(code, rt, rs, (u32)(u16) op->i.imm);
303 lightrec_free_reg(reg_cache, rs);
304 lightrec_free_reg(reg_cache, rt);
307 static void rec_alu_special(const struct block *block, const struct opcode *op,
308 jit_code_t code, bool out_ext)
310 struct regcache *reg_cache = block->state->reg_cache;
311 jit_state_t *_jit = block->_jit;
314 jit_note(__FILE__, __LINE__);
315 rs = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rs);
316 rt = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rt);
319 rd = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->r.rd);
321 rd = lightrec_alloc_reg_out(reg_cache, _jit, op->r.rd);
323 jit_new_node_www(code, rd, rs, rt);
325 lightrec_free_reg(reg_cache, rs);
326 lightrec_free_reg(reg_cache, rt);
327 lightrec_free_reg(reg_cache, rd);
330 static void rec_alu_shiftv(const struct block *block,
331 const struct opcode *op, jit_code_t code)
333 struct regcache *reg_cache = block->state->reg_cache;
334 jit_state_t *_jit = block->_jit;
337 jit_note(__FILE__, __LINE__);
338 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rs);
339 temp = lightrec_alloc_reg_temp(reg_cache, _jit);
341 if (code == jit_code_rshr) {
342 rt = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rt);
343 rd = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->r.rd);
345 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rt);
346 rd = lightrec_alloc_reg_out(reg_cache, _jit, op->r.rd);
349 jit_andi(temp, rs, 0x1f);
352 if (code == jit_code_rshr_u) {
354 jit_new_node_www(code, rd, rd, temp);
358 if (__WORDSIZE == 32 || code != jit_code_rshr_u)
359 jit_new_node_www(code, rd, rt, temp);
361 lightrec_free_reg(reg_cache, rs);
362 lightrec_free_reg(reg_cache, temp);
363 lightrec_free_reg(reg_cache, rt);
364 lightrec_free_reg(reg_cache, rd);
367 static void rec_ADDIU(const struct block *block,
368 const struct opcode *op, u32 pc)
370 _jit_name(block->_jit, __func__);
371 rec_alu_imm(block, op, jit_code_addi, true);
374 static void rec_ADDI(const struct block *block, const struct opcode *op, u32 pc)
376 /* TODO: Handle the exception? */
377 _jit_name(block->_jit, __func__);
378 rec_alu_imm(block, op, jit_code_addi, true);
381 static void rec_SLTIU(const struct block *block,
382 const struct opcode *op, u32 pc)
384 _jit_name(block->_jit, __func__);
385 rec_alu_imm(block, op, jit_code_lti_u, true);
388 static void rec_SLTI(const struct block *block, const struct opcode *op, u32 pc)
390 _jit_name(block->_jit, __func__);
391 rec_alu_imm(block, op, jit_code_lti, true);
394 static void rec_ANDI(const struct block *block, const struct opcode *op, u32 pc)
396 struct regcache *reg_cache = block->state->reg_cache;
397 jit_state_t *_jit = block->_jit;
400 _jit_name(block->_jit, __func__);
401 jit_note(__FILE__, __LINE__);
402 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rs);
403 rt = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->i.rt);
405 /* PSX code uses ANDI 0xff / ANDI 0xffff a lot, which are basically
406 * casts to uint8_t / uint16_t. */
407 if (op->i.imm == 0xff)
409 else if (op->i.imm == 0xffff)
412 jit_andi(rt, rs, (u32)(u16) op->i.imm);
414 lightrec_free_reg(reg_cache, rs);
415 lightrec_free_reg(reg_cache, rt);
418 static void rec_ORI(const struct block *block, const struct opcode *op, u32 pc)
420 _jit_name(block->_jit, __func__);
421 rec_alu_imm(block, op, jit_code_ori, false);
424 static void rec_XORI(const struct block *block, const struct opcode *op, u32 pc)
426 _jit_name(block->_jit, __func__);
427 rec_alu_imm(block, op, jit_code_xori, false);
430 static void rec_LUI(const struct block *block, const struct opcode *op, u32 pc)
432 struct regcache *reg_cache = block->state->reg_cache;
433 jit_state_t *_jit = block->_jit;
437 jit_note(__FILE__, __LINE__);
438 rt = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->i.rt);
440 jit_movi(rt, (s32)(op->i.imm << 16));
442 lightrec_free_reg(reg_cache, rt);
445 static void rec_special_ADDU(const struct block *block,
446 const struct opcode *op, u32 pc)
448 _jit_name(block->_jit, __func__);
449 rec_alu_special(block, op, jit_code_addr, false);
452 static void rec_special_ADD(const struct block *block,
453 const struct opcode *op, u32 pc)
455 /* TODO: Handle the exception? */
456 _jit_name(block->_jit, __func__);
457 rec_alu_special(block, op, jit_code_addr, false);
460 static void rec_special_SUBU(const struct block *block,
461 const struct opcode *op, u32 pc)
463 _jit_name(block->_jit, __func__);
464 rec_alu_special(block, op, jit_code_subr, false);
467 static void rec_special_SUB(const struct block *block,
468 const struct opcode *op, u32 pc)
470 /* TODO: Handle the exception? */
471 _jit_name(block->_jit, __func__);
472 rec_alu_special(block, op, jit_code_subr, false);
475 static void rec_special_AND(const struct block *block,
476 const struct opcode *op, u32 pc)
478 _jit_name(block->_jit, __func__);
479 rec_alu_special(block, op, jit_code_andr, false);
482 static void rec_special_OR(const struct block *block,
483 const struct opcode *op, u32 pc)
485 _jit_name(block->_jit, __func__);
486 rec_alu_special(block, op, jit_code_orr, false);
489 static void rec_special_XOR(const struct block *block,
490 const struct opcode *op, u32 pc)
492 _jit_name(block->_jit, __func__);
493 rec_alu_special(block, op, jit_code_xorr, false);
496 static void rec_special_NOR(const struct block *block,
497 const struct opcode *op, u32 pc)
499 struct regcache *reg_cache = block->state->reg_cache;
500 jit_state_t *_jit = block->_jit;
504 rec_alu_special(block, op, jit_code_orr, false);
505 rd = lightrec_alloc_reg_out(reg_cache, _jit, op->r.rd);
509 lightrec_free_reg(reg_cache, rd);
512 static void rec_special_SLTU(const struct block *block,
513 const struct opcode *op, u32 pc)
515 _jit_name(block->_jit, __func__);
516 rec_alu_special(block, op, jit_code_ltr_u, true);
519 static void rec_special_SLT(const struct block *block,
520 const struct opcode *op, u32 pc)
522 _jit_name(block->_jit, __func__);
523 rec_alu_special(block, op, jit_code_ltr, true);
526 static void rec_special_SLLV(const struct block *block,
527 const struct opcode *op, u32 pc)
529 _jit_name(block->_jit, __func__);
530 rec_alu_shiftv(block, op, jit_code_lshr);
533 static void rec_special_SRLV(const struct block *block,
534 const struct opcode *op, u32 pc)
536 _jit_name(block->_jit, __func__);
537 rec_alu_shiftv(block, op, jit_code_rshr_u);
540 static void rec_special_SRAV(const struct block *block,
541 const struct opcode *op, u32 pc)
543 _jit_name(block->_jit, __func__);
544 rec_alu_shiftv(block, op, jit_code_rshr);
547 static void rec_alu_shift(const struct block *block,
548 const struct opcode *op, jit_code_t code)
550 struct regcache *reg_cache = block->state->reg_cache;
551 jit_state_t *_jit = block->_jit;
554 jit_note(__FILE__, __LINE__);
556 if (code == jit_code_rshi) {
557 rt = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rt);
558 rd = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->r.rd);
560 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rt);
561 rd = lightrec_alloc_reg_out(reg_cache, _jit, op->r.rd);
565 if (code == jit_code_rshi_u) {
567 jit_new_node_www(code, rd, rd, op->r.imm);
570 if (__WORDSIZE == 32 || code != jit_code_rshi_u)
571 jit_new_node_www(code, rd, rt, op->r.imm);
573 lightrec_free_reg(reg_cache, rt);
574 lightrec_free_reg(reg_cache, rd);
577 static void rec_special_SLL(const struct block *block,
578 const struct opcode *op, u32 pc)
580 _jit_name(block->_jit, __func__);
581 rec_alu_shift(block, op, jit_code_lshi);
584 static void rec_special_SRL(const struct block *block,
585 const struct opcode *op, u32 pc)
587 _jit_name(block->_jit, __func__);
588 rec_alu_shift(block, op, jit_code_rshi_u);
591 static void rec_special_SRA(const struct block *block,
592 const struct opcode *op, u32 pc)
594 _jit_name(block->_jit, __func__);
595 rec_alu_shift(block, op, jit_code_rshi);
598 static void rec_alu_mult(const struct block *block,
599 const struct opcode *op, bool is_signed)
601 struct regcache *reg_cache = block->state->reg_cache;
602 jit_state_t *_jit = block->_jit;
605 jit_note(__FILE__, __LINE__);
607 lo = lightrec_alloc_reg_out(reg_cache, _jit, REG_LO);
608 if (!(op->flags & LIGHTREC_MULT32))
609 hi = lightrec_alloc_reg_out_ext(reg_cache, _jit, REG_HI);
610 else if (__WORDSIZE == 64)
611 hi = lightrec_alloc_reg_temp(reg_cache, _jit);
613 if (__WORDSIZE == 32 || !is_signed) {
614 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rs);
615 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rt);
617 rs = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rs);
618 rt = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rt);
622 /* On 32-bit systems, do a 32*32->64 bit operation, or a 32*32->32 bit
623 * operation if the MULT was detected a 32-bit only. */
624 if (!(op->flags & LIGHTREC_MULT32)) {
626 jit_qmulr(lo, hi, rs, rt);
628 jit_qmulr_u(lo, hi, rs, rt);
630 jit_mulr(lo, rs, rt);
633 /* On 64-bit systems, do a 64*64->64 bit operation.
634 * The input registers must be 32 bits, so we first sign-extend (if
635 * mult) or clear (if multu) the input registers. */
637 jit_mulr(lo, rs, rt);
641 jit_mulr(lo, hi, lo);
644 /* The 64-bit output value is in $lo, store the upper 32 bits in $hi */
645 if (!(op->flags & LIGHTREC_MULT32))
646 jit_rshi(hi, lo, 32);
649 lightrec_free_reg(reg_cache, rs);
650 lightrec_free_reg(reg_cache, rt);
651 lightrec_free_reg(reg_cache, lo);
652 if (__WORDSIZE == 64 || !(op->flags & LIGHTREC_MULT32))
653 lightrec_free_reg(reg_cache, hi);
656 static void rec_alu_div(const struct block *block,
657 const struct opcode *op, bool is_signed)
659 struct regcache *reg_cache = block->state->reg_cache;
660 jit_state_t *_jit = block->_jit;
661 jit_node_t *branch, *to_end;
664 jit_note(__FILE__, __LINE__);
665 lo = lightrec_alloc_reg_out(reg_cache, _jit, REG_LO);
666 hi = lightrec_alloc_reg_out(reg_cache, _jit, REG_HI);
668 if (__WORDSIZE == 32 || !is_signed) {
669 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rs);
670 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->r.rt);
672 rs = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rs);
673 rt = lightrec_alloc_reg_in_ext(reg_cache, _jit, op->r.rt);
676 /* Jump to special handler if dividing by zero */
677 branch = jit_beqi(rt, 0);
681 jit_qdivr(lo, hi, rs, rt);
683 jit_qdivr_u(lo, hi, rs, rt);
685 /* On 64-bit systems, the input registers must be 32 bits, so we first sign-extend
686 * (if div) or clear (if divu) the input registers. */
688 jit_qdivr(lo, hi, rs, rt);
692 jit_qdivr_u(lo, hi, hi, lo);
696 /* Jump above the div-by-zero handler */
706 jit_movi(lo, 0xffffffff);
713 lightrec_free_reg(reg_cache, rs);
714 lightrec_free_reg(reg_cache, rt);
715 lightrec_free_reg(reg_cache, lo);
716 lightrec_free_reg(reg_cache, hi);
719 static void rec_special_MULT(const struct block *block,
720 const struct opcode *op, u32 pc)
722 _jit_name(block->_jit, __func__);
723 rec_alu_mult(block, op, true);
726 static void rec_special_MULTU(const struct block *block,
727 const struct opcode *op, u32 pc)
729 _jit_name(block->_jit, __func__);
730 rec_alu_mult(block, op, false);
733 static void rec_special_DIV(const struct block *block,
734 const struct opcode *op, u32 pc)
736 _jit_name(block->_jit, __func__);
737 rec_alu_div(block, op, true);
740 static void rec_special_DIVU(const struct block *block,
741 const struct opcode *op, u32 pc)
743 _jit_name(block->_jit, __func__);
744 rec_alu_div(block, op, false);
747 static void rec_alu_mv_lo_hi(const struct block *block, u8 dst, u8 src)
749 struct regcache *reg_cache = block->state->reg_cache;
750 jit_state_t *_jit = block->_jit;
752 jit_note(__FILE__, __LINE__);
753 src = lightrec_alloc_reg_in(reg_cache, _jit, src);
754 dst = lightrec_alloc_reg_out_ext(reg_cache, _jit, dst);
759 jit_extr_i(dst, src);
762 lightrec_free_reg(reg_cache, src);
763 lightrec_free_reg(reg_cache, dst);
766 static void rec_special_MFHI(const struct block *block,
767 const struct opcode *op, u32 pc)
769 _jit_name(block->_jit, __func__);
770 rec_alu_mv_lo_hi(block, op->r.rd, REG_HI);
773 static void rec_special_MTHI(const struct block *block,
774 const struct opcode *op, u32 pc)
776 _jit_name(block->_jit, __func__);
777 rec_alu_mv_lo_hi(block, REG_HI, op->r.rs);
780 static void rec_special_MFLO(const struct block *block,
781 const struct opcode *op, u32 pc)
783 _jit_name(block->_jit, __func__);
784 rec_alu_mv_lo_hi(block, op->r.rd, REG_LO);
787 static void rec_special_MTLO(const struct block *block,
788 const struct opcode *op, u32 pc)
790 _jit_name(block->_jit, __func__);
791 rec_alu_mv_lo_hi(block, REG_LO, op->r.rs);
794 static void rec_io(const struct block *block, const struct opcode *op,
795 bool load_rt, bool read_rt)
797 struct regcache *reg_cache = block->state->reg_cache;
798 jit_state_t *_jit = block->_jit;
799 bool is_tagged = op->flags & (LIGHTREC_HW_IO | LIGHTREC_DIRECT_IO);
803 jit_note(__FILE__, __LINE__);
805 tmp = lightrec_alloc_reg(reg_cache, _jit, JIT_R0);
808 offset = offsetof(struct lightrec_state, rw_func);
810 tmp3 = lightrec_alloc_reg(reg_cache, _jit, JIT_R1);
811 offset = offsetof(struct lightrec_state, rw_generic_func);
814 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
815 jit_ldxi(tmp2, LIGHTREC_REG_STATE, offset);
817 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rs, false);
819 if (read_rt && likely(op->i.rt))
820 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rt, true);
822 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rt, false);
825 jit_movi(tmp, op->opcode);
827 jit_movi(tmp, (uintptr_t)op);
828 jit_movi(tmp3, (uintptr_t)block);
833 lightrec_free_reg(reg_cache, tmp);
834 lightrec_free_reg(reg_cache, tmp2);
836 lightrec_free_reg(reg_cache, tmp3);
837 lightrec_regcache_mark_live(reg_cache, _jit);
840 static void rec_store_direct_no_invalidate(const struct block *block,
841 const struct opcode *op,
844 struct lightrec_state *state = block->state;
845 struct regcache *reg_cache = state->reg_cache;
846 jit_state_t *_jit = block->_jit;
847 jit_node_t *to_not_ram, *to_end;
848 u8 tmp, tmp2, rs, rt;
851 jit_note(__FILE__, __LINE__);
852 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rs);
853 tmp = lightrec_alloc_reg_temp(reg_cache, _jit);
854 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
856 /* Convert to KUNSEG and avoid RAM mirrors */
857 if (state->mirrors_mapped) {
858 imm = (s16)op->i.imm;
859 jit_andi(tmp, rs, 0x1f800000 | (4 * RAM_SIZE - 1));
860 } else if (op->i.imm) {
862 jit_addi(tmp, rs, (s16)op->i.imm);
863 jit_andi(tmp, tmp, 0x1f800000 | (RAM_SIZE - 1));
866 jit_andi(tmp, rs, 0x1f800000 | (RAM_SIZE - 1));
869 lightrec_free_reg(reg_cache, rs);
871 if (state->offset_ram != state->offset_scratch) {
872 to_not_ram = jit_bmsi(tmp, BIT(28));
874 jit_movi(tmp2, state->offset_ram);
877 jit_patch(to_not_ram);
879 jit_movi(tmp2, state->offset_scratch);
881 } else if (state->offset_ram) {
882 jit_movi(tmp2, state->offset_ram);
885 if (state->offset_ram || state->offset_scratch)
886 jit_addr(tmp, tmp, tmp2);
888 lightrec_free_reg(reg_cache, tmp2);
890 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rt);
891 jit_new_node_www(code, imm, tmp, rt);
893 lightrec_free_reg(reg_cache, rt);
894 lightrec_free_reg(reg_cache, tmp);
897 static void rec_store_direct(const struct block *block, const struct opcode *op,
900 struct lightrec_state *state = block->state;
901 struct regcache *reg_cache = state->reg_cache;
902 jit_state_t *_jit = block->_jit;
903 jit_node_t *to_not_ram, *to_end = 0;
904 u8 tmp, tmp2, tmp3, rs, rt;
906 jit_note(__FILE__, __LINE__);
908 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rs);
909 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
910 tmp3 = lightrec_alloc_reg_in(reg_cache, _jit, 0);
912 /* Convert to KUNSEG and avoid RAM mirrors */
914 jit_addi(tmp2, rs, (s16)op->i.imm);
915 jit_andi(tmp2, tmp2, 0x1f800000 | (RAM_SIZE - 1));
917 jit_andi(tmp2, rs, 0x1f800000 | (RAM_SIZE - 1));
920 lightrec_free_reg(reg_cache, rs);
921 tmp = lightrec_alloc_reg_temp(reg_cache, _jit);
923 to_not_ram = jit_bgti(tmp2, RAM_SIZE);
925 /* Compute the offset to the code LUT */
926 jit_andi(tmp, tmp2, (RAM_SIZE - 1) & ~3);
928 jit_lshi(tmp, tmp, 1);
930 jit_addr(tmp, LIGHTREC_REG_STATE, tmp);
932 /* Write NULL to the code LUT to invalidate any block that's there */
933 jit_stxi(offsetof(struct lightrec_state, code_lut), tmp, tmp3);
935 if (state->offset_ram != state->offset_scratch) {
936 jit_movi(tmp, state->offset_ram);
941 jit_patch(to_not_ram);
943 if (state->offset_ram || state->offset_scratch)
944 jit_movi(tmp, state->offset_scratch);
946 if (state->offset_ram != state->offset_scratch)
949 if (state->offset_ram || state->offset_scratch)
950 jit_addr(tmp2, tmp2, tmp);
952 lightrec_free_reg(reg_cache, tmp);
953 lightrec_free_reg(reg_cache, tmp3);
955 rt = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rt);
956 jit_new_node_www(code, 0, tmp2, rt);
958 lightrec_free_reg(reg_cache, rt);
959 lightrec_free_reg(reg_cache, tmp2);
962 static void rec_store(const struct block *block, const struct opcode *op,
965 if (op->flags & LIGHTREC_NO_INVALIDATE) {
966 rec_store_direct_no_invalidate(block, op, code);
967 } else if (op->flags & LIGHTREC_DIRECT_IO) {
968 if (block->state->invalidate_from_dma_only)
969 rec_store_direct_no_invalidate(block, op, code);
971 rec_store_direct(block, op, code);
973 rec_io(block, op, true, false);
977 static void rec_SB(const struct block *block, const struct opcode *op, u32 pc)
979 _jit_name(block->_jit, __func__);
980 rec_store(block, op, jit_code_stxi_c);
983 static void rec_SH(const struct block *block, const struct opcode *op, u32 pc)
985 _jit_name(block->_jit, __func__);
986 rec_store(block, op, jit_code_stxi_s);
989 static void rec_SW(const struct block *block, const struct opcode *op, u32 pc)
991 _jit_name(block->_jit, __func__);
992 rec_store(block, op, jit_code_stxi_i);
995 static void rec_SWL(const struct block *block, const struct opcode *op, u32 pc)
997 _jit_name(block->_jit, __func__);
998 rec_io(block, op, true, false);
1001 static void rec_SWR(const struct block *block, const struct opcode *op, u32 pc)
1003 _jit_name(block->_jit, __func__);
1004 rec_io(block, op, true, false);
1007 static void rec_SWC2(const struct block *block, const struct opcode *op, u32 pc)
1009 _jit_name(block->_jit, __func__);
1010 rec_io(block, op, false, false);
1013 static void rec_load_direct(const struct block *block, const struct opcode *op,
1016 struct lightrec_state *state = block->state;
1017 struct regcache *reg_cache = state->reg_cache;
1018 jit_state_t *_jit = block->_jit;
1019 jit_node_t *to_not_ram, *to_not_bios = 0, *to_end, *to_end2;
1020 u8 tmp, rs, rt, addr_reg;
1026 jit_note(__FILE__, __LINE__);
1027 rs = lightrec_alloc_reg_in(reg_cache, _jit, op->i.rs);
1028 rt = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->i.rt);
1030 if ((state->offset_ram == state->offset_bios &&
1031 state->offset_ram == state->offset_scratch &&
1032 state->mirrors_mapped) || !op->i.imm) {
1034 imm = (s16)op->i.imm;
1036 jit_addi(rt, rs, (s16)op->i.imm);
1040 if (op->i.rs != op->i.rt)
1041 lightrec_free_reg(reg_cache, rs);
1044 tmp = lightrec_alloc_reg_temp(reg_cache, _jit);
1046 if (state->offset_ram == state->offset_bios &&
1047 state->offset_ram == state->offset_scratch) {
1048 if (!state->mirrors_mapped) {
1049 jit_andi(tmp, addr_reg, BIT(28));
1050 jit_rshi_u(tmp, tmp, 28 - 22);
1051 jit_ori(tmp, tmp, 0x1f800000 | (RAM_SIZE - 1));
1052 jit_andr(rt, addr_reg, tmp);
1054 jit_andi(rt, addr_reg, 0x1fffffff);
1057 if (state->offset_ram)
1058 jit_movi(tmp, state->offset_ram);
1060 to_not_ram = jit_bmsi(addr_reg, BIT(28));
1062 /* Convert to KUNSEG and avoid RAM mirrors */
1063 jit_andi(rt, addr_reg, RAM_SIZE - 1);
1065 if (state->offset_ram)
1066 jit_movi(tmp, state->offset_ram);
1068 to_end = jit_jmpi();
1070 jit_patch(to_not_ram);
1072 if (state->offset_bios != state->offset_scratch)
1073 to_not_bios = jit_bmci(addr_reg, BIT(22));
1075 /* Convert to KUNSEG */
1076 jit_andi(rt, addr_reg, 0x1fc00000 | (BIOS_SIZE - 1));
1078 jit_movi(tmp, state->offset_bios);
1080 if (state->offset_bios != state->offset_scratch) {
1081 to_end2 = jit_jmpi();
1083 jit_patch(to_not_bios);
1085 /* Convert to KUNSEG */
1086 jit_andi(rt, addr_reg, 0x1f800fff);
1088 if (state->offset_scratch)
1089 jit_movi(tmp, state->offset_scratch);
1097 if (state->offset_ram || state->offset_bios || state->offset_scratch)
1098 jit_addr(rt, rt, tmp);
1100 jit_new_node_www(code, rt, rt, imm);
1102 lightrec_free_reg(reg_cache, addr_reg);
1103 lightrec_free_reg(reg_cache, rt);
1104 lightrec_free_reg(reg_cache, tmp);
1107 static void rec_load(const struct block *block, const struct opcode *op,
1110 if (op->flags & LIGHTREC_DIRECT_IO)
1111 rec_load_direct(block, op, code);
1113 rec_io(block, op, false, true);
1116 static void rec_LB(const struct block *block, const struct opcode *op, u32 pc)
1118 _jit_name(block->_jit, __func__);
1119 rec_load(block, op, jit_code_ldxi_c);
1122 static void rec_LBU(const struct block *block, const struct opcode *op, u32 pc)
1124 _jit_name(block->_jit, __func__);
1125 rec_load(block, op, jit_code_ldxi_uc);
1128 static void rec_LH(const struct block *block, const struct opcode *op, u32 pc)
1130 _jit_name(block->_jit, __func__);
1131 rec_load(block, op, jit_code_ldxi_s);
1134 static void rec_LHU(const struct block *block, const struct opcode *op, u32 pc)
1136 _jit_name(block->_jit, __func__);
1137 rec_load(block, op, jit_code_ldxi_us);
1140 static void rec_LWL(const struct block *block, const struct opcode *op, u32 pc)
1142 _jit_name(block->_jit, __func__);
1143 rec_io(block, op, true, true);
1146 static void rec_LWR(const struct block *block, const struct opcode *op, u32 pc)
1148 _jit_name(block->_jit, __func__);
1149 rec_io(block, op, true, true);
1152 static void rec_LW(const struct block *block, const struct opcode *op, u32 pc)
1154 _jit_name(block->_jit, __func__);
1155 rec_load(block, op, jit_code_ldxi_i);
1158 static void rec_LWC2(const struct block *block, const struct opcode *op, u32 pc)
1160 _jit_name(block->_jit, __func__);
1161 rec_io(block, op, false, false);
1164 static void rec_break_syscall(const struct block *block,
1165 const struct opcode *op, u32 pc, bool is_break)
1167 struct regcache *reg_cache = block->state->reg_cache;
1168 jit_state_t *_jit = block->_jit;
1172 jit_note(__FILE__, __LINE__);
1175 offset = offsetof(struct lightrec_state, break_func);
1177 offset = offsetof(struct lightrec_state, syscall_func);
1179 tmp = lightrec_alloc_reg_temp(reg_cache, _jit);
1180 jit_ldxi(tmp, LIGHTREC_REG_STATE, offset);
1182 lightrec_free_reg(reg_cache, tmp);
1184 lightrec_regcache_mark_live(reg_cache, _jit);
1186 /* TODO: the return address should be "pc - 4" if we're a delay slot */
1187 lightrec_emit_end_of_block(block, op, pc, -1, pc, 31, 0, true);
1190 static void rec_special_SYSCALL(const struct block *block,
1191 const struct opcode *op, u32 pc)
1193 _jit_name(block->_jit, __func__);
1194 rec_break_syscall(block, op, pc, false);
1197 static void rec_special_BREAK(const struct block *block,
1198 const struct opcode *op, u32 pc)
1200 _jit_name(block->_jit, __func__);
1201 rec_break_syscall(block, op, pc, true);
1204 static void rec_mfc(const struct block *block, const struct opcode *op)
1207 struct lightrec_state *state = block->state;
1208 struct regcache *reg_cache = state->reg_cache;
1209 jit_state_t *_jit = block->_jit;
1211 jit_note(__FILE__, __LINE__);
1213 tmp = lightrec_alloc_reg(reg_cache, _jit, JIT_R0);
1214 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
1216 jit_ldxi(tmp2, LIGHTREC_REG_STATE,
1217 offsetof(struct lightrec_state, mfc_func));
1219 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rt, true);
1221 jit_movi(tmp, op->opcode);
1223 lightrec_free_reg(reg_cache, tmp);
1224 lightrec_free_reg(reg_cache, tmp2);
1226 lightrec_regcache_mark_live(reg_cache, _jit);
1229 static void rec_mtc(const struct block *block, const struct opcode *op, u32 pc)
1231 struct lightrec_state *state = block->state;
1232 struct regcache *reg_cache = state->reg_cache;
1233 jit_state_t *_jit = block->_jit;
1236 jit_note(__FILE__, __LINE__);
1238 tmp = lightrec_alloc_reg(reg_cache, _jit, JIT_R0);
1239 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
1240 jit_ldxi(tmp2, LIGHTREC_REG_STATE,
1241 offsetof(struct lightrec_state, mtc_func));
1243 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rs, false);
1244 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rt, false);
1246 jit_movi(tmp, op->opcode);
1248 lightrec_free_reg(reg_cache, tmp);
1249 lightrec_free_reg(reg_cache, tmp2);
1251 lightrec_regcache_mark_live(reg_cache, _jit);
1253 if (op->i.op == OP_CP0 && !(op->flags & LIGHTREC_NO_DS) &&
1254 (op->r.rd == 12 || op->r.rd == 13))
1255 lightrec_emit_end_of_block(block, op, pc, -1, pc + 4, 0, 0, true);
1258 static void rec_cp0_MFC0(const struct block *block,
1259 const struct opcode *op, u32 pc)
1261 _jit_name(block->_jit, __func__);
1265 static void rec_cp0_CFC0(const struct block *block,
1266 const struct opcode *op, u32 pc)
1268 _jit_name(block->_jit, __func__);
1272 static void rec_cp0_MTC0(const struct block *block,
1273 const struct opcode *op, u32 pc)
1275 _jit_name(block->_jit, __func__);
1276 rec_mtc(block, op, pc);
1279 static void rec_cp0_CTC0(const struct block *block,
1280 const struct opcode *op, u32 pc)
1282 _jit_name(block->_jit, __func__);
1283 rec_mtc(block, op, pc);
1286 static void rec_cp2_basic_MFC2(const struct block *block,
1287 const struct opcode *op, u32 pc)
1289 _jit_name(block->_jit, __func__);
1293 static void rec_cp2_basic_CFC2(const struct block *block,
1294 const struct opcode *op, u32 pc)
1296 _jit_name(block->_jit, __func__);
1300 static void rec_cp2_basic_MTC2(const struct block *block,
1301 const struct opcode *op, u32 pc)
1303 _jit_name(block->_jit, __func__);
1304 rec_mtc(block, op, pc);
1307 static void rec_cp2_basic_CTC2(const struct block *block,
1308 const struct opcode *op, u32 pc)
1310 _jit_name(block->_jit, __func__);
1311 rec_mtc(block, op, pc);
1314 static void rec_cp0_RFE(const struct block *block,
1315 const struct opcode *op, u32 pc)
1317 struct lightrec_state *state = block->state;
1318 jit_state_t *_jit = block->_jit;
1322 jit_note(__FILE__, __LINE__);
1324 tmp = lightrec_alloc_reg_temp(state->reg_cache, _jit);
1325 jit_ldxi(tmp, LIGHTREC_REG_STATE,
1326 offsetof(struct lightrec_state, rfe_func));
1328 lightrec_free_reg(state->reg_cache, tmp);
1330 lightrec_regcache_mark_live(state->reg_cache, _jit);
1333 static void rec_CP(const struct block *block, const struct opcode *op, u32 pc)
1335 struct regcache *reg_cache = block->state->reg_cache;
1336 jit_state_t *_jit = block->_jit;
1340 jit_note(__FILE__, __LINE__);
1342 tmp = lightrec_alloc_reg(reg_cache, _jit, JIT_R0);
1343 tmp2 = lightrec_alloc_reg_temp(reg_cache, _jit);
1345 jit_ldxi(tmp2, LIGHTREC_REG_STATE,
1346 offsetof(struct lightrec_state, cp_func));
1348 jit_movi(tmp, op->opcode);
1350 lightrec_free_reg(reg_cache, tmp);
1351 lightrec_free_reg(reg_cache, tmp2);
1353 lightrec_regcache_mark_live(reg_cache, _jit);
1356 static void rec_meta_unload(const struct block *block,
1357 const struct opcode *op, u32 pc)
1359 struct lightrec_state *state = block->state;
1360 struct regcache *reg_cache = state->reg_cache;
1361 jit_state_t *_jit = block->_jit;
1364 jit_note(__FILE__, __LINE__);
1366 pr_debug("Unloading reg %s\n", lightrec_reg_name(op->i.rs));
1367 lightrec_clean_reg_if_loaded(reg_cache, _jit, op->i.rs, true);
1370 static void rec_meta_BEQZ(const struct block *block,
1371 const struct opcode *op, u32 pc)
1373 _jit_name(block->_jit, __func__);
1374 rec_b(block, op, pc, jit_code_bnei, 0, false, true);
1377 static void rec_meta_BNEZ(const struct block *block,
1378 const struct opcode *op, u32 pc)
1380 _jit_name(block->_jit, __func__);
1381 rec_b(block, op, pc, jit_code_beqi, 0, false, true);
1384 static void rec_meta_MOV(const struct block *block,
1385 const struct opcode *op, u32 pc)
1387 struct lightrec_state *state = block->state;
1388 struct regcache *reg_cache = state->reg_cache;
1389 jit_state_t *_jit = block->_jit;
1392 _jit_name(block->_jit, __func__);
1393 jit_note(__FILE__, __LINE__);
1394 rs = op->r.rs ? lightrec_alloc_reg_in(reg_cache, _jit, op->r.rs) : 0;
1395 rd = lightrec_alloc_reg_out_ext(reg_cache, _jit, op->r.rd);
1397 if (op->r.rs == 0) {
1400 #if __WORDSIZE == 32
1407 lightrec_free_reg(state->reg_cache, rs);
1408 lightrec_free_reg(state->reg_cache, rd);
1411 static void rec_meta_sync(const struct block *block,
1412 const struct opcode *op, u32 pc)
1414 struct lightrec_state *state = block->state;
1415 struct lightrec_branch_target *target;
1416 jit_state_t *_jit = block->_jit;
1419 jit_note(__FILE__, __LINE__);
1421 jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE, state->cycles);
1424 lightrec_storeback_regs(state->reg_cache, _jit);
1425 lightrec_regcache_reset(state->reg_cache);
1427 pr_debug("Adding branch target at offset 0x%x\n",
1429 target = &state->targets[state->nb_targets++];
1430 target->offset = op->offset;
1431 target->label = jit_indirect();
1434 static const lightrec_rec_func_t rec_standard[64] = {
1435 [OP_SPECIAL] = rec_SPECIAL,
1436 [OP_REGIMM] = rec_REGIMM,
1441 [OP_BLEZ] = rec_BLEZ,
1442 [OP_BGTZ] = rec_BGTZ,
1443 [OP_ADDI] = rec_ADDI,
1444 [OP_ADDIU] = rec_ADDIU,
1445 [OP_SLTI] = rec_SLTI,
1446 [OP_SLTIU] = rec_SLTIU,
1447 [OP_ANDI] = rec_ANDI,
1449 [OP_XORI] = rec_XORI,
1465 [OP_LWC2] = rec_LWC2,
1466 [OP_SWC2] = rec_SWC2,
1468 [OP_META_REG_UNLOAD] = rec_meta_unload,
1469 [OP_META_BEQZ] = rec_meta_BEQZ,
1470 [OP_META_BNEZ] = rec_meta_BNEZ,
1471 [OP_META_MOV] = rec_meta_MOV,
1472 [OP_META_SYNC] = rec_meta_sync,
1475 static const lightrec_rec_func_t rec_special[64] = {
1476 [OP_SPECIAL_SLL] = rec_special_SLL,
1477 [OP_SPECIAL_SRL] = rec_special_SRL,
1478 [OP_SPECIAL_SRA] = rec_special_SRA,
1479 [OP_SPECIAL_SLLV] = rec_special_SLLV,
1480 [OP_SPECIAL_SRLV] = rec_special_SRLV,
1481 [OP_SPECIAL_SRAV] = rec_special_SRAV,
1482 [OP_SPECIAL_JR] = rec_special_JR,
1483 [OP_SPECIAL_JALR] = rec_special_JALR,
1484 [OP_SPECIAL_SYSCALL] = rec_special_SYSCALL,
1485 [OP_SPECIAL_BREAK] = rec_special_BREAK,
1486 [OP_SPECIAL_MFHI] = rec_special_MFHI,
1487 [OP_SPECIAL_MTHI] = rec_special_MTHI,
1488 [OP_SPECIAL_MFLO] = rec_special_MFLO,
1489 [OP_SPECIAL_MTLO] = rec_special_MTLO,
1490 [OP_SPECIAL_MULT] = rec_special_MULT,
1491 [OP_SPECIAL_MULTU] = rec_special_MULTU,
1492 [OP_SPECIAL_DIV] = rec_special_DIV,
1493 [OP_SPECIAL_DIVU] = rec_special_DIVU,
1494 [OP_SPECIAL_ADD] = rec_special_ADD,
1495 [OP_SPECIAL_ADDU] = rec_special_ADDU,
1496 [OP_SPECIAL_SUB] = rec_special_SUB,
1497 [OP_SPECIAL_SUBU] = rec_special_SUBU,
1498 [OP_SPECIAL_AND] = rec_special_AND,
1499 [OP_SPECIAL_OR] = rec_special_OR,
1500 [OP_SPECIAL_XOR] = rec_special_XOR,
1501 [OP_SPECIAL_NOR] = rec_special_NOR,
1502 [OP_SPECIAL_SLT] = rec_special_SLT,
1503 [OP_SPECIAL_SLTU] = rec_special_SLTU,
1506 static const lightrec_rec_func_t rec_regimm[64] = {
1507 [OP_REGIMM_BLTZ] = rec_regimm_BLTZ,
1508 [OP_REGIMM_BGEZ] = rec_regimm_BGEZ,
1509 [OP_REGIMM_BLTZAL] = rec_regimm_BLTZAL,
1510 [OP_REGIMM_BGEZAL] = rec_regimm_BGEZAL,
1513 static const lightrec_rec_func_t rec_cp0[64] = {
1514 [OP_CP0_MFC0] = rec_cp0_MFC0,
1515 [OP_CP0_CFC0] = rec_cp0_CFC0,
1516 [OP_CP0_MTC0] = rec_cp0_MTC0,
1517 [OP_CP0_CTC0] = rec_cp0_CTC0,
1518 [OP_CP0_RFE] = rec_cp0_RFE,
1521 static const lightrec_rec_func_t rec_cp2_basic[64] = {
1522 [OP_CP2_BASIC_MFC2] = rec_cp2_basic_MFC2,
1523 [OP_CP2_BASIC_CFC2] = rec_cp2_basic_CFC2,
1524 [OP_CP2_BASIC_MTC2] = rec_cp2_basic_MTC2,
1525 [OP_CP2_BASIC_CTC2] = rec_cp2_basic_CTC2,
1528 static void rec_SPECIAL(const struct block *block,
1529 const struct opcode *op, u32 pc)
1531 lightrec_rec_func_t f = rec_special[op->r.op];
1533 (*f)(block, op, pc);
1535 unknown_opcode(block, op, pc);
1538 static void rec_REGIMM(const struct block *block,
1539 const struct opcode *op, u32 pc)
1541 lightrec_rec_func_t f = rec_regimm[op->r.rt];
1543 (*f)(block, op, pc);
1545 unknown_opcode(block, op, pc);
1548 static void rec_CP0(const struct block *block, const struct opcode *op, u32 pc)
1550 lightrec_rec_func_t f = rec_cp0[op->r.rs];
1552 (*f)(block, op, pc);
1554 rec_CP(block, op, pc);
1557 static void rec_CP2(const struct block *block, const struct opcode *op, u32 pc)
1559 if (op->r.op == OP_CP2_BASIC) {
1560 lightrec_rec_func_t f = rec_cp2_basic[op->r.rs];
1562 (*f)(block, op, pc);
1567 rec_CP(block, op, pc);
1570 void lightrec_rec_opcode(const struct block *block,
1571 const struct opcode *op, u32 pc)
1573 lightrec_rec_func_t f = rec_standard[op->i.op];
1575 (*f)(block, op, pc);
1577 unknown_opcode(block, op, pc);