1/* BSD Zero Clause License */
2
3/* Copyright (C) 2022-2024 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#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <stdint.h>
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#ifdef __GNUC__
35# define LIMINE_DEPRECATED __attribute__((__deprecated__))
36# define LIMINE_DEPRECATED_IGNORE_START \
37 _Pragma("GCC diagnostic push") \
38 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
39# define LIMINE_DEPRECATED_IGNORE_END \
40 _Pragma("GCC diagnostic pop")
41#else
42# define LIMINE_DEPRECATED
43# define LIMINE_DEPRECATED_IGNORE_START
44# define LIMINE_DEPRECATED_IGNORE_END
45#endif
46
47#define LIMINE_REQUESTS_START_MARKER \
48 uint64_t limine_requests_start_marker[4] = { 0xf6b8f4b39de7d1ae, 0xfab91a6940fcb9cf, \
49 0x785c6ed015d3e316, 0x181e920a7852b9d9 };
50#define LIMINE_REQUESTS_END_MARKER \
51 uint64_t limine_requests_end_marker[2] = { 0xadc0e0531bb10d03, 0x9572709f31764c62 };
52
53#define LIMINE_REQUESTS_DELIMITER LIMINE_REQUESTS_END_MARKER
54
55#define LIMINE_BASE_REVISION(N) \
56 uint64_t limine_base_revision[3] = { 0xf9562b2d5c95a6c8, 0x6a7b384944536bdc, (N) };
57
58#define LIMINE_BASE_REVISION_SUPPORTED (limine_base_revision[2] == 0)
59
60#define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
61
62struct limine_uuid {
63 uint32_t a;
64 uint16_t b;
65 uint16_t c;
66 uint8_t d[8];
67};
68
69#define LIMINE_MEDIA_TYPE_GENERIC 0
70#define LIMINE_MEDIA_TYPE_OPTICAL 1
71#define LIMINE_MEDIA_TYPE_TFTP 2
72
73struct limine_file {
74 uint64_t revision;
75 LIMINE_PTR(void *) address;
76 uint64_t size;
77 LIMINE_PTR(char *) path;
78 LIMINE_PTR(char *) cmdline;
79 uint32_t media_type;
80 uint32_t unused;
81 uint32_t tftp_ip;
82 uint32_t tftp_port;
83 uint32_t partition_index;
84 uint32_t mbr_disk_id;
85 struct limine_uuid gpt_disk_uuid;
86 struct limine_uuid gpt_part_uuid;
87 struct limine_uuid part_uuid;
88};
89
90/* Boot info */
91
92#define LIMINE_BOOTLOADER_INFO_REQUEST { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
93
94struct limine_bootloader_info_response {
95 uint64_t revision;
96 LIMINE_PTR(char *) name;
97 LIMINE_PTR(char *) version;
98};
99
100struct limine_bootloader_info_request {
101 uint64_t id[4];
102 uint64_t revision;
103 LIMINE_PTR(struct limine_bootloader_info_response *) response;
104};
105
106/* Stack size */
107
108#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
109
110struct limine_stack_size_response {
111 uint64_t revision;
112};
113
114struct limine_stack_size_request {
115 uint64_t id[4];
116 uint64_t revision;
117 LIMINE_PTR(struct limine_stack_size_response *) response;
118 uint64_t stack_size;
119};
120
121/* HHDM */
122
123#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
124
125struct limine_hhdm_response {
126 uint64_t revision;
127 uint64_t offset;
128};
129
130struct limine_hhdm_request {
131 uint64_t id[4];
132 uint64_t revision;
133 LIMINE_PTR(struct limine_hhdm_response *) response;
134};
135
136/* Framebuffer */
137
138#define LIMINE_FRAMEBUFFER_REQUEST { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
139
140#define LIMINE_FRAMEBUFFER_RGB 1
141
142struct limine_video_mode {
143 uint64_t pitch;
144 uint64_t width;
145 uint64_t height;
146 uint16_t bpp;
147 uint8_t memory_model;
148 uint8_t red_mask_size;
149 uint8_t red_mask_shift;
150 uint8_t green_mask_size;
151 uint8_t green_mask_shift;
152 uint8_t blue_mask_size;
153 uint8_t blue_mask_shift;
154};
155
156struct limine_framebuffer {
157 LIMINE_PTR(void *) address;
158 uint64_t width;
159 uint64_t height;
160 uint64_t pitch;
161 uint16_t bpp;
162 uint8_t memory_model;
163 uint8_t red_mask_size;
164 uint8_t red_mask_shift;
165 uint8_t green_mask_size;
166 uint8_t green_mask_shift;
167 uint8_t blue_mask_size;
168 uint8_t blue_mask_shift;
169 uint8_t unused[7];
170 uint64_t edid_size;
171 LIMINE_PTR(void *) edid;
172 /* Response revision 1 */
173 uint64_t mode_count;
174 LIMINE_PTR(struct limine_video_mode **) modes;
175};
176
177struct limine_framebuffer_response {
178 uint64_t revision;
179 uint64_t framebuffer_count;
180 LIMINE_PTR(struct limine_framebuffer **) framebuffers;
181};
182
183struct limine_framebuffer_request {
184 uint64_t id[4];
185 uint64_t revision;
186 LIMINE_PTR(struct limine_framebuffer_response *) response;
187};
188
189/* Terminal */
190
191#define LIMINE_TERMINAL_REQUEST { LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
192
193#define LIMINE_TERMINAL_CB_DEC 10
194#define LIMINE_TERMINAL_CB_BELL 20
195#define LIMINE_TERMINAL_CB_PRIVATE_ID 30
196#define LIMINE_TERMINAL_CB_STATUS_REPORT 40
197#define LIMINE_TERMINAL_CB_POS_REPORT 50
198#define LIMINE_TERMINAL_CB_KBD_LEDS 60
199#define LIMINE_TERMINAL_CB_MODE 70
200#define LIMINE_TERMINAL_CB_LINUX 80
201
202#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t)(-1))
203#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t)(-2))
204#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t)(-3))
205#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t)(-4))
206
207/* Response revision 1 */
208#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t)(-10))
209#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t)(-11))
210
211#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
212#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
213#define LIMINE_TERMINAL_OOB_OUTPUT_OFILL (1 << 2)
214#define LIMINE_TERMINAL_OOB_OUTPUT_OLCUC (1 << 3)
215#define LIMINE_TERMINAL_OOB_OUTPUT_ONLCR (1 << 4)
216#define LIMINE_TERMINAL_OOB_OUTPUT_ONLRET (1 << 5)
217#define LIMINE_TERMINAL_OOB_OUTPUT_ONOCR (1 << 6)
218#define LIMINE_TERMINAL_OOB_OUTPUT_OPOST (1 << 7)
219
220LIMINE_DEPRECATED_IGNORE_START
221
222struct LIMINE_DEPRECATED limine_terminal;
223
224typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t);
225typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
226
227struct LIMINE_DEPRECATED limine_terminal {
228 uint64_t columns;
229 uint64_t rows;
230 LIMINE_PTR(struct limine_framebuffer *) framebuffer;
231};
232
233struct LIMINE_DEPRECATED limine_terminal_response {
234 uint64_t revision;
235 uint64_t terminal_count;
236 LIMINE_PTR(struct limine_terminal **) terminals;
237 LIMINE_PTR(limine_terminal_write) write;
238};
239
240struct LIMINE_DEPRECATED limine_terminal_request {
241 uint64_t id[4];
242 uint64_t revision;
243 LIMINE_PTR(struct limine_terminal_response *) response;
244 LIMINE_PTR(limine_terminal_callback) callback;
245};
246
247LIMINE_DEPRECATED_IGNORE_END
248
249/* Paging mode */
250
251#define LIMINE_PAGING_MODE_REQUEST { LIMINE_COMMON_MAGIC, 0x95c1a0edab0944cb, 0xa4e5cb3842f7488a }
252
253#if defined (__x86_64__) || defined (__i386__)
254#define LIMINE_PAGING_MODE_X86_64_4LVL 0
255#define LIMINE_PAGING_MODE_X86_64_5LVL 1
256#define LIMINE_PAGING_MODE_MAX LIMINE_PAGING_MODE_X86_64_5LVL
257#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_X86_64_4LVL
258#elif defined (__aarch64__)
259#define LIMINE_PAGING_MODE_AARCH64_4LVL 0
260#define LIMINE_PAGING_MODE_AARCH64_5LVL 1
261#define LIMINE_PAGING_MODE_MAX LIMINE_PAGING_MODE_AARCH64_5LVL
262#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_AARCH64_4LVL
263#elif defined (__riscv) && (__riscv_xlen == 64)
264#define LIMINE_PAGING_MODE_RISCV_SV39 0
265#define LIMINE_PAGING_MODE_RISCV_SV48 1
266#define LIMINE_PAGING_MODE_RISCV_SV57 2
267#define LIMINE_PAGING_MODE_MAX LIMINE_PAGING_MODE_RISCV_SV57
268#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_RISCV_SV48
269#else
270#error Unknown architecture
271#endif
272
273struct limine_paging_mode_response {
274 uint64_t revision;
275 uint64_t mode;
276 uint64_t flags;
277};
278
279struct limine_paging_mode_request {
280 uint64_t id[4];
281 uint64_t revision;
282 LIMINE_PTR(struct limine_paging_mode_response *) response;
283 uint64_t mode;
284 uint64_t flags;
285};
286
287/* 5-level paging */
288
289#define LIMINE_5_LEVEL_PAGING_REQUEST { LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
290
291LIMINE_DEPRECATED_IGNORE_START
292
293struct LIMINE_DEPRECATED limine_5_level_paging_response {
294 uint64_t revision;
295};
296
297struct LIMINE_DEPRECATED limine_5_level_paging_request {
298 uint64_t id[4];
299 uint64_t revision;
300 LIMINE_PTR(struct limine_5_level_paging_response *) response;
301};
302
303LIMINE_DEPRECATED_IGNORE_END
304
305/* SMP */
306
307#define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
308
309struct limine_smp_info;
310
311typedef void (*limine_goto_address)(struct limine_smp_info *);
312
313#if defined (__x86_64__) || defined (__i386__)
314
315#define LIMINE_SMP_X2APIC (1 << 0)
316
317struct limine_smp_info {
318 uint32_t processor_id;
319 uint32_t lapic_id;
320 uint64_t reserved;
321 LIMINE_PTR(limine_goto_address) goto_address;
322 uint64_t extra_argument;
323};
324
325struct limine_smp_response {
326 uint64_t revision;
327 uint32_t flags;
328 uint32_t bsp_lapic_id;
329 uint64_t cpu_count;
330 LIMINE_PTR(struct limine_smp_info **) cpus;
331};
332
333#elif defined (__aarch64__)
334
335struct limine_smp_info {
336 uint32_t processor_id;
337 uint32_t gic_iface_no;
338 uint64_t mpidr;
339 uint64_t reserved;
340 LIMINE_PTR(limine_goto_address) goto_address;
341 uint64_t extra_argument;
342};
343
344struct limine_smp_response {
345 uint64_t revision;
346 uint64_t flags;
347 uint64_t bsp_mpidr;
348 uint64_t cpu_count;
349 LIMINE_PTR(struct limine_smp_info **) cpus;
350};
351
352#elif defined (__riscv) && (__riscv_xlen == 64)
353
354struct limine_smp_info {
355 uint64_t processor_id;
356 uint64_t hartid;
357 uint64_t reserved;
358 LIMINE_PTR(limine_goto_address) goto_address;
359 uint64_t extra_argument;
360};
361
362struct limine_smp_response {
363 uint64_t revision;
364 uint64_t flags;
365 uint64_t bsp_hartid;
366 uint64_t cpu_count;
367 LIMINE_PTR(struct limine_smp_info **) cpus;
368};
369
370#else
371#error Unknown architecture
372#endif
373
374struct limine_smp_request {
375 uint64_t id[4];
376 uint64_t revision;
377 LIMINE_PTR(struct limine_smp_response *) response;
378 uint64_t flags;
379};
380
381/* Memory map */
382
383#define LIMINE_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
384
385#define LIMINE_MEMMAP_USABLE 0
386#define LIMINE_MEMMAP_RESERVED 1
387#define LIMINE_MEMMAP_ACPI_RECLAIMABLE 2
388#define LIMINE_MEMMAP_ACPI_NVS 3
389#define LIMINE_MEMMAP_BAD_MEMORY 4
390#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
391#define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
392#define LIMINE_MEMMAP_FRAMEBUFFER 7
393
394struct limine_memmap_entry {
395 uint64_t base;
396 uint64_t length;
397 uint64_t type;
398};
399
400struct limine_memmap_response {
401 uint64_t revision;
402 uint64_t entry_count;
403 LIMINE_PTR(struct limine_memmap_entry **) entries;
404};
405
406struct limine_memmap_request {
407 uint64_t id[4];
408 uint64_t revision;
409 LIMINE_PTR(struct limine_memmap_response *) response;
410};
411
412/* Entry point */
413
414#define LIMINE_ENTRY_POINT_REQUEST { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
415
416typedef void (*limine_entry_point)(void);
417
418struct limine_entry_point_response {
419 uint64_t revision;
420};
421
422struct limine_entry_point_request {
423 uint64_t id[4];
424 uint64_t revision;
425 LIMINE_PTR(struct limine_entry_point_response *) response;
426 LIMINE_PTR(limine_entry_point) entry;
427};
428
429/* Kernel File */
430
431#define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
432
433struct limine_kernel_file_response {
434 uint64_t revision;
435 LIMINE_PTR(struct limine_file *) kernel_file;
436};
437
438struct limine_kernel_file_request {
439 uint64_t id[4];
440 uint64_t revision;
441 LIMINE_PTR(struct limine_kernel_file_response *) response;
442};
443
444/* Module */
445
446#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
447
448#define LIMINE_INTERNAL_MODULE_REQUIRED (1 << 0)
449#define LIMINE_INTERNAL_MODULE_COMPRESSED (1 << 1)
450
451struct limine_internal_module {
452 LIMINE_PTR(const char *) path;
453 LIMINE_PTR(const char *) cmdline;
454 uint64_t flags;
455};
456
457struct limine_module_response {
458 uint64_t revision;
459 uint64_t module_count;
460 LIMINE_PTR(struct limine_file **) modules;
461};
462
463struct limine_module_request {
464 uint64_t id[4];
465 uint64_t revision;
466 LIMINE_PTR(struct limine_module_response *) response;
467
468 /* Request revision 1 */
469 uint64_t internal_module_count;
470 LIMINE_PTR(struct limine_internal_module **) internal_modules;
471};
472
473/* RSDP */
474
475#define LIMINE_RSDP_REQUEST { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
476
477struct limine_rsdp_response {
478 uint64_t revision;
479 LIMINE_PTR(void *) address;
480};
481
482struct limine_rsdp_request {
483 uint64_t id[4];
484 uint64_t revision;
485 LIMINE_PTR(struct limine_rsdp_response *) response;
486};
487
488/* SMBIOS */
489
490#define LIMINE_SMBIOS_REQUEST { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
491
492struct limine_smbios_response {
493 uint64_t revision;
494 LIMINE_PTR(void *) entry_32;
495 LIMINE_PTR(void *) entry_64;
496};
497
498struct limine_smbios_request {
499 uint64_t id[4];
500 uint64_t revision;
501 LIMINE_PTR(struct limine_smbios_response *) response;
502};
503
504/* EFI system table */
505
506#define LIMINE_EFI_SYSTEM_TABLE_REQUEST { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
507
508struct limine_efi_system_table_response {
509 uint64_t revision;
510 LIMINE_PTR(void *) address;
511};
512
513struct limine_efi_system_table_request {
514 uint64_t id[4];
515 uint64_t revision;
516 LIMINE_PTR(struct limine_efi_system_table_response *) response;
517};
518
519/* EFI memory map */
520
521#define LIMINE_EFI_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x7df62a431d6872d5, 0xa4fcdfb3e57306c8 }
522
523struct limine_efi_memmap_response {
524 uint64_t revision;
525 LIMINE_PTR(void *) memmap;
526 uint64_t memmap_size;
527 uint64_t desc_size;
528 uint64_t desc_version;
529};
530
531struct limine_efi_memmap_request {
532 uint64_t id[4];
533 uint64_t revision;
534 LIMINE_PTR(struct limine_efi_memmap_response *) response;
535};
536
537/* Boot time */
538
539#define LIMINE_BOOT_TIME_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
540
541struct limine_boot_time_response {
542 uint64_t revision;
543 int64_t boot_time;
544};
545
546struct limine_boot_time_request {
547 uint64_t id[4];
548 uint64_t revision;
549 LIMINE_PTR(struct limine_boot_time_response *) response;
550};
551
552/* Kernel address */
553
554#define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
555
556struct limine_kernel_address_response {
557 uint64_t revision;
558 uint64_t physical_base;
559 uint64_t virtual_base;
560};
561
562struct limine_kernel_address_request {
563 uint64_t id[4];
564 uint64_t revision;
565 LIMINE_PTR(struct limine_kernel_address_response *) response;
566};
567
568/* Device Tree Blob */
569
570#define LIMINE_DTB_REQUEST { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
571
572struct limine_dtb_response {
573 uint64_t revision;
574 LIMINE_PTR(void *) dtb_ptr;
575};
576
577struct limine_dtb_request {
578 uint64_t id[4];
579 uint64_t revision;
580 LIMINE_PTR(struct limine_dtb_response *) response;
581};
582
583#ifdef __cplusplus
584}
585#endif
586
587#endif
588