PatchworkOS
966e257
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
mem.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
stdint.h
>
4
5
#include <
boot/boot_info.h
>
6
#include <
kernel/mem/paging_types.h
>
7
8
/**
9
* @brief Basic memory managment.
10
* @defgroup boot_mem Memory Management
11
* @ingroup boot
12
*
13
* Handles the loading of the UEFI memory map and setting up a basic memory allocator for after we have exited boot
14
* services but before we jump to the kernel as we cant use the normal memory allocator after exiting boot services.
15
*
16
* @{
17
*/
18
19
/**
20
* @brief The minimum amount of pages that we will reserve for the basic allocator.
21
*/
22
#define MEM_BASIC_ALLOCATOR_MIN_PAGES 8192
23
24
/**
25
* @brief The percentage of available memory that we will reserve for the basic allocator.
26
*
27
* This is rounded up to at least `MEM_BASIC_ALLOCATOR_MIN_PAGES`.
28
*/
29
#define MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE 5
30
31
/**
32
* @brief Initializes the basic memory allocator.
33
*
34
* @return On success, `EFI_SUCCESS`. On failure, an error code.
35
*/
36
EFI_STATUS
mem_init
(
void
);
37
38
/**
39
* @brief Initialize and load the memory map provided by the UEFI firmware.
40
*
41
* @param map The boot memory map structure to initialize.
42
* @return On success, `EFI_SUCCESS`. On failure, an error code.
43
*/
44
EFI_STATUS
mem_map_init
(
boot_memory_map_t
*
map
);
45
46
/**
47
* @brief Deinitializes the memory map and frees any allocated resources.
48
*
49
* @param map The boot memory map structure to deinitialize.
50
*/
51
void
mem_map_deinit
(
boot_memory_map_t
*
map
);
52
53
/**
54
* @brief Initializes a page table for use by the kernel.
55
*
56
* This function sets up a new page table and maps the memory regions specified in the boot memory map, the graphics
57
* output protocol (GOP) framebuffer, and the kernel itself.
58
*
59
* It is intended to be used after exiting UEFI boot services and will fill the screen with a solid color and halt the
60
* CPU if it encounters an error, as there is very little we can do in that situation.
61
*
62
* @param table The page table to initialize.
63
* @param map The boot memory map containing memory descriptors to be mapped.
64
* @param gop The graphics output protocol information for mapping the framebuffer.
65
* @param kernel The kernel information for mapping the kernel binary.
66
*/
67
void
mem_page_table_init
(
page_table_t
* table,
boot_memory_map_t
*
map
,
boot_gop_t
*
gop
,
boot_kernel_t
* kernel);
68
69
/** @} */
boot_info.h
mem_map_init
EFI_STATUS mem_map_init(boot_memory_map_t *map)
Initialize and load the memory map provided by the UEFI firmware.
Definition
mem.c:64
mem_page_table_init
void mem_page_table_init(page_table_t *table, boot_memory_map_t *map, boot_gop_t *gop, boot_kernel_t *kernel)
Initializes a page table for use by the kernel.
Definition
mem.c:125
mem_map_deinit
void mem_map_deinit(boot_memory_map_t *map)
Deinitializes the memory map and frees any allocated resources.
Definition
mem.c:83
mem_init
EFI_STATUS mem_init(void)
Initializes the basic memory allocator.
Definition
mem.c:22
gop
boot_gop_t * gop
Definition
mem.c:18
map
boot_memory_map_t * map
Definition
mem.c:19
paging_types.h
stdint.h
boot_gop_t
Definition
boot_info.h:43
boot_kernel_t
Definition
boot_info.h:88
boot_memory_map_t
Definition
boot_info.h:56
page_table_t
A page table structure.
Definition
paging_types.h:378
src
boot
mem.h
Generated on Mon Dec 15 2025 21:55:53 for PatchworkOS by
1.9.8