Main: include/kernaux/memmap.h: Added

This commit is contained in:
Alex Kotov 2022-06-15 10:58:14 +03:00
parent 0446478ce4
commit 5f668d05fe
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
11 changed files with 100 additions and 0 deletions

1
.gitignore vendored
View File

@ -109,6 +109,7 @@
/examples/cmdline
/examples/fprintf
/examples/fprintf_va
/examples/memmap
/examples/ntoa
/examples/panic
/examples/pfa

View File

@ -1,3 +1,7 @@
2022-06-15 Alex Kotov <kotovalexarian@gmail.com>
* include/kernaux/memmap.h: Added
2022-06-13 Alex Kotov <kotovalexarian@gmail.com>
* include/kernaux/version.h.in: Added

View File

@ -54,6 +54,9 @@ endif
if WITH_MBR
libkernaux_la_SOURCES += src/mbr.c
endif
if WITH_MEMMAP
libkernaux_la_SOURCES += src/memmap.c
endif
if WITH_MULTIBOOT2
libkernaux_la_SOURCES += \
src/multiboot2/enums_to_str.c \

View File

@ -63,6 +63,8 @@ zero). Work-in-progress APIs can change at any time.
* Utilities
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
* [To human](/examples/units_human.c)
* [Memory map](/include/kernaux/memmap.h) (*work in progress*)
* [Example](/examples/memmap.c)
* [printf format parser](/include/kernaux/printf_fmt.h) (*work in progress*)
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you!
* [Example](/examples/printf_fmt.c)

View File

@ -62,6 +62,7 @@ AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without E
AC_ARG_WITH( [framebuffer], AS_HELP_STRING([--without-framebuffer], [without framebuffer]))
AC_ARG_WITH( [io], AS_HELP_STRING([--without-io], [without input/output]))
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record]))
AC_ARG_WITH( [memmap], AS_HELP_STRING([--without-memmap], [without memory map]))
AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser]))
AC_ARG_WITH( [ntoa], AS_HELP_STRING([--without-ntoa], [without itoa/ftoa]))
AC_ARG_WITH( [pfa], AS_HELP_STRING([--without-pfa], [without Page Frame Allocator]))
@ -93,6 +94,7 @@ if test -z "$with_elf"; then with_elf=no; fi
if test -z "$with_framebuffer"; then with_framebuffer=no; fi
if test -z "$with_io"; then with_io=no; fi
if test -z "$with_mbr"; then with_mbr=no; fi
if test -z "$with_memmap"; then with_memmap=no; fi
if test -z "$with_multiboot2"; then with_multiboot2=no; fi
if test -z "$with_ntoa"; then with_ntoa=no; fi
if test -z "$with_pfa"; then with_pfa=no; fi
@ -128,6 +130,7 @@ AS_IF([test "$with_elf" = no ], [with_elf=no], [with_elf=
AS_IF([test "$with_framebuffer" = no ], [with_framebuffer=no], [with_framebuffer=yes])
AS_IF([test "$with_io" = no ], [with_io=no], [with_io=yes])
AS_IF([test "$with_mbr" = no ], [with_mbr=no], [with_mbr=yes])
AS_IF([test "$with_memmap" = no ], [with_memmap=no], [with_memmap=yes])
AS_IF([test "$with_multiboot2" = no ], [with_multiboot2=no], [with_multiboot2=yes])
AS_IF([test "$with_ntoa" = no ], [with_ntoa=no], [with_ntoa=yes])
AS_IF([test "$with_pfa" = no ], [with_pfa=no], [with_pfa=yes])
@ -184,6 +187,7 @@ AM_CONDITIONAL([WITH_ELF], [test "$with_elf" = yes])
AM_CONDITIONAL([WITH_FRAMEBUFFER], [test "$with_framebuffer" = yes])
AM_CONDITIONAL([WITH_IO], [test "$with_io" = yes])
AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" = yes])
AM_CONDITIONAL([WITH_MEMMAP], [test "$with_memmap" = yes])
AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" = yes])
AM_CONDITIONAL([WITH_NTOA], [test "$with_ntoa" = yes])
AM_CONDITIONAL([WITH_PFA], [test "$with_pfa" = yes])
@ -223,6 +227,7 @@ AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1]
AS_IF([test "$with_framebuffer" = yes], [AC_DEFINE([WITH_FRAMEBUFFER], [1], [with framebuffer])])
AS_IF([test "$with_io" = yes], [AC_DEFINE([WITH_IO], [1], [with input/output])])
AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])])
AS_IF([test "$with_memmap" = yes], [AC_DEFINE([WITH_MEMMAP], [1], [with memory map])])
AS_IF([test "$with_multiboot2" = yes], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])])
AS_IF([test "$with_ntoa" = yes], [AC_DEFINE([WITH_NTOA], [1], [with ntoa])])
AS_IF([test "$with_pfa" = yes], [AC_DEFINE([WITH_PFA], [1], [with Page Frame Allocator])])
@ -249,6 +254,7 @@ AS_IF([test "$with_elf" = no], [AC_SUBST([comment_line_elf], [//
AS_IF([test "$with_framebuffer" = no], [AC_SUBST([comment_line_framebuffer], [//])])
AS_IF([test "$with_io" = no], [AC_SUBST([comment_line_io], [//])])
AS_IF([test "$with_mbr" = no], [AC_SUBST([comment_line_mbr], [//])])
AS_IF([test "$with_memmap" = no], [AC_SUBST([comment_line_memmap], [//])])
AS_IF([test "$with_multiboot2" = no], [AC_SUBST([comment_line_multiboot2], [//])])
AS_IF([test "$with_ntoa" = no], [AC_SUBST([comment_line_ntoa], [//])])
AS_IF([test "$with_pfa" = no], [AC_SUBST([comment_line_pfa], [//])])

View File

@ -45,6 +45,16 @@ fprintf_va_SOURCES = fprintf_va.c
endif
endif
##########
# memmap #
##########
if WITH_MEMMAP
TESTS += memmap
memmap_LDADD = $(top_builddir)/libkernaux.la
memmap_SOURCES = memmap.c
endif
########
# ntoa #
########

15
examples/memmap.c Normal file
View File

@ -0,0 +1,15 @@
#include <kernaux/memmap.h>
#include <assert.h>
#include <string.h>
#define SIZE_1GiB (1024 * 1024 * 1024)
KernAux_MemMap memmap;
int main()
{
KernAux_MemMap_init(memmap, SIZE_1GiB);
return 0;
}

View File

@ -34,6 +34,9 @@ endif
if WITH_MBR
nobase_include_HEADERS += kernaux/mbr.h
endif
if WITH_MEMMAP
nobase_include_HEADERS += kernaux/memmap.h
endif
if WITH_MULTIBOOT2
nobase_include_HEADERS += kernaux/multiboot2.h
endif

View File

@ -13,6 +13,7 @@
@comment_line_framebuffer@#include <kernaux/framebuffer.h>
@comment_line_io@#include <kernaux/io.h>
@comment_line_mbr@#include <kernaux/mbr.h>
@comment_line_memmap@#include <kernaux/memmap.h>
@comment_line_multiboot2@#include <kernaux/multiboot2.h>
@comment_line_ntoa@#include <kernaux/ntoa.h>
@comment_line_pfa@#include <kernaux/pfa.h>

35
include/kernaux/memmap.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef KERNAUX_INCLUDED_MEMMAP
#define KERNAUX_INCLUDED_MEMMAP
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#define KERNAUX_MEMMAP_ENTRIES_MAX 100
#define KERNAUX_MEMMAP_ENTRY_TAG_SLEN_MAX 24
#define KERNAUX_MEMMAP_ENTRY_TAG_SIZE_MAX (KERNAUX_MEMMAP_ENTRY_TAG_SLEN_MAX + 1)
typedef struct KernAux_MemMap_Entry {
bool is_available;
char tag[KERNAUX_MEMMAP_ENTRY_TAG_SIZE_MAX];
size_t start, size, end, limit;
} KernAux_MemMap_Entry[1];
typedef struct KernAux_MemMap {
bool is_finished;
size_t memory_size;
size_t entries_count;
KernAux_MemMap_Entry entries[KERNAUX_MEMMAP_ENTRIES_MAX];
} KernAux_MemMap[1];
void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size);
#ifdef __cplusplus
}
#endif
#endif

20
src/memmap.c Normal file
View File

@ -0,0 +1,20 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/memmap.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#define MEMMAP (*memmap)
void KernAux_MemMap_init(KernAux_MemMap memmap, const size_t memory_size)
{
MEMMAP.is_finished = false;
MEMMAP.memory_size = memory_size;
MEMMAP.entries_count = 0;
memset(MEMMAP.entries, 0, sizeof(MEMMAP.entries));
}