libkernaux/include/kernaux/multiboot2.h

459 lines
12 KiB
C
Raw Normal View History

2020-11-27 20:02:43 +00:00
#ifndef KERNAUX_INCLUDED_MULTIBOOT2
2021-12-20 06:17:53 +00:00
#define KERNAUX_INCLUDED_MULTIBOOT2
2020-11-27 20:02:43 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
2021-12-13 20:46:58 +00:00
#include <stdbool.h>
#define KERNAUX_MULTIBOOT2_MAGIC 0x36d76289
2022-01-11 09:29:56 +00:00
#define KERNAUX_MULTIBOOT2_DATA(ptr) (((uint8_t*)(ptr)) + sizeof(*(ptr)))
2022-01-13 02:56:08 +00:00
/***********************
* Header common types *
***********************/
2022-01-13 02:42:10 +00:00
enum KernAux_Multiboot2_HTag {
KERNAUX_MULTIBOOT2_HTAG_NONE = 0,
KERNAUX_MULTIBOOT2_HTAG_INFO_REQ = 1,
KERNAUX_MULTIBOOT2_HTAG_ADDR = 2,
KERNAUX_MULTIBOOT2_HTAG_ENTRY_ADDR = 3,
KERNAUX_MULTIBOOT2_HTAG_FLAGS = 4,
KERNAUX_MULTIBOOT2_HTAG_FRAMEBUFFER = 5,
KERNAUX_MULTIBOOT2_HTAG_MODULE_ALIGN = 6,
KERNAUX_MULTIBOOT2_HTAG_EFI_BOOT_SERVICES = 7,
KERNAUX_MULTIBOOT2_HTAG_EFI_I386_ENTRY_ADDR = 8,
KERNAUX_MULTIBOOT2_HTAG_EFI_AMD64_ENTRY_ADDR = 9,
KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER = 10,
};
2022-01-13 02:56:08 +00:00
struct KernAux_Multiboot2_Header {
uint32_t magic;
uint32_t arch;
uint32_t total_size;
uint32_t checksum;
}
__attribute__((packed));
struct KernAux_Multiboot2_HTagBase {
enum KernAux_Multiboot2_HTag type : 16;
uint16_t flags;
uint32_t size;
}
__attribute__((packed));
/****************************
* Information common types *
****************************/
2022-01-13 02:49:25 +00:00
enum KernAux_Multiboot2_ITag {
KERNAUX_MULTIBOOT2_ITAG_NONE = 0,
KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE = 1,
KERNAUX_MULTIBOOT2_ITAG_BOOT_LOADER_NAME = 2,
KERNAUX_MULTIBOOT2_ITAG_MODULE = 3,
KERNAUX_MULTIBOOT2_ITAG_BASIC_MEMORY_INFO = 4,
KERNAUX_MULTIBOOT2_ITAG_BIOS_BOOT_DEVICE = 5,
KERNAUX_MULTIBOOT2_ITAG_MEMORY_MAP = 6,
KERNAUX_MULTIBOOT2_ITAG_VBE_INFO = 7,
KERNAUX_MULTIBOOT2_ITAG_FRAMEBUFFER_INFO = 8,
KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS = 9,
KERNAUX_MULTIBOOT2_ITAG_APM_TABLE = 10,
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR = 11,
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR = 12,
KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES = 13,
KERNAUX_MULTIBOOT2_ITAG_ACPI_OLD_RSDP = 14,
KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP = 15,
KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO = 16,
KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP = 17,
KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED = 18,
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR = 19,
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR = 20,
KERNAUX_MULTIBOOT2_ITAG_IMAGE_LOAD_BASE_PHYS_ADDR = 21,
};
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2 {
2022-01-13 02:57:20 +00:00
uint32_t total_size;
uint32_t reserved1;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase {
2022-01-13 02:49:25 +00:00
enum KernAux_Multiboot2_ITag type : 32;
2022-01-13 02:57:20 +00:00
uint32_t size;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
/******************
* Tag structures *
******************/
struct KernAux_Multiboot2_Tag_None {
// type = 0
// size = 8
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_BootCmdLine {
// type = 1
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_BootLoaderName {
// type = 2
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_Module {
// type = 3
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned mod_start : 32;
unsigned mod_end : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_BasicMemoryInfo {
// type = 4
// size = 16
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned mem_lower : 32;
unsigned mem_upper : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_BIOSBootDevice {
// type = 5
// size = 20
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned bios_dev : 32;
unsigned partition : 32;
unsigned sub_partition : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_MemoryMap {
2020-11-27 20:14:18 +00:00
// type = 6
2020-11-27 20:02:43 +00:00
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned entry_size : 32;
unsigned entry_version : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_VBEInfo {
// type = 7
// size = 784
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned vbe_mode : 16;
unsigned vbe_interface_seg : 16;
unsigned vbe_interface_off : 16;
unsigned vbe_interface_len : 16;
2020-11-27 20:02:43 +00:00
unsigned char vbe_control_info[512];
unsigned char vbe_mode_info[256];
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_FramebufferInfo {
// type = 8
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
2020-11-27 20:10:21 +00:00
unsigned long long framebuffer_addr : 64;
unsigned framebuffer_pitch : 32;
unsigned framebuffer_width : 32;
unsigned framebuffer_height : 32;
unsigned framebuffer_bpp : 8;
unsigned framebuffer_type : 8;
unsigned reserved1 : 8;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_ELFSymbols {
// type = 9
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned num : 16;
unsigned ent_size : 16;
unsigned shndx : 16;
unsigned reserved1 : 16;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_APMTable {
// type = 10
2020-11-27 20:14:18 +00:00
// size = 28
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned version : 16;
unsigned cseg : 16;
unsigned offset : 32;
unsigned cseg_16 : 16;
unsigned dseg : 16;
unsigned flags : 16;
unsigned cseg_len : 16;
unsigned cseg_16_len : 16;
unsigned dseg_len : 16;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFI32bitSystemTablePtr {
2020-11-27 20:02:43 +00:00
// type = 11
// size = 12
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned pointer : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFI64bitSystemTablePtr {
2020-11-27 20:02:43 +00:00
// type = 12
// size = 16
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
2020-11-27 20:10:21 +00:00
unsigned long long pointer : 64;
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_SMBIOSTables {
// type = 13
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned major : 8;
unsigned minor : 8;
2020-11-27 20:02:43 +00:00
unsigned char reserved1[6];
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_ACPIOldRSDP {
// type = 14
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_ACPINewRSDP {
// type = 15
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_NetworkingInfo {
// type = 16
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFIMemoryMap {
// type = 17
// size = ?
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned descriptor_size : 32;
unsigned descriptor_version : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFIBootServicesNotTerminated {
// type = 18
// size = 8
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFI32bitImageHandlePtr {
2020-11-27 20:02:43 +00:00
// type = 19
// size = 12
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned pointer : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_EFI64bitImageHandlePtr {
2020-11-27 20:02:43 +00:00
// type = 20
// size = 16
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
2020-11-27 20:10:21 +00:00
unsigned long long pointer : 64;
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
struct KernAux_Multiboot2_Tag_ImageLoadBasePhysAddr {
// type = 21
// size = 12
2022-01-13 03:03:15 +00:00
struct KernAux_Multiboot2_ITagBase base;
2020-11-27 20:02:43 +00:00
unsigned load_base_addr : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
/*************************
* Additional structures *
*************************/
struct KernAux_Multiboot2_Tag_MemoryMap_EntryBase {
2020-11-27 20:10:21 +00:00
unsigned long long base_addr : 64;
unsigned long long length : 64;
unsigned type : 32;
unsigned reserved1 : 32;
2020-11-27 20:10:21 +00:00
}
__attribute__((packed));
2020-11-27 20:02:43 +00:00
/********************
* Helper functions *
********************/
2022-01-13 03:03:15 +00:00
const struct KernAux_Multiboot2_ITagBase
*KernAux_Multiboot2_first_tag_with_type(
const struct KernAux_Multiboot2 *multiboot2,
2022-01-13 02:49:25 +00:00
enum KernAux_Multiboot2_ITag tag_type
2021-12-14 22:27:06 +00:00
);
2022-01-13 03:03:15 +00:00
const struct KernAux_Multiboot2_ITagBase
*KernAux_Multiboot2_tag_with_type_after(
const struct KernAux_Multiboot2 *multiboot2,
2022-01-13 02:49:25 +00:00
enum KernAux_Multiboot2_ITag tag_type,
2022-01-13 03:03:15 +00:00
const struct KernAux_Multiboot2_ITagBase *after_tag
2021-12-14 22:27:06 +00:00
);
const char *KernAux_Multiboot2_boot_cmd_line(
const struct KernAux_Multiboot2 *multiboot2
2021-12-14 22:27:06 +00:00
);
2020-11-28 01:27:41 +00:00
/*******************
* Print functions *
*******************/
void KernAux_Multiboot2_print(
const struct KernAux_Multiboot2 *multiboot2,
2020-12-06 02:47:45 +00:00
void (*printf)(const char *format, ...)
2021-12-14 22:27:06 +00:00
);
2020-11-28 01:27:41 +00:00
2022-01-13 03:03:15 +00:00
void KernAux_Multiboot2_ITagBase_print(
const struct KernAux_Multiboot2_ITagBase *tag_base,
2020-12-06 02:47:45 +00:00
void (*printf)(const char *format, ...)
2021-12-14 22:27:06 +00:00
);
2020-11-28 01:27:41 +00:00
/************************
* Validation functions *
************************/
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_is_valid(
const struct KernAux_Multiboot2 *multiboot2
2021-12-14 22:27:06 +00:00
);
2022-01-13 03:03:15 +00:00
bool KernAux_Multiboot2_ITagBase_is_valid(
const struct KernAux_Multiboot2_ITagBase *tag_base
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_None_is_valid(
const struct KernAux_Multiboot2_Tag_None *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
const struct KernAux_Multiboot2_Tag_BootCmdLine *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
const struct KernAux_Multiboot2_Tag_BootLoaderName *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_Module_is_valid(
const struct KernAux_Multiboot2_Tag_Module *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_BasicMemoryInfo_is_valid(
const struct KernAux_Multiboot2_Tag_BasicMemoryInfo *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_BIOSBootDevice_is_valid(
const struct KernAux_Multiboot2_Tag_BIOSBootDevice *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_MemoryMap_is_valid(
const struct KernAux_Multiboot2_Tag_MemoryMap *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_VBEInfo_is_valid(
const struct KernAux_Multiboot2_Tag_VBEInfo *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_FramebufferInfo_is_valid(
const struct KernAux_Multiboot2_Tag_FramebufferInfo *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_ELFSymbols_is_valid(
const struct KernAux_Multiboot2_Tag_ELFSymbols *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_APMTable_is_valid(
const struct KernAux_Multiboot2_Tag_APMTable *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFI32bitSystemTablePtr_is_valid(
const struct KernAux_Multiboot2_Tag_EFI32bitSystemTablePtr *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFI64bitSystemTablePtr_is_valid(
const struct KernAux_Multiboot2_Tag_EFI64bitSystemTablePtr *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_SMBIOSTables_is_valid(
const struct KernAux_Multiboot2_Tag_SMBIOSTables *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_ACPIOldRSDP_is_valid(
const struct KernAux_Multiboot2_Tag_ACPIOldRSDP *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_ACPINewRSDP_is_valid(
const struct KernAux_Multiboot2_Tag_ACPINewRSDP *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_NetworkingInfo_is_valid(
const struct KernAux_Multiboot2_Tag_NetworkingInfo *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFIMemoryMap_is_valid(
const struct KernAux_Multiboot2_Tag_EFIMemoryMap *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFIBootServicesNotTerminated_is_valid(
const struct KernAux_Multiboot2_Tag_EFIBootServicesNotTerminated *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFI32bitImageHandlePtr_is_valid(
const struct KernAux_Multiboot2_Tag_EFI32bitImageHandlePtr *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_EFI64bitImageHandlePtr_is_valid(
const struct KernAux_Multiboot2_Tag_EFI64bitImageHandlePtr *tag
2021-12-14 22:27:06 +00:00
);
2020-12-06 10:16:15 +00:00
bool KernAux_Multiboot2_Tag_ImageLoadBasePhysAddr_is_valid(
const struct KernAux_Multiboot2_Tag_ImageLoadBasePhysAddr *tag
2021-12-14 22:27:06 +00:00
);
2020-11-27 20:02:43 +00:00
#ifdef __cplusplus
}
#endif
#endif