From 5a7a745c2285cf6e2e2c698a9f2696549c7a3206 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 14 Jan 2022 09:43:59 +0500 Subject: [PATCH] Add enum KernAux_Multiboot2_HTag_RelocatableHeader_Preference --- include/kernaux/multiboot2.h | 14 ++++++++++---- src/multiboot2/header_is_valid.c | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/kernaux/multiboot2.h b/include/kernaux/multiboot2.h index f98bbb8..edc915b 100644 --- a/include/kernaux/multiboot2.h +++ b/include/kernaux/multiboot2.h @@ -35,6 +35,12 @@ extern "C" { #define KERNAUX_MULTIBOOT2_HTAG_FLAGS_REQUIRE_CONSOLE (1 << 0) #define KERNAUX_MULTIBOOT2_HTAG_FLAGS_EGA_SUPPORT (1 << 1) +enum KernAux_Multiboot2_HTag_RelocatableHeader_Preference { + KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_NONE = 0, + KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_LOWEST = 1, + KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_HIGHEST = 2, +}; + /**************** * Common types * ****************/ @@ -214,10 +220,10 @@ struct KernAux_Multiboot2_HTag_RelocatableHeader { // size = 24 struct KernAux_Multiboot2_HTagBase base; - unsigned min_addr : 32; - unsigned max_addr : 32; - unsigned align : 32; - unsigned preferences : 32; + unsigned min_addr : 32; + unsigned max_addr : 32; + unsigned align : 32; + enum KernAux_Multiboot2_HTag_RelocatableHeader_Preference preferences : 32; } __attribute__((packed)); diff --git a/src/multiboot2/header_is_valid.c b/src/multiboot2/header_is_valid.c index f296c3a..0e0d924 100644 --- a/src/multiboot2/header_is_valid.c +++ b/src/multiboot2/header_is_valid.c @@ -238,10 +238,22 @@ bool KernAux_Multiboot2_HTag_EFIAmd64EntryAddr_is_valid( bool KernAux_Multiboot2_HTag_RelocatableHeader_is_valid( const struct KernAux_Multiboot2_HTag_RelocatableHeader *tag ) { - return ( + if (!( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER && tag->base.size == 24 && // TODO: write this true - ); + )) { + return false; + } + + switch (tag->preferences) { + case KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_NONE: break; + case KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_LOWEST: break; + case KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER_PREFERENCE_HIGHEST: break; + default: + return false; + } + + return true; }