Physical Memory Manager.
More...
|
enum | pmm_flags_t { PMM_UNUSED,
PMM_RESERVED,
PMM_KERNEL,
PMM_USER
} |
| information on who uses a page frame (needs to fit in TYPE_BITS)
|
|
Physical Memory Manager.
The PMM allocates and frees physical page frames (blocks of 4KiB). It obtains an initial memory map from GRUB.
- See also
- http://wiki.osdev.org/Memory_management
-
http://wiki.osdev.org/Page_Frame_Allocation
-
http://www.lowlevel.eu/wiki/Physische_Speicherverwaltung
-
http://wiki.osdev.org/Detecting_Memory_(x86)
Allocates page frames.
- Parameters
-
len | requested number of consecutive free bytes |
flags | whether to allocate for kernel or user space |
- Returns
- the physical start address of the allocated memory range
Definition at line 183 of file pmm.c.
static uint32_t pmm_bitmap_get |
( |
uint32_t |
idx | ) |
|
|
static |
Returns a bitmap entry.
- Parameters
-
- Returns
- value of the bitmap entry, can be 9 to TYPE_MASK
Definition at line 72 of file pmm.c.
static void pmm_bitmap_set |
( |
uint32_t |
idx, |
|
|
uint32_t |
value |
|
) |
| |
|
static |
Sets a bitmap entry to a value.
- Parameters
-
idx | index into the bitmap |
value | value to set the entry to, can be 0 to TYPE_MASK |
Definition at line 58 of file pmm.c.
Returns whether a page frame is used or unused.
- Parameters
-
ptr | the physical address of the page frame to check |
- Returns
- information on who uses the page
Definition at line 206 of file pmm.c.
void pmm_dump |
( |
void * |
ptr, |
|
|
size_t |
len |
|
) |
| |
Dumps information on page frames for a given memory range.
The dump is logged.
- Parameters
-
ptr | the physical start address of the memory range |
len | the length of the memory range in bytes |
Definition at line 215 of file pmm.c.
static void* pmm_find_free |
( |
size_t |
len | ) |
|
|
static |
Finds free page frames.
- Parameters
-
len | requested number of consecutive free bytes |
- Returns
- the physical address of a suitable free memory range
Definition at line 160 of file pmm.c.
void pmm_free |
( |
void * |
ptr, |
|
|
size_t |
len |
|
) |
| |
Frees page frames.
- Parameters
-
ptr | the physical start address of the memory range |
len | the length of the memory range in bytes |
Definition at line 196 of file pmm.c.
void * pmm_get_address |
( |
uint32_t |
page, |
|
|
uint32_t |
offset |
|
) |
| |
Returns a memory address belonging to a given page.
- Parameters
-
page | a page index |
offset | number of bytes to add to the start of the page |
- Returns
- the first address of the page (if given, the offset is added)
Definition at line 130 of file pmm.c.
uint32_t pmm_get_highest_kernel_page |
( |
| ) |
|
Returns the highest page used by the kernel.
- Returns
- highest kernel page
Definition at line 235 of file pmm.c.
uint32_t pmm_get_page |
( |
void * |
ptr, |
|
|
uint32_t |
offset |
|
) |
| |
Returns to which page a given memory address belongs.
- Parameters
-
ptr | a physical or virtual address |
offset | number of bytes to add to ptr |
- Returns
- the page index that contains the address ptr
Definition at line 120 of file pmm.c.
Initializes the PMM.
First assumes the whole memory is used, GRUB tells us about free memory.
Prevents that we allocate or dereference the null pointer or BIOS data by pmm_use()'ing the first page table.
Copies the multiboot structures somewhere into the kernel so we can overwrite lower memory in VM86 mode later. Because our kernel starts at 4 MiB (the 2nd page table) we reserved the first page table above so that the multiboot structures lie directly after the kernel.
After the structures were copied from lower memory, frees 0x100000-0x3FFFFF to not waste too much memory.
Definition at line 87 of file pmm.c.
void pmm_use |
( |
void * |
ptr, |
|
|
size_t |
len, |
|
|
pmm_flags_t |
flags, |
|
|
char * |
tag |
|
) |
| |
Marks page frames for a given memory range as used or unused.
- Parameters
-
ptr | the physical start address of the memory range |
len | the length of the memory range in bytes |
flags | whether to allocate or free page frames |
tag | a short string for the debug log |
Definition at line 141 of file pmm.c.
Holds information on used page frames.
We could save some space here with dynamic allocation if we had it. This way we use up 2MiB of memory.
Definition at line 40 of file pmm.c.
void* main_kernel_stack_start |
|
static |
Initial value:= (void*) ((uintptr_t)
const void main_kernel_stack_end
end of the main kernel stack
start of the main kernel stack
Definition at line 50 of file pmm.c.