From: negativeExponent Date: Wed, 20 May 2020 16:23:50 +0000 (+0800) Subject: Update Lightrec API X-Git-Tag: r24l~642^2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b02f240d929ffa0cb488bc6bb4d27b023e1a822;p=pcsx_rearmed.git Update Lightrec API --- diff --git a/Makefile b/Makefile index 98660501..1496f4ee 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,8 @@ OBJS += deps/lightning/lib/jit_disasm.o \ deps/lightrec/memmanager.o \ deps/lightrec/optimizer.o \ deps/lightrec/regcache.o \ - deps/lightrec/recompiler.o + deps/lightrec/recompiler.o \ + deps/lightrec/reaper.o ifeq ($(MMAP_WIN32),1) CFLAGS += -Ideps/mman OBJS += deps/mman/mman.o diff --git a/deps/lightrec/config.h b/deps/lightrec/config.h new file mode 100644 index 00000000..b72ae10a --- /dev/null +++ b/deps/lightrec/config.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Paul Cercueil + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + +#ifndef __LIGHTREC_CONFIG_H__ +#define __LIGHTREC_CONFIG_H__ + +#define ENABLE_THREADED_COMPILER 1 +#define ENABLE_FIRST_PASS 1 +#define ENABLE_DISASSEMBLER 0 +#define ENABLE_TINYMM 0 + +#endif /* __LIGHTREC_CONFIG_H__ */ diff --git a/libpcsxcore/lightrec/plugin.c b/libpcsxcore/lightrec/plugin.c index 8c64c67f..79bf0215 100644 --- a/libpcsxcore/lightrec/plugin.c +++ b/libpcsxcore/lightrec/plugin.c @@ -42,6 +42,7 @@ static struct lightrec_state *lightrec_state; static char *name = "retroarch.exe"; static bool use_lightrec_interpreter; +static bool use_pcsx_interpreter; static bool lightrec_debug; static bool lightrec_very_debug; static u32 lightrec_begin_cycles; @@ -111,7 +112,7 @@ static void (*cp2_ops[])(struct psxCP2Regs *) = { static char cache_buf[64 * 1024]; -static u32 cop0_mfc(struct lightrec_state *state, u8 reg) +static u32 cop0_mfc(struct lightrec_state *state, u32 op, u8 reg) { return psxRegs.CP0.r[reg]; } @@ -124,12 +125,12 @@ static u32 cop2_mfc_cfc(struct lightrec_state *state, u8 reg, bool cfc) return MFC2(reg); } -static u32 cop2_mfc(struct lightrec_state *state, u8 reg) +static u32 cop2_mfc(struct lightrec_state *state, u32 op, u8 reg) { return cop2_mfc_cfc(state, reg, false); } -static u32 cop2_cfc(struct lightrec_state *state, u8 reg) +static u32 cop2_cfc(struct lightrec_state *state, u32 op, u8 reg) { return cop2_mfc_cfc(state, reg, true); } @@ -176,22 +177,22 @@ static void cop2_mtc_ctc(struct lightrec_state *state, MTC2(value, reg); } -static void cop0_mtc(struct lightrec_state *state, u8 reg, u32 value) +static void cop0_mtc(struct lightrec_state *state, u32 op, u8 reg, u32 value) { cop0_mtc_ctc(state, reg, value, false); } -static void cop0_ctc(struct lightrec_state *state, u8 reg, u32 value) +static void cop0_ctc(struct lightrec_state *state, u32 op, u8 reg, u32 value) { cop0_mtc_ctc(state, reg, value, true); } -static void cop2_mtc(struct lightrec_state *state, u8 reg, u32 value) +static void cop2_mtc(struct lightrec_state *state, u32 op, u8 reg, u32 value) { cop2_mtc_ctc(state, reg, value, false); } -static void cop2_ctc(struct lightrec_state *state, u8 reg, u32 value) +static void cop2_ctc(struct lightrec_state *state, u32 op, u8 reg, u32 value) { cop2_mtc_ctc(state, reg, value, true); } @@ -211,7 +212,8 @@ static void cop2_op(struct lightrec_state *state, u32 func) cp2_ops[func & 0x3f](&psxRegs.CP2); } -static void hw_write_byte(struct lightrec_state *state, u32 mem, u8 val) +static void hw_write_byte(struct lightrec_state *state, + u32 op, void *host, u32 mem, u8 val) { psxRegs.cycle = lightrec_current_cycle_count(state); @@ -221,7 +223,8 @@ static void hw_write_byte(struct lightrec_state *state, u32 mem, u8 val) lightrec_reset_cycle_count(state, psxRegs.cycle); } -static void hw_write_half(struct lightrec_state *state, u32 mem, u16 val) +static void hw_write_half(struct lightrec_state *state, + u32 op, void *host, u32 mem, u16 val) { psxRegs.cycle = lightrec_current_cycle_count(state); @@ -231,7 +234,8 @@ static void hw_write_half(struct lightrec_state *state, u32 mem, u16 val) lightrec_reset_cycle_count(state, psxRegs.cycle); } -static void hw_write_word(struct lightrec_state *state, u32 mem, u32 val) +static void hw_write_word(struct lightrec_state *state, + u32 op, void *host, u32 mem, u32 val) { psxRegs.cycle = lightrec_current_cycle_count(state); @@ -241,7 +245,7 @@ static void hw_write_word(struct lightrec_state *state, u32 mem, u32 val) lightrec_reset_cycle_count(state, psxRegs.cycle); } -static u8 hw_read_byte(struct lightrec_state *state, u32 mem) +static u8 hw_read_byte(struct lightrec_state *state, u32 op, void *host, u32 mem) { u8 val; @@ -254,7 +258,8 @@ static u8 hw_read_byte(struct lightrec_state *state, u32 mem) return val; } -static u16 hw_read_half(struct lightrec_state *state, u32 mem) +static u16 hw_read_half(struct lightrec_state *state, + u32 op, void *host, u32 mem) { u16 val; @@ -267,7 +272,8 @@ static u16 hw_read_half(struct lightrec_state *state, u32 mem) return val; } -static u32 hw_read_word(struct lightrec_state *state, u32 mem) +static u32 hw_read_word(struct lightrec_state *state, + u32 op, void *host, u32 mem) { u32 val; @@ -291,12 +297,14 @@ static struct lightrec_mem_map_ops hw_regs_ops = { static u32 cache_ctrl; -static void cache_ctrl_write_word(struct lightrec_state *state, u32 mem, u32 val) +static void cache_ctrl_write_word(struct lightrec_state *state, + u32 op, void *host, u32 mem, u32 val) { cache_ctrl = val; } -static u32 cache_ctrl_read_word(struct lightrec_state *state, u32 mem) +static u32 cache_ctrl_read_word(struct lightrec_state *state, + u32 op, void *host, u32 mem) { return cache_ctrl; } @@ -489,6 +497,9 @@ static void print_for_big_ass_debugger(void) printf("\n"); } + +extern void intExecuteBlock(); + static u32 old_cycle_counter; static void lightrec_plugin_execute_block(void) @@ -496,27 +507,33 @@ static void lightrec_plugin_execute_block(void) u32 old_pc = psxRegs.pc; u32 flags; - lightrec_reset_cycle_count(lightrec_state, psxRegs.cycle); - lightrec_restore_registers(lightrec_state, psxRegs.GPR.r); + if (use_pcsx_interpreter) { + intExecuteBlock(); + } else { + lightrec_reset_cycle_count(lightrec_state, psxRegs.cycle); + lightrec_restore_registers(lightrec_state, psxRegs.GPR.r); - if (use_lightrec_interpreter) - psxRegs.pc = lightrec_run_interpreter(lightrec_state, psxRegs.pc); - else - psxRegs.pc = lightrec_execute_one(lightrec_state, psxRegs.pc); + if (use_lightrec_interpreter) + psxRegs.pc = lightrec_run_interpreter(lightrec_state, + psxRegs.pc); + else + psxRegs.pc = lightrec_execute_one(lightrec_state, + psxRegs.pc); - psxRegs.cycle = lightrec_current_cycle_count(lightrec_state); + psxRegs.cycle = lightrec_current_cycle_count(lightrec_state); - lightrec_dump_registers(lightrec_state, psxRegs.GPR.r); - flags = lightrec_exit_flags(lightrec_state); + lightrec_dump_registers(lightrec_state, psxRegs.GPR.r); + flags = lightrec_exit_flags(lightrec_state); - if (flags & LIGHTREC_EXIT_SEGFAULT) { - fprintf(stderr, "Exiting at cycle 0x%08x\n", - psxRegs.cycle); - exit(1); - } + if (flags & LIGHTREC_EXIT_SEGFAULT) { + fprintf(stderr, "Exiting at cycle 0x%08x\n", + psxRegs.cycle); + exit(1); + } - if (flags & LIGHTREC_EXIT_SYSCALL) - psxException(0x20, 0); + if (flags & LIGHTREC_EXIT_SYSCALL) + psxException(0x20, 0); + } psxBranchTest(); @@ -532,8 +549,9 @@ static void lightrec_plugin_execute_block(void) } if ((psxRegs.cycle & ~0xfffffff) != old_cycle_counter) { - printf("RAM usage: IR %u KiB, CODE %u KiB, " + printf("RAM usage: Lightrec %u KiB, IR %u KiB, CODE %u KiB, " "MIPS %u KiB, TOTAL %u KiB, avg. IPI %f\n", + lightrec_get_mem_usage(MEM_FOR_LIGHTREC) / 1024, lightrec_get_mem_usage(MEM_FOR_IR) / 1024, lightrec_get_mem_usage(MEM_FOR_CODE) / 1024, lightrec_get_mem_usage(MEM_FOR_MIPS_CODE) / 1024,