1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
use core::{mem, fmt};
#[repr(C)]
#[derive(Debug)]
pub struct EFI_TIME {
pub Year: UINT16,
pub Month: UINT8,
pub Day: UINT8,
pub Hour: UINT8,
pub Minute: UINT8,
pub Second: UINT8,
pub Pad1: UINT8,
pub Nanosecond: UINT32,
pub TimeZone: INT16,
pub Daylight: UINT8,
pub Pad2: UINT8,
}
impl EFI_TIME {
pub fn zero() -> Self {
EFI_TIME {
Year: 0,
Month: 0,
Day: 0,
Hour: 0,
Minute: 0,
Second: 0,
Pad1: 0,
Nanosecond: 0,
TimeZone: 0,
Daylight: 0,
Pad2: 0,
}
}
}
impl Default for EFI_TIME {
fn default() -> Self {
Self::zero()
}
}
pub const EFI_TIME_ADJUST_DAYLIGHT: UINTN = 0x01;
pub const EFI_TIME_IN_DAYLIGHT: UINTN = 0x02;
pub const EFI_UNSPECIFIED_TIMEZONE: UINTN = 0x07FF;
#[repr(C)]
#[derive(Debug)]
pub struct EFI_TIME_CAPABILITIES {
pub Resolution: UINT32,
pub Accuracy: UINT32,
pub SetsToZero: BOOLEAN,
}
impl EFI_TIME_CAPABILITIES {
pub fn zero() -> Self {
Self {
Resolution: 0,
Accuracy: 0,
SetsToZero: 0,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct EFI_IPv4_ADDRESS {
pub Addr: [UINT8; 4],
}
impl EFI_IPv4_ADDRESS {
pub fn zero() -> Self {
Self { Addr: [0, 0, 0, 0] }
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct EFI_IPv6_ADDRESS {
pub Addr: [UINT8; 16],
}
impl EFI_IPv6_ADDRESS {
pub fn zero() -> Self {
Self { Addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
}
}
#[derive(PartialEq, Eq)]
#[repr(C)]
pub struct EFI_MAC_ADDRESS {
pub Addr: [UINT8; 32],
}
impl EFI_MAC_ADDRESS {
pub fn zero() -> Self {
Self { Addr: [0; 32] }
}
}
impl Default for EFI_MAC_ADDRESS {
fn default() -> Self {
Self::zero()
}
}
impl fmt::Debug for EFI_MAC_ADDRESS {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("EFI_MAC_ADDRESS ")
.field("Addr", &format_args!("{:x?}", self.Addr))
.finish()
}
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union EFI_IP_ADDRESS {
pub Addr: [UINT32; 4],
pub v4: EFI_IPv4_ADDRESS,
pub v6: EFI_IPv6_ADDRESS,
}
impl EFI_IP_ADDRESS {
pub fn zero() -> Self {
Self { Addr: [0; 4] }
}
}
impl fmt::Debug for EFI_IP_ADDRESS {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("EFI_IP_ADDRESS")
.field("Addr", &format_args!("{:?}", unsafe { self.Addr }))
.finish()
}
}
pub type EFI_PHYSICAL_ADDRESS = UINT64;
#[derive(Debug)]
#[repr(C)]
pub struct EFI_TABLE_HEADER {
Signature : UINT64,
Revision : UINT32,
HeaderSize : UINT32,
CRC32 : UINT32,
Reserved : UINT32
}
macro_rules! with_high_bit_set {
($num:expr) => { (1 << ((mem::size_of::<UINTN>() * 8) - 1)) | $num };
}
pub const EFI_SUCCESS: UINTN = 0;
pub const EFI_LOAD_ERROR: UINTN = with_high_bit_set!(1);
pub const EFI_INVALID_PARAMETER: UINTN = with_high_bit_set!(2);
pub const EFI_UNSUPPORTED: UINTN = with_high_bit_set!(3);
pub const EFI_BAD_BUFFER_SIZE: UINTN = with_high_bit_set!(4);
pub const EFI_BUFFER_TOO_SMALL: UINTN = with_high_bit_set!(5);
pub const EFI_NOT_READY: UINTN = with_high_bit_set!(6);
pub const EFI_DEVICE_ERROR: UINTN = with_high_bit_set!(7);
pub const EFI_WRITE_PROTECTED: UINTN = with_high_bit_set!(8);
pub const EFI_OUT_OF_RESOURCES: UINTN = with_high_bit_set!(9);
pub const EFI_VOLUME_CORRUPTED: UINTN = with_high_bit_set!(10);
pub const EFI_VOLUME_FULL: UINTN = with_high_bit_set!(11);
pub const EFI_NO_MEDIA: UINTN = with_high_bit_set!(12);
pub const EFI_MEDIA_CHANGED: UINTN = with_high_bit_set!(13);
pub const EFI_NOT_FOUND: UINTN = with_high_bit_set!(14);
pub const EFI_ACCESS_DENIED: UINTN = with_high_bit_set!(15);
pub const EFI_NO_RESPONSE: UINTN = with_high_bit_set!(16);
pub const EFI_NO_MAPPING: UINTN = with_high_bit_set!(17);
pub const EFI_TIMEOUT: UINTN = with_high_bit_set!(18);
pub const EFI_NOT_STARTED: UINTN = with_high_bit_set!(19);
pub const EFI_ALREADY_STARTED: UINTN = with_high_bit_set!(20);
pub const EFI_ABORTED: UINTN = with_high_bit_set!(21);
pub const EFI_ICMP_ERROR: UINTN = with_high_bit_set!(22);
pub const EFI_TFTP_ERROR: UINTN = with_high_bit_set!(23);
pub const EFI_PROTOCOL_ERROR: UINTN = with_high_bit_set!(24);
pub const EFI_INCOMPATIBLE_VERSION: UINTN = with_high_bit_set!(25);
pub const EFI_SECURITY_VIOLATION: UINTN = with_high_bit_set!(26);
pub const EFI_CRC_ERROR: UINTN = with_high_bit_set!(27);
pub const EFI_END_OF_MEDIA: UINTN = with_high_bit_set!(28);
pub const EFI_END_OF_FILE: UINTN = with_high_bit_set!(31);
pub const EFI_INVALID_LANGUAGE: UINTN = with_high_bit_set!(32);
pub const EFI_COMPROMISED_DATA: UINTN = with_high_bit_set!(33);
pub const EFI_IP_ADDRESS_CONFLICT: UINTN = with_high_bit_set!(34);
pub const EFI_WARN_UNKNOWN_GLYPH: UINTN = 1;
pub const EFI_WARN_DELETE_FAILURE: UINTN = 2;
pub const EFI_WARN_WRITE_FAILURE: UINTN = 3;
pub const EFI_WARN_BUFFER_TOO_SMALL: UINTN = 4;
pub const EFI_WARN_STALE_DATA: UINTN = 5;
#[derive(Debug, PartialEq, Eq)]
pub enum EFI_STATUS_TYPE {
SUCCESS,
ERROR,
WARNING
}
fn has_high_bit_set(value: UINTN) -> bool {
((1 << ((mem::size_of::<UINTN>() * 8) - 1)) & value) != 0
}
pub fn StatusType(status: EFI_STATUS) -> EFI_STATUS_TYPE {
match status {
EFI_SUCCESS => EFI_STATUS_TYPE::SUCCESS,
s if has_high_bit_set(s) => EFI_STATUS_TYPE::ERROR,
_ => EFI_STATUS_TYPE::WARNING
}
}
pub fn IsSuccess(status: EFI_STATUS) -> bool {
StatusType(status) == EFI_STATUS_TYPE::SUCCESS
}
pub fn IsError(status: EFI_STATUS) -> bool {
StatusType(status) == EFI_STATUS_TYPE::ERROR
}
pub fn IsWarning(status: EFI_STATUS) -> bool {
StatusType(status) == EFI_STATUS_TYPE::WARNING
}
pub type UINT64 = u64;
pub type INT64 = i64;
pub type UINT32 = u32;
pub type INT32 = i32;
pub type UINT16 = u16;
pub type CHAR16 = u16;
pub type INT16 = i16;
pub type BOOLEAN = u8;
pub type UINT8 = u8;
pub type CHAR8 = i8;
pub type INT8 = i8;
pub type UINTN = usize;
pub const TRUE: BOOLEAN = 1;
pub const FALSE: BOOLEAN = 0;
#[derive(Copy, Clone)]
pub enum VOID { }
pub type EFI_HANDLE = *const VOID;
pub type EFI_EVENT = *const VOID;
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EFI_GUID(pub UINT32, pub UINT16, pub UINT16, pub [UINT8; 8]);
pub type EFI_STATUS = UINTN;
pub enum NOT_DEFINED {}