libkernaux/src/multiboot2/info_print.c

269 lines
9.0 KiB
C
Raw Normal View History

2020-12-07 04:46:37 +00:00
#ifdef HAVE_CONFIG_H
2020-12-07 04:42:52 +00:00
#include "config.h"
2020-12-07 04:46:37 +00:00
#endif
2020-11-30 11:40:33 +00:00
2020-11-28 01:27:41 +00:00
#include <kernaux/multiboot2.h>
2020-12-06 10:16:15 +00:00
#include <stddef.h>
2022-01-13 14:18:18 +00:00
#include <stdint.h>
2020-12-06 10:16:15 +00:00
2022-01-13 03:59:52 +00:00
void KernAux_Multiboot2_Info_print(
const struct KernAux_Multiboot2_Info *const multiboot2_info,
2022-01-15 06:31:49 +00:00
void (*const printf)(const char *format, ...)
2020-11-28 01:27:41 +00:00
) {
2020-12-06 02:47:45 +00:00
printf("Multiboot 2 info\n");
2022-01-13 03:59:52 +00:00
printf(" size: %u\n", multiboot2_info->total_size);
printf(" reserved1: %u\n", multiboot2_info->reserved1);
2020-11-28 01:27:41 +00:00
2022-01-13 03:03:15 +00:00
const struct KernAux_Multiboot2_ITagBase *tag_base =
(struct KernAux_Multiboot2_ITagBase*)
2022-01-13 03:59:52 +00:00
KERNAUX_MULTIBOOT2_DATA(multiboot2_info);
2020-11-28 01:27:41 +00:00
2021-12-14 19:13:18 +00:00
while (tag_base <
2022-01-13 03:03:15 +00:00
(struct KernAux_Multiboot2_ITagBase*)
2022-01-13 14:18:18 +00:00
((uint8_t*)multiboot2_info + multiboot2_info->total_size))
2021-12-14 19:13:18 +00:00
{
2022-01-13 03:03:15 +00:00
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return;
2020-11-28 01:27:41 +00:00
2022-01-13 03:03:15 +00:00
KernAux_Multiboot2_ITagBase_print(tag_base, printf);
2020-11-28 01:27:41 +00:00
tag_base = KERNAUX_MULTIBOOT2_ITAG_NEXT(tag_base);
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 *const tag_base,
2022-01-15 06:31:49 +00:00
void (*const printf)(const char *format, ...)
2020-11-28 01:27:41 +00:00
) {
2022-01-13 03:03:15 +00:00
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return;
2020-11-28 01:27:41 +00:00
2022-01-13 14:18:18 +00:00
printf("Multiboot 2 info tag\n");
2020-11-28 01:27:41 +00:00
2020-12-06 02:47:45 +00:00
printf(
2020-11-28 01:27:41 +00:00
" type: %u (%s)\n",
tag_base->type,
2022-01-13 02:49:25 +00:00
KernAux_Multiboot2_ITag_to_str(tag_base->type)
2020-11-28 01:27:41 +00:00
);
2020-12-06 02:47:45 +00:00
printf(" size: %u\n", tag_base->size);
2020-11-28 01:27:41 +00:00
switch (tag_base->type) {
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_NONE:
2020-11-28 21:39:04 +00:00
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE:
2020-12-06 02:47:45 +00:00
printf(
2020-11-28 01:27:41 +00:00
" cmdline: %s\n",
2022-01-11 09:29:56 +00:00
KERNAUX_MULTIBOOT2_DATA(
2022-01-13 03:38:51 +00:00
(struct KernAux_Multiboot2_ITag_BootCmdLine*)tag_base
)
2020-11-28 01:27:41 +00:00
);
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_BOOT_LOADER_NAME:
2020-12-06 02:47:45 +00:00
printf(
2020-11-28 01:27:41 +00:00
" name: %s\n",
2022-01-11 09:29:56 +00:00
KERNAUX_MULTIBOOT2_DATA(
2022-01-13 03:38:51 +00:00
(struct KernAux_Multiboot2_ITag_BootLoaderName*)tag_base
)
2020-11-28 01:27:41 +00:00
);
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_MODULE:
2020-11-28 01:27:41 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_Module *const tag_module =
(struct KernAux_Multiboot2_ITag_Module*)tag_base;
2020-11-28 01:27:41 +00:00
2020-12-06 02:47:45 +00:00
printf(" start: %u\n", tag_module->mod_start);
printf(" end: %u\n", tag_module->mod_end);
2022-01-11 09:29:56 +00:00
printf(" cmdline: %s\n", KERNAUX_MULTIBOOT2_DATA(tag_module));
2020-11-28 01:27:41 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_BASIC_MEMORY_INFO:
2020-11-28 01:27:41 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_BasicMemoryInfo *const tag_bmi =
(struct KernAux_Multiboot2_ITag_BasicMemoryInfo*)tag_base;
2020-11-28 01:27:41 +00:00
2020-12-06 02:47:45 +00:00
printf(" mem lower: %u\n", tag_bmi->mem_lower);
printf(" mem upper: %u\n", tag_bmi->mem_upper);
2020-11-28 01:27:41 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_BIOS_BOOT_DEVICE:
2020-11-28 01:27:41 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_BIOSBootDevice *const tag_bbd =
(struct KernAux_Multiboot2_ITag_BIOSBootDevice*)tag_base;
2020-11-28 01:27:41 +00:00
2020-12-06 02:47:45 +00:00
printf(" bios dev: %u\n", tag_bbd->bios_dev);
printf(" partition: %u\n", tag_bbd->partition);
printf(" sub_partition: %u\n", tag_bbd->sub_partition);
2020-11-28 01:27:41 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_MEMORY_MAP:
2022-01-13 03:12:28 +00:00
KernAux_Multiboot2_ITag_MemoryMap_print(
2022-01-13 03:38:51 +00:00
(struct KernAux_Multiboot2_ITag_MemoryMap*)tag_base,
2020-12-06 02:47:45 +00:00
printf
2020-11-28 23:24:14 +00:00
);
2020-11-28 21:39:04 +00:00
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_VBE_INFO:
2020-11-28 21:39:04 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_VBEInfo *const tag_vbe =
(struct KernAux_Multiboot2_ITag_VBEInfo*)tag_base;
2020-12-06 02:47:45 +00:00
printf(" VBE mode: %hu\n", tag_vbe->vbe_mode);
printf(" VBE interface seg: %hu\n", tag_vbe->vbe_interface_seg);
printf(" VBE interface off: %hu\n", tag_vbe->vbe_interface_off);
printf(" VBE interface len: %hu\n", tag_vbe->vbe_interface_len);
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_FRAMEBUFFER_INFO:
2020-11-28 21:39:04 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_FramebufferInfo *const tag_fb =
(struct KernAux_Multiboot2_ITag_FramebufferInfo*)tag_base;
2020-12-06 02:47:45 +00:00
printf(" framebuffer addr: %llu\n", tag_fb->framebuffer_addr);
printf(" framebuffer pitch: %u\n", tag_fb->framebuffer_pitch);
printf(" framebuffer width: %u\n", tag_fb->framebuffer_width);
printf(" framebuffer height: %u\n", tag_fb->framebuffer_height);
printf(" framebuffer bpp: %u\n", tag_fb->framebuffer_bpp);
printf(" framebuffer type: %u\n", tag_fb->framebuffer_type);
printf(" reserved1: %u\n", tag_fb->reserved1);
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS:
2022-01-13 03:12:28 +00:00
KernAux_Multiboot2_ITag_ELFSymbols_print(
2022-01-13 03:38:51 +00:00
(struct KernAux_Multiboot2_ITag_ELFSymbols*)tag_base,
2020-12-06 02:47:45 +00:00
printf
);
2020-11-28 21:39:04 +00:00
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_APM_TABLE:
2020-11-28 21:39:04 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_APMTable *const tag_apm =
(struct KernAux_Multiboot2_ITag_APMTable*)tag_base;
2020-11-28 22:06:25 +00:00
2020-12-06 02:47:45 +00:00
printf(" version: %hu\n", tag_apm->version);
printf(" cseg: %hu\n", tag_apm->cseg);
printf(" offset: %u\n", tag_apm->offset);
printf(" cseg 16: %hu\n", tag_apm->cseg_16);
printf(" dseg: %hu\n", tag_apm->dseg);
printf(" flags: %hu\n", tag_apm->flags);
printf(" cseg len: %hu\n", tag_apm->cseg_len);
printf(" cseg 16 len: %hu\n", tag_apm->cseg_16_len);
printf(" dseg len: %hu\n", tag_apm->dseg_len);
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES:
2020-11-28 21:39:04 +00:00
{
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_SMBIOSTables *const tag_smbios =
(struct KernAux_Multiboot2_ITag_SMBIOSTables*)tag_base;
2020-11-29 14:30:46 +00:00
2020-12-06 02:47:45 +00:00
printf(" major: %u\n", tag_smbios->major);
printf(" minor: %u\n", tag_smbios->minor);
2020-11-29 15:06:46 +00:00
2020-12-06 02:47:45 +00:00
printf(
2020-11-29 15:06:46 +00:00
" reserved1: {%u, %u, %u, %u, %u, %u}\n",
tag_smbios->reserved1[0],
tag_smbios->reserved1[1],
tag_smbios->reserved1[2],
tag_smbios->reserved1[3],
tag_smbios->reserved1[4],
tag_smbios->reserved1[5]
);
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_ACPI_OLD_RSDP:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED:
2020-11-28 21:39:04 +00:00
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR:
2020-11-28 21:39:04 +00:00
{
2020-11-28 22:14:46 +00:00
// TODO: print
2020-11-28 21:39:04 +00:00
}
break;
2022-01-13 02:49:25 +00:00
case KERNAUX_MULTIBOOT2_ITAG_IMAGE_LOAD_BASE_PHYS_ADDR:
2020-12-06 02:47:45 +00:00
printf(
2020-11-28 01:43:51 +00:00
" load base addr: %u\n",
2022-01-13 03:38:51 +00:00
((struct KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr*)tag_base)->
2020-11-28 01:43:51 +00:00
load_base_addr
);
break;
2020-11-28 01:27:41 +00:00
}
}
2020-11-28 23:24:14 +00:00
2022-01-13 03:12:28 +00:00
void KernAux_Multiboot2_ITag_MemoryMap_print(
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_MemoryMap *const tag,
2022-01-15 06:31:49 +00:00
void (*printf)(const char *format, ...)
2020-11-28 23:24:14 +00:00
) {
if (!KernAux_Multiboot2_ITag_MemoryMap_is_valid(tag)) {
2020-12-06 02:47:45 +00:00
printf(" invalid!\n");
2020-11-28 23:24:14 +00:00
return;
}
2020-12-06 02:47:45 +00:00
printf(" entry size: %u\n", tag->entry_size);
printf(" entry version: %u\n", tag->entry_version);
2020-11-28 23:24:14 +00:00
2020-12-06 02:47:45 +00:00
printf(" entries:\n");
2020-11-28 23:24:14 +00:00
2022-01-13 03:22:17 +00:00
const struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase *const entries =
(struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*)
2022-01-13 03:38:51 +00:00
KERNAUX_MULTIBOOT2_DATA((struct KernAux_Multiboot2_ITag_MemoryMap*)tag);
2020-11-28 23:24:14 +00:00
for (
2021-12-16 15:26:16 +00:00
size_t index = 0;
2020-11-28 23:24:14 +00:00
index < (tag->base.size - sizeof(*tag)) / tag->entry_size;
++index
) {
2021-12-16 15:26:16 +00:00
printf(" entry %lu\n", index);
2020-12-06 02:47:45 +00:00
printf(" base addr: %llu\n", entries[index].base_addr);
printf(" length: %llu\n", entries[index].length);
printf(" type: %u\n", entries[index].type);
printf(" reserved1: %u\n", entries[index].reserved1);
2020-11-28 23:24:14 +00:00
}
}
2022-01-13 03:12:28 +00:00
void KernAux_Multiboot2_ITag_ELFSymbols_print(
2022-01-13 03:38:51 +00:00
const struct KernAux_Multiboot2_ITag_ELFSymbols *const tag,
2022-01-15 06:31:49 +00:00
void (*printf)(const char *format, ...)
) {
if (!KernAux_Multiboot2_ITag_ELFSymbols_is_valid(tag)) {
2020-12-06 02:47:45 +00:00
printf(" invalid!\n");
return;
}
2020-12-06 02:47:45 +00:00
printf(" num: %hu\n", tag->num);
printf(" entsize: %hu\n", tag->ent_size);
printf(" shndx: %hu\n", tag->shndx);
printf(" reserved1: %hu\n", tag->reserved1);
2020-11-29 14:25:35 +00:00
// TODO: implement this
}