LF OS
Hobby operating system for amd64 with high ambitions
|
Go to the source code of this file.
Data Structures | |
struct | region_t |
Macros | |
#define | ALLOCATOR_REGION_NULL (region_t){ .name = "NULL", .start = 0, .end = 0 } |
#define | ALLOCATOR_REGION_USER_STACK (region_t){ .name = "User stack", .start = 0x00003F0000001000, .end = 0x00003FFFFFFFEFF8 } |
#define | ALLOCATOR_REGION_USER_HARDWARE (region_t){ .name = "User MMIO", .start = 0x00007F0000000000, .end = 0x00007FFFFFFFDFFF } |
#define | ALLOCATOR_REGION_USER_IOPERM (region_t){ .name = "User ioperm bitmask", .start = 0x00007FFFFFFFE000, .end = 0x00007FFFFFFFFFFF } |
#define | ALLOCATOR_REGION_SCRATCHPAD (region_t){ .name = "Kernel scratchpad", .start = 0xFFFFFFFF80000000, .end = 0xFFFFFFFF80FFFFFF } |
#define | ALLOCATOR_REGION_KERNEL_BINARY (region_t){ .name = "Kernel binary", .start = 0xFFFFFFFF81000000, .end = 0xFFFFFFFF88FFFFFF } |
#define | ALLOCATOR_REGION_SLAB_4K (region_t){ .name = "4k slab allocator", .start = 0xFFFFFFFF89000000, .end = 0xFFFFFFFF8FFFFFFF } |
#define | ALLOCATOR_REGION_KERNEL_HEAP (region_t){ .name = "Kernel heap", .start = 0xFFFFFFFF90000000, .end = 0xFFFFFFFFFFFFFFFF } |
#define | ALLOCATOR_REGION_DIRECT_MAPPING (region_t){ .name = "Physical mapping", .start = 0xFFFF800000000000, .end = 0xFFFF83FFFFFFFFFF } |
Functions | |
void | init_vm (void) |
void | cleanup_boot_vm (void) |
void * | vm_alloc (size_t size) |
Like malloc but allocates full pages only. 16 byte data overhead. | |
void | vm_free (void *ptr) |
the matching free() like function for vm_alloc | |
struct vm_table * | vm_context_new (void) |
struct vm_table * | vm_current_context (void) |
void | vm_context_activate (struct vm_table *context) |
void | vm_context_map (struct vm_table *context, ptr_t virt, ptr_t physical, uint8_t pat) |
void | vm_context_unmap (struct vm_table *context, ptr_t virt) |
ptr_t | vm_context_find_free (struct vm_table *context, region_t region, size_t num) |
int | vm_table_get_free_index1 (struct vm_table *table) |
int | vm_table_get_free_index3 (struct vm_table *table, int start, int end) |
ptr_t | vm_context_get_physical_for_virtual (struct vm_table *context, ptr_t virt) |
ptr_t | vm_context_alloc_pages (struct vm_table *context, region_t region, size_t num) |
void | vm_copy_range (struct vm_table *dst_ctx, struct vm_table *src_ctx, ptr_t addr, size_t size) |
ptr_t | vm_map_hardware (ptr_t hw, size_t len) |
Map a given memory area in the currently running userspace process at a random location. | |
Variables | |
static const uint32_t | PageUsageKernel = 1 |
static const uint32_t | PageUsageHardware = 2 |
Page is used by kernel, userspace otherwise. | |
static const uint32_t | PageCoW = 4 |
Page accesses MMIO hardware, plain memory otherwise. | |
static const uint32_t | PageSharedMemory = 8 |
Copy page on fault and give RW access on new page, normal #PF logic otherwise. | |
static const uint32_t | PageLocked = 16 |
Page is mapped in multiple processes as shared memory. | |
static const uint32_t | PageUsagePagingStructure = 32 |
Page is locked and cannot be unmapped. | |
static const uint8_t | PageSize4KiB = 0 |
Page is used as paging structure. | |
static const uint8_t | PageSize2MiB = 1 |
static const uint8_t | PageSize1GiB = 2 |
struct vm_table * | VM_KERNEL_CONTEXT |
struct region_t |
void cleanup_boot_vm | ( | void | ) |
Definition at line 334 of file vm.c.
References BASE_TO_TABLE, vm_table::entries, GiB, vm_table_entry::huge, KiB, logi, MiB, vm_table_entry::next_base, vm_table_entry::present, and VM_KERNEL_CONTEXT.
void init_vm | ( | void | ) |
Definition at line 228 of file vm.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, ALLOCATOR_REGION_KERNEL_HEAP, BASE_TO_TABLE, vm_table::entries, vm_table_entry::global, vm_table_entry::huge, kernel_alloc, KiB, logd, logw, memcpy(), memset(), vm_table_entry::next_base, page_descriptors, PageSize1GiB, PageSize2MiB, PageSize4KiB, PageUsageKernel, PageUsagePagingStructure, PML4_INDEX, vm_table_entry::present, read_msr(), tpa_new(), vm_context_alloc_pages(), VM_KERNEL_CONTEXT, vm_page_alloc(), vm_ref_inc(), vm_set_page_descriptor(), vm_setup_direct_mapping_init(), and write_msr().
void * vm_alloc | ( | size_t | size | ) |
Like malloc but allocates full pages only. 16 byte data overhead.
Definition at line 697 of file vm.c.
References ALLOCATOR_REGION_KERNEL_HEAP, size, vm_context_alloc_pages(), and VM_KERNEL_CONTEXT.
void vm_context_activate | ( | struct vm_table * | context | ) |
Definition at line 388 of file vm.c.
References load_cr3(), vm_context_get_physical_for_virtual(), and VM_KERNEL_CONTEXT.
Definition at line 560 of file vm.c.
References mm_alloc_pages(), num, vm_context_find_free(), and vm_context_map().
Definition at line 531 of file vm.c.
References region_t::end, num, region_t::start, and vm_context_page_present().
Definition at line 475 of file vm.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, BASE_TO_TABLE, vm_table::entries, huge, next_base, PD_INDEX, PDP_INDEX, PML4_INDEX, present, and PT_INDEX.
Definition at line 406 of file vm.c.
References BASE_TO_TABLE, vm_table::entries, vm_table_entry::huge, next_base, vm_table_entry::next_base, vm_table_entry::pat0, vm_table_entry::pat1, PD_INDEX, PDP_INDEX, PML4_INDEX, vm_table_entry::present, PT_INDEX, vm_table_entry::userspace, vm_ensure_table(), and vm_table_entry::writeable.
struct vm_table * vm_context_new | ( | void | ) |
Definition at line 381 of file vm.c.
References ALLOCATOR_REGION_KERNEL_HEAP, memcpy(), vm_context_alloc_pages(), and VM_KERNEL_CONTEXT.
Definition at line 427 of file vm.c.
References BASE_TO_TABLE, vm_table::entries, vm_table_entry::next_base, PD_INDEX, PDP_INDEX, PML4_INDEX, vm_table_entry::present, PT_INDEX, vm_table_entry::userspace, and vm_table_entry::writeable.
void vm_copy_range | ( | struct vm_table * | dst_ctx, |
struct vm_table * | src_ctx, | ||
ptr_t | addr, | ||
size_t | size | ||
) |
Definition at line 597 of file vm.c.
References addr, BASE_TO_DIRECT_MAPPED, BASE_TO_TABLE, vm_table::entries, GiB, vm_table_entry::huge, KiB, logw, memcpy(), MiB, mm_alloc_pages(), vm_table_entry::next_base, panic_message(), PD_INDEX, PDP_INDEX, PML4_INDEX, vm_table_entry::present, PT_INDEX, size, and vm_ensure_table().
struct vm_table * vm_current_context | ( | void | ) |
Definition at line 743 of file vm.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, and vm_direct_mapping_initialized.
void vm_free | ( | void * | ptr | ) |
the matching free() like function for vm_alloc
Definition at line 707 of file vm.c.
References MM_FREE, mm_mark_physical_pages(), panic_message(), size, vm_context_get_physical_for_virtual(), vm_context_unmap(), and VM_KERNEL_CONTEXT.
Map a given memory area in the currently running userspace process at a random location.
Definition at line 755 of file vm.c.
References ALLOCATOR_REGION_USER_HARDWARE, vm_context_find_free(), vm_context_map(), and vm_current_context().
int vm_table_get_free_index1 | ( | struct vm_table * | table | ) |
Definition at line 461 of file vm.c.
References vm_table_get_free_index3().
int vm_table_get_free_index3 | ( | struct vm_table * | table, |
int | start, | ||
int | end | ||
) |
Definition at line 465 of file vm.c.
References vm_table::entries, and vm_table_entry::present.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |