2022-06-15 03:58:14 -04:00
|
|
|
#include <kernaux/memmap.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2022-06-15 04:50:16 -04:00
|
|
|
#include <stdbool.h>
|
2022-06-16 06:55:32 -04:00
|
|
|
#include <stddef.h>
|
2022-06-15 03:58:14 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2022-06-15 04:50:16 -04:00
|
|
|
#define SIZE_256MiB ( 256 * 1024 * 1024)
|
|
|
|
#define SIZE_512MiB ( 512 * 1024 * 1024)
|
|
|
|
#define SIZE_1GiB (1024 * 1024 * 1024)
|
2022-06-15 03:58:14 -04:00
|
|
|
|
2022-06-16 13:35:09 -04:00
|
|
|
void example_main()
|
2022-06-15 03:58:14 -04:00
|
|
|
{
|
2022-06-15 06:10:44 -04:00
|
|
|
KernAux_MemMap memmap = { KernAux_MemMap_create(SIZE_1GiB) };
|
2022-06-15 03:58:14 -04:00
|
|
|
|
2022-06-15 04:50:16 -04:00
|
|
|
assert(KernAux_MemMap_add_entry(memmap, true, NULL, 0, SIZE_256MiB));
|
|
|
|
assert(KernAux_MemMap_add_entry(memmap, false, "foo", SIZE_256MiB, SIZE_256MiB));
|
|
|
|
assert(KernAux_MemMap_add_entry(memmap, true, "bar", SIZE_512MiB, SIZE_512MiB));
|
|
|
|
|
2022-06-15 05:16:29 -04:00
|
|
|
assert(KernAux_MemMap_finish(memmap));
|
|
|
|
|
2022-06-15 06:41:10 -04:00
|
|
|
// You can get the entry by it's index:
|
2022-06-15 05:49:37 -04:00
|
|
|
assert( KernAux_MemMap_entry_by_index(memmap, 0)->is_available == true);
|
|
|
|
assert(strcmp(KernAux_MemMap_entry_by_index(memmap, 0)->tag, "") == 0);
|
|
|
|
assert( KernAux_MemMap_entry_by_index(memmap, 0)->start == 0);
|
|
|
|
assert( KernAux_MemMap_entry_by_index(memmap, 0)->size == SIZE_256MiB);
|
|
|
|
assert( KernAux_MemMap_entry_by_index(memmap, 0)->end == SIZE_256MiB - 1);
|
|
|
|
assert( KernAux_MemMap_entry_by_index(memmap, 0)->limit == SIZE_256MiB);
|
|
|
|
|
2022-06-15 06:41:10 -04:00
|
|
|
// You can get the entry by it's start address:
|
2022-06-15 05:49:37 -04:00
|
|
|
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->is_available == false);
|
|
|
|
assert(strcmp(KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->tag, "foo") == 0);
|
|
|
|
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->start == SIZE_256MiB);
|
|
|
|
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->size == SIZE_256MiB);
|
|
|
|
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->end == SIZE_512MiB - 1);
|
|
|
|
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->limit == SIZE_512MiB);
|
|
|
|
|
2022-06-15 06:41:10 -04:00
|
|
|
// You can get the entry by any address inside it:
|
|
|
|
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_512MiB )->is_available == true);
|
|
|
|
assert(strcmp(KernAux_MemMap_entry_by_addr(memmap, SIZE_512MiB + 1 )->tag, "bar") == 0);
|
|
|
|
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_512MiB + SIZE_256MiB)->start == SIZE_512MiB);
|
|
|
|
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 3 )->size == SIZE_512MiB);
|
|
|
|
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 2 )->end == SIZE_1GiB - 1);
|
|
|
|
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 1 )->limit == SIZE_1GiB);
|
2022-06-15 03:58:14 -04:00
|
|
|
}
|