PatchworkOS
Loading...
Searching...
No Matches
pmm_stack.c
Go to the documentation of this file.
2
3#include <sys/math.h>
4
6{
7 stack->last = NULL;
8 stack->index = 0;
9 stack->free = 0;
10}
11
13{
14 if (stack->last == NULL)
15 {
16 return NULL;
17 }
18
19 void* address;
20 if (stack->index == 0)
21 {
25 }
26 else
27 {
29 }
30
31 stack->free--;
32
33 return address;
34}
35
37{
39
40 if (stack->last == NULL)
41 {
43 stack->last->prev = NULL;
44 stack->index = 0;
45 }
46 else if (stack->index == PMM_BUFFER_MAX)
47 {
49 next->prev = stack->last;
50 stack->last = next;
51 stack->index = 0;
52 }
53 else
54 {
56 }
57
58 stack->free++;
59}
void * pmm_stack_alloc(pmm_stack_t *stack)
Allocates a single page from the stack.
Definition pmm_stack.c:12
#define PMM_BUFFER_MAX
The maximum number of pages that can be stored in a page_buffer_t.
Definition pmm_stack.h:36
void pmm_stack_init(pmm_stack_t *stack)
Initializes a PMM stack.
Definition pmm_stack.c:5
void pmm_stack_free(pmm_stack_t *stack, void *address)
Frees a single page, returning it to the stack.
Definition pmm_stack.c:36
#define ROUND_DOWN(number, multiple)
Definition math.h:21
#define PAGE_SIZE
Memory page size.
Definition proc.h:140
#define NULL
Pointer error value.
Definition NULL.h:23
static uintptr_t address
Definition hpet.c:12
static pmm_stack_t stack
Definition pmm.c:36
static atomic_long next
Definition main.c:10
Structure for a page buffer in the PMM stack.
Definition pmm_stack.h:22
void * pages[]
Flexible array member to store free physical pages.
Definition pmm_stack.h:30
struct page_buffer * prev
Pointer to the previous page buffer in the stack.
Definition pmm_stack.h:26
PMM stack structure for managing higher physical memory.
Definition pmm_stack.h:42
uint64_t free
The number of free pages in the stack.
Definition pmm_stack.h:54
page_buffer_t * last
Pointer to the last page buffer in the stack.
Definition pmm_stack.h:46
uint64_t index
Current index within the pages array of the last page buffer.
Definition pmm_stack.h:50