Skip to content

Commit 92bb759

Browse files
committed
Merge branch 'master' into libretro
2 parents 30829ae + f232ffb commit 92bb759

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

frontend/3ds/3ds_utils.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ void wait_for_input(void);
1515
void ctr_clear_cache(void);
1616
void ctr_clear_cache_range(void *start, void *end);
1717
void ctr_invalidate_icache(void); // only icache
18+
int ctr_get_tlbdesc(void *ptr);
19+
20+
int svcCustomBackdoor(void *callback, void *a0, void *a1, void *a2);
21+
int svcConvertVAToPA(const void *VA, int writeCheck);
1822

1923
extern __attribute__((weak)) int __ctr_svchax;
2024

frontend/3ds/utils.S

+14
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,17 @@ ctr_invalidate_icache:
7979
svc 0x80 @ svcCustomBackdoor
8080
bx lr
8181
.endfunc
82+
83+
.global svcCustomBackdoor
84+
.func svcCustomBackdoor
85+
svcCustomBackdoor:
86+
svc 0x80 @ svcCustomBackdoor
87+
bx lr
88+
.endfunc
89+
90+
.global svcConvertVAToPA
91+
.func svcConvertVAToPA
92+
svcConvertVAToPA:
93+
svc 0x90 @ svcConvertVAToPA
94+
bx lr
95+
.endfunc

frontend/libretro.c

+42-4
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ static void vout_flip(const void *vram, int stride, int bgr24,
395395
#ifdef _3DS
396396
static u32 mapped_addrs[8];
397397
static u32 mapped_ram, mapped_ram_src;
398+
static void *vram_mem;
398399

399400
// http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions
400401
static void *pl_3ds_mmap(unsigned long addr, size_t size,
@@ -404,6 +405,9 @@ static void *pl_3ds_mmap(unsigned long addr, size_t size,
404405
*can_retry_addr = 0;
405406
(void)addr;
406407

408+
if (tag == MAP_TAG_VRAM && vram_mem)
409+
return vram_mem;
410+
407411
if (__ctr_svchax) do
408412
{
409413
// idea from fbalpha2012_neogeo
@@ -474,6 +478,9 @@ static void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
474478
{
475479
(void)tag;
476480

481+
if (ptr && ptr == vram_mem)
482+
return;
483+
477484
if (ptr && __ctr_svchax)
478485
{
479486
size_t i;
@@ -497,6 +504,26 @@ static void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
497504

498505
free(ptr);
499506
}
507+
508+
// debug
509+
static int ctr_get_tlbe_k(u32 ptr)
510+
{
511+
u32 tlb_base = -1, tlb_ctl = -1, *l1;
512+
s32 tlb_mask = 0xffffc000;
513+
514+
asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r"(tlb_base));
515+
asm volatile("mrc p15, 0, %0, c2, c0, 2" : "=r"(tlb_ctl));
516+
tlb_mask >>= tlb_ctl & 7;
517+
l1 = (u32 *)((tlb_base & tlb_mask) | 0xe0000000);
518+
return l1[ptr >> 20];
519+
}
520+
521+
static int ctr_get_tlbe(void *ptr)
522+
{
523+
if (svcConvertVAToPA((void *)0xe0000000, 0) != 0x20000000)
524+
return -1;
525+
return svcCustomBackdoor(ctr_get_tlbe_k, ptr, NULL, NULL);
526+
}
500527
#endif
501528

502529
#ifdef HAVE_LIBNX
@@ -628,8 +655,9 @@ static void log_mem_usage(void)
628655
if (__ctr_svchax)
629656
svcGetSystemInfo(&mem_used, 0, 1);
630657

631-
SysPrintf("mem: %d/%d heap: %d linear: %d stack: %d exe: %d\n", (int)mem_used, app_memory,
632-
__heap_size, __linear_heap_size, __stacksize__, (int)&__end__ - 0x100000);
658+
SysPrintf("mem: %d/%d heap: %d linear: %d/%d stack: %d exe: %d\n",
659+
(int)mem_used, app_memory, __heap_size, __linear_heap_size - linearSpaceFree(),
660+
__linear_heap_size, __stacksize__, (int)&__end__ - 0x100000);
633661
#endif
634662
}
635663

@@ -3577,7 +3605,16 @@ void retro_init(void)
35773605
}
35783606

35793607
#ifdef _3DS
3580-
vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
3608+
// Place psx vram in linear mem to take advantage of it's supersection mapping.
3609+
// The emu allocs 2x (0x201000 to be exact) but doesn't really need that much,
3610+
// so place vout_buf below to also act as an overdraw guard.
3611+
vram_mem = linearMemAlign(1024*1024 + 4096 + VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 4096);
3612+
if (vram_mem) {
3613+
vout_buf = (char *)vram_mem + 1024*1024 + 4096;
3614+
if (__ctr_svchax)
3615+
SysPrintf("vram: %p PA %08x tlb %08x\n", vram_mem,
3616+
svcConvertVAToPA(vram_mem, 0), ctr_get_tlbe(vram_mem));
3617+
}
35813618
#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && P_HAVE_POSIX_MEMALIGN
35823619
if (posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2) != 0)
35833620
vout_buf = NULL;
@@ -3635,7 +3672,8 @@ void retro_deinit(void)
36353672
}
36363673
SysClose();
36373674
#ifdef _3DS
3638-
linearFree(vout_buf);
3675+
linearFree(vram_mem);
3676+
vram_mem = NULL;
36393677
#else
36403678
free(vout_buf);
36413679
#endif

0 commit comments

Comments
 (0)