IBNOS
|
Classes | |
struct | physMemExtraInfo |
Macros | |
#define | PAGE_SIZE 0x1000 |
#define | PAGE_MASK 0xFFF |
#define | PAGE_BITS 12 |
#define | PAGE_COUNT 0x100000 |
#define | PHYSMEM_FREE 0 |
#define | PHYSMEM_RESERVED 1 |
#define | PHYSMEMEXTRA_SIZE 0x1000 /* must match PAGE_SIZE for now */ |
#define | PHYSMEMEXTRA_MASK 0x3FF |
#define | PHYSMEMEXTRA_BITS 10 |
#define | PHYSMEMEXTRA_COUNT 0x400 |
#define | LINKER_KERNEL_BEGIN ((uint32_t)&__kernelBegin) |
#define | LINKER_KERNEL_SIZE ((uint32_t)&__kernelEnd - (uint32_t)&__kernelBegin) |
Functions | |
void | physMemInit (multiboot_info_t *bootInfo) |
Initializes the physical memory management. More... | |
uint32_t | physMemRAMSize () |
Query RAM size. More... | |
uint32_t | physMemUsableMemory () |
Query usable RAM size. More... | |
void | physMemProtectBootEntry (uint32_t addr, uint32_t length) |
Marks all pages within a memory range as reserved and adds them to the boot map. More... | |
void | physMemClearMemoryBits (bool reserved) |
Marks the full memory range as reserved or free. More... | |
void | physMemReserveMemory (uint32_t addr, uint32_t length) |
Marks all pages within a memory range as reserved. More... | |
void | physMemFreeMemory (uint32_t addr, uint32_t length) |
Marks all pages fully contained within the memory range as free. More... | |
void | physMemSetMemoryBits (uint32_t startIndex, uint32_t length, bool reserved) |
Marks a specific range of pages as reserved or free. More... | |
uint32_t | physMemAllocPage (bool lowmem) |
Allocates a page of physical memory. More... | |
uint32_t | physMemReleasePage (uint32_t index) |
Releases a page of physical memory. More... | |
uint32_t | physMemAddRefPage (uint32_t index) |
Increment the refcounter of a physical page. More... | |
uint32_t | physMemMarkUnpageable (uint32_t index) |
Marks a physical page as unpageable. More... | |
bool | physMemIsLastRef (uint32_t index) |
Checks if a physical page is only referenced exactly one time. More... | |
void | physMemPageOut (UNUSED uint32_t length) |
Pages out some memory to the hard drive. More... | |
uint32_t | physMemPageIn (UNUSED uint32_t hdd_index) |
Pages in some data from the hard drive. More... | |
void | physMemDumpMemInfo () |
Dumps information about the physical memory usage. More... | |
struct physMemExtraInfo | __attribute__ ((packed)) |
uint32_t | __getCR0 () |
asm (".text\align 4\ "__getCR0:\" " movl %cr0, %eax\" " ret\") | |
Variables | |
uint32_t | ramSize = 0 |
uint32_t | ramUsableSize = 0 |
uint32_t | __kernelBegin |
uint32_t | __kernelEnd |
#define LINKER_KERNEL_BEGIN ((uint32_t)&__kernelBegin) |
#define LINKER_KERNEL_SIZE ((uint32_t)&__kernelEnd - (uint32_t)&__kernelBegin) |
#define PHYSMEMEXTRA_SIZE 0x1000 /* must match PAGE_SIZE for now */ |
struct physMemExtraInfo __attribute__ | ( | (packed) | ) |
uint32_t __getCR0 | ( | ) |
asm | ( | ".text\ign 4\__getCR0:\ " movl % | cr0, |
%eax\" " ret\" | |||
) |
uint32_t physMemAddRefPage | ( | uint32_t | index | ) |
uint32_t physMemAllocPage | ( | bool | lowmem | ) |
Allocates a page of physical memory.
This command searches for an unused page in the physical memory bitmap and afterwards marks the specific page as reserved. If there is no physical memory left then the algorithm tries to page out some memory to the hard drive. If this fails then a system failure is triggered.
lowmem | If true then the search also includes the physical memory area below 1MB |
void physMemClearMemoryBits | ( | bool | reserved | ) |
void physMemDumpMemInfo | ( | ) |
void physMemFreeMemory | ( | uint32_t | addr, |
uint32_t | length | ||
) |
void physMemInit | ( | multiboot_info_t * | bootInfo | ) |
Initializes the physical memory management.
In order to implement physMemAllocPage() the operating system has to keep track of all used and unused physical pages. Internally this module works using a huge bitmap, where a 1 represents a used page, and 0 an unused page. This function initializes all the structures using the memory layout information filled by the GRUB boot loader.
bootInfo | Bootinfo structure filled by the GRUB boot loader |
bool physMemIsLastRef | ( | uint32_t | index | ) |
Checks if a physical page is only referenced exactly one time.
Looks up the refcount of a specific page, and returns true if the refcount is exactly one.
index | Index of the physical page |
uint32_t physMemMarkUnpageable | ( | uint32_t | index | ) |
Marks a physical page as unpageable.
Marks a physical page as unpageable, to ensure that it is never paged out to the hard drive. This is necessary for some kernel related pages, like GDT or interrupt handler functions.
index | Index of the physical page |
uint32_t physMemPageIn | ( | UNUSED uint32_t | hdd_index | ) |
Pages in some data from the hard drive.
Allocates a physical page (which possibily pages out other stuff, if the physical memory is exhausted). Afterwards loads the data from the hard drive (including permission bits and other stuff which was modified).
hdd_index | Index to a page on the hard drive |
void physMemPageOut | ( | UNUSED uint32_t | length | ) |
void physMemProtectBootEntry | ( | uint32_t | addr, |
uint32_t | length | ||
) |
uint32_t physMemRAMSize | ( | ) |
Query RAM size.
Returns the amount of available physical memory. This information is only available after the physical memory management was initialized by calling physMemInit().
uint32_t physMemReleasePage | ( | uint32_t | index | ) |
Releases a page of physical memory.
Deallocates a page of physical memory, or if the page has a refcount of greater than 1, then decrements the refcount. The refcounting menchanism ensures that the memory is not released before all processes containing the same physical memory page have released it again.
index | Index of the physical page to deallocate |
void physMemReserveMemory | ( | uint32_t | addr, |
uint32_t | length | ||
) |
void physMemSetMemoryBits | ( | uint32_t | startIndex, |
uint32_t | length, | ||
bool | reserved | ||
) |
uint32_t physMemUsableMemory | ( | ) |
Query usable RAM size.
Returns the amount of useable physical memory. This is similar to physMemRAMSize(), except that all unpageable and kernel related pages are subtracted. This information is only available after the physical memory management was initialized.
uint32_t __kernelBegin |
uint32_t __kernelEnd |