libctru  v1.6.0
types.h
Go to the documentation of this file.
1 /**
2  * @file types.h
3  * @brief Various system types.
4  */
5 #pragma once
6 
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include <stddef.h>
10 
11 /// The maximum value of a u64.
12 #define U64_MAX UINT64_MAX
13 
14 /// would be nice if newlib had this already
15 #ifndef SSIZE_MAX
16 #ifdef SIZE_MAX
17 #define SSIZE_MAX ((SIZE_MAX) >> 1)
18 #endif
19 #endif
20 
21 typedef uint8_t u8; ///< 8-bit unsigned integer
22 typedef uint16_t u16; ///< 16-bit unsigned integer
23 typedef uint32_t u32; ///< 32-bit unsigned integer
24 typedef uint64_t u64; ///< 64-bit unsigned integer
25 
26 typedef int8_t s8; ///< 8-bit signed integer
27 typedef int16_t s16; ///< 16-bit signed integer
28 typedef int32_t s32; ///< 32-bit signed integer
29 typedef int64_t s64; ///< 64-bit signed integer
30 
31 typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
32 typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
33 typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
34 typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
35 
36 typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
37 typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
38 typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
39 typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
40 
41 typedef u32 Handle; ///< Resource handle.
42 typedef s32 Result; ///< Function result.
43 typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function.
44 typedef void (*voidfn)(void);
45 
46 /// Creates a bitmask from a bit number.
47 #define BIT(n) (1U<<(n))
48 
49 /// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m.
50 #define ALIGN(m) __attribute__((aligned(m)))
51 /// Packs a struct (and other types?) so it won't include padding bytes.
52 #define PACKED __attribute__((packed))
53 
54 #ifndef LIBCTRU_NO_DEPRECATION
55 /// Flags a function as deprecated.
56 #define DEPRECATED __attribute__ ((deprecated))
57 #else
58 /// Flags a function as deprecated.
59 #define DEPRECATED
60 #endif
61 
62 /// Structure representing CPU registers
63 typedef struct {
64  u32 r[13]; ///< r0-r12.
65  u32 sp; ///< sp.
66  u32 lr; ///< lr.
67  u32 pc; ///< pc. May need to be adjusted.
68  u32 cpsr; ///< cpsr.
69 } CpuRegisters;
70 
71 /// Structure representing FPU registers
72 typedef struct {
73  union {
74  struct PACKED { double d[16]; }; ///< d0-d15.
75  float s[32]; ///< s0-s31.
76  };
77  u32 fpscr; ///< fpscr.
78  u32 fpexc; ///< fpexc.
79 } FpuRegisters;
volatile u64 vu64
64-bit volatile unsigned integer.
Definition: types.h:34
int8_t s8
8-bit signed integer
Definition: types.h:26
#define PACKED
Packs a struct (and other types?) so it won't include padding bytes.
Definition: types.h:52
volatile u32 vu32
32-bit volatile unsigned integer.
Definition: types.h:33
u32 pc
pc. May need to be adjusted.
Definition: types.h:67
s32 Result
Function result.
Definition: types.h:42
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:43
volatile s64 vs64
64-bit volatile signed integer.
Definition: types.h:39
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
u32 cpsr
cpsr.
Definition: types.h:68
u32 Handle
Resource handle.
Definition: types.h:41
volatile u8 vu8
8-bit volatile unsigned integer.
Definition: types.h:31
volatile s32 vs32
32-bit volatile signed integer.
Definition: types.h:38
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
volatile u16 vu16
16-bit volatile unsigned integer.
Definition: types.h:32
Structure representing CPU registers.
Definition: types.h:63
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
volatile s16 vs16
16-bit volatile signed integer.
Definition: types.h:37
int32_t s32
32-bit signed integer
Definition: types.h:28
volatile s8 vs8
8-bit volatile signed integer.
Definition: types.h:36
u32 fpscr
fpscr.
Definition: types.h:77
Structure representing FPU registers.
Definition: types.h:72
u32 sp
sp.
Definition: types.h:65
int64_t s64
64-bit signed integer
Definition: types.h:29
u32 lr
lr.
Definition: types.h:66
u32 fpexc
fpexc.
Definition: types.h:78
int16_t s16
16-bit signed integer
Definition: types.h:27