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

Kernel physical (and virtual) memory map. More...

#include <core.h>
#include <libc/string.h>
#include <kernel/x86/cpu.h>
#include <kernel/interrupt/interrupt.h>
#include <kernel/mem/kmem.h>
#include <kernel/mem/paging.h>
#include <kernel/mem/pmap.h>

Go to the source code of this file.

Functions

static uint64_t get_pdflags (uint32_t memtype)
 Return flags for large-page leaf entries in level 3 (PDPT) and level 2 (PDT) tables. More...
 
static uint64_t get_ptflags (uint32_t memtype)
 Return flags for entries in level 1 (PT) tables. More...
 
static uint64_t alloc_page (pagetable_t *pt)
 Allocate the next available page in the kernel page table and return its virtual address. More...
 
static void create_huge_page (pagetable_t *pt, uint64_t addr, uint32_t memtype)
 Create a 1GiB page entry in the kernel page table. More...
 
static void create_large_page (pagetable_t *pt, uint64_t addr, uint32_t memtype)
 Create a 2MiB page entry in the kernel page table. More...
 
static void create_small_page (pagetable_t *pt, uint64_t addr, uint32_t memtype)
 Create a 4KiB page entry in the kernel page table. More...
 
static void map_region (pagetable_t *pt, const pmap_t *map, const pmapregion_t *region)
 Map a region of memory into the kernel page table, using the largest page sizes possible. More...
 
void kmem_init (pagetable_t *pt)
 Using the contents of the physical memory map, identity map all physical memory into the kernel's page table. More...
 

Detailed Description

Kernel physical (and virtual) memory map.

Definition in file kmem.c.

Function Documentation

static uint64_t get_pdflags ( uint32_t  memtype)
static

Return flags for large-page leaf entries in level 3 (PDPT) and level 2 (PDT) tables.

Definition at line 21 of file kmem.c.

Referenced by create_huge_page(), and create_large_page().

static uint64_t get_ptflags ( uint32_t  memtype)
static

Return flags for entries in level 1 (PT) tables.

Definition at line 47 of file kmem.c.

Referenced by create_small_page().

static uint64_t alloc_page ( pagetable_t pt)
inlinestatic

Allocate the next available page in the kernel page table and return its virtual address.

Definition at line 74 of file kmem.c.

Referenced by create_huge_page(), create_large_page(), and create_small_page().

static void create_huge_page ( pagetable_t pt,
uint64_t  addr,
uint32_t  memtype 
)
static

Create a 1GiB page entry in the kernel page table.

Definition at line 86 of file kmem.c.

Referenced by map_region().

static void create_large_page ( pagetable_t pt,
uint64_t  addr,
uint32_t  memtype 
)
static

Create a 2MiB page entry in the kernel page table.

Definition at line 101 of file kmem.c.

Referenced by map_region().

static void create_small_page ( pagetable_t pt,
uint64_t  addr,
uint32_t  memtype 
)
static

Create a 4KiB page entry in the kernel page table.

Definition at line 121 of file kmem.c.

Referenced by map_region().

static void map_region ( pagetable_t pt,
const pmap_t *  map,
const pmapregion_t *  region 
)
static

Map a region of memory into the kernel page table, using the largest page sizes possible.

Definition at line 147 of file kmem.c.

Referenced by kmem_init().

void kmem_init ( pagetable_t pt)

Using the contents of the physical memory map, identity map all physical memory into the kernel's page table.

Parameters
[in,out]ptThe pagetable structure to hold a description of the kernel's page table.

Definition at line 189 of file kmem.c.

Referenced by page_init().