Merge pull request #351 from SindenLightgun/master
[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>
fc99395c 6
f72db18e 7#define MEMOP_PROT 6
8#define MEMOP_MAP 4
9#define MEMOP_UNMAP 5
fc99395c 10
f72db18e 11void* linearMemAlign(size_t size, size_t alignment);
12void linearFree(void* mem);
13
14int32_t svcDuplicateHandle(uint32_t* out, uint32_t original);
15int32_t svcCloseHandle(uint32_t handle);
16int32_t svcControlMemory(void* addr_out, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm);
17int32_t svcControlProcessMemory(uint32_t process, void* addr0, void* addr1, uint32_t size, uint32_t op, uint32_t perm);
18
93c24a56
JW
19int32_t threadCreate(void *(*entrypoint)(void*), void* arg, size_t stack_size, int32_t prio, int32_t affinity, bool detached);
20int32_t threadJoin(int32_t thread, int64_t timeout_ns);
21void threadFree(int32_t thread);
22void threadExit(int32_t rc) __attribute__((noreturn));
f72db18e 23
24int32_t svcBackdoor(int32_t (*callback)(void));
e4d84733 25
e4d84733 26#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
27
28void wait_for_input(void);
fc99395c 29
f72db18e 30extern __attribute__((weak)) int __ctr_svchax;
31
32typedef int32_t (*ctr_callback_type)(void);
33
34static inline void ctr_invalidate_ICache_kernel(void)
35{
36 __asm__ volatile(
37 "cpsid aif\n\t"
38 "mov r0, #0\n\t"
39 "mcr p15, 0, r0, c7, c5, 0\n\t");
40}
41
42static inline void ctr_flush_DCache_kernel(void)
43{
44 __asm__ volatile(
45 "cpsid aif\n\t"
46 "mov r0, #0\n\t"
47 "mcr p15, 0, r0, c7, c10, 0\n\t");
48}
49
50static inline void ctr_invalidate_ICache(void)
51{
52 svcBackdoor((ctr_callback_type)ctr_invalidate_ICache_kernel);
53}
54
55static inline void ctr_flush_DCache(void)
56{
57 svcBackdoor((ctr_callback_type)ctr_flush_DCache_kernel);
58}
59
60
61static inline void ctr_flush_invalidate_cache(void)
62{
63 ctr_flush_DCache();
64 ctr_invalidate_ICache();
65}
66
67
fc99395c 68#endif // _3DS_UTILS_H