X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2Fdrc%2Fcmn.c;h=721340a39189a5cd3737d2a5cf9a9658d0eacee9;hb=3d5e32fe21b56d59a116195a66f300735af5a7ec;hp=08059f2ddbe92e73b66bbf4ede03e979db0e02a9;hpb=f4bb5d6b2c96a94317c4edb7805eb6d6ed8589ef;p=picodrive.git diff --git a/cpu/drc/cmn.c b/cpu/drc/cmn.c index 08059f2..721340a 100644 --- a/cpu/drc/cmn.c +++ b/cpu/drc/cmn.c @@ -1,31 +1,66 @@ +/* + * PicoDrive + * Copyright (C) 2009,2010 notaz + * Copyright (C) 2016 lentillog + * Copyright (C) 2016 Daniel De Matteis + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ #include -#if defined(__linux__) && defined(ARM) -#include -#endif +#include #include "cmn.h" +#ifdef _MSC_VER +u8 tcache[DRC_TCACHE_SIZE]; +#elif defined(VITA) +#include +u8 *tcache; +static int sceBlock; +int getVMBlock(); +#else u8 __attribute__((aligned(4096))) tcache[DRC_TCACHE_SIZE]; +#endif void drc_cmn_init(void) { -#if defined(__linux__) && defined(ARM) - void *tmp; - - tmp = mmap(tcache, DRC_TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0); - printf("mmap tcache: %p, asked %p\n", tmp, tcache); +#ifdef VITA + sceBlock = getVMBlock(); + sceKernelGetMemBlockBase(sceBlock, (void **)&tcache); #endif + int ret = plat_mem_set_exec(tcache, sizeof(tcache)); + elprintf(EL_STATUS, "drc_cmn_init: %p, %zd bytes: %d", + tcache, sizeof(tcache), ret); + +#ifdef __arm__ + if (PicoOpt & POPT_EN_DRC) + { + static int test_done; + if (!test_done) + { + int *test_out = (void *)tcache; + int (*testfunc)(void) = (void *)tcache; + + elprintf(EL_STATUS, "testing if we can run recompiled code.."); + *test_out++ = 0xe3a000dd; // mov r0, 0xdd + *test_out++ = 0xe12fff1e; // bx lr + cache_flush_d_inval_i(tcache, test_out); + + // we'll usually crash on broken platforms or bad ports, + // but do a value check too just in case + ret = testfunc(); + elprintf(EL_STATUS, "test %s.", ret == 0xdd ? "passed" : "failed"); + test_done = 1; + } + } +#endif } -// TODO: add calls in core, possibly to cart.c? void drc_cmn_cleanup(void) { -#if defined(__linux__) && defined(ARM) - int ret; - ret = munmap(tcache, DRC_TCACHE_SIZE); - printf("munmap tcache: %i\n", ret); -#endif } +// vim:shiftwidth=2:expandtab