mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Remove unnecessary code
This commit is contained in:
parent
1efc8f9537
commit
198742526c
@ -74,11 +74,11 @@ NIF void tracepagetable(PageTable *pt)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NIF void MapFromZero(PageTable *PT, BootInfo *Info)
|
NIF void MapFromZero(PageTable *PT)
|
||||||
{
|
{
|
||||||
debug("Mapping from 0x0 to %#llx", Info->Memory.Size);
|
debug("Mapping from 0x0 to %#llx", bInfo.Memory.Size);
|
||||||
Virtual va = Virtual(PT);
|
Virtual va = Virtual(PT);
|
||||||
size_t MemSize = Info->Memory.Size;
|
size_t MemSize = bInfo.Memory.Size;
|
||||||
|
|
||||||
if (Page1GBSupport && PSESupport)
|
if (Page1GBSupport && PSESupport)
|
||||||
{
|
{
|
||||||
@ -104,19 +104,19 @@ NIF void MapFromZero(PageTable *PT, BootInfo *Info)
|
|||||||
va.Unmap((void *)0);
|
va.Unmap((void *)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NIF void MapFramebuffer(PageTable *PT, BootInfo *Info)
|
NIF void MapFramebuffer(PageTable *PT)
|
||||||
{
|
{
|
||||||
debug("Mapping Framebuffer");
|
debug("Mapping Framebuffer");
|
||||||
Virtual va = Virtual(PT);
|
Virtual va = Virtual(PT);
|
||||||
int itrfb = 0;
|
int itrfb = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (!Info->Framebuffer[itrfb].BaseAddress)
|
if (!bInfo.Framebuffer[itrfb].BaseAddress)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
va.OptimizedMap((void *)Info->Framebuffer[itrfb].BaseAddress,
|
va.OptimizedMap((void *)bInfo.Framebuffer[itrfb].BaseAddress,
|
||||||
(void *)Info->Framebuffer[itrfb].BaseAddress,
|
(void *)bInfo.Framebuffer[itrfb].BaseAddress,
|
||||||
Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height,
|
bInfo.Framebuffer[itrfb].Pitch * bInfo.Framebuffer[itrfb].Height,
|
||||||
PTFlag::RW | PTFlag::US | PTFlag::G);
|
PTFlag::RW | PTFlag::US | PTFlag::G);
|
||||||
itrfb++;
|
itrfb++;
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ NIF void MapFramebuffer(PageTable *PT, BootInfo *Info)
|
|||||||
strcat_unsafe(LockTmpStr, "_memTrk");
|
strcat_unsafe(LockTmpStr, "_memTrk");
|
||||||
mExtTrkLock.TimeoutLock(LockTmpStr, 10000);
|
mExtTrkLock.TimeoutLock(LockTmpStr, 10000);
|
||||||
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
||||||
Info->Framebuffer[itrfb].BaseAddress,
|
bInfo.Framebuffer[itrfb].BaseAddress,
|
||||||
(Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height) + PAGE_SIZE);
|
(bInfo.Framebuffer[itrfb].Pitch * bInfo.Framebuffer[itrfb].Height) + PAGE_SIZE);
|
||||||
UniversalAsynchronousReceiverTransmitter::UART mTrkUART = UniversalAsynchronousReceiverTransmitter::UART(UniversalAsynchronousReceiverTransmitter::COM3);
|
UniversalAsynchronousReceiverTransmitter::UART mTrkUART = UniversalAsynchronousReceiverTransmitter::UART(UniversalAsynchronousReceiverTransmitter::COM3);
|
||||||
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
||||||
{
|
{
|
||||||
@ -143,7 +143,7 @@ NIF void MapFramebuffer(PageTable *PT, BootInfo *Info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
NIF void MapKernel(PageTable *PT)
|
||||||
{
|
{
|
||||||
debug("Mapping Kernel");
|
debug("Mapping Kernel");
|
||||||
|
|
||||||
@ -169,8 +169,8 @@ NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
|||||||
|
|
||||||
uintptr_t KernelStart = (uintptr_t)&_kernel_start;
|
uintptr_t KernelStart = (uintptr_t)&_kernel_start;
|
||||||
uintptr_t KernelEnd = (uintptr_t)&_kernel_end;
|
uintptr_t KernelEnd = (uintptr_t)&_kernel_end;
|
||||||
uintptr_t KernelFileStart = (uintptr_t)Info->Kernel.FileBase;
|
uintptr_t KernelFileStart = (uintptr_t)bInfo.Kernel.FileBase;
|
||||||
uintptr_t KernelFileEnd = KernelFileStart + Info->Kernel.Size;
|
uintptr_t KernelFileEnd = KernelFileStart + bInfo.Kernel.Size;
|
||||||
|
|
||||||
debug("Bootstrap: %#lx-%#lx", BootstrapStart, BootstrapEnd);
|
debug("Bootstrap: %#lx-%#lx", BootstrapStart, BootstrapEnd);
|
||||||
debug("Kernel text: %#lx-%#lx", KernelTextStart, KernelTextEnd);
|
debug("Kernel text: %#lx-%#lx", KernelTextStart, KernelTextEnd);
|
||||||
@ -180,14 +180,14 @@ NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
|||||||
debug("Kernel: %#lx-%#lx", KernelStart, KernelEnd);
|
debug("Kernel: %#lx-%#lx", KernelStart, KernelEnd);
|
||||||
debug("Kernel file: %#lx-%#lx", KernelFileStart, KernelFileEnd);
|
debug("Kernel file: %#lx-%#lx", KernelFileStart, KernelFileEnd);
|
||||||
|
|
||||||
debug("File size: %ld KB", TO_KB(Info->Kernel.Size));
|
debug("File size: %ld KB", TO_KB(bInfo.Kernel.Size));
|
||||||
debug(".bootstrap size: %ld KB", TO_KB(BootstrapEnd - BootstrapStart));
|
debug(".bootstrap size: %ld KB", TO_KB(BootstrapEnd - BootstrapStart));
|
||||||
debug(".text size: %ld KB", TO_KB(KernelTextEnd - KernelTextStart));
|
debug(".text size: %ld KB", TO_KB(KernelTextEnd - KernelTextStart));
|
||||||
debug(".data size: %ld KB", TO_KB(KernelDataEnd - KernelDataStart));
|
debug(".data size: %ld KB", TO_KB(KernelDataEnd - KernelDataStart));
|
||||||
debug(".rodata size: %ld KB", TO_KB(KernelRoDataEnd - KernelRoDataStart));
|
debug(".rodata size: %ld KB", TO_KB(KernelRoDataEnd - KernelRoDataStart));
|
||||||
debug(".bss size: %ld KB", TO_KB(KernelBssEnd - KernelBssStart));
|
debug(".bss size: %ld KB", TO_KB(KernelBssEnd - KernelBssStart));
|
||||||
|
|
||||||
uintptr_t BaseKernelMapAddress = (uintptr_t)Info->Kernel.PhysicalBase;
|
uintptr_t BaseKernelMapAddress = (uintptr_t)bInfo.Kernel.PhysicalBase;
|
||||||
debug("Base kernel map address: %#lx", BaseKernelMapAddress);
|
debug("Base kernel map address: %#lx", BaseKernelMapAddress);
|
||||||
uintptr_t k;
|
uintptr_t k;
|
||||||
Virtual va = Virtual(PT);
|
Virtual va = Virtual(PT);
|
||||||
@ -260,8 +260,8 @@ NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
|||||||
strcat_unsafe(LockTmpStr, "_memTrk");
|
strcat_unsafe(LockTmpStr, "_memTrk");
|
||||||
mExtTrkLock.TimeoutLock(LockTmpStr, 10000);
|
mExtTrkLock.TimeoutLock(LockTmpStr, 10000);
|
||||||
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
||||||
Info->Kernel.PhysicalBase,
|
bInfo.Kernel.PhysicalBase,
|
||||||
Info->Kernel.Size);
|
bInfo.Kernel.Size);
|
||||||
UniversalAsynchronousReceiverTransmitter::UART mTrkUART = UniversalAsynchronousReceiverTransmitter::UART(UniversalAsynchronousReceiverTransmitter::COM3);
|
UniversalAsynchronousReceiverTransmitter::UART mTrkUART = UniversalAsynchronousReceiverTransmitter::UART(UniversalAsynchronousReceiverTransmitter::COM3);
|
||||||
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
||||||
{
|
{
|
||||||
@ -271,8 +271,8 @@ NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
sprintf(mExtTrkLog, "Rsrv( %p %ld )\n\r",
|
||||||
Info->Kernel.VirtualBase,
|
bInfo.Kernel.VirtualBase,
|
||||||
Info->Kernel.Size);
|
bInfo.Kernel.Size);
|
||||||
mExtTrkLock.Unlock();
|
mExtTrkLock.Unlock();
|
||||||
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
for (short i = 0; i < MEM_TRK_MAX_SIZE; i++)
|
||||||
{
|
{
|
||||||
@ -284,17 +284,17 @@ NIF void MapKernel(PageTable *PT, BootInfo *Info)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
NIF void InitializeMemoryManagement(BootInfo *Info)
|
NIF void InitializeMemoryManagement()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (uint64_t i = 0; i < Info->Memory.Entries; i++)
|
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)
|
||||||
{
|
{
|
||||||
uintptr_t Base = r_cst(uintptr_t, Info->Memory.Entry[i].BaseAddress);
|
uintptr_t Base = r_cst(uintptr_t, bInfo.Memory.Entry[i].BaseAddress);
|
||||||
size_t Length = Info->Memory.Entry[i].Length;
|
size_t Length = bInfo.Memory.Entry[i].Length;
|
||||||
uintptr_t End = Base + Length;
|
uintptr_t End = Base + Length;
|
||||||
const char *Type = "Unknown";
|
const char *Type = "Unknown";
|
||||||
|
|
||||||
switch (Info->Memory.Entry[i].Type)
|
switch (bInfo.Memory.Entry[i].Type)
|
||||||
{
|
{
|
||||||
case likely(Usable):
|
case likely(Usable):
|
||||||
Type = "Usable";
|
Type = "Usable";
|
||||||
@ -333,7 +333,7 @@ NIF void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
#endif
|
#endif
|
||||||
trace("Initializing Physical Memory Manager");
|
trace("Initializing Physical Memory Manager");
|
||||||
// KernelAllocator = Physical(); <- Already called in the constructor
|
// KernelAllocator = Physical(); <- Already called in the constructor
|
||||||
KernelAllocator.Init(Info);
|
KernelAllocator.Init();
|
||||||
debug("Memory Info: %lldMB / %lldMB (%lldMB reserved)",
|
debug("Memory Info: %lldMB / %lldMB (%lldMB reserved)",
|
||||||
TO_MB(KernelAllocator.GetUsedMemory()),
|
TO_MB(KernelAllocator.GetUsedMemory()),
|
||||||
TO_MB(KernelAllocator.GetTotalMemory()),
|
TO_MB(KernelAllocator.GetTotalMemory()),
|
||||||
@ -384,9 +384,9 @@ NIF void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MapFromZero(KernelPageTable, Info);
|
MapFromZero(KernelPageTable);
|
||||||
MapFramebuffer(KernelPageTable, Info);
|
MapFramebuffer(KernelPageTable);
|
||||||
MapKernel(KernelPageTable, Info);
|
MapKernel(KernelPageTable);
|
||||||
|
|
||||||
trace("Applying new page table from address %#lx", KernelPageTable);
|
trace("Applying new page table from address %#lx", KernelPageTable);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -394,13 +394,13 @@ NIF void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
#endif
|
#endif
|
||||||
CPU::PageTable(KernelPageTable);
|
CPU::PageTable(KernelPageTable);
|
||||||
debug("Page table updated.");
|
debug("Page table updated.");
|
||||||
if (strstr(Info->Kernel.CommandLine, "xallocv1"))
|
if (strstr(bInfo.Kernel.CommandLine, "xallocv1"))
|
||||||
{
|
{
|
||||||
XallocV1Allocator = new Xalloc::V1((void *)KERNEL_HEAP_BASE, false, false);
|
XallocV1Allocator = new Xalloc::V1((void *)KERNEL_HEAP_BASE, false, false);
|
||||||
AllocatorType = MemoryAllocatorType::XallocV1;
|
AllocatorType = MemoryAllocatorType::XallocV1;
|
||||||
trace("XallocV1 Allocator initialized (%p)", XallocV1Allocator);
|
trace("XallocV1 Allocator initialized (%p)", XallocV1Allocator);
|
||||||
}
|
}
|
||||||
else if (strstr(Info->Kernel.CommandLine, "liballoc11"))
|
else if (strstr(bInfo.Kernel.CommandLine, "liballoc11"))
|
||||||
{
|
{
|
||||||
AllocatorType = MemoryAllocatorType::liballoc11;
|
AllocatorType = MemoryAllocatorType::liballoc11;
|
||||||
}
|
}
|
||||||
|
@ -368,11 +368,11 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::Init(BootInfo *Info)
|
void Physical::Init()
|
||||||
{
|
{
|
||||||
SmartLock(this->MemoryLock);
|
SmartLock(this->MemoryLock);
|
||||||
|
|
||||||
uint64_t MemorySize = Info->Memory.Size;
|
uint64_t MemorySize = bInfo.Memory.Size;
|
||||||
debug("Memory size: %lld bytes (%ld pages)", MemorySize, TO_PAGES(MemorySize));
|
debug("Memory size: %lld bytes (%ld pages)", MemorySize, TO_PAGES(MemorySize));
|
||||||
TotalMemory = MemorySize;
|
TotalMemory = MemorySize;
|
||||||
FreeMemory = MemorySize;
|
FreeMemory = MemorySize;
|
||||||
@ -380,22 +380,22 @@ namespace Memory
|
|||||||
void *LargestFreeMemorySegment = nullptr;
|
void *LargestFreeMemorySegment = nullptr;
|
||||||
uint64_t LargestFreeMemorySegmentSize = 0;
|
uint64_t LargestFreeMemorySegmentSize = 0;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Info->Memory.Entries; i++)
|
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)
|
||||||
{
|
{
|
||||||
if (Info->Memory.Entry[i].Type == Usable)
|
if (bInfo.Memory.Entry[i].Type == Usable)
|
||||||
{
|
{
|
||||||
if (Info->Memory.Entry[i].Length > LargestFreeMemorySegmentSize)
|
if (bInfo.Memory.Entry[i].Length > LargestFreeMemorySegmentSize)
|
||||||
{
|
{
|
||||||
/* We don't want to use 0 as a memory address. */
|
/* We don't want to use 0 as a memory address. */
|
||||||
if (Info->Memory.Entry[i].BaseAddress == 0x0)
|
if (bInfo.Memory.Entry[i].BaseAddress == 0x0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LargestFreeMemorySegment = (void *)Info->Memory.Entry[i].BaseAddress;
|
LargestFreeMemorySegment = (void *)bInfo.Memory.Entry[i].BaseAddress;
|
||||||
LargestFreeMemorySegmentSize = Info->Memory.Entry[i].Length;
|
LargestFreeMemorySegmentSize = bInfo.Memory.Entry[i].Length;
|
||||||
|
|
||||||
debug("Largest free memory segment: %llp (%lldMB)",
|
debug("Largest free memory segment: %llp (%lldMB)",
|
||||||
(void *)Info->Memory.Entry[i].BaseAddress,
|
(void *)bInfo.Memory.Entry[i].BaseAddress,
|
||||||
TO_MB(Info->Memory.Entry[i].Length));
|
TO_MB(bInfo.Memory.Entry[i].Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,13 +419,13 @@ namespace Memory
|
|||||||
*(uint8_t *)(PageBitmap.Buffer + i) = 0;
|
*(uint8_t *)(PageBitmap.Buffer + i) = 0;
|
||||||
|
|
||||||
debug("Reserving pages...");
|
debug("Reserving pages...");
|
||||||
this->ReservePages(0, TO_PAGES(Info->Memory.Size));
|
this->ReservePages(0, TO_PAGES(bInfo.Memory.Size));
|
||||||
debug("Unreserving usable pages...");
|
debug("Unreserving usable pages...");
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Info->Memory.Entries; i++)
|
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)
|
||||||
{
|
{
|
||||||
if (Info->Memory.Entry[i].Type == Usable)
|
if (bInfo.Memory.Entry[i].Type == Usable)
|
||||||
this->UnreservePages(Info->Memory.Entry[i].BaseAddress, TO_PAGES(Info->Memory.Entry[i].Length));
|
this->UnreservePages(bInfo.Memory.Entry[i].BaseAddress, TO_PAGES(bInfo.Memory.Entry[i].Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Reserving pages for SMP...");
|
debug("Reserving pages for SMP...");
|
||||||
|
20
Kernel.cpp
20
Kernel.cpp
@ -488,16 +488,7 @@ EXTERNC __no_stack_protector NIF void Entry(BootInfo *Info)
|
|||||||
for (CallPtr *func = __init_array_start; func != __init_array_end; func++)
|
for (CallPtr *func = __init_array_start; func != __init_array_end; func++)
|
||||||
(*func)();
|
(*func)();
|
||||||
|
|
||||||
InitializeMemoryManagement(Info);
|
InitializeMemoryManagement();
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
/* I had to do this because KernelAllocator
|
|
||||||
* is a global constructor but we need
|
|
||||||
* memory management to be initialized first.
|
|
||||||
*/
|
|
||||||
TestString();
|
|
||||||
TestMemoryAllocation();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void *KernelStackAddress = KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE));
|
void *KernelStackAddress = KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE));
|
||||||
uintptr_t KernelStack = (uintptr_t)KernelStackAddress + STACK_SIZE - 0x10;
|
uintptr_t KernelStack = (uintptr_t)KernelStackAddress + STACK_SIZE - 0x10;
|
||||||
@ -508,6 +499,15 @@ EXTERNC __no_stack_protector NIF void Entry(BootInfo *Info)
|
|||||||
: "memory");
|
: "memory");
|
||||||
asmv("mov $0, %rbp");
|
asmv("mov $0, %rbp");
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
/* I had to do this because KernelAllocator
|
||||||
|
* is a global constructor but we need
|
||||||
|
* memory management to be initialized first.
|
||||||
|
*/
|
||||||
|
TestString();
|
||||||
|
TestMemoryAllocation();
|
||||||
|
#endif
|
||||||
|
|
||||||
EnableProfiler = true;
|
EnableProfiler = true;
|
||||||
Main();
|
Main();
|
||||||
}
|
}
|
||||||
|
@ -588,7 +588,7 @@ namespace Memory
|
|||||||
void FreePages(void *Address, size_t Count);
|
void FreePages(void *Address, size_t Count);
|
||||||
|
|
||||||
/** @brief Do not use. */
|
/** @brief Do not use. */
|
||||||
void Init(BootInfo *Info);
|
void Init();
|
||||||
|
|
||||||
/** @brief Do not use. */
|
/** @brief Do not use. */
|
||||||
Physical();
|
Physical();
|
||||||
@ -905,7 +905,7 @@ namespace Memory
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeMemoryManagement(BootInfo *Info);
|
void InitializeMemoryManagement();
|
||||||
|
|
||||||
void *operator new(size_t Size);
|
void *operator new(size_t Size);
|
||||||
void *operator new[](size_t Size);
|
void *operator new[](size_t Size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user