Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Physical_memory Class Reference

The Physical_memory map keeps track of which physical memory pages are available for allocation. More...

#include <physmem.h>

List of all members.

Public Methods

unsigned int * get_map_begin () const
unsigned int * get_map_end () const
unsigned int get_mem_size () const
unsigned int * phys_to_map (void *physical_address) const
void * map_to_phys (unsigned int *map_entry) const
unsigned int * get_first_free_page_entry (Memory_class mem_class) const
unsigned int * get_next_free_page_entry (unsigned int *entry, Memory_class mem_class) const
void * alloc_page (Memory_class mem_class=MEM_CLASS_ANY)
void free_page (void *page)
void init (unsigned short int kernel_size)

Protected Methods

void calc_memory_size ()

Protected Attributes

unsigned int * map_begin
unsigned int * map_end
unsigned int * heads [MEM_CLASS_ANY]
unsigned int * tails [MEM_CLASS_ANY]
unsigned int mem_size


Detailed Description

The Physical_memory map keeps track of which physical memory pages are available for allocation.

The map uses an array of 32-bit pointers, one per page of physical memory. The pointer for a free page points to the pointer in the map of the next free page. So the map constitutes a sort of statically allocated singly linked list. Any entry that can be reached by following this linked list is considered a free page. The heads and tails arrays are indexed by specific memory classes. E.g., heads[MEM_CLASS_BELOW_1MB] points to the map entry for the first free page in the "below 1 megabyte" memory class. So actually, there is one distinct linked list (head/tail pair) per memory class. But all the lists point into the same memory map.

If this is all a little confusing, well, it should be. The Physical_memory class is currently optimized for speed and the need to avoid doing allocations for its own data structures. It is unfortunately not optimized for making sense. If you have any questions, please ask. This whole scheme will probably have to be replaced at some point in the future since it doesn't support requesting contiguous pages of physical memory, as may be needed for certain DMA transfers.


Member Function Documentation

void * Physical_memory::alloc_page Memory_class    mem_class = MEM_CLASS_ANY
 

Allocate a free page for use and return its physical address. Return NULL if there are no free pages to allocate.

void Physical_memory::calc_memory_size   [protected]
 

Calculate how much physical memory is available on the system and store it in mem_size.

void Physical_memory::free_page void *    page
 

Deallocate a page and add it to the list of free pages, given its physical address.

unsigned int* Physical_memory::get_first_free_page_entry Memory_class    mem_class const [inline]
 

Return the map entry for the first free physical page in the linked list. First does not mean lowest in memory, but rather first in the linked list, which is not necessarily in order of ascending pages. Return NULL if there are no free pages. Note that mem_class cannot be MEM_CLASS_ANY here.

unsigned int* Physical_memory::get_map_begin   const [inline]
 

Return a pointer to the beginning of the map.

unsigned int* Physical_memory::get_map_end   const [inline]
 

Return a pointer to the end of the map.

unsigned int Physical_memory::get_mem_size   const [inline]
 

Return physical system memory size in bytes.

unsigned int * Physical_memory::get_next_free_page_entry unsigned int *    entry,
Memory_class    mem_class
const
 

Return the map entry for the next free physical page in the linked list following the given entry. Return NULL if there are no subsequent free pages. Note that mem_class cannot be MEM_CLASS_ANY here.

void Physical_memory::init unsigned short int    kernel_size
 

Initialize the memory map according to the size of system memory. Kernel size is the size of the kernel in disk sectors.

void* Physical_memory::map_to_phys unsigned int *    map_entry const [inline]
 

Convert an entry in map to the physical page address corresponding to it.

unsigned int* Physical_memory::phys_to_map void *    physical_address const [inline]
 

Convert a physical memory address to the entry in the map corresponding to it.


Member Data Documentation

unsigned int* Physical_memory::heads[MEM_CLASS_ANY] [protected]
 

array of ptrs to first free pages.

unsigned int* Physical_memory::map_begin [protected]
 

beginning of the map.

unsigned int* Physical_memory::map_end [protected]
 

end of the map.

unsigned int Physical_memory::mem_size [protected]
 

size of system memory in bytes.

unsigned int* Physical_memory::tails[MEM_CLASS_ANY] [protected]
 

array of ptrs to last free pages.


The documentation for this class was generated from the following files:

Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman