Skip to content

Commit

Permalink
Refactor the mapping functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Nov 12, 2023
1 parent 22f1b89 commit 7f957cc
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 63 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ gdb: $(BUILD_FOLDER)/$(ISO_IMAGE_FILENAME)

tests:
#rm -f tests/*.o
$(X_CC) ${TESTFLAGS} tests/test_mem.c tests/test_common.c src/kernel/mem/bitmap.c src/kernel/mem/vmm_util.c src/kernel/mem/pmm.c src/kernel/mem/mmap.c -o tests/test_mem.o
$(X_CC) ${TESTFLAGS} tests/test_number_conversion.c tests/test_common.c src/base/numbers.c -o tests/test_number_conversion.o
$(X_CC) ${TESTFLAGS} tests/test_kheap.c tests/test_common.c src/kernel/mem/kheap.c src/kernel/mem/bitmap.c src/kernel/mem/pmm.c src/kernel/mem/mmap.c src/kernel/mem/vmm_util.c -o tests/test_kheap.o
$(X_CC) ${TESTFLAGS} tests/test_vm.c tests/test_common.c src/kernel/arch/x86_64/system/vm.c src/kernel/mem/vmm_util.c -o tests/test_vm.o
$(X_CC) ${TESTFLAGS} tests/test_vfs.c tests/test_common.c src/fs/vfs.c src/drivers/fs/ustar.c -o tests/test_vfs.o
$(X_CC) ${TESTFLAGS} tests/test_utils.c src/kernel/mem/vmm_util.c -o tests/test_utils.o
gcc ${TESTFLAGS} tests/test_mem.c tests/test_common.c src/kernel/mem/bitmap.c src/kernel/mem/vmm_util.c src/kernel/mem/pmm.c src/kernel/mem/mmap.c -o tests/test_mem.o
gcc ${TESTFLAGS} tests/test_number_conversion.c tests/test_common.c src/base/numbers.c -o tests/test_number_conversion.o
gcc ${TESTFLAGS} tests/test_kheap.c tests/test_common.c src/kernel/mem/kheap.c src/kernel/mem/bitmap.c src/kernel/mem/pmm.c src/kernel/mem/mmap.c src/kernel/mem/vmm_util.c -o tests/test_kheap.o
gcc ${TESTFLAGS} tests/test_vm.c tests/test_common.c src/kernel/arch/x86_64/system/vm.c src/kernel/mem/vmm_util.c -o tests/test_vm.o
gcc ${TESTFLAGS} tests/test_vfs.c tests/test_common.c src/fs/vfs.c src/drivers/fs/ustar.c -o tests/test_vfs.o
gcc ${TESTFLAGS} tests/test_utils.c src/kernel/mem/vmm_util.c -o tests/test_utils.o
./tests/test_mem.o && ./tests/test_kheap.o && ./tests/test_number_conversion.o && ./tests/test_vm.o && ./tests/test_vfs.o && ./tests/test_utils.o

12 changes: 6 additions & 6 deletions src/kernel/arch/x86_64/cpu/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void parse_SDT(uint64_t address, uint8_t type) {
void parse_RSDT(RSDPDescriptor *descriptor){
loglinef(Verbose, "(parse_RSDT): - Parse RSDP Descriptor");
loglinef(Verbose, "(parse_RSDT): - descriptor Address: 0x%x", descriptor->RsdtAddress);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(descriptor->RsdtAddress), (void *) ensure_address_in_higher_half(descriptor->RsdtAddress), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(descriptor->RsdtAddress), (void *) ensure_address_in_higher_half(descriptor->RsdtAddress), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(descriptor->RsdtAddress));
rsdt_root = (RSDT *) ensure_address_in_higher_half((uint64_t) descriptor->RsdtAddress);
ACPISDTHeader header = rsdt_root->header;
Expand All @@ -46,15 +46,15 @@ void parse_RSDT(RSDPDescriptor *descriptor){
//loglinef(Verbose, "(parse_RSDT): - RSDT_PAGES_NEEDED: %d", required_extra_pages);
for (size_t j = 1; j < required_extra_pages; j++) {
uint64_t new_physical_address = descriptor->RsdtAddress + (j * KERNEL_PAGE_SIZE);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(new_physical_address), (void *) ensure_address_in_higher_half(new_physical_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(new_physical_address), (void *) ensure_address_in_higher_half(new_physical_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(new_physical_address));
}
}
rsdtTablesTotal = (header.Length - sizeof(ACPISDTHeader)) / sizeof(uint32_t);
loglinef(Verbose, "(parse_RSDT): - Total rsdt Tables: %d", rsdtTablesTotal);

for(uint32_t i=0; i < rsdtTablesTotal; i++) {
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(rsdt_root->tables[i]), (void *) ensure_address_in_higher_half(rsdt_root->tables[i]), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(rsdt_root->tables[i]), (void *) ensure_address_in_higher_half(rsdt_root->tables[i]), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
ACPISDTHeader *tableHeader = (ACPISDTHeader *) ensure_address_in_higher_half(rsdt_root->tables[i]);
loglinef(Verbose, "(parse_RSDT): \tTable header %d: Signature: %.4s", i, tableHeader->Signature);
}
Expand All @@ -63,7 +63,7 @@ void parse_RSDT(RSDPDescriptor *descriptor){
void parse_RSDTv2(RSDPDescriptor20 *descriptor){
loglinef(Verbose, "(parse_RSDTv2): Parse RSDP v2 Descriptor\n");
loglinef(Verbose, "(parse_RSDTv2): - Descriptor physical address: 0x%x", ALIGN_PHYSADDRESS(descriptor->XsdtAddress));
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(descriptor->XsdtAddress), (void *) ensure_address_in_higher_half(descriptor->XsdtAddress), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(descriptor->XsdtAddress), (void *) ensure_address_in_higher_half(descriptor->XsdtAddress), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(descriptor->XsdtAddress));
xsdt_root = (XSDT *) ensure_address_in_higher_half((uint64_t) descriptor->XsdtAddress);
loglinef(Verbose, "(parse_RSDTv2): - XSDT_Length: 0x%x", descriptor->Length);
Expand All @@ -76,7 +76,7 @@ void parse_RSDTv2(RSDPDescriptor20 *descriptor){
if (required_extra_pages > 1) {
for (size_t j = 1; j < required_extra_pages; j++) {
uint64_t new_physical_address = descriptor->XsdtAddress + (j * KERNEL_PAGE_SIZE);
map_phys_to_virt_addr((uint64_t *) new_physical_address, (uint64_t *) ensure_address_in_higher_half(new_physical_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((uint64_t *) new_physical_address, (uint64_t *) ensure_address_in_higher_half(new_physical_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(new_physical_address));
}
}
Expand All @@ -85,7 +85,7 @@ void parse_RSDTv2(RSDPDescriptor20 *descriptor){
loglinef(Verbose, "(parse_RSDTv2): - Total xsdt Tables: %d", rsdtTablesTotal);

for(uint32_t i=0; i < rsdtTablesTotal; i++) {
map_phys_to_virt_addr((uint64_t *) ALIGN_PHYSADDRESS(xsdt_root->tables[i]), (uint64_t *) ensure_address_in_higher_half(xsdt_root->tables[i]), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((uint64_t *) ALIGN_PHYSADDRESS(xsdt_root->tables[i]), (uint64_t *) ensure_address_in_higher_half(xsdt_root->tables[i]), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(xsdt_root->tables[i]));
ACPISDTHeader *tableHeader = (ACPISDTHeader *) ensure_address_in_higher_half(xsdt_root->tables[i]);
loglinef(Verbose, "(parse_RSDTv2): \tTable header %d: Signature: %.4s", i, tableHeader->Signature);
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/arch/x86_64/cpu/ioapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void init_ioapic(MADT *madt_table){
loglinef(Verbose, "(init_ioapic): IOAPIC Item address: 0x%x - length: 0x%x", item, item->length);
IO_APIC_Item *ioapic_item = (IO_APIC_Item *) ( ensure_address_in_higher_half((uint64_t) item + sizeof(MADT_Item)));
if (is_phyisical_address_mapped(ALIGN_PHYSADDRESS((uint64_t) item), ensure_address_in_higher_half((uint64_t) item)) == PHYS_ADDRESS_NOT_MAPPED) {
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS((uint64_t) item), (void *)ensure_address_in_higher_half((uint64_t) item),VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS((uint64_t) item), (void *)ensure_address_in_higher_half((uint64_t) item),VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
}
loglinef(Verbose, "(init_ioapic): IOAPIC_ID: 0x%x, Address: 0x%x", ioapic_item->ioapic_id, ioapic_item->address );
loglinef(Verbose, "(init_ioapic): IOApic_Global_System_Interrupt_Base: 0x%x", ioapic_item->global_system_interrupt_base);
Expand All @@ -30,7 +30,7 @@ void init_ioapic(MADT *madt_table){
io_apic_hh_base_address = ensure_address_in_higher_half(ioapic_item->address);
// This one should be mapped in the higher half ??
//map_phys_to_virt_addr(VPTR(io_apic_base_address), VPTR(io_apic_base_address), 0);
map_phys_to_virt_addr(VPTR(io_apic_base_address), (void *) io_apic_hh_base_address, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr(VPTR(io_apic_base_address), (void *) io_apic_hh_base_address, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit(ADDRESS_TO_BITMAP_ENTRY(io_apic_base_address));
uint32_t ioapic_version = read_io_apic_register(IO_APIC_VER_OFFSET);
loglinef(Info, "(init_ioapic): IOAPIC Version: 0x%x", ioapic_version);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/arch/x86_64/cpu/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void init_apic() {
kernel_settings.use_x2_apic = false;

//registers are accessed via mmio, make sure they're identity mapped
map_phys_to_virt_addr(VPTR(apic_base_address), VPTR(apic_hh_base_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr(VPTR(apic_base_address), VPTR(apic_hh_base_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
}
else {
kernel_settings.use_x2_apic = false;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/arch/x86_64/cpu/madt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void map_madt(MADT* table){
}

uint64_t madt_address = ((uint64_t) table + sizeof(MADT));
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(madt_address), (void *) ensure_address_in_higher_half(madt_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void *) ALIGN_PHYSADDRESS(madt_address), (void *) ensure_address_in_higher_half(madt_address), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
_bitmap_set_bit_from_address(ALIGN_PHYSADDRESS(madt_address));
loglinef(Verbose, "(map_madt): Sizeof MADT struct: 0x%x", sizeof(MADT));
madt_base = (MADT_Item *) ensure_address_in_higher_half((uint64_t)madt_address);
Expand Down
6 changes: 2 additions & 4 deletions src/kernel/arch/x86_64/mem/vmm_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ void *map_phys_to_virt_addr(void* physical_address, void* address, size_t flags)
uint16_t pd_e = PD_ENTRY((uint64_t) address);

uint64_t *pml4_table = (uint64_t *) (SIGN_EXTENSION | ENTRIES_TO_ADDRESS(510l,510l,510l,510l));
uint64_t *pdpr_root = NULL;
uint64_t *pd_root = NULL;

uint8_t user_mode_status = 0;

Expand Down Expand Up @@ -177,7 +175,7 @@ void *map_phys_to_virt_addr(void* physical_address, void* address, size_t flags)
void *map_vaddress(void *virtual_address, size_t flags, uint64_t *pml4_root){
loglinef(Verbose, "(map_vaddress) address: 0x%x", virtual_address);
void *new_addr = pmm_alloc_frame();
return map_phys_to_virt_addr(new_addr, virtual_address, flags, pml4_root);
return map_phys_to_virt_addr_hh(new_addr, virtual_address, flags, pml4_root);
}

void map_vaddress_range(void *virtual_address, size_t flags, size_t required_pages, uint64_t *pml4_root) {
Expand Down Expand Up @@ -222,5 +220,5 @@ int unmap_vaddress(void *address){
}

void identity_map_phys_address(void *physical_address, size_t flags) {
map_phys_to_virt_addr(physical_address, physical_address, flags, NULL);
map_phys_to_virt_addr(physical_address, physical_address, flags);
}
27 changes: 14 additions & 13 deletions src/kernel/framebuffer/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ size_t cur_fb_line;
void map_framebuffer(struct framebuffer_info fbdata) {
uint32_t fb_entries = fbdata.memory_size / PAGE_SIZE_IN_BYTES;
uint32_t fb_entries_mod = fbdata.memory_size % PAGE_SIZE_IN_BYTES;

uint64_t phys_address = (uint64_t) fbdata.phys_address;

uint32_t pd = PD_ENTRY(_FRAMEBUFFER_MEM_START);
uint32_t pd = PD_ENTRY(_FRAMEBUFFER_MEM_START);
uint32_t pdpr = PDPR_ENTRY(_FRAMEBUFFER_MEM_START);
uint32_t pml4 = PML4_ENTRY(_FRAMEBUFFER_MEM_START);
#if SMALL_PAGES == 1
uint32_t fb_pd_entries = fb_entries / VM_PAGES_PER_TABLE;
uint32_t pt = PT_ENTRY(_FRAMEBUFFER_MEM_START);
#endif


if(p4_table[pml4] == 0x00l || p3_table_hh[pdpr] == 0x00l){
loglinef(Verbose, "PANIC - PML4 or PDPR Empty - not supported for now\n");
Expand All @@ -56,6 +56,7 @@ void map_framebuffer(struct framebuffer_info fbdata) {
uint64_t *current_page_table = pt_tables;
for(uint32_t i = 0; i <= fb_pd_entries; i++){
bool newly_allocated = false;
// Probably should be safer to rely on the direct map if possible?
if(p2_table[pd] == 0x00){
uint64_t *new_table = pmm_alloc_frame();
p2_table[pd] = (uint64_t)new_table | (PRESENT_BIT | WRITE_BIT);
Expand All @@ -64,11 +65,11 @@ void map_framebuffer(struct framebuffer_info fbdata) {
newly_allocated = true;
}
for(int j=0; j < VM_PAGES_PER_TABLE && fb_entries > 0; j++){
if(newly_allocated == false){
} else {
if(newly_allocated == false){
} else {
current_page_table[j] = phys_address + (((VM_PAGES_PER_TABLE * i) + j) * PAGE_SIZE_IN_BYTES) | PAGE_ENTRY_FLAGS;
}
fb_entries--;
fb_entries--;
}
newly_allocated = false;
pd++;
Expand All @@ -80,8 +81,8 @@ void map_framebuffer(struct framebuffer_info fbdata) {
}
for(int j=0; fb_entries > 0; j++){
fb_entries--;
if((p2_table[pd+j] < phys_address
|| p2_table[pd+j] > (phys_address + fbdata.memory_size))
if((p2_table[pd+j] < phys_address
|| p2_table[pd+j] > (phys_address + fbdata.memory_size))
|| p2_table[pd+j] == 0x00l){
p2_table[pd+j] = (phys_address + (j * PAGE_SIZE_IN_BYTES)) | PAGE_ENTRY_FLAGS;
}
Expand Down Expand Up @@ -116,12 +117,12 @@ void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
height = get_height(psf_font_version);

//uint32_t charsize = default_font->height * ((default_font->width + 7)/8);
//uint8_t *glyph = (uint8_t*)&_binary_fonts_default_psf_start +
//uint8_t *glyph = (uint8_t*)&_binary_fonts_default_psf_start +
// default_font->headersize + (symbol>0&&symbol<default_font->numglyph?symbol:0) * default_font->bytesperglyph;
uint8_t *glyph = get_glyph(symbol, psf_font_version);
//bytesperline is the number of bytes per each row of the glyph
size_t bytesperline = (width + 7)/8;
size_t offset = (cy * height * pitch) +
size_t offset = (cy * height * pitch) +
(cx * (width) * sizeof(PIXEL));
// x,y = current coordinates on the glyph bitmap

Expand All @@ -134,7 +135,7 @@ void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
//*((uint32_t*) (framebuffer + line)) = *((unsigned int*) glyph) & mask ? fg : bg;
//We are plotting the pixel
//0x80 = 0b10000000, it is shifted right at every iteration this for loop.
//glyph[x/8] if widht > 8, x/8 = byte selector
//glyph[x/8] if widht > 8, x/8 = byte selector
//(ie width = 16bits, when x < 8, x/8, so we read glyph[0]. if x>8 then x/8 = 1, and we read glyph[1]
//if the bit at position x is 1 plot the foreground color if is 0 plot the background color
*((PIXEL*) (framebuffer + line)) = glyph[x/8] & (0x80 >> (x & 7)) ? fg : bg;
Expand All @@ -161,7 +162,7 @@ void _fb_printStr(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_

void _fb_printStrAndNumber(const char *string, uint64_t number, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
char buffer[30];

_getHexString(buffer, number, true);
_fb_printStr(string, cx, cy, fg, bg);
int counter = 0;
Expand Down Expand Up @@ -198,7 +199,7 @@ void draw_logo(uint32_t start_x, uint32_t start_y) {
char pixel[4];
for (uint32_t i = 0; i < height; i++) {
for(uint32_t j = 0; j < width; j++) {
HEADER_PIXEL(logo_data, pixel);
HEADER_PIXEL(logo_data, pixel);
pixel[3] = 0;
uint32_t num = (uint32_t) pixel[0] << 24 |
(uint32_t)pixel[1] << 16 |
Expand Down
1 change: 1 addition & 0 deletions src/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <vfs.h>
#include <vm.h>
#include <vmm.h>
#include <vmm_mapping.h>
//#include <runtime_tests.h>

extern uint32_t FRAMEBUFFER_MEMORY_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/mem/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void _initialize_bitmap ( unsigned long end_of_reserved_area ) {
if(memory_map_phys_addr > end_of_mapped_physical_memory) {
loglinef(Verbose, "(%s): The address 0x%x is above the initally mapped memory: 0x%x", __FUNCTION__, memory_map_phys_addr, end_of_mapped_physical_memory);
//TODO: This need to be fixed map_phys_to_virt_addr can't be used here since it relies on the bitmap, and it is not initialized yet.
map_phys_to_virt_addr((void*)ALIGN_PHYSADDRESS(memory_map_phys_addr), (void*)(memory_map_phys_addr + _HIGHER_HALF_KERNEL_MEM_START), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void*)ALIGN_PHYSADDRESS(memory_map_phys_addr), (void*)(memory_map_phys_addr + _HIGHER_HALF_KERNEL_MEM_START), VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
} else {
loglinef(Verbose, "(%s): The address 0x%x is not above the initially mapped memory: 0x%x", __FUNCTION__, memory_map_phys_addr, end_of_mapped_physical_memory);
}
Expand Down
18 changes: 1 addition & 17 deletions src/kernel/mem/hh_direct_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extern uint64_t p3_table_hh[];
extern uint64_t p2_table[];
extern uint64_t pt_tables[];

uintptr_t temporaryPage = NULL;

/**
* This function return the hhdm pointer of the physycal address provided
Expand Down Expand Up @@ -41,8 +40,6 @@ void hhdm_map_physical_memory() {
}

uint64_t address_to_map = 0;
temporaryPage = ((uint64_t) HIGHER_HALF_ADDRESS_OFFSET + VM_KERNEL_MEMORY_PADDING);
//higherHalfDirectMapBase = ((uint64_t) temporaryPage + VM_KERNEL_MEMORY_PADDING);
uint64_t virtual_address = higherHalfDirectMapBase;

loglinef(Verbose, "(%s): HigherHalf Initial entries: pml4: %d, pdpr: %d, pd: %d", __FUNCTION__, PML4_ENTRY((uint64_t) higherHalfDirectMapBase), PDPR_ENTRY((uint64_t) higherHalfDirectMapBase), PD_ENTRY((uint64_t) higherHalfDirectMapBase));
Expand All @@ -57,24 +54,11 @@ void hhdm_map_physical_memory() {
while ( address_to_map < memory_size_in_bytes) {
//loglinef(Verbose, "(direct_map_physical_memory) Mapping physical address: 0x%x", address_to_map);
//p4_table[current_entry] = address_to_map | HUGEPAGE_BIT| WRITE_BIT | PRESENT_BIT;
map_phys_to_virt_addr((void*)address_to_map, (void*)virtual_address, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE, NULL);
map_phys_to_virt_addr((void*)address_to_map, (void*)virtual_address, VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE);
address_to_map += PAGE_SIZE_IN_BYTES;
virtual_address += PAGE_SIZE_IN_BYTES;
}

loglinef(Verbose, "(%s) Physical memory mapped end: 0x%x - Virtual memory direct end: 0x%x - counter: %d", __FUNCTION__, end_of_mapped_physical_memory, end_of_mapped_memory, current_pml4_entry);

}

void hh_map_entry(uint64_t phys_address, uint64_t virt_address) {
size_t pml4_entry = PML4_ENTRY((uint64_t) virt_address);
size_t pdpr_entry = PDPR_ENTRY((uint64_t) virt_address);
size_t pd_entry = PML4_ENTRY((uint64_t) virt_address);
//loglinef(Verbose, "(%s): p4_table: 0x%x - current_entry: %d", __FUNCTION__, p4_table, current_pml4_entry);

if ( !(p4_table[pml4_entry] & 0b1)) {
//uint64_t *new_table = pmm_alloc_frame();
//p4_table[pml4_entry] = address_to_map | WRITE_BIT | PRESENT_BIT;
}

}
Loading

0 comments on commit 7f957cc

Please sign in to comment.