From: notaz Date: Mon, 28 Jan 2013 03:09:23 +0000 (+0200) Subject: psxmem: try to choose mem addresses more carefully X-Git-Tag: r19~29 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0dd9956467322aca812db75b5e0f11f23c1910b;p=pcsx_rearmed.git psxmem: try to choose mem addresses more carefully --- diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 27663f1f..9e442675 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -42,10 +42,15 @@ void *psxMap(unsigned long addr, size_t size, int is_fixed, enum psxMapTag tag) { int flags = MAP_PRIVATE | MAP_ANONYMOUS; + int tried_to_align = 0; + unsigned long mask; void *req, *ret; - if (psxMapHook != NULL) - return psxMapHook(addr, size, is_fixed, tag); +retry: + if (psxMapHook != NULL) { + ret = psxMapHook(addr, size, is_fixed, tag); + goto out; + } if (is_fixed) flags |= MAP_FIXED; @@ -55,9 +60,24 @@ void *psxMap(unsigned long addr, size_t size, int is_fixed, if (ret == MAP_FAILED) return NULL; - if (req != NULL && ret != req) - SysMessage("psxMap: warning: wanted to map @%p, got %p\n", - req, ret); +out: + if (addr != 0 && ret != (void *)addr) { + SysMessage("psxMap: warning: wanted to map @%08x, got %p\n", + addr, ret); + + if (ret != NULL && ((addr ^ (long)ret) & 0x00ffffff) + && !tried_to_align) + { + psxUnmap(ret, size, tag); + + // try to use similarly aligned memory instead + // (recompiler needs this) + mask = (addr - 1) & ~addr & 0x07ffffff; + addr = (unsigned long)(ret + mask) & ~mask; + tried_to_align = 1; + goto retry; + } + } return ret; } @@ -110,7 +130,7 @@ int psxMemInit() { psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM); #ifndef RAM_FIXED if (psxM == NULL) - psxM = psxMap(0x70000000, 0x00210000, 0, MAP_TAG_RAM); + psxM = psxMap(0x78000000, 0x00210000, 0, MAP_TAG_RAM); #endif if (psxM == NULL) { SysMessage(_("mapping main RAM failed"));