OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
kalloc.h
Go to the documentation of this file.
1#ifndef KALLOC_H
2#define KALLOC_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7/**
8 * @brief Aligns the given value `x` up to the nearest multiple of `a`.
9 *
10 * @param x The value to align.
11 * @param a The alignment boundary.
12 * @return The aligned value.
13 */
14#define ALIGNMENT_MASK(x, a) ((typeof(x))(a) - 1)
15/**
16 * @brief Aligns the given value `x` up to the nearest multiple of `a`.
17 *
18 * @param x The value to align.
19 * @param a The alignment boundary.
20 * @return The aligned value.
21 */
22#define ALIGN_UP(x, a) (((x) + ALIGNMENT_MASK(x, a)) & ~ALIGNMENT_MASK(x, a))
23/**
24 * @brief Aligns the given value `x` down to the nearest multiple of `a`.
25 *
26 * @param x The value to align.
27 * @param a The alignment boundary.
28 * @return The aligned value.
29 */
30#define ALIGN_DOWN(x, a) ((x) & ~ALIGNMENT_MASK(x, a))
31
32/**
33 * @brief The size of a memory page in bytes.
34 */
35#define PAGE_SIZE 4096
36
37/**
38 * @brief Rounds up the given address to the nearest page boundary
39 *
40 * @param addr The address to align.
41 * @return The aligned address.
42 */
43size_t page_align_up(size_t addr);
44/**
45 * @brief Rounds down the given address to the nearest page boundary
46 *
47 * @param addr The address to align.
48 * @return The aligned address.
49 */
50size_t page_align_down(size_t addr);
51
52/**
53 * @brief Initializes the kernel memory allocator.
54 */
55void kalloc_init(void);
56
57/**
58 * @brief Converts a physical address to a virtual address according to the Higher Half
59 * Direct Mapping (HHDM) scheme
60 *
61 * @param phys The physical address to convert.
62 * @return The virtual address.
63 */
64void *hhdm_physical_to_virtual(size_t phys);
65/**
66 * @brief Converts a virtual address to a physical address according to the Higher Half
67 * Direct Mapping (HHDM) scheme
68 *
69 * @param virt The virtual address to convert.
70 * @return The physical address.
71 */
72size_t hhdm_virtual_to_physical(void *virt);
73
74#endif
void * hhdm_physical_to_virtual(size_t phys)
Converts a physical address to a virtual address according to the Higher Half Direct Mapping (HHDM) s...
Definition kalloc.c:25
void kalloc_init(void)
Initializes the kernel memory allocator.
Definition kalloc.c:32
size_t page_align_down(size_t addr)
Rounds down the given address to the nearest page boundary.
Definition kalloc.c:16
size_t hhdm_virtual_to_physical(void *virt)
Converts a virtual address to a physical address according to the Higher Half Direct Mapping (HHDM) s...
Definition kalloc.c:28
size_t page_align_up(size_t addr)
Rounds up the given address to the nearest page boundary.
Definition kalloc.c:13