#include <physmem.h>
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 |
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.
|
Allocate a free page for use and return its physical address. Return NULL if there are no free pages to allocate.
|
|
Calculate how much physical memory is available on the system and store it in mem_size.
|
|
Deallocate a page and add it to the list of free pages, given its physical address.
|
|
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.
|
|
Return a pointer to the beginning of the map.
|
|
Return a pointer to the end of the map.
|
|
Return physical system memory size in bytes.
|
|
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.
|
|
Initialize the memory map according to the size of system memory. Kernel size is the size of the kernel in disk sectors.
|
|
Convert an entry in map to the physical page address corresponding to it.
|
|
Convert a physical memory address to the entry in the map corresponding to it.
|
|
array of ptrs to first free pages.
|
|
beginning of the map.
|
|
end of the map.
|
|
size of system memory in bytes.
|
|
array of ptrs to last free pages.
|
Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman