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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
use super::responses::*;
use crate::LimineRequest;
use crate::{impl_request, LimineRequestMarker};
use core::{cell::UnsafeCell, ptr::NonNull};

const COMMON_MAGIC: [u64; 2] = [0xc7b1dd30df4c8b88, 0x0a82e883a194f07b];

#[macro_export]
/// Implement `new` for structs with the proper ID values
macro_rules! impl_request {
    ($id1:expr, $id2:expr, $item:ident) => {
        impl $item {
            /// The ID of the request
            pub const ID: [u64; 4] = [COMMON_MAGIC[0], COMMON_MAGIC[1], $id1, $id2];

            /// Return a new instance of the item with the correct ID values
            pub fn new() -> $item {
                Self {
                    id: Self::ID,
                    ..Self::default()
                }
            }

            /// Convert the request into a [LimineRequest]
            pub const fn into_request(self) -> LimineRequest<Self> {
                LimineRequest(UnsafeCell::new(self))
            }
        }

        impl LimineRequestMarker for $item {}
    };
}

#[macro_export]
/// Implement `new` for structs with lifetimes with the proper ID values
macro_rules! impl_request_with_lifetime {
    ($id1:expr, $id2:expr, $item:ident) => {
        impl<'a> $item<'a> {
            /// The ID of the request
            pub const ID: [u64; 4] = [COMMON_MAGIC[0], COMMON_MAGIC[1], $id1, $id2];

            /// Return a new instance of the item with the correct ID values
            pub fn new() -> $item<'a> {
                Self {
                    id: [COMMON_MAGIC[0], COMMON_MAGIC[1], $id1, $id2],
                    ..Self::default()
                }
            }

            /// Convert the request into a [LimineRequest]
            pub const fn into_request(self) -> LimineRequest<Self> {
                LimineRequest(UnsafeCell::new(self))
            }
        }

        impl<'a> LimineRequestMarker for $item<'a> {}
    };
}

#[repr(C)]
#[derive(Debug, Default)]
/// Get information regarding the bootloader
pub struct InfoRequest<'a> {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<InfoResponse<'a>>>,
}

impl_request_with_lifetime!(0xf55038d8e2a1202f, 0x279426fcf5f59740, InfoRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Specify how much stack you desire the bootloader to give you
pub struct StackSizeRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<StackSizeResponse>>,
    /// The amount of stack to request
    pub stack_size: u64,
}

impl_request!(0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d, StackSizeRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request Higher Half Direct Mapping be enabled
pub struct HHDMRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<HHDMResponse>>,
}

impl_request!(0x48dcf1cb8ad2b852, 0x63984e959a98244b, HHDMRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request a terminal
pub struct TerminalRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<TerminalResponse>>,
}

impl_request!(0x0785a0aea5d0750f, 0x1c1936fee0d6cf6e, TerminalRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request a framebuffer
pub struct FramebufferRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<FramebufferResponse>>,
}

impl_request!(0xcbfe81d7dd2d1977, 0x063150319ebc9b71, FramebufferRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request Level 5 paging be enabled
pub struct Level5PagingRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<Level5PagingResponse>>,
}

impl_request!(0x94469551da9b3192, 0xebe5e86db7382888, Level5PagingRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the bootloader bootstrap the secondary processors
pub struct SMPRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<SMPResponse>>,
    /// Flags for the bootloader
    /// `Bit 0` - Enable X2APIC if available
    pub flags: u64,
}

impl_request!(0x95a67b819a1b857e, 0xa0b61b723b6a73e0, SMPRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request for receiving the Memory Map from the bootloader
pub struct MemoryMapRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<MemoryMapResponse>>,
}

impl_request!(0x67cf3d9d378a806f, 0xe304acdfc50c3c62, MemoryMapRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the bootloader use the specified entry point instead of the default one
pub struct EntryPointRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<EntryPointResponse>>,
    /// Function to the entry point
    pub entry: Option<*mut ()>,
}

impl_request!(0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a, EntryPointRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the file the Kernel was loaded from
pub struct KernelFileRequest<'a> {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<KernelFileResponse<'a>>>,
}

impl_request_with_lifetime!(0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69, KernelFileRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the loaded modules
pub struct ModuleRequest<'a> {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<ModuleResponse<'a>>>,
}

impl_request_with_lifetime!(0x3e7e279702be32af, 0xca1c4f3bd1280cee, ModuleRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the address of the RSDP
pub struct RSDPRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<RSDPResponse>>,
}

impl_request!(0xc5e77b6b397e7b43, 0x27637845accdcf3c, RSDPRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the SMBIOS entry point
pub struct SMBIOSRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<SMBIOSResponse>>,
}

impl_request!(0x9e9046f11e095391, 0xaa4a520fefbde5ee, SMBIOSRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the address of the EFI System Table
pub struct EfiSystemTableRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<EfiSystemTableResponse>>,
}

impl_request!(
    0x5ceba5163eaaf6d6,
    0x0a6981610cf65fcc,
    EfiSystemTableRequest
);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the time on boot
pub struct BootTimeRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<BootTimeResponse>>,
}

impl_request!(0x502746e184c088aa, 0xfbc5ec83e6327893, BootTimeRequest);

#[repr(C)]
#[derive(Debug, Default)]
/// Request the physical and virtual address of the Kernel
pub struct KernelAddressRequest {
    /// ID Array
    pub id: [u64; 4],
    /// Revision numbers
    pub revision: u64,
    /// Response pointer
    pub response: Option<NonNull<KernelAddressResponse>>,
}

impl_request!(0x71ba76863cc55f63, 0xb2644a48c516a487, KernelAddressRequest);