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