Commit | Line | Data |
---|---|---|
fc99395c | 1 | #ifndef _3DS_UTILS_H |
2 | #define _3DS_UTILS_H | |
3 | ||
f72db18e | 4 | #include <stdio.h> |
93c24a56 | 5 | #include <stdbool.h> |
31f52a9f | 6 | #include <3ds.h> |
fc99395c | 7 | |
f72db18e | 8 | #define MEMOP_PROT 6 |
9 | #define MEMOP_MAP 4 | |
10 | #define MEMOP_UNMAP 5 | |
fc99395c | 11 | |
e4d84733 | 12 | #define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0) |
13 | ||
14 | void wait_for_input(void); | |
fc99395c | 15 | |
f72db18e | 16 | extern __attribute__((weak)) int __ctr_svchax; |
17 | ||
31f52a9f | 18 | static bool has_rosalina; |
b37c639e JW |
19 | |
20 | static void check_rosalina() { | |
21 | int64_t version; | |
22 | uint32_t major; | |
23 | ||
24 | has_rosalina = false; | |
25 | ||
26 | if (!svcGetSystemInfo(&version, 0x10000, 0)) { | |
27 | major = GET_VERSION_MAJOR(version); | |
28 | ||
29 | if (major >= 8) | |
30 | has_rosalina = true; | |
31 | } | |
32 | } | |
33 | ||
34 | void ctr_clear_cache(void); | |
35 | ||
f72db18e | 36 | typedef int32_t (*ctr_callback_type)(void); |
37 | ||
38 | static inline void ctr_invalidate_ICache_kernel(void) | |
39 | { | |
40 | __asm__ volatile( | |
41 | "cpsid aif\n\t" | |
42 | "mov r0, #0\n\t" | |
43 | "mcr p15, 0, r0, c7, c5, 0\n\t"); | |
44 | } | |
45 | ||
46 | static inline void ctr_flush_DCache_kernel(void) | |
47 | { | |
48 | __asm__ volatile( | |
49 | "cpsid aif\n\t" | |
50 | "mov r0, #0\n\t" | |
51 | "mcr p15, 0, r0, c7, c10, 0\n\t"); | |
52 | } | |
53 | ||
54 | static inline void ctr_invalidate_ICache(void) | |
55 | { | |
56 | svcBackdoor((ctr_callback_type)ctr_invalidate_ICache_kernel); | |
57 | } | |
58 | ||
59 | static inline void ctr_flush_DCache(void) | |
60 | { | |
61 | svcBackdoor((ctr_callback_type)ctr_flush_DCache_kernel); | |
62 | } | |
63 | ||
f72db18e | 64 | static inline void ctr_flush_invalidate_cache(void) |
65 | { | |
b37c639e JW |
66 | if (has_rosalina) { |
67 | ctr_clear_cache(); | |
68 | } else { | |
69 | ctr_flush_DCache(); | |
70 | ctr_invalidate_ICache(); | |
71 | } | |
f72db18e | 72 | } |
73 | ||
fc99395c | 74 | #endif // _3DS_UTILS_H |