MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / MapVirtualMemory4K

Function MapVirtualMemory4K

Kernel/src/arch/x86_64/paging.cpp:538–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

536 }
537
538 void MapVirtualMemory4K(uint64_t phys, uint64_t virt, uint64_t amount, address_space_t* addressSpace){
539 uint64_t pml4Index, pdptIndex, pageDirIndex, pageIndex;
540
541 //phys &= ~(PAGE_SIZE_4K-1);
542 //virt &= ~(PAGE_SIZE_4K-1);
543
544 while(amount--){
545 pml4Index = PML4_GET_INDEX(virt);
546 pdptIndex = PDPT_GET_INDEX(virt);
547 pageDirIndex = PAGE_DIR_GET_INDEX(virt);
548 pageIndex = PAGE_TABLE_GET_INDEX(virt);
549
550 const char* panic[1] = {"Process address space cannot be >512GB"};
551 if(pdptIndex > MAX_PDPT_INDEX || pml4Index) KernelPanic(panic,1);
552
553 if(!(addressSpace->pageDirs[pdptIndex][pageDirIndex] & 0x1)) CreatePageTable(pdptIndex,pageDirIndex,addressSpace); // If we don't have a page table at this address, create one.
554
555 addressSpace->pageTables[pdptIndex][pageDirIndex][pageIndex] = PAGE_PRESENT | PAGE_WRITABLE | PAGE_USER;
556 SetPageFrame(&(addressSpace->pageTables[pdptIndex][pageDirIndex][pageIndex]), phys);
557
558 invlpg(virt);
559
560 phys += PAGE_SIZE_4K;
561 virt += PAGE_SIZE_4K; /* Go to next page */
562 }
563 }
564
565 uintptr_t GetIOMapping(uintptr_t addr){
566 if(addr > 0xffffffff){ // Typically most MMIO will not reside > 4GB, but check just in case

Callers 6

MapSharedMemoryFunction · 0.85
LoadELFSegmentsFunction · 0.85
CreateELFProcessFunction · 0.85
SysMapFBFunction · 0.85
SysAllocFunction · 0.85
SysMmapFunction · 0.85

Calls 4

KernelPanicFunction · 0.85
CreatePageTableFunction · 0.85
SetPageFrameFunction · 0.85
invlpgFunction · 0.85

Tested by

no test coverage detected