From: notaz Date: Thu, 27 Jun 2013 22:41:52 +0000 (+0300) Subject: drc: some portability fixes X-Git-Tag: v1.85~84 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=picodrive.git;a=commitdiff_plain;h=c25d78eec11d2a22adbd0bc7d42a24e2d79e40e7 drc: some portability fixes --- diff --git a/cpu/drc/cmn.c b/cpu/drc/cmn.c index 3ec039b..91bd7ed 100644 --- a/cpu/drc/cmn.c +++ b/cpu/drc/cmn.c @@ -6,10 +6,8 @@ * See COPYING file in the top-level directory. */ #include -#ifdef __linux__ -#include -#endif +#include #include "cmn.h" u8 __attribute__((aligned(4096))) tcache[DRC_TCACHE_SIZE]; @@ -17,20 +15,9 @@ u8 __attribute__((aligned(4096))) tcache[DRC_TCACHE_SIZE]; void drc_cmn_init(void) { -#ifdef __linux__ - void *tmp; - - tmp = mmap(tcache, DRC_TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - printf("mmap tcache: %p, asked %p\n", tmp, tcache); -#endif + plat_mem_set_exec(tcache, sizeof(tcache)); } void drc_cmn_cleanup(void) { -#ifdef __linux__ - int ret; - ret = munmap(tcache, DRC_TCACHE_SIZE); - printf("munmap tcache: %i\n", ret); -#endif } - diff --git a/cpu/sh2/compiler.c b/cpu/sh2/compiler.c index 43f2bc3..392af29 100644 --- a/cpu/sh2/compiler.c +++ b/cpu/sh2/compiler.c @@ -431,6 +431,12 @@ static void REGPARM(3) *dr_lookup_block(u32 pc, int is_slave, int *tcache_id) return block; } +static void *dr_failure(void) +{ + lprintf("recompilation failed\n"); + exit(1); +} + static void *dr_prepare_ext_branch(u32 pc, SH2 *sh2, int tcache_id) { #if LINK_BRANCHES @@ -1126,13 +1132,15 @@ static void emit_do_static_regs(int is_write, int tmpr) static void emit_block_entry(void) { - int arg0, arg1, arg2; + int arg0; host_arg2reg(arg0, 0); + +#if (DRC_DEBUG & 8) || defined(PDB) + int arg1, arg2; host_arg2reg(arg1, 1); host_arg2reg(arg2, 2); -#if (DRC_DEBUG & 8) || defined(PDB) emit_do_static_regs(1, arg2); emith_move_r_r(arg1, CONTEXT_REG); emith_move_r_r(arg2, rcache_get_reg(SHR_SR, RC_GR_READ)); @@ -1296,10 +1304,16 @@ static void REGPARM(2) *sh2_translate(SH2 *sh2, int tcache_id) pc = branch_target_pc[i]; if (base_pc <= pc && pc <= end_pc && !(OP_FLAGS(pc) & OF_DELAY_OP)) branch_target_pc[tmp++] = branch_target_pc[i]; + + if (i == branch_target_count - 1) // workaround gcc 4.5.2 bug? + break; } + branch_target_count = tmp; - memset(branch_target_ptr, 0, sizeof(branch_target_ptr[0]) * branch_target_count); - memset(branch_target_blkid, 0, sizeof(branch_target_blkid[0]) * branch_target_count); + if (branch_target_count > 0) { + memset(branch_target_ptr, 0, sizeof(branch_target_ptr[0]) * branch_target_count); + memset(branch_target_blkid, 0, sizeof(branch_target_blkid[0]) * branch_target_count); + } // ------------------------------------------------- // 2nd pass: actual compilation @@ -2702,7 +2716,7 @@ static void sh2_generate_utils(void) emith_call(sh2_translate); emit_block_entry(); // XXX: can't translate, fail - emith_call(exit); + emith_call(dr_failure); // sh2_drc_test_irq(void) // assumes it's called from main function (may jump to dispatcher) diff --git a/pico/pico.h b/pico/pico.h index 6c6e7c5..e5e832b 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -37,6 +37,7 @@ extern void cache_flush_d_inval_i(void *start_addr, void *end_addr); extern void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed); extern void *plat_mremap(void *ptr, size_t oldsize, size_t newsize); extern void plat_munmap(void *ptr, size_t size); +extern int plat_mem_set_exec(void *ptr, size_t size); // this one should handle display mode changes extern void emu_video_mode_change(int start_line, int line_count, int is_32cols); diff --git a/platform/libpicofe b/platform/libpicofe index c2981fc..6282e17 160000 --- a/platform/libpicofe +++ b/platform/libpicofe @@ -1 +1 @@ -Subproject commit c2981fc0ee15d3b1aff69901550fda32460bb1b1 +Subproject commit 6282e17ef5f37915df1a77b5d7138c666e94d0fb diff --git a/platform/libretro.c b/platform/libretro.c index 40dc394..ebf6e65 100644 --- a/platform/libretro.c +++ b/platform/libretro.c @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef __MACH__ #include #endif @@ -71,8 +72,10 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) req = (void *)addr; ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0); - if (ret == MAP_FAILED) + if (ret == MAP_FAILED) { + lprintf("mmap(%08lx, %zd) failed: %d\n", addr, size, errno); return NULL; + } if (addr != 0 && ret != (void *)addr) { lprintf("warning: wanted to map @%08lx, got %p\n", @@ -102,6 +105,15 @@ void plat_munmap(void *ptr, size_t size) munmap(ptr, size); } +int plat_mem_set_exec(void *ptr, size_t size) +{ + int ret = mprotect(ptr, size, PROT_READ | PROT_WRITE | PROT_EXEC); + if (ret != 0) + lprintf("mprotect(%p, %zd) failed: %d\n", ptr, size, errno); + + return ret; +} + void emu_video_mode_change(int start_line, int line_count, int is_32cols) { memset(vout_buf, 0, 320 * 240 * 2);