MonkOS  v0.1
A simple 64-bit operating system (x86_64)
pmap.c File Reference

Physical memory map describing usable and reserved regions of physical memory. More...

#include <core.h>
#include <libc/stdlib.h>
#include <libc/string.h>
#include <kernel/mem/kmem.h>
#include <kernel/mem/pmap.h>

Go to the source code of this file.

Functions

static void add_region (uint64_t addr, uint64_t size, enum pmemtype type)
 Add a memory region to the end of the memory map. More...
 
static int cmp_region (const void *a, const void *b)
 Compare two memory region records and return a sorting integer. More...
 
static void collapse (pmapregion_t *r, pmapregion_t *term)
 Remove a region from the memory map and shift all subsequent regions down by one. More...
 
static void insertafter (pmapregion_t *r, pmapregion_t *term)
 Insert a new, uninitialized memory region record after an existing record in the memory map. More...
 
static void resort (pmapregion_t *r, pmapregion_t *term)
 Re-sort all unsorted region records starting from the requested record. More...
 
static void collapse_overlaps ()
 Find all overlapping memory regions in the memory map and collapse or reorganize them. More...
 
static void fill_gaps (int32_t type)
 Find missing memory regions in the map, and fill them with entries of the requested type. More...
 
static void consolidate_neighbors ()
 Find adjacent memory entries of the same type and merge them. More...
 
static void update_last_usable ()
 
static void normalize ()
 
void pmap_init ()
 Initialize the physical memory map using data installed by the BIOS during boot loading. More...
 
const pmap_t * pmap ()
 Return a pointer to the current physical memory map. More...
 
void pmap_add (uint64_t addr, uint64_t size, enum pmemtype type)
 Add a region of memory to the physical memory map. More...
 

Variables

static pmap_t * map = (pmap_t *)KMEM_TABLE_BIOS
 
static bool initialized = false
 

Detailed Description

Physical memory map describing usable and reserved regions of physical memory.

Before this code is ever executed, the boot code has filled much of the memory map with memory regions supplied by the BIOS.

Definition in file pmap.c.

Function Documentation

static void add_region ( uint64_t  addr,
uint64_t  size,
enum pmemtype  type 
)
static

Add a memory region to the end of the memory map.

Definition at line 26 of file pmap.c.

Referenced by pmap_add(), and pmap_init().

static int cmp_region ( const void *  a,
const void *  b 
)
static

Compare two memory region records and return a sorting integer.

Definition at line 39 of file pmap.c.

Referenced by normalize(), and resort().

static void collapse ( pmapregion_t *  r,
pmapregion_t *  term 
)
inlinestatic

Remove a region from the memory map and shift all subsequent regions down by one.

Definition at line 57 of file pmap.c.

Referenced by collapse_overlaps(), and consolidate_neighbors().

static void insertafter ( pmapregion_t *  r,
pmapregion_t *  term 
)
inlinestatic

Insert a new, uninitialized memory region record after an existing record in the memory map.

Definition at line 67 of file pmap.c.

Referenced by collapse_overlaps(), and fill_gaps().

static void resort ( pmapregion_t *  r,
pmapregion_t *  term 
)
static

Re-sort all unsorted region records starting from the requested record.

Definition at line 76 of file pmap.c.

Referenced by collapse_overlaps().

static void collapse_overlaps ( )
static

Find all overlapping memory regions in the memory map and collapse or reorganize them.

Definition at line 91 of file pmap.c.

Referenced by normalize().

static void fill_gaps ( int32_t  type)
static

Find missing memory regions in the map, and fill them with entries of the requested type.

Definition at line 205 of file pmap.c.

Referenced by normalize().

static void consolidate_neighbors ( )
static

Find adjacent memory entries of the same type and merge them.

Definition at line 245 of file pmap.c.

Referenced by normalize().

static void update_last_usable ( )
static

Definition at line 263 of file pmap.c.

Referenced by normalize().

static void normalize ( )
static

Definition at line 276 of file pmap.c.

Referenced by pmap_add(), and pmap_init().

void pmap_init ( )

Initialize the physical memory map using data installed by the BIOS during boot loading.

Definition at line 292 of file pmap.c.

Referenced by kmain().

const pmap_t* pmap ( )

Return a pointer to the current physical memory map.

Returns
A pointer to the physical memory map.

Definition at line 316 of file pmap.c.

Referenced by kmem_init(), and page_init().

void pmap_add ( uint64_t  addr,
uint64_t  size,
enum pmemtype  type 
)

Add a region of memory to the physical memory map.

Parameters
[in]addrThe starting address of the region.
[in]sizeThe size of the region.
[in]typeThe type of memory to add.

Definition at line 322 of file pmap.c.

Referenced by acpi_init(), map_table(), and reserve_region().

Variable Documentation

bool initialized = false
static

Definition at line 22 of file pmap.c.

Referenced by pmap_add(), and pmap_init().