mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-20 11:06:41 -05:00
Multiboot 2 header macros (#123)
This commit is contained in:
parent
1507d3ec21
commit
cb834226a7
8 changed files with 153 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -113,6 +113,7 @@
|
||||||
/examples/macro_container_of
|
/examples/macro_container_of
|
||||||
/examples/macro_packing
|
/examples/macro_packing
|
||||||
/examples/memmap
|
/examples/memmap
|
||||||
|
/examples/multiboot2_header_macro
|
||||||
/examples/ntoa
|
/examples/ntoa
|
||||||
/examples/panic
|
/examples/panic
|
||||||
/examples/pfa
|
/examples/pfa
|
||||||
|
|
|
@ -63,6 +63,7 @@ zero). Work-in-progress APIs can change at any time.
|
||||||
* [ELF](/include/kernaux/elf.h) (*work in progress*)
|
* [ELF](/include/kernaux/elf.h) (*work in progress*)
|
||||||
* [MBR](/include/kernaux/mbr.h) (*work in progress*)
|
* [MBR](/include/kernaux/mbr.h) (*work in progress*)
|
||||||
* [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h.in) (*work in progress*)
|
* [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h.in) (*work in progress*)
|
||||||
|
* [Example: header macros](/examples/multiboot2_header_macro.c)
|
||||||
* Utilities
|
* Utilities
|
||||||
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
|
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
|
||||||
* [Example: To human](/examples/units_human.c)
|
* [Example: To human](/examples/units_human.c)
|
||||||
|
|
|
@ -71,6 +71,16 @@ memmap_LDADD = $(top_builddir)/libkernaux.la
|
||||||
memmap_SOURCES = main.c memmap.c
|
memmap_SOURCES = main.c memmap.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# multiboot2_header_macro #
|
||||||
|
###########################
|
||||||
|
|
||||||
|
if WITH_MULTIBOOT2
|
||||||
|
TESTS += multiboot2_header_macro
|
||||||
|
multiboot2_header_macro_LDADD = $(top_builddir)/libkernaux.la
|
||||||
|
multiboot2_header_macro_SOURCES = main.c multiboot2_header_macro.c
|
||||||
|
endif
|
||||||
|
|
||||||
########
|
########
|
||||||
# ntoa #
|
# ntoa #
|
||||||
########
|
########
|
||||||
|
|
97
examples/multiboot2_header_macro.c
Normal file
97
examples/multiboot2_header_macro.c
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
#include <kernaux/multiboot2.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <kernaux/macro/packing_start.run>
|
||||||
|
|
||||||
|
__attribute__((aligned(KERNAUX_MULTIBOOT2_HEADER_ALIGN)))
|
||||||
|
static const struct {
|
||||||
|
struct KernAux_Multiboot2_Header header;
|
||||||
|
// This macro may be used to create the tag
|
||||||
|
// of type "KernAux_Multiboot2_HTag_InfoReq"
|
||||||
|
// when the number of requested information
|
||||||
|
// tag types is even (n % 2 == 0).
|
||||||
|
KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_EVEN(
|
||||||
|
// This is the name of the structure field.
|
||||||
|
tag_info_req_even,
|
||||||
|
// This is the number of requested information tag types.
|
||||||
|
// IT MUST BE EVEN!!! (n % 2 == 0)
|
||||||
|
2
|
||||||
|
)
|
||||||
|
// This macro may be used to create the tag
|
||||||
|
// of type "KernAux_Multiboot2_HTag_InfoReq"
|
||||||
|
// when the number of requested information
|
||||||
|
// tag types is odd (n % 2 == 1).
|
||||||
|
KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_ODD(
|
||||||
|
// This is the name of the structure field.
|
||||||
|
tag_info_req_odd,
|
||||||
|
// This is the number of requested information tag types.
|
||||||
|
// IT MUST BE ODD!!! (n % 2 == 1)
|
||||||
|
1,
|
||||||
|
// This is the name of the additional structure field
|
||||||
|
// which will be used to align the following tags properly.
|
||||||
|
// You may keep it unassigned.
|
||||||
|
_align1
|
||||||
|
)
|
||||||
|
// This macro may be used for all other header tag types.
|
||||||
|
KERNAUX_MULTIBOOT2_HFIELDS_COMMON(
|
||||||
|
// This is the name of the structure field.
|
||||||
|
tag_none,
|
||||||
|
// This is the type of the structure field
|
||||||
|
// without the "KernAux_Multiboot2_HTag_" prefix.
|
||||||
|
None
|
||||||
|
)
|
||||||
|
}
|
||||||
|
KERNAUX_PACKED
|
||||||
|
multiboot2_header = {
|
||||||
|
.header = {
|
||||||
|
.magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC,
|
||||||
|
.arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||||
|
.total_size = sizeof(multiboot2_header),
|
||||||
|
.checksum = KERNAUX_MULTIBOOT2_HEADER_CHECKSUM(
|
||||||
|
KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||||
|
sizeof(multiboot2_header)
|
||||||
|
),
|
||||||
|
},
|
||||||
|
.tag_info_req_even = {
|
||||||
|
.tag = {
|
||||||
|
.base = {
|
||||||
|
.type = KERNAUX_MULTIBOOT2_HTAG_INFO_REQ,
|
||||||
|
.flags = KERNAUX_MULTIBOOT2_HTAG_BASE_FLAG_OPTIONAL,
|
||||||
|
.size = sizeof(multiboot2_header.tag_info_req_even),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.mbi_tag_types = {
|
||||||
|
KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE,
|
||||||
|
KERNAUX_MULTIBOOT2_ITAG_BOOT_LOADER_NAME,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tag_info_req_odd = {
|
||||||
|
.tag = {
|
||||||
|
.base = {
|
||||||
|
.type = KERNAUX_MULTIBOOT2_HTAG_INFO_REQ,
|
||||||
|
.flags = KERNAUX_MULTIBOOT2_HTAG_BASE_FLAG_OPTIONAL,
|
||||||
|
.size = sizeof(multiboot2_header.tag_info_req_odd),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.mbi_tag_types = {
|
||||||
|
KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tag_none = {
|
||||||
|
.tag = {
|
||||||
|
.base = {
|
||||||
|
.type = KERNAUX_MULTIBOOT2_HTAG_NONE,
|
||||||
|
.flags = 0,
|
||||||
|
.size = sizeof(multiboot2_header.tag_none),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <kernaux/macro/packing_end.run>
|
||||||
|
|
||||||
|
void example_main()
|
||||||
|
{
|
||||||
|
assert(KernAux_Multiboot2_Header_is_valid(&multiboot2_header.header));
|
||||||
|
}
|
|
@ -70,7 +70,9 @@ if WITH_MEMMAP
|
||||||
nobase_include_HEADERS += kernaux/memmap.h
|
nobase_include_HEADERS += kernaux/memmap.h
|
||||||
endif
|
endif
|
||||||
if WITH_MULTIBOOT2
|
if WITH_MULTIBOOT2
|
||||||
nobase_include_HEADERS += kernaux/multiboot2.h
|
nobase_include_HEADERS += \
|
||||||
|
kernaux/multiboot2.h \
|
||||||
|
kernaux/multiboot2/header_macro.h
|
||||||
endif
|
endif
|
||||||
if WITH_NTOA
|
if WITH_NTOA
|
||||||
nobase_include_HEADERS += kernaux/ntoa.h
|
nobase_include_HEADERS += kernaux/ntoa.h
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
@comment_line_mbr@#include <kernaux/mbr.h>
|
@comment_line_mbr@#include <kernaux/mbr.h>
|
||||||
@comment_line_memmap@#include <kernaux/memmap.h>
|
@comment_line_memmap@#include <kernaux/memmap.h>
|
||||||
@comment_line_multiboot2@#include <kernaux/multiboot2.h>
|
@comment_line_multiboot2@#include <kernaux/multiboot2.h>
|
||||||
|
@comment_line_multiboot2@#include <kernaux/multiboot2/header_macro.h>
|
||||||
@comment_line_ntoa@#include <kernaux/ntoa.h>
|
@comment_line_ntoa@#include <kernaux/ntoa.h>
|
||||||
@comment_line_pfa@#include <kernaux/pfa.h>
|
@comment_line_pfa@#include <kernaux/pfa.h>
|
||||||
@comment_line_printf@#include <kernaux/printf.h>
|
@comment_line_printf@#include <kernaux/printf.h>
|
||||||
|
|
|
@ -7,6 +7,7 @@ extern "C" {
|
||||||
|
|
||||||
#include <kernaux/macro.h>
|
#include <kernaux/macro.h>
|
||||||
@comment_line_memmap@#include <kernaux/memmap.h>
|
@comment_line_memmap@#include <kernaux/memmap.h>
|
||||||
|
#include <kernaux/multiboot2/header_macro.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
39
include/kernaux/multiboot2/header_macro.h
Normal file
39
include/kernaux/multiboot2/header_macro.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef KERNAUX_INCLUDED_MULTIBOOT2_HEADER_MACRO
|
||||||
|
#define KERNAUX_INCLUDED_MULTIBOOT2_HEADER_MACRO
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <kernaux/macro.h>
|
||||||
|
#include <kernaux/multiboot2.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define KERNAUX_MULTIBOOT2_HFIELDS_COMMON(name, type) \
|
||||||
|
struct { \
|
||||||
|
struct KernAux_Multiboot2_HTag_##type tag; \
|
||||||
|
} KERNAUX_PACKED name;
|
||||||
|
|
||||||
|
#define KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_ODD( \
|
||||||
|
name, mbi_tag_types_count, align_name \
|
||||||
|
) \
|
||||||
|
struct { \
|
||||||
|
struct KernAux_Multiboot2_HTag_InfoReq tag; \
|
||||||
|
uint32_t mbi_tag_types[mbi_tag_types_count]; \
|
||||||
|
} KERNAUX_PACKED name; \
|
||||||
|
uint8_t align_name[4];
|
||||||
|
|
||||||
|
#define KERNAUX_MULTIBOOT2_HFIELDS_INFO_REQ_EVEN( \
|
||||||
|
name, mbi_tag_types_count \
|
||||||
|
) \
|
||||||
|
struct { \
|
||||||
|
struct KernAux_Multiboot2_HTag_InfoReq tag; \
|
||||||
|
uint32_t mbi_tag_types[mbi_tag_types_count]; \
|
||||||
|
} KERNAUX_PACKED name;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue