add primary megadrive memory access, allow get cheevos.
[picodrive.git] / platform / libretro / 3ds / 3ds_utils.c
1
2 #include "3ds_utils.h"
3
4 typedef int (*ctr_callback_type)(void);
5
6 int srvGetServiceHandle(unsigned int* out, const char* name);
7 int svcCloseHandle(unsigned int handle);
8 int svcBackdoor(ctr_callback_type);
9
10
11 static void ctr_enable_all_svc_kernel(void)
12 {
13    __asm__ volatile("cpsid aif");
14
15    unsigned int*  svc_access_control = *(*(unsigned int***)0xFFFF9000 + 0x22) - 0x6;
16
17    svc_access_control[0]=0xFFFFFFFE;
18    svc_access_control[1]=0xFFFFFFFF;
19    svc_access_control[2]=0xFFFFFFFF;
20    svc_access_control[3]=0x3FFFFFFF;
21 }
22
23
24 static void ctr_invalidate_ICache_kernel(void)
25 {
26    __asm__ volatile(
27       "cpsid aif\n\t"
28       "mov r0, #0\n\t"
29       "mcr p15, 0, r0, c7, c5, 0\n\t");
30 }
31
32 static void ctr_flush_DCache_kernel(void)
33 {
34    __asm__ volatile(
35       "cpsid aif\n\t"
36       "mov r0, #0\n\t"
37       "mcr p15, 0, r0, c7, c10, 0\n\t");
38
39 }
40
41
42 static void ctr_enable_all_svc(void)
43 {
44    svcBackdoor((ctr_callback_type)ctr_enable_all_svc_kernel);
45 }
46
47 void ctr_invalidate_ICache(void)
48 {
49 //   __asm__ volatile("svc 0x2E\n\t");
50    svcBackdoor((ctr_callback_type)ctr_invalidate_ICache_kernel);
51
52 }
53
54 void ctr_flush_DCache(void)
55 {
56 //   __asm__ volatile("svc 0x4B\n\t");
57    svcBackdoor((ctr_callback_type)ctr_flush_DCache_kernel);
58 }
59
60
61 void ctr_flush_invalidate_cache(void)
62 {
63    ctr_flush_DCache();
64    ctr_invalidate_ICache();
65 }
66
67 int ctr_svchack_init(void)
68 {
69    extern unsigned int __service_ptr;
70
71    if(__service_ptr)
72       return 0;
73
74    /* CFW */
75    ctr_enable_all_svc();
76    return 1;
77 }
78