2022-01-13 12:44:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2022-05-24 23:01:51 +00:00
|
|
|
#include <kernaux/assert.h>
|
2022-01-13 12:44:22 +00:00
|
|
|
#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,
|
2022-12-17 02:31:09 +00:00
|
|
|
const uint16_t tag_type
|
2022-01-13 12:44:22 +00:00
|
|
|
) {
|
2022-06-13 16:28:00 +00:00
|
|
|
KERNAUX_ASSERT(multiboot2_header);
|
2022-05-24 23:01:51 +00:00
|
|
|
|
2022-01-13 12:44:22 +00:00
|
|
|
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))
|
|
|
|
{
|
2022-01-14 06:42:36 +00:00
|
|
|
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return NULL;
|
2022-01-13 12:44:22 +00:00
|
|
|
if (tag_base->type == tag_type) return tag_base;
|
|
|
|
|
2022-01-13 12:55:59 +00:00
|
|
|
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
|
2022-01-13 12:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct KernAux_Multiboot2_HTagBase
|
|
|
|
*KernAux_Multiboot2_Header_tag_with_type_after(
|
|
|
|
const struct KernAux_Multiboot2_Header *const multiboot2_header,
|
2022-12-17 02:31:09 +00:00
|
|
|
const uint16_t tag_type,
|
2022-01-13 12:44:22 +00:00
|
|
|
const struct KernAux_Multiboot2_HTagBase *const after_tag
|
|
|
|
) {
|
2022-06-13 16:28:00 +00:00
|
|
|
KERNAUX_ASSERT(multiboot2_header);
|
|
|
|
KERNAUX_ASSERT(after_tag);
|
2022-05-24 23:01:51 +00:00
|
|
|
|
2022-01-13 12:44:22 +00:00
|
|
|
const struct KernAux_Multiboot2_HTagBase *tag_base =
|
|
|
|
(struct KernAux_Multiboot2_HTagBase*)
|
|
|
|
KERNAUX_MULTIBOOT2_DATA(multiboot2_header);
|
|
|
|
|
2022-06-13 16:28:00 +00:00
|
|
|
KERNAUX_ASSERT(tag_base <= after_tag);
|
2022-05-24 23:01:51 +00:00
|
|
|
|
2022-01-13 12:44:22 +00:00
|
|
|
while (tag_base <
|
|
|
|
(struct KernAux_Multiboot2_HTagBase*)
|
|
|
|
((uint8_t*)multiboot2_header + multiboot2_header->total_size))
|
|
|
|
{
|
2022-01-14 06:42:36 +00:00
|
|
|
if (!KernAux_Multiboot2_HTagBase_is_valid(tag_base)) return NULL;
|
2022-01-13 12:44:22 +00:00
|
|
|
if (tag_base->type == tag_type && tag_base > after_tag) return tag_base;
|
|
|
|
|
2022-01-13 12:55:59 +00:00
|
|
|
tag_base = KERNAUX_MULTIBOOT2_HTAG_NEXT(tag_base);
|
2022-01-13 12:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|