OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
limine.h
1/* SPDX-License-Identifier: 0BSD */
2
3/* Copyright (C) 2022-2026 Mintsuki and contributors.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef LIMINE_H
18#define LIMINE_H 1
19
20#include <stdint.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* Misc */
27
28#ifdef LIMINE_NO_POINTERS
29# define LIMINE_PTR(TYPE) uint64_t
30#else
31# define LIMINE_PTR(TYPE) TYPE
32#endif
33
34#define LIMINE_REQUESTS_START_MARKER { 0xf6b8f4b39de7d1ae, 0xfab91a6940fcb9cf, \
35 0x785c6ed015d3e316, 0x181e920a7852b9d9 }
36#define LIMINE_REQUESTS_END_MARKER { 0xadc0e0531bb10d03, 0x9572709f31764c62 }
37
38#define LIMINE_BASE_REVISION(N) { 0xf9562b2d5c95a6c8, 0x6a7b384944536bdc, (N) }
39
40#define LIMINE_BASE_REVISION_SUPPORTED(VAR) ((VAR)[2] == 0)
41
42#define LIMINE_LOADED_BASE_REVISION_VALID(VAR) ((VAR)[1] != 0x6a7b384944536bdc)
43#define LIMINE_LOADED_BASE_REVISION(VAR) ((VAR)[1])
44
45#define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
46
47struct limine_uuid {
48 uint32_t a;
49 uint16_t b;
50 uint16_t c;
51 uint8_t d[8];
52};
53
54#define LIMINE_MEDIA_TYPE_GENERIC 0
55#define LIMINE_MEDIA_TYPE_OPTICAL 1
56#define LIMINE_MEDIA_TYPE_TFTP 2
57
58struct limine_file {
59 uint64_t revision;
60 LIMINE_PTR(void *) address;
61 uint64_t size;
62 LIMINE_PTR(char *) path;
63 LIMINE_PTR(char *) string;
64 uint32_t media_type;
65 uint32_t unused;
66 uint32_t tftp_ip;
67 uint32_t tftp_port;
68 uint32_t partition_index;
69 uint32_t mbr_disk_id;
70 struct limine_uuid gpt_disk_uuid;
71 struct limine_uuid gpt_part_uuid;
72 struct limine_uuid part_uuid;
73};
74
75/* Boot info */
76
77#define LIMINE_BOOTLOADER_INFO_REQUEST_ID { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
78
79struct limine_bootloader_info_response {
80 uint64_t revision;
81 LIMINE_PTR(char *) name;
82 LIMINE_PTR(char *) version;
83};
84
85struct limine_bootloader_info_request {
86 uint64_t id[4];
87 uint64_t revision;
88 LIMINE_PTR(struct limine_bootloader_info_response *) response;
89};
90
91/* Executable command line */
92
93#define LIMINE_EXECUTABLE_CMDLINE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x4b161536e598651e, 0xb390ad4a2f1f303a }
94
95struct limine_executable_cmdline_response {
96 uint64_t revision;
97 LIMINE_PTR(char *) cmdline;
98};
99
100struct limine_executable_cmdline_request {
101 uint64_t id[4];
102 uint64_t revision;
103 LIMINE_PTR(struct limine_executable_cmdline_response *) response;
104};
105
106/* Firmware type */
107
108#define LIMINE_FIRMWARE_TYPE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x8c2f75d90bef28a8, 0x7045a4688eac00c3 }
109
110#define LIMINE_FIRMWARE_TYPE_X86BIOS 0
111#define LIMINE_FIRMWARE_TYPE_EFI32 1
112#define LIMINE_FIRMWARE_TYPE_EFI64 2
113#define LIMINE_FIRMWARE_TYPE_SBI 3
114
115struct limine_firmware_type_response {
116 uint64_t revision;
117 uint64_t firmware_type;
118};
119
120struct limine_firmware_type_request {
121 uint64_t id[4];
122 uint64_t revision;
123 LIMINE_PTR(struct limine_firmware_type_response *) response;
124};
125
126/* Stack size */
127
128#define LIMINE_STACK_SIZE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
129
130struct limine_stack_size_response {
131 uint64_t revision;
132};
133
134struct limine_stack_size_request {
135 uint64_t id[4];
136 uint64_t revision;
137 LIMINE_PTR(struct limine_stack_size_response *) response;
138 uint64_t stack_size;
139};
140
141/* HHDM */
142
143#define LIMINE_HHDM_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
144
145struct limine_hhdm_response {
146 uint64_t revision;
147 uint64_t offset;
148};
149
150struct limine_hhdm_request {
151 uint64_t id[4];
152 uint64_t revision;
153 LIMINE_PTR(struct limine_hhdm_response *) response;
154};
155
156/* Framebuffer */
157
158#define LIMINE_FRAMEBUFFER_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
159
160#define LIMINE_FRAMEBUFFER_RGB 1
161
162struct limine_video_mode {
163 uint64_t pitch;
164 uint64_t width;
165 uint64_t height;
166 uint16_t bpp;
167 uint8_t memory_model;
168 uint8_t red_mask_size;
169 uint8_t red_mask_shift;
170 uint8_t green_mask_size;
171 uint8_t green_mask_shift;
172 uint8_t blue_mask_size;
173 uint8_t blue_mask_shift;
174};
175
176struct limine_framebuffer {
177 LIMINE_PTR(void *) address;
178 uint64_t width;
179 uint64_t height;
180 uint64_t pitch;
181 uint16_t bpp;
182 uint8_t memory_model;
183 uint8_t red_mask_size;
184 uint8_t red_mask_shift;
185 uint8_t green_mask_size;
186 uint8_t green_mask_shift;
187 uint8_t blue_mask_size;
188 uint8_t blue_mask_shift;
189 uint8_t unused[7];
190 uint64_t edid_size;
191 LIMINE_PTR(void *) edid;
192 /* Response revision 1 */
193 uint64_t mode_count;
194 LIMINE_PTR(struct limine_video_mode **) modes;
195};
196
197struct limine_framebuffer_response {
198 uint64_t revision;
199 uint64_t framebuffer_count;
200 LIMINE_PTR(struct limine_framebuffer **) framebuffers;
201};
202
203struct limine_framebuffer_request {
204 uint64_t id[4];
205 uint64_t revision;
206 LIMINE_PTR(struct limine_framebuffer_response *) response;
207};
208
209/* Paging mode */
210
211#define LIMINE_PAGING_MODE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x95c1a0edab0944cb, 0xa4e5cb3842f7488a }
212
213#define LIMINE_PAGING_MODE_X86_64_4LVL 0
214#define LIMINE_PAGING_MODE_X86_64_5LVL 1
215#define LIMINE_PAGING_MODE_X86_64_MIN LIMINE_PAGING_MODE_X86_64_4LVL
216#define LIMINE_PAGING_MODE_X86_64_DEFAULT LIMINE_PAGING_MODE_X86_64_4LVL
217
218#define LIMINE_PAGING_MODE_AARCH64_4LVL 0
219#define LIMINE_PAGING_MODE_AARCH64_5LVL 1
220#define LIMINE_PAGING_MODE_AARCH64_MIN LIMINE_PAGING_MODE_AARCH64_4LVL
221#define LIMINE_PAGING_MODE_AARCH64_DEFAULT LIMINE_PAGING_MODE_AARCH64_4LVL
222
223#define LIMINE_PAGING_MODE_RISCV_SV39 0
224#define LIMINE_PAGING_MODE_RISCV_SV48 1
225#define LIMINE_PAGING_MODE_RISCV_SV57 2
226#define LIMINE_PAGING_MODE_RISCV_MIN LIMINE_PAGING_MODE_RISCV_SV39
227#define LIMINE_PAGING_MODE_RISCV_DEFAULT LIMINE_PAGING_MODE_RISCV_SV48
228
229#define LIMINE_PAGING_MODE_LOONGARCH_4LVL 0
230#define LIMINE_PAGING_MODE_LOONGARCH_MIN LIMINE_PAGING_MODE_LOONGARCH_4LVL
231#define LIMINE_PAGING_MODE_LOONGARCH_DEFAULT LIMINE_PAGING_MODE_LOONGARCH_4LVL
232
233struct limine_paging_mode_response {
234 uint64_t revision;
235 uint64_t mode;
236};
237
238struct limine_paging_mode_request {
239 uint64_t id[4];
240 uint64_t revision;
241 LIMINE_PTR(struct limine_paging_mode_response *) response;
242 uint64_t mode;
243 uint64_t max_mode;
244 uint64_t min_mode;
245};
246
247/* MP */
248
249#define LIMINE_MP_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
250
251struct limine_mp_info;
252
253typedef void (*limine_goto_address)(struct limine_mp_info *);
254
255#if defined (__x86_64__) || defined (__i386__)
256
257#define LIMINE_MP_RESPONSE_X86_64_X2APIC (1 << 0)
258
259struct limine_mp_info {
260 uint32_t processor_id;
261 uint32_t lapic_id;
262 uint64_t reserved;
263 LIMINE_PTR(limine_goto_address) goto_address;
264 uint64_t extra_argument;
265};
266
267struct limine_mp_response {
268 uint64_t revision;
269 uint32_t flags;
270 uint32_t bsp_lapic_id;
271 uint64_t cpu_count;
272 LIMINE_PTR(struct limine_mp_info **) cpus;
273};
274
275#elif defined (__aarch64__)
276
277struct limine_mp_info {
278 uint32_t processor_id;
279 uint32_t reserved1;
280 uint64_t mpidr;
281 uint64_t reserved;
282 LIMINE_PTR(limine_goto_address) goto_address;
283 uint64_t extra_argument;
284};
285
286struct limine_mp_response {
287 uint64_t revision;
288 uint64_t flags;
289 uint64_t bsp_mpidr;
290 uint64_t cpu_count;
291 LIMINE_PTR(struct limine_mp_info **) cpus;
292};
293
294#elif defined (__riscv) && (__riscv_xlen == 64)
295
296struct limine_mp_info {
297 uint64_t processor_id;
298 uint64_t hartid;
299 uint64_t reserved;
300 LIMINE_PTR(limine_goto_address) goto_address;
301 uint64_t extra_argument;
302};
303
304struct limine_mp_response {
305 uint64_t revision;
306 uint64_t flags;
307 uint64_t bsp_hartid;
308 uint64_t cpu_count;
309 LIMINE_PTR(struct limine_mp_info **) cpus;
310};
311
312#elif defined (__loongarch__) && (__loongarch_grlen == 64)
313
314struct limine_mp_info {
315 uint64_t reserved;
316};
317
318struct limine_mp_response {
319 uint64_t cpu_count;
320 LIMINE_PTR(struct limine_mp_info **) cpus;
321};
322
323#else
324#error Unknown architecture
325#endif
326
327#define LIMINE_MP_REQUEST_X86_64_X2APIC (1 << 0)
328
329struct limine_mp_request {
330 uint64_t id[4];
331 uint64_t revision;
332 LIMINE_PTR(struct limine_mp_response *) response;
333 uint64_t flags;
334};
335
336/* Memory map */
337
338#define LIMINE_MEMMAP_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
339
340#define LIMINE_MEMMAP_USABLE 0
341#define LIMINE_MEMMAP_RESERVED 1
342#define LIMINE_MEMMAP_ACPI_RECLAIMABLE 2
343#define LIMINE_MEMMAP_ACPI_NVS 3
344#define LIMINE_MEMMAP_BAD_MEMORY 4
345#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
346#define LIMINE_MEMMAP_EXECUTABLE_AND_MODULES 6
347#define LIMINE_MEMMAP_FRAMEBUFFER 7
348#define LIMINE_MEMMAP_ACPI_TABLES 8
349
350struct limine_memmap_entry {
351 uint64_t base;
352 uint64_t length;
353 uint64_t type;
354};
355
356struct limine_memmap_response {
357 uint64_t revision;
358 uint64_t entry_count;
359 LIMINE_PTR(struct limine_memmap_entry **) entries;
360};
361
362struct limine_memmap_request {
363 uint64_t id[4];
364 uint64_t revision;
365 LIMINE_PTR(struct limine_memmap_response *) response;
366};
367
368/* Entry point */
369
370#define LIMINE_ENTRY_POINT_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
371
372typedef void (*limine_entry_point)(void);
373
374struct limine_entry_point_response {
375 uint64_t revision;
376};
377
378struct limine_entry_point_request {
379 uint64_t id[4];
380 uint64_t revision;
381 LIMINE_PTR(struct limine_entry_point_response *) response;
382 LIMINE_PTR(limine_entry_point) entry;
383};
384
385/* Executable File */
386
387#define LIMINE_EXECUTABLE_FILE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
388
389struct limine_executable_file_response {
390 uint64_t revision;
391 LIMINE_PTR(struct limine_file *) executable_file;
392};
393
394struct limine_executable_file_request {
395 uint64_t id[4];
396 uint64_t revision;
397 LIMINE_PTR(struct limine_executable_file_response *) response;
398};
399
400/* Module */
401
402#define LIMINE_MODULE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
403
404#define LIMINE_INTERNAL_MODULE_REQUIRED (1 << 0)
405#define LIMINE_INTERNAL_MODULE_COMPRESSED (1 << 1)
406
407struct limine_internal_module {
408 LIMINE_PTR(const char *) path;
409 LIMINE_PTR(const char *) string;
410 uint64_t flags;
411};
412
413struct limine_module_response {
414 uint64_t revision;
415 uint64_t module_count;
416 LIMINE_PTR(struct limine_file **) modules;
417};
418
419struct limine_module_request {
420 uint64_t id[4];
421 uint64_t revision;
422 LIMINE_PTR(struct limine_module_response *) response;
423
424 /* Request revision 1 */
425 uint64_t internal_module_count;
426 LIMINE_PTR(struct limine_internal_module **) internal_modules;
427};
428
429/* RSDP */
430
431#define LIMINE_RSDP_REQUEST_ID { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
432
433struct limine_rsdp_response {
434 uint64_t revision;
435 LIMINE_PTR(void *) address;
436};
437
438struct limine_rsdp_request {
439 uint64_t id[4];
440 uint64_t revision;
441 LIMINE_PTR(struct limine_rsdp_response *) response;
442};
443
444/* SMBIOS */
445
446#define LIMINE_SMBIOS_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
447
448struct limine_smbios_response {
449 uint64_t revision;
450 uint64_t entry_32;
451 uint64_t entry_64;
452};
453
454struct limine_smbios_request {
455 uint64_t id[4];
456 uint64_t revision;
457 LIMINE_PTR(struct limine_smbios_response *) response;
458};
459
460/* EFI system table */
461
462#define LIMINE_EFI_SYSTEM_TABLE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
463
464struct limine_efi_system_table_response {
465 uint64_t revision;
466 uint64_t address;
467};
468
469struct limine_efi_system_table_request {
470 uint64_t id[4];
471 uint64_t revision;
472 LIMINE_PTR(struct limine_efi_system_table_response *) response;
473};
474
475/* EFI memory map */
476
477#define LIMINE_EFI_MEMMAP_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x7df62a431d6872d5, 0xa4fcdfb3e57306c8 }
478
479struct limine_efi_memmap_response {
480 uint64_t revision;
481 LIMINE_PTR(void *) memmap;
482 uint64_t memmap_size;
483 uint64_t desc_size;
484 uint64_t desc_version;
485};
486
487struct limine_efi_memmap_request {
488 uint64_t id[4];
489 uint64_t revision;
490 LIMINE_PTR(struct limine_efi_memmap_response *) response;
491};
492
493/* Date at boot */
494
495#define LIMINE_DATE_AT_BOOT_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
496
497struct limine_date_at_boot_response {
498 uint64_t revision;
499 int64_t timestamp;
500};
501
502struct limine_date_at_boot_request {
503 uint64_t id[4];
504 uint64_t revision;
505 LIMINE_PTR(struct limine_date_at_boot_response *) response;
506};
507
508/* Executable address */
509
510#define LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
511
512struct limine_executable_address_response {
513 uint64_t revision;
514 uint64_t physical_base;
515 uint64_t virtual_base;
516};
517
518struct limine_executable_address_request {
519 uint64_t id[4];
520 uint64_t revision;
521 LIMINE_PTR(struct limine_executable_address_response *) response;
522};
523
524/* Device Tree Blob */
525
526#define LIMINE_DTB_REQUEST_ID { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
527
528struct limine_dtb_response {
529 uint64_t revision;
530 LIMINE_PTR(void *) dtb_ptr;
531};
532
533struct limine_dtb_request {
534 uint64_t id[4];
535 uint64_t revision;
536 LIMINE_PTR(struct limine_dtb_response *) response;
537};
538
539/* RISC-V Boot Hart ID */
540
541#define LIMINE_RISCV_BSP_HARTID_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x1369359f025525f9, 0x2ff2a56178391bb6 }
542
543struct limine_riscv_bsp_hartid_response {
544 uint64_t revision;
545 uint64_t bsp_hartid;
546};
547
548struct limine_riscv_bsp_hartid_request {
549 uint64_t id[4];
550 uint64_t revision;
551 LIMINE_PTR(struct limine_riscv_bsp_hartid_response *) response;
552};
553
554/* Bootloader Performance */
555
556#define LIMINE_BOOTLOADER_PERFORMANCE_REQUEST_ID { LIMINE_COMMON_MAGIC, 0x6b50ad9bf36d13ad, 0xdc4c7e88fc759e17 }
557
558struct limine_bootloader_performance_response {
559 uint64_t revision;
560 uint64_t reset_usec;
561 uint64_t init_usec;
562 uint64_t exec_usec;
563};
564
565struct limine_bootloader_performance_request {
566 uint64_t id[4];
567 uint64_t revision;
568 LIMINE_PTR(struct limine_bootloader_performance_response *) response;
569};
570
571#ifdef __cplusplus
572}
573#endif
574
575#endif