libkernaux/src/multiboot2/header_helpers.c

56 lines
1.7 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/multiboot2.h>
#include <stddef.h>
#include <stdint.h>
const struct KernAux_Multiboot2_HTagBase
*KernAux_Multiboot2_Header_first_tag_with_type(
const struct KernAux_Multiboot2_Header *const multiboot2_header,
const enum KernAux_Multiboot2_HTag tag_type
) {
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))
{
// TODO: uncommend when implemented
// if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return NULL;
if (tag_base->type == tag_type) return tag_base;
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
}
return NULL;
}
const struct KernAux_Multiboot2_HTagBase
*KernAux_Multiboot2_Header_tag_with_type_after(
const struct KernAux_Multiboot2_Header *const multiboot2_header,
const enum KernAux_Multiboot2_HTag tag_type,
const struct KernAux_Multiboot2_HTagBase *const after_tag
) {
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))
{
// TODO: uncommend when implemented
// if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return NULL;
if (tag_base->type == tag_type && tag_base > after_tag) return tag_base;
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
}
return NULL;
}