sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

macros.h (2209B)


      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 #ifdef VERSION_CN
     29 #define UNUSED_CN UNUSED
     30 #else
     31 #define UNUSED_CN
     32 #endif
     33 
     34 // Avoid undefined behaviour for non-returning functions
     35 #ifdef __GNUC__
     36 #define NORETURN __attribute__((noreturn))
     37 #else
     38 #define NORETURN
     39 #endif
     40 
     41 // Static assertions
     42 #ifdef __GNUC__
     43 #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
     44 #else
     45 #define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
     46 #endif
     47 
     48 // Align to 8-byte boundary for DMA requirements
     49 #ifdef __GNUC__
     50 #define ALIGNED8 __attribute__((aligned(8)))
     51 #else
     52 #define ALIGNED8
     53 #endif
     54 
     55 // Align to 16-byte boundary for audio lib requirements
     56 #ifdef __GNUC__
     57 #define ALIGNED16 __attribute__((aligned(16)))
     58 #else
     59 #define ALIGNED16
     60 #endif
     61 
     62 #ifndef NO_SEGMENTED_MEMORY
     63 // convert a virtual address to physical.
     64 #define VIRTUAL_TO_PHYSICAL(addr)   ((uintptr_t)(addr) & 0x1FFFFFFF)
     65 
     66 // convert a physical address to virtual.
     67 #define PHYSICAL_TO_VIRTUAL(addr)   ((uintptr_t)(addr) | 0x80000000)
     68 
     69 // another way of converting virtual to physical
     70 #define VIRTUAL_TO_PHYSICAL2(addr)  ((u8 *)(addr) - 0x80000000U)
     71 #else
     72 // no conversion needed other than cast
     73 #define VIRTUAL_TO_PHYSICAL(addr)   ((uintptr_t)(addr))
     74 #define PHYSICAL_TO_VIRTUAL(addr)   ((uintptr_t)(addr))
     75 #define VIRTUAL_TO_PHYSICAL2(addr)  ((void *)(addr))
     76 #endif
     77 
     78 // Stubbed CN debug prints
     79 #ifdef VERSION_CN
     80 #define CN_DEBUG_PRINTF(args) osSyncPrintf args
     81 #else
     82 #define CN_DEBUG_PRINTF(args)
     83 #endif
     84 
     85 #ifdef VERSION_CN
     86 #define FORCE_BSS __attribute__((nocommon)) __attribute__((section (".bss_cn")))
     87 #else
     88 #define FORCE_BSS
     89 #endif
     90 
     91 #endif // MACROS_H