mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Map kernel file too
This commit is contained in:
parent
338df2d9fa
commit
8b082ac98a
@ -32,9 +32,8 @@ NewLock(OperatorAllocatorLock);
|
|||||||
Physical KernelAllocator;
|
Physical KernelAllocator;
|
||||||
PageTable4 *KernelPageTable = nullptr;
|
PageTable4 *KernelPageTable = nullptr;
|
||||||
PageTable4 *UserspaceKernelOnlyPageTable = nullptr;
|
PageTable4 *UserspaceKernelOnlyPageTable = nullptr;
|
||||||
void *KPT = nullptr;
|
|
||||||
|
|
||||||
static MemoryAllocatorType AllocatorType = MemoryAllocatorType::None;
|
static MemoryAllocatorType AllocatorType = MemoryAllocatorType::Pages;
|
||||||
Xalloc::V1 *XallocV1Allocator = nullptr;
|
Xalloc::V1 *XallocV1Allocator = nullptr;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -131,6 +130,8 @@ NIF void MapKernel(PageTable4 *PT, BootInfo *Info)
|
|||||||
uintptr_t KernelDataEnd = (uintptr_t)&_kernel_data_end;
|
uintptr_t KernelDataEnd = (uintptr_t)&_kernel_data_end;
|
||||||
uintptr_t KernelRoDataEnd = (uintptr_t)&_kernel_rodata_end;
|
uintptr_t KernelRoDataEnd = (uintptr_t)&_kernel_rodata_end;
|
||||||
uintptr_t KernelEnd = (uintptr_t)&_kernel_end;
|
uintptr_t KernelEnd = (uintptr_t)&_kernel_end;
|
||||||
|
uintptr_t KernelFileStart = (uintptr_t)Info->Kernel.FileBase;
|
||||||
|
uintptr_t KernelFileEnd = KernelFileStart + Info->Kernel.Size;
|
||||||
|
|
||||||
uintptr_t BaseKernelMapAddress = (uintptr_t)Info->Kernel.PhysicalBase;
|
uintptr_t BaseKernelMapAddress = (uintptr_t)Info->Kernel.PhysicalBase;
|
||||||
uintptr_t k;
|
uintptr_t k;
|
||||||
@ -163,6 +164,12 @@ NIF void MapKernel(PageTable4 *PT, BootInfo *Info)
|
|||||||
BaseKernelMapAddress += PAGE_SIZE;
|
BaseKernelMapAddress += PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (k = KernelFileStart; k < KernelFileEnd; k += PAGE_SIZE)
|
||||||
|
{
|
||||||
|
va.Map((void *)k, (void *)k, PTFlag::RW | PTFlag::G);
|
||||||
|
KernelAllocator.LockPage((void *)k);
|
||||||
|
}
|
||||||
|
|
||||||
debug("\nStart: %#llx - Text End: %#llx - RoEnd: %#llx - End: %#llx\nStart Physical: %#llx - End Physical: %#llx",
|
debug("\nStart: %#llx - Text End: %#llx - RoEnd: %#llx - End: %#llx\nStart Physical: %#llx - End Physical: %#llx",
|
||||||
KernelStart, KernelTextEnd, KernelRoDataEnd, KernelEnd, Info->Kernel.PhysicalBase, BaseKernelMapAddress - PAGE_SIZE);
|
KernelStart, KernelTextEnd, KernelRoDataEnd, KernelEnd, Info->Kernel.PhysicalBase, BaseKernelMapAddress - PAGE_SIZE);
|
||||||
|
|
||||||
@ -253,8 +260,6 @@ NIF void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
TO_MB(KernelAllocator.GetTotalMemory()),
|
TO_MB(KernelAllocator.GetTotalMemory()),
|
||||||
TO_MB(KernelAllocator.GetReservedMemory()));
|
TO_MB(KernelAllocator.GetReservedMemory()));
|
||||||
|
|
||||||
AllocatorType = MemoryAllocatorType::Pages;
|
|
||||||
|
|
||||||
trace("Initializing Virtual Memory Manager");
|
trace("Initializing Virtual Memory Manager");
|
||||||
KernelPageTable = (PageTable4 *)KernelAllocator.RequestPages(TO_PAGES(PAGE_SIZE));
|
KernelPageTable = (PageTable4 *)KernelAllocator.RequestPages(TO_PAGES(PAGE_SIZE));
|
||||||
memset(KernelPageTable, 0, PAGE_SIZE);
|
memset(KernelPageTable, 0, PAGE_SIZE);
|
||||||
@ -286,11 +291,10 @@ NIF void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
debug("Userspace:");
|
debug("Userspace:");
|
||||||
tracepagetable(UserspaceKernelOnlyPageTable);
|
tracepagetable(UserspaceKernelOnlyPageTable);
|
||||||
#endif
|
#endif
|
||||||
KPT = KernelPageTable;
|
|
||||||
#if defined(a64) || defined(a32)
|
#if defined(a64) || defined(a32)
|
||||||
asmv("mov %0, %%cr3" ::"r"(KPT));
|
asmv("mov %0, %%cr3" ::"r"(KernelPageTable));
|
||||||
#elif defined(aa64)
|
#elif defined(aa64)
|
||||||
asmv("msr ttbr0_el1, %0" ::"r"(KPT));
|
asmv("msr ttbr0_el1, %0" ::"r"(KernelPageTable));
|
||||||
#endif
|
#endif
|
||||||
debug("Page table updated.");
|
debug("Page table updated.");
|
||||||
if (strstr(Info->Kernel.CommandLine, "xallocv1"))
|
if (strstr(Info->Kernel.CommandLine, "xallocv1"))
|
||||||
|
@ -676,8 +676,6 @@ extern Memory::PageTable4 *UserspaceKernelOnlyPageTable;
|
|||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
extern void *KPT;
|
|
||||||
|
|
||||||
EXTERNC void *HeapMalloc(size_t Size);
|
EXTERNC void *HeapMalloc(size_t Size);
|
||||||
EXTERNC void *HeapCalloc(size_t n, size_t Size);
|
EXTERNC void *HeapCalloc(size_t n, size_t Size);
|
||||||
EXTERNC void *HeapRealloc(void *Address, size_t Size);
|
EXTERNC void *HeapRealloc(void *Address, size_t Size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user