Write code

This commit is contained in:
Alex Kotov 2022-01-13 19:18:18 +05:00
parent 172dff9f48
commit 47389e8875
5 changed files with 63 additions and 39 deletions

View File

@ -5,6 +5,7 @@
#include <kernaux/multiboot2.h>
#include <stddef.h>
#include <stdint.h>
void KernAux_Multiboot2_Header_print(
const struct KernAux_Multiboot2_Header *const multiboot2_header,
@ -16,5 +17,27 @@ void KernAux_Multiboot2_Header_print(
printf(" size: %u\n", multiboot2_header->total_size);
printf(" checksum: %u\n", multiboot2_header->checksum);
// TODO: write this
const struct KernAux_Multiboot2_HTagBase *tag_base =
(struct KernAux_Multiboot2_HTagBase*)
KERNAUX_MULTIBOOT2_DATA(multiboot2_header);
while (tag_base <
(struct KernAux_Multiboot2_HTagBase*)
((uint8_t*)multiboot2_header + multiboot2_header->total_size))
{
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return;
KernAux_Multiboot2_HTagBase_print(tag_base, printf);
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
}
}
void KernAux_Multiboot2_HTagBase_print(
const struct KernAux_Multiboot2_HTagBase *const tag_base,
void (*const printf)(const char *format, ...) __attribute__((format(printf, 1, 2)))
) {
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return;
printf("Multiboot 2 header tag\n");
}

View File

@ -5,6 +5,7 @@
#include <kernaux/multiboot2.h>
#include <stddef.h>
#include <stdint.h>
static void KernAux_Multiboot2_ITag_MemoryMap_print(
const struct KernAux_Multiboot2_ITag_MemoryMap *tag,
@ -30,7 +31,7 @@ void KernAux_Multiboot2_Info_print(
while (tag_base <
(struct KernAux_Multiboot2_ITagBase*)
((unsigned char*)multiboot2_info + multiboot2_info->total_size))
((uint8_t*)multiboot2_info + multiboot2_info->total_size))
{
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return;
@ -46,7 +47,7 @@ void KernAux_Multiboot2_ITagBase_print(
) {
if (!KernAux_Multiboot2_ITagBase_is_valid(tag_base)) return;
printf("Multiboot 2 tag\n");
printf("Multiboot 2 info tag\n");
printf(
" type: %u (%s)\n",

View File

@ -11,19 +11,19 @@ static const char output1[] =
"Multiboot 2 info\n"
" size: 864\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 21 (image load base phys addr)\n"
" size: 12\n"
" load base addr: 4194304\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 1 (boot cmd line)\n"
" size: 21\n"
" cmdline: hello kernel\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 2 (boot loader name)\n"
" size: 30\n"
" name: GRUB 2.02-2ubuntu8.20\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 10 (APM table)\n"
" size: 28\n"
" version: 258\n"
@ -35,19 +35,19 @@ static const char output1[] =
" cseg len: 65520\n"
" cseg 16 len: 65520\n"
" dseg len: 65520\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 3 (module)\n"
" size: 29\n"
" start: 1056768\n"
" end: 1061532\n"
" cmdline: hello module\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 3 (module)\n"
" size: 17\n"
" start: 1064960\n"
" end: 1069652\n"
" cmdline: \n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 6 (memory map)\n"
" size: 160\n"
" entry size: 24\n"
@ -83,25 +83,25 @@ static const char output1[] =
" length: 262144\n"
" type: 2\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 9 (ELF symbols)\n"
" size: 420\n"
" num: 10\n"
" entsize: 0\n"
" shndx: 40\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 4 (basic memory info)\n"
" size: 16\n"
" mem lower: 639\n"
" mem upper: 129920\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 5 (BIOS boot device)\n"
" size: 20\n"
" bios dev: 224\n"
" partition: 4294967295\n"
" sub_partition: 4294967295\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 8 (framebuffer info)\n"
" size: 32\n"
" framebuffer addr: 753664\n"
@ -111,10 +111,10 @@ static const char output1[] =
" framebuffer bpp: 16\n"
" framebuffer type: 2\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 14 (ACPI old RSDP)\n"
" size: 28\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 0 (none)\n"
" size: 8\n";
@ -122,38 +122,38 @@ static const char output2[] =
"Multiboot 2 info\n"
" size: 1816\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 1 (boot cmd line)\n"
" size: 23\n"
" cmdline: Hello, Kernel!\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 2 (boot loader name)\n"
" size: 30\n"
" name: GRUB 2.02-2ubuntu8.20\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 3 (module)\n"
" size: 33\n"
" start: 123\n"
" end: 456\n"
" cmdline: Hello, Module 1!\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 3 (module)\n"
" size: 33\n"
" start: 123\n"
" end: 456\n"
" cmdline: Hello, Module 2!\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 4 (basic memory info)\n"
" size: 16\n"
" mem lower: 123\n"
" mem upper: 456\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 5 (BIOS boot device)\n"
" size: 20\n"
" bios dev: 0\n"
" partition: 1\n"
" sub_partition: 2\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 6 (memory map)\n"
" size: 160\n"
" entry size: 24\n"
@ -189,14 +189,14 @@ static const char output2[] =
" length: 262144\n"
" type: 2\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 7 (VBE info)\n"
" size: 784\n"
" VBE mode: 0\n"
" VBE interface seg: 123\n"
" VBE interface off: 456\n"
" VBE interface len: 789\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 8 (framebuffer info)\n"
" size: 39\n"
" framebuffer addr: 123\n"
@ -206,14 +206,14 @@ static const char output2[] =
" framebuffer bpp: 8\n"
" framebuffer type: 1\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 9 (ELF symbols)\n"
" size: 420\n"
" num: 10\n"
" entsize: 0\n"
" shndx: 40\n"
" reserved1: 0\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 10 (APM table)\n"
" size: 28\n"
" version: 0\n"
@ -225,44 +225,44 @@ static const char output2[] =
" cseg len: 456\n"
" cseg 16 len: 789\n"
" dseg len: 123\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 11 (EFI 32bit system table ptr)\n"
" size: 12\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 12 (EFI 64bit system table ptr)\n"
" size: 16\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 13 (SMBIOS tables)\n"
" size: 24\n"
" major: 1\n"
" minor: 2\n"
" reserved1: {0, 0, 0, 0, 0, 0}\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 14 (ACPI old RSDP)\n"
" size: 16\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 15 (ACPI new RSDP)\n"
" size: 16\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 16 (networking info)\n"
" size: 16\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 17 (EFI memory map)\n"
" size: 24\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 18 (EFI boot services not terminated)\n"
" size: 8\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 19 (EFI 32bit image handle ptr)\n"
" size: 12\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 20 (EFI 64bit image handle ptr)\n"
" size: 16\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 21 (image load base phys addr)\n"
" size: 12\n"
" load base addr: 123\n"
"Multiboot 2 tag\n"
"Multiboot 2 info tag\n"
" type: 0 (none)\n"
" size: 8\n";