Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/include/macros.h
7854 views
1
#ifndef MACROS_H
2
#define MACROS_H
3
4
#include "platform_info.h"
5
6
#ifndef __sgi
7
#define GLOBAL_ASM(...)
8
#endif
9
10
#if !defined(__sgi) && (!defined(NON_MATCHING) || !defined(AVOID_UB))
11
// asm-process isn't supported outside of IDO, and undefined behavior causes
12
// crashes.
13
#error Matching build is only possible on IDO; please build with NON_MATCHING=1.
14
#endif
15
16
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
17
18
#define GLUE(a, b) a ## b
19
#define GLUE2(a, b) GLUE(a, b)
20
21
// Avoid compiler warnings for unused variables
22
#ifdef __GNUC__
23
#define UNUSED __attribute__((unused))
24
#else
25
#define UNUSED
26
#endif
27
28
// Avoid undefined behaviour for non-returning functions
29
#ifdef __GNUC__
30
#define NORETURN __attribute__((noreturn))
31
#else
32
#define NORETURN
33
#endif
34
35
// Static assertions
36
#ifdef __GNUC__
37
#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
38
#else
39
#define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
40
#endif
41
42
// Align to 8-byte boundary for DMA requirements
43
#ifdef __GNUC__
44
#define ALIGNED8 __attribute__((aligned(8)))
45
#else
46
#define ALIGNED8
47
#endif
48
49
// Align to 16-byte boundary for audio lib requirements
50
#ifdef __GNUC__
51
#define ALIGNED16 __attribute__((aligned(16)))
52
#else
53
#define ALIGNED16
54
#endif
55
56
#ifndef NO_SEGMENTED_MEMORY
57
// convert a virtual address to physical.
58
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF)
59
60
// convert a physical address to virtual.
61
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) | 0x80000000)
62
63
// another way of converting virtual to physical
64
#define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U)
65
#else
66
// no conversion needed other than cast
67
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr))
68
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr))
69
#define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
70
#endif
71
72
#endif // MACROS_H
73
74