Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/utils/types.h
1476 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2022 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef _TYPES_H_
19
#define _TYPES_H_
20
21
#include <assert.h>
22
23
/* Types */
24
typedef signed char s8;
25
typedef short s16;
26
typedef short SHORT;
27
typedef int s32;
28
typedef int INT;
29
typedef int bool;
30
typedef long LONG;
31
typedef long long int s64;
32
33
typedef unsigned char u8;
34
typedef unsigned char BYTE;
35
typedef unsigned short u16;
36
typedef unsigned short WORD;
37
typedef unsigned short WCHAR;
38
typedef unsigned int u32;
39
typedef unsigned int UINT;
40
typedef unsigned long DWORD;
41
typedef unsigned long long QWORD;
42
typedef unsigned long long int u64;
43
44
typedef volatile unsigned char vu8;
45
typedef volatile unsigned short vu16;
46
typedef volatile unsigned int vu32;
47
48
#ifdef __aarch64__
49
typedef unsigned long long uptr;
50
#else /* __arm__ or __thumb__ */
51
typedef unsigned long uptr;
52
#endif
53
54
/* Important */
55
#define false 0
56
#define true 1
57
58
#define NULL ((void *)0)
59
60
/* Misc */
61
#define DISABLE 0
62
#define ENABLE 1
63
64
/* Sizes */
65
#define SZ_1K 0x400
66
#define SZ_2K 0x800
67
#define SZ_4K 0x1000
68
#define SZ_8K 0x2000
69
#define SZ_16K 0x4000
70
#define SZ_32K 0x8000
71
#define SZ_64K 0x10000
72
#define SZ_128K 0x20000
73
#define SZ_256K 0x40000
74
#define SZ_512K 0x80000
75
#define SZ_1M 0x100000
76
#define SZ_2M 0x200000
77
#define SZ_4M 0x400000
78
#define SZ_8M 0x800000
79
#define SZ_16M 0x1000000
80
#define SZ_32M 0x2000000
81
#define SZ_64M 0x4000000
82
#define SZ_128M 0x8000000
83
#define SZ_256M 0x10000000
84
#define SZ_512M 0x20000000
85
#define SZ_1G 0x40000000
86
#define SZ_2G 0x80000000
87
#define SZ_PAGE SZ_4K
88
89
/* Macros */
90
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
91
#define ALIGN_DOWN(x, a) ((x) & ~((a) - 1))
92
#define BIT(n) (1U << (n))
93
#define MAX(a, b) ((a) > (b) ? (a) : (b))
94
#define MIN(a, b) ((a) < (b) ? (a) : (b))
95
96
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
97
98
#define OFFSET_OF(t, m) ((uptr)&((t *)NULL)->m)
99
#define CONTAINER_OF(mp, t, mn) ((t *)((uptr)mp - OFFSET_OF(t, mn)))
100
101
#define byte_swap_16(num) ((((num) >> 8) & 0xFF) | (((num) & 0xFF) << 8))
102
#define byte_swap_32(num) ((((num) >> 24) & 0xFF) | (((num) & 0xFF00) << 8 ) | \
103
(((num) >> 8 ) & 0xFF00) | (((num) & 0xFF) << 24))
104
105
#define likely(x) (__builtin_expect((x) != 0, 1))
106
#define unlikely(x) (__builtin_expect((x) != 0, 0))
107
108
/* Bootloader/Nyx */
109
#define BOOT_CFG_AUTOBOOT_EN BIT(0)
110
#define BOOT_CFG_FROM_LAUNCH BIT(1)
111
#define BOOT_CFG_FROM_ID BIT(2)
112
#define BOOT_CFG_TO_EMUMMC BIT(3)
113
114
#define EXTRA_CFG_KEYS BIT(0)
115
#define EXTRA_CFG_PAYLOAD BIT(1)
116
#define EXTRA_CFG_MODULE BIT(2)
117
118
#define EXTRA_CFG_NYX_UMS BIT(5)
119
#define EXTRA_CFG_NYX_RELOAD BIT(6)
120
121
typedef enum _nyx_ums_type
122
{
123
NYX_UMS_SD_CARD = 0,
124
NYX_UMS_EMMC_BOOT0,
125
NYX_UMS_EMMC_BOOT1,
126
NYX_UMS_EMMC_GPP,
127
NYX_UMS_EMUMMC_BOOT0,
128
NYX_UMS_EMUMMC_BOOT1,
129
NYX_UMS_EMUMMC_GPP
130
} nyx_ums_type;
131
132
typedef struct __attribute__((__packed__)) _boot_cfg_t
133
{
134
u8 boot_cfg;
135
u8 autoboot;
136
u8 autoboot_list;
137
u8 extra_cfg;
138
union
139
{
140
struct
141
{
142
char id[8]; // 7 char ASCII null terminated.
143
char emummc_path[0x78]; // emuMMC/XXX, ASCII null terminated.
144
};
145
u8 ums; // nyx_ums_type.
146
u8 xt_str[0x80];
147
};
148
} boot_cfg_t;
149
150
static_assert(sizeof(boot_cfg_t) == 0x84, "Boot cfg storage size is wrong!");
151
152
typedef struct __attribute__((__packed__)) _ipl_ver_meta_t
153
{
154
u32 magic;
155
u32 version;
156
u16 rsvd0;
157
u16 rsvd1;
158
} ipl_ver_meta_t;
159
160
typedef struct __attribute__((__packed__)) _reloc_meta_t
161
{
162
u32 start;
163
u32 stack;
164
u32 end;
165
u32 ep;
166
} reloc_meta_t;
167
168
#endif
169
170