OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
kalloc.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define ALIGNMENT_MASK(x, a)   ((typeof(x))(a) - 1)
 Aligns the given value x up to the nearest multiple of a.
 
#define ALIGN_UP(x, a)   (((x) + ALIGNMENT_MASK(x, a)) & ~ALIGNMENT_MASK(x, a))
 Aligns the given value x up to the nearest multiple of a.
 
#define ALIGN_DOWN(x, a)   ((x) & ~ALIGNMENT_MASK(x, a))
 Aligns the given value x down to the nearest multiple of a.
 
#define PAGE_SIZE   4096
 The size of a memory page in bytes.
 

Functions

size_t page_align_up (size_t addr)
 Rounds up the given address to the nearest page boundary.
 
size_t page_align_down (size_t addr)
 Rounds down the given address to the nearest page boundary.
 
void kalloc_init (void)
 Initializes the kernel memory allocator.
 
void * hhdm_physical_to_virtual (size_t phys)
 Converts a physical address to a virtual address according to the Higher Half Direct Mapping (HHDM) scheme.
 
size_t hhdm_virtual_to_physical (void *virt)
 Converts a virtual address to a physical address according to the Higher Half Direct Mapping (HHDM) scheme.
 

Macro Definition Documentation

◆ ALIGN_DOWN

#define ALIGN_DOWN (   x,
  a 
)    ((x) & ~ALIGNMENT_MASK(x, a))

Aligns the given value x down to the nearest multiple of a.

Parameters
xThe value to align.
aThe alignment boundary.
Returns
The aligned value.

◆ ALIGN_UP

#define ALIGN_UP (   x,
  a 
)    (((x) + ALIGNMENT_MASK(x, a)) & ~ALIGNMENT_MASK(x, a))

Aligns the given value x up to the nearest multiple of a.

Parameters
xThe value to align.
aThe alignment boundary.
Returns
The aligned value.

◆ ALIGNMENT_MASK

#define ALIGNMENT_MASK (   x,
  a 
)    ((typeof(x))(a) - 1)

Aligns the given value x up to the nearest multiple of a.

Parameters
xThe value to align.
aThe alignment boundary.
Returns
The aligned value.

◆ PAGE_SIZE

#define PAGE_SIZE   4096

The size of a memory page in bytes.

Function Documentation

◆ hhdm_physical_to_virtual()

void * hhdm_physical_to_virtual ( size_t  phys)

Converts a physical address to a virtual address according to the Higher Half Direct Mapping (HHDM) scheme.

Parameters
physThe physical address to convert.
Returns
The virtual address.

◆ hhdm_virtual_to_physical()

size_t hhdm_virtual_to_physical ( void *  virt)

Converts a virtual address to a physical address according to the Higher Half Direct Mapping (HHDM) scheme.

Parameters
virtThe virtual address to convert.
Returns
The physical address.

◆ kalloc_init()

void kalloc_init ( void  )

Initializes the kernel memory allocator.

◆ page_align_down()

size_t page_align_down ( size_t  addr)

Rounds down the given address to the nearest page boundary.

Parameters
addrThe address to align.
Returns
The aligned address.

◆ page_align_up()

size_t page_align_up ( size_t  addr)

Rounds up the given address to the nearest page boundary.

Parameters
addrThe address to align.
Returns
The aligned address.