mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-29 07:47:59 +00:00
Updated types
This commit is contained in:
parent
684b76a1ca
commit
a677f3c159
31
Core/CPU.cpp
31
Core/CPU.cpp
@ -102,23 +102,21 @@ namespace CPU
|
|||||||
{
|
{
|
||||||
case Check:
|
case Check:
|
||||||
{
|
{
|
||||||
|
uintptr_t Flags;
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
uint64_t rflags;
|
|
||||||
asmv("pushfq");
|
asmv("pushfq");
|
||||||
asmv("popq %0"
|
asmv("popq %0"
|
||||||
: "=r"(rflags));
|
: "=r"(Flags));
|
||||||
return rflags & (1 << 9);
|
return Flags & (1 << 9);
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
uint32_t rflags;
|
|
||||||
asmv("pushfl");
|
asmv("pushfl");
|
||||||
asmv("popl %0"
|
asmv("popl %0"
|
||||||
: "=r"(rflags));
|
: "=r"(Flags));
|
||||||
return rflags & (1 << 9);
|
return Flags & (1 << 9);
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
uint64_t daif;
|
|
||||||
asmv("mrs %0, daif"
|
asmv("mrs %0, daif"
|
||||||
: "=r"(daif));
|
: "=r"(Flags));
|
||||||
return !(daif & (1 << 2));
|
return !(Flags & (1 << 2));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
case Enable:
|
case Enable:
|
||||||
@ -254,21 +252,20 @@ namespace CPU
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Counter()
|
uintptr_t Counter()
|
||||||
{
|
{
|
||||||
// TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs)
|
// TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs)
|
||||||
|
uintptr_t Counter;
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
uint64_t counter;
|
|
||||||
asmv("rdtsc"
|
asmv("rdtsc"
|
||||||
: "=A"(counter));
|
: "=A"(Counter));
|
||||||
return counter;
|
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
return 0;
|
asmv("rdtsc"
|
||||||
|
: "=A"(Counter));
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
uint64_t counter;
|
|
||||||
asmv("mrs %0, cntvct_el0"
|
asmv("mrs %0, cntvct_el0"
|
||||||
: "=r"(counter));
|
: "=r"(Counter));
|
||||||
return counter;
|
|
||||||
#endif
|
#endif
|
||||||
|
return Counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
CrashHandler::EHPrint(PageFaultDescriptions[Frame->ErrorCode & 0b111]);
|
CrashHandler::EHPrint(PageFaultDescriptions[Frame->ErrorCode & 0b111]);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
uint64_t CheckPageFaultAddress = 0;
|
uintptr_t CheckPageFaultAddress = 0;
|
||||||
CheckPageFaultAddress = CPU::x64::readcr2().PFLA;
|
CheckPageFaultAddress = CPU::x64::readcr2().PFLA;
|
||||||
if (CheckPageFaultAddress == 0)
|
if (CheckPageFaultAddress == 0)
|
||||||
CheckPageFaultAddress = Frame->rip;
|
CheckPageFaultAddress = Frame->rip;
|
||||||
@ -155,11 +155,11 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
|
|
||||||
if (Present)
|
if (Present)
|
||||||
{
|
{
|
||||||
uint64_t CheckPageFaultLinearAddress = (uint64_t)CheckPageFaultAddress;
|
uintptr_t CheckPageFaultLinearAddress = (uintptr_t)CheckPageFaultAddress;
|
||||||
CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000;
|
CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000;
|
||||||
debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress);
|
debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress);
|
||||||
|
|
||||||
Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uint64_t)CheckPageFaultLinearAddress);
|
Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uintptr_t)CheckPageFaultLinearAddress);
|
||||||
debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d",
|
debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d",
|
||||||
CheckPageFaultLinearAddress,
|
CheckPageFaultLinearAddress,
|
||||||
Index.PMLIndex,
|
Index.PMLIndex,
|
||||||
@ -168,9 +168,9 @@ SafeFunction void PageFaultExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
Index.PTEIndex);
|
Index.PTEIndex);
|
||||||
Memory::PageMapLevel4 PML4 = ((Memory::PageTable4 *)CPU::x64::readcr3().raw)->Entries[Index.PMLIndex];
|
Memory::PageMapLevel4 PML4 = ((Memory::PageTable4 *)CPU::x64::readcr3().raw)->Entries[Index.PMLIndex];
|
||||||
|
|
||||||
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12);
|
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
|
||||||
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
||||||
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
||||||
|
|
||||||
debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx",
|
debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx",
|
||||||
Index.PMLIndex, 0, 0, 0,
|
Index.PMLIndex, 0, 0, 0,
|
||||||
|
@ -294,8 +294,8 @@ namespace CrashHandler
|
|||||||
else if (strncmp(Input, "ifr", 3) == 0)
|
else if (strncmp(Input, "ifr", 3) == 0)
|
||||||
{
|
{
|
||||||
char *arg = TrimWhiteSpace(Input + 3);
|
char *arg = TrimWhiteSpace(Input + 3);
|
||||||
uint64_t CountI = atoi(arg);
|
int CountI = atoi(arg);
|
||||||
uint64_t TotalCount = sizeof(EHIntFrames) / sizeof(EHIntFrames[0]);
|
int TotalCount = sizeof(EHIntFrames) / sizeof(EHIntFrames[0]);
|
||||||
|
|
||||||
debug("Printing %ld interrupt frames.", CountI);
|
debug("Printing %ld interrupt frames.", CountI);
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ namespace CrashHandler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < CountI; i++)
|
for (int i = 0; i < CountI; i++)
|
||||||
{
|
{
|
||||||
if (EHIntFrames[i])
|
if (EHIntFrames[i])
|
||||||
{
|
{
|
||||||
@ -315,12 +315,12 @@ namespace CrashHandler
|
|||||||
EHPrint("\n\e2565CC%p", EHIntFrames[i]);
|
EHPrint("\n\e2565CC%p", EHIntFrames[i]);
|
||||||
EHPrint("\e7925CC-");
|
EHPrint("\e7925CC-");
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
if ((uint64_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end)
|
if ((uintptr_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end)
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
if ((uint64_t)EHIntFrames[i] >= 0xC0000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end)
|
if ((uintptr_t)EHIntFrames[i] >= 0xC0000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end)
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#endif
|
#endif
|
||||||
EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uint64_t)EHIntFrames[i]));
|
EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uintptr_t)EHIntFrames[i]));
|
||||||
else
|
else
|
||||||
EHPrint("\eFF4CA9Outside Kernel");
|
EHPrint("\eFF4CA9Outside Kernel");
|
||||||
for (int i = 0; i < 20000; i++)
|
for (int i = 0; i < 20000; i++)
|
||||||
@ -333,7 +333,7 @@ namespace CrashHandler
|
|||||||
else if (strncmp(Input, "tlb", 3) == 0)
|
else if (strncmp(Input, "tlb", 3) == 0)
|
||||||
{
|
{
|
||||||
char *arg = TrimWhiteSpace(Input + 3);
|
char *arg = TrimWhiteSpace(Input + 3);
|
||||||
uint64_t Address = NULL;
|
uintptr_t Address = NULL;
|
||||||
Address = strtol(arg, NULL, 16);
|
Address = strtol(arg, NULL, 16);
|
||||||
debug("Converted %s to %#lx", arg, Address);
|
debug("Converted %s to %#lx", arg, Address);
|
||||||
Memory::PageTable4 *BasePageTable = (Memory::PageTable4 *)Address;
|
Memory::PageTable4 *BasePageTable = (Memory::PageTable4 *)Address;
|
||||||
@ -355,7 +355,7 @@ namespace CrashHandler
|
|||||||
Display->SetBuffer(SBIdx);
|
Display->SetBuffer(SBIdx);
|
||||||
if (PML4.Present)
|
if (PML4.Present)
|
||||||
{
|
{
|
||||||
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12);
|
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
|
||||||
if (PDPTE)
|
if (PDPTE)
|
||||||
{
|
{
|
||||||
for (int PDPTEIndex = 0; PDPTEIndex < 512; PDPTEIndex++)
|
for (int PDPTEIndex = 0; PDPTEIndex < 512; PDPTEIndex++)
|
||||||
@ -373,7 +373,7 @@ namespace CrashHandler
|
|||||||
Display->SetBuffer(SBIdx);
|
Display->SetBuffer(SBIdx);
|
||||||
if ((PDPTE->Entries[PDPTEIndex].Present))
|
if ((PDPTE->Entries[PDPTEIndex].Present))
|
||||||
{
|
{
|
||||||
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[PDPTEIndex].GetAddress() << 12);
|
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[PDPTEIndex].GetAddress() << 12);
|
||||||
if (PDE)
|
if (PDE)
|
||||||
{
|
{
|
||||||
for (int PDEIndex = 0; PDEIndex < 512; PDEIndex++)
|
for (int PDEIndex = 0; PDEIndex < 512; PDEIndex++)
|
||||||
@ -391,7 +391,7 @@ namespace CrashHandler
|
|||||||
Display->SetBuffer(SBIdx);
|
Display->SetBuffer(SBIdx);
|
||||||
if ((PDE->Entries[PDEIndex].Present))
|
if ((PDE->Entries[PDEIndex].Present))
|
||||||
{
|
{
|
||||||
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[PDEIndex].GetAddress() << 12);
|
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[PDEIndex].GetAddress() << 12);
|
||||||
if (PTE)
|
if (PTE)
|
||||||
{
|
{
|
||||||
for (int PTEIndex = 0; PTEIndex < 512; PTEIndex++)
|
for (int PTEIndex = 0; PTEIndex < 512; PTEIndex++)
|
||||||
@ -428,7 +428,7 @@ namespace CrashHandler
|
|||||||
Bitmap bm = KernelAllocator.GetPageBitmap();
|
Bitmap bm = KernelAllocator.GetPageBitmap();
|
||||||
|
|
||||||
EHPrint("\n\eFAFAFA[0%%] %08ld: ", 0);
|
EHPrint("\n\eFAFAFA[0%%] %08ld: ", 0);
|
||||||
for (uint64_t i = 0; i < bm.Size; i++)
|
for (size_t i = 0; i < bm.Size; i++)
|
||||||
{
|
{
|
||||||
if (bm.Get(i))
|
if (bm.Get(i))
|
||||||
EHPrint("\eFF00001");
|
EHPrint("\eFF00001");
|
||||||
@ -436,7 +436,7 @@ namespace CrashHandler
|
|||||||
EHPrint("\e00FF000");
|
EHPrint("\e00FF000");
|
||||||
if (i % 128 == 127)
|
if (i % 128 == 127)
|
||||||
{
|
{
|
||||||
uint64_t Percentage = (i * 100) / bm.Size;
|
short Percentage = (i * 100) / bm.Size;
|
||||||
EHPrint("\n\eFAFAFA[%03ld%%] %08ld: ", Percentage, i);
|
EHPrint("\n\eFAFAFA[%03ld%%] %08ld: ", Percentage, i);
|
||||||
Display->SetBuffer(SBIdx);
|
Display->SetBuffer(SBIdx);
|
||||||
}
|
}
|
||||||
@ -642,7 +642,7 @@ namespace CrashHandler
|
|||||||
CPU::x64::CR8 cr8 = CPU::x64::readcr8();
|
CPU::x64::CR8 cr8 = CPU::x64::readcr8();
|
||||||
CPU::x64::EFER efer;
|
CPU::x64::EFER efer;
|
||||||
efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
||||||
uint64_t ds;
|
uintptr_t ds;
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
|
|
||||||
@ -703,7 +703,7 @@ namespace CrashHandler
|
|||||||
crashdata.cr4 = CPU::x64::readcr4();
|
crashdata.cr4 = CPU::x64::readcr4();
|
||||||
crashdata.cr8 = CPU::x64::readcr8();
|
crashdata.cr8 = CPU::x64::readcr8();
|
||||||
crashdata.efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
crashdata.efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
||||||
uint64_t ds;
|
uintptr_t ds;
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace CrashHandler
|
|||||||
struct StackFrame
|
struct StackFrame
|
||||||
{
|
{
|
||||||
struct StackFrame *rbp;
|
struct StackFrame *rbp;
|
||||||
uint64_t rip;
|
uintptr_t rip;
|
||||||
};
|
};
|
||||||
|
|
||||||
SafeFunction void TraceFrames(CHArchTrapFrame *Frame, int Count, SymbolResolver::Symbols *SymHandle, bool Kernel)
|
SafeFunction void TraceFrames(CHArchTrapFrame *Frame, int Count, SymbolResolver::Symbols *SymHandle, bool Kernel)
|
||||||
@ -75,14 +75,14 @@ namespace CrashHandler
|
|||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
EHPrint("\e2565CC%p", (void *)Frame->rip);
|
EHPrint("\e2565CC%p", (void *)Frame->rip);
|
||||||
EHPrint("\e7925CC-");
|
EHPrint("\e7925CC-");
|
||||||
if ((Frame->rip >= 0xFFFFFFFF80000000 && Frame->rip <= (uint64_t)&_kernel_end) || !Kernel)
|
if ((Frame->rip >= 0xFFFFFFFF80000000 && Frame->rip <= (uintptr_t)&_kernel_end) || !Kernel)
|
||||||
EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->rip));
|
EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->rip));
|
||||||
else
|
else
|
||||||
EHPrint("Outside Kernel");
|
EHPrint("Outside Kernel");
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
EHPrint("\e2565CC%p", (void *)Frame->eip);
|
EHPrint("\e2565CC%p", (void *)Frame->eip);
|
||||||
EHPrint("\e7925CC-");
|
EHPrint("\e7925CC-");
|
||||||
if ((Frame->eip >= 0xC0000000 && Frame->eip <= (uint64_t)&_kernel_end) || !Kernel)
|
if ((Frame->eip >= 0xC0000000 && Frame->eip <= (uintptr_t)&_kernel_end) || !Kernel)
|
||||||
EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->eip));
|
EHPrint("\eAA25CC%s", SymHandle->GetSymbolFromAddress(Frame->eip));
|
||||||
else
|
else
|
||||||
EHPrint("Outside Kernel");
|
EHPrint("Outside Kernel");
|
||||||
@ -96,9 +96,9 @@ namespace CrashHandler
|
|||||||
EHPrint("\n\e2565CC%p", (void *)frames->rip);
|
EHPrint("\n\e2565CC%p", (void *)frames->rip);
|
||||||
EHPrint("\e7925CC-");
|
EHPrint("\e7925CC-");
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
if ((frames->rip >= 0xFFFFFFFF80000000 && frames->rip <= (uint64_t)&_kernel_end) || !Kernel)
|
if ((frames->rip >= 0xFFFFFFFF80000000 && frames->rip <= (uintptr_t)&_kernel_end) || !Kernel)
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
if ((frames->rip >= 0xC0000000 && frames->rip <= (uint64_t)&_kernel_end) || !Kernel)
|
if ((frames->rip >= 0xC0000000 && frames->rip <= (uintptr_t)&_kernel_end) || !Kernel)
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#endif
|
#endif
|
||||||
EHPrint("\e25CCC9%s", SymHandle->GetSymbolFromAddress(frames->rip));
|
EHPrint("\e25CCC9%s", SymHandle->GetSymbolFromAddress(frames->rip));
|
||||||
|
@ -28,6 +28,7 @@ namespace CrashHandler
|
|||||||
data.Thread->Name,
|
data.Thread->Name,
|
||||||
data.Thread->ID);
|
data.Thread->ID);
|
||||||
EHPrint("\e7981FCTechnical Informations on CPU %lld:\n", data.ID);
|
EHPrint("\e7981FCTechnical Informations on CPU %lld:\n", data.ID);
|
||||||
|
uintptr_t ds;
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
|
|
||||||
CPUData *cpu = (CPUData *)data.CPUData;
|
CPUData *cpu = (CPUData *)data.CPUData;
|
||||||
@ -46,11 +47,9 @@ namespace CrashHandler
|
|||||||
EHPrint("Checksum: 0x%X\n", cpu->Checksum);
|
EHPrint("Checksum: 0x%X\n", cpu->Checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ds;
|
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
uint32_t ds;
|
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
|
@ -32,7 +32,7 @@ namespace CrashHandler
|
|||||||
TraceFrames(data.Frame, 40, sh, false);
|
TraceFrames(data.Frame, 40, sh, false);
|
||||||
}
|
}
|
||||||
EHPrint("\n\eFAFAFATracing interrupt frames...");
|
EHPrint("\n\eFAFAFATracing interrupt frames...");
|
||||||
for (uint64_t i = 0; i < 8; i++)
|
for (short i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
if (EHIntFrames[i])
|
if (EHIntFrames[i])
|
||||||
{
|
{
|
||||||
@ -41,12 +41,12 @@ namespace CrashHandler
|
|||||||
EHPrint("\n\e2565CC%p", EHIntFrames[i]);
|
EHPrint("\n\e2565CC%p", EHIntFrames[i]);
|
||||||
EHPrint("\e7925CC-");
|
EHPrint("\e7925CC-");
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
if ((uint64_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end)
|
if ((uintptr_t)EHIntFrames[i] >= 0xFFFFFFFF80000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end)
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
if ((uint64_t)EHIntFrames[i] >= 0xC0000000 && (uint64_t)EHIntFrames[i] <= (uint64_t)&_kernel_end)
|
if ((uintptr_t)EHIntFrames[i] >= 0xC0000000 && (uintptr_t)EHIntFrames[i] <= (uintptr_t)&_kernel_end)
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#endif
|
#endif
|
||||||
EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uint64_t)EHIntFrames[i]));
|
EHPrint("\e25CCC9%s", KernelSymbolTable->GetSymbolFromAddress((uintptr_t)EHIntFrames[i]));
|
||||||
else
|
else
|
||||||
EHPrint("\eFF4CA9Outside Kernel");
|
EHPrint("\eFF4CA9Outside Kernel");
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ namespace CrashHandler
|
|||||||
if (!sh)
|
if (!sh)
|
||||||
EHPrint("\n\eFFA500Warning: No symbol table available.");
|
EHPrint("\n\eFFA500Warning: No symbol table available.");
|
||||||
int SameItr = 0;
|
int SameItr = 0;
|
||||||
uint64_t LastRIP = 0;
|
uintptr_t LastRIP = 0;
|
||||||
for (int i = 0; i < 128; i++)
|
for (int i = 0; i < 128; i++)
|
||||||
{
|
{
|
||||||
if (data.Thread->RIPHistory[i] == 0)
|
if (data.Thread->RIPHistory[i] == 0)
|
||||||
@ -75,7 +75,7 @@ namespace CrashHandler
|
|||||||
if (!sh)
|
if (!sh)
|
||||||
EHPrint("\n\e2565CC%p", data.Thread->RIPHistory[i]);
|
EHPrint("\n\e2565CC%p", data.Thread->RIPHistory[i]);
|
||||||
else
|
else
|
||||||
EHPrint("\n\e2565CC%p\e7925CC-\e25CCC9%s", data.Thread->RIPHistory[i], sh->GetSymbolFromAddress((uint64_t)data.Thread->RIPHistory[i]));
|
EHPrint("\n\e2565CC%p\e7925CC-\e25CCC9%s", data.Thread->RIPHistory[i], sh->GetSymbolFromAddress(data.Thread->RIPHistory[i]));
|
||||||
}
|
}
|
||||||
EHPrint("\n\e7925CCNote: \e2565CCSame RIPs are not shown more than 3 times.\n");
|
EHPrint("\n\e7925CCNote: \e2565CCSame RIPs are not shown more than 3 times.\n");
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,11 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
efer.raw = CPU::x64::rdmsr(CPU::x64::MSR_EFER);
|
||||||
|
|
||||||
error("Technical Informations on CPU %lld:", CurCPU->ID);
|
error("Technical Informations on CPU %lld:", CurCPU->ID);
|
||||||
|
uintptr_t ds;
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
uint64_t ds;
|
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
uint32_t ds;
|
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
@ -177,7 +176,7 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
}
|
}
|
||||||
case CPU::x64::PageFault:
|
case CPU::x64::PageFault:
|
||||||
{
|
{
|
||||||
uint64_t CheckPageFaultAddress = 0;
|
uintptr_t CheckPageFaultAddress = 0;
|
||||||
CPU::x64::PageFaultErrorCode params = {.raw = (uint32_t)Frame->ErrorCode};
|
CPU::x64::PageFaultErrorCode params = {.raw = (uint32_t)Frame->ErrorCode};
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
CheckPageFaultAddress = CPU::x64::readcr2().PFLA;
|
CheckPageFaultAddress = CPU::x64::readcr2().PFLA;
|
||||||
@ -234,11 +233,11 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
|
|
||||||
if (Present)
|
if (Present)
|
||||||
{
|
{
|
||||||
uint64_t CheckPageFaultLinearAddress = (uint64_t)CheckPageFaultAddress;
|
uintptr_t CheckPageFaultLinearAddress = (uintptr_t)CheckPageFaultAddress;
|
||||||
CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000;
|
CheckPageFaultLinearAddress &= 0xFFFFFFFFFFFFF000;
|
||||||
debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress);
|
debug("%#lx -> %#lx", CheckPageFaultAddress, CheckPageFaultLinearAddress);
|
||||||
|
|
||||||
Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uint64_t)CheckPageFaultLinearAddress);
|
Memory::Virtual::PageMapIndexer Index = Memory::Virtual::PageMapIndexer((uintptr_t)CheckPageFaultLinearAddress);
|
||||||
debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d",
|
debug("Index for %#lx is PML:%d PDPTE:%d PDE:%d PTE:%d",
|
||||||
CheckPageFaultLinearAddress,
|
CheckPageFaultLinearAddress,
|
||||||
Index.PMLIndex,
|
Index.PMLIndex,
|
||||||
@ -247,9 +246,9 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame)
|
|||||||
Index.PTEIndex);
|
Index.PTEIndex);
|
||||||
Memory::PageMapLevel4 PML4 = CurCPU->CurrentProcess->PageTable->Entries[Index.PMLIndex];
|
Memory::PageMapLevel4 PML4 = CurCPU->CurrentProcess->PageTable->Entries[Index.PMLIndex];
|
||||||
|
|
||||||
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12);
|
Memory::PageDirectoryPointerTableEntryPtr *PDPTE = (Memory::PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
|
||||||
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
Memory::PageDirectoryEntryPtr *PDE = (Memory::PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
||||||
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
Memory::PageTableEntryPtr *PTE = (Memory::PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
||||||
|
|
||||||
debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx",
|
debug("# %03d-%03d-%03d-%03d: P:%s RW:%s US:%s PWT:%s PCB:%s A:%s NX:%s Address:%#lx",
|
||||||
Index.PMLIndex, 0, 0, 0,
|
Index.PMLIndex, 0, 0, 0,
|
||||||
|
@ -20,7 +20,7 @@ struct CRData
|
|||||||
CPU::x64::CR4 cr4;
|
CPU::x64::CR4 cr4;
|
||||||
CPU::x64::CR8 cr8;
|
CPU::x64::CR8 cr8;
|
||||||
CPU::x64::EFER efer;
|
CPU::x64::EFER efer;
|
||||||
uint64_t dr0, dr1, dr2, dr3, dr6;
|
uintptr_t dr0, dr1, dr2, dr3, dr6;
|
||||||
CPU::x64::DR7 dr7;
|
CPU::x64::DR7 dr7;
|
||||||
|
|
||||||
long ID;
|
long ID;
|
||||||
@ -42,7 +42,7 @@ struct CRData
|
|||||||
CPU::x32::CR4 cr4;
|
CPU::x32::CR4 cr4;
|
||||||
CPU::x32::CR8 cr8;
|
CPU::x32::CR8 cr8;
|
||||||
CPU::x32::EFER efer;
|
CPU::x32::EFER efer;
|
||||||
uint64_t dr0, dr1, dr2, dr3, dr6;
|
uintptr_t dr0, dr1, dr2, dr3, dr6;
|
||||||
CPU::x32::DR7 dr7;
|
CPU::x32::DR7 dr7;
|
||||||
|
|
||||||
long ID;
|
long ID;
|
||||||
|
@ -77,8 +77,8 @@ namespace Driver
|
|||||||
foreach (auto var in Drivers)
|
foreach (auto var in Drivers)
|
||||||
if (var->DriverUID == DUID)
|
if (var->DriverUID == DUID)
|
||||||
{
|
{
|
||||||
FexExtended *DrvExtHdr = (FexExtended *)((uint64_t)var->Address + EXTENDED_SECTION_ADDRESS);
|
FexExtended *DrvExtHdr = (FexExtended *)((uintptr_t)var->Address + EXTENDED_SECTION_ADDRESS);
|
||||||
return ((int (*)(void *))((uint64_t)DrvExtHdr->Driver.Callback + (uint64_t)var->Address))(KCB);
|
return ((int (*)(void *))((uintptr_t)DrvExtHdr->Driver.Callback + (uintptr_t)var->Address))(KCB);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -91,14 +91,14 @@ namespace Driver
|
|||||||
((KernelAPI *)KAPIAddress)->Info.DriverUID = DriverUIDs++;
|
((KernelAPI *)KAPIAddress)->Info.DriverUID = DriverUIDs++;
|
||||||
|
|
||||||
debug("Calling driver entry point ( %#lx %ld )", (unsigned long)fex, ((KernelAPI *)KAPIAddress)->Info.DriverUID);
|
debug("Calling driver entry point ( %#lx %ld )", (unsigned long)fex, ((KernelAPI *)KAPIAddress)->Info.DriverUID);
|
||||||
int ret = ((int (*)(KernelAPI *))((uint64_t)((Fex *)fex)->EntryPoint + (uint64_t)fex))(((KernelAPI *)KAPIAddress));
|
int ret = ((int (*)(KernelAPI *))((uintptr_t)((Fex *)fex)->EntryPoint + (uintptr_t)fex))(((KernelAPI *)KAPIAddress));
|
||||||
|
|
||||||
if (DriverReturnCode::OK != ret)
|
if (DriverReturnCode::OK != ret)
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
return DriverCode::OK;
|
return DriverCode::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DriverCode Driver::LoadDriver(uint64_t DriverAddress, uint64_t Size)
|
DriverCode Driver::LoadDriver(uintptr_t DriverAddress, uintptr_t Size)
|
||||||
{
|
{
|
||||||
Fex *DrvHdr = (Fex *)DriverAddress;
|
Fex *DrvHdr = (Fex *)DriverAddress;
|
||||||
if (DrvHdr->Magic[0] != 'F' || DrvHdr->Magic[1] != 'E' || DrvHdr->Magic[2] != 'X' || DrvHdr->Magic[3] != '\0')
|
if (DrvHdr->Magic[0] != 'F' || DrvHdr->Magic[1] != 'E' || DrvHdr->Magic[2] != 'X' || DrvHdr->Magic[3] != '\0')
|
||||||
@ -114,7 +114,7 @@ namespace Driver
|
|||||||
|
|
||||||
if (ElfDrvHdr->Type == FexFormatType::FexFormatType_Driver)
|
if (ElfDrvHdr->Type == FexFormatType::FexFormatType_Driver)
|
||||||
{
|
{
|
||||||
FexExtended *ElfDrvExtHdr = (FexExtended *)((uint64_t)ElfDrvHdr + EXTENDED_SECTION_ADDRESS);
|
FexExtended *ElfDrvExtHdr = (FexExtended *)((uintptr_t)ElfDrvHdr + EXTENDED_SECTION_ADDRESS);
|
||||||
debug("Name: \"%s\"; Type: %d; Callback: %#lx", ElfDrvExtHdr->Driver.Name, ElfDrvExtHdr->Driver.Type, ElfDrvExtHdr->Driver.Callback);
|
debug("Name: \"%s\"; Type: %d; Callback: %#lx", ElfDrvExtHdr->Driver.Name, ElfDrvExtHdr->Driver.Type, ElfDrvExtHdr->Driver.Callback);
|
||||||
|
|
||||||
if (ElfDrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI)
|
if (ElfDrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI)
|
||||||
@ -139,7 +139,7 @@ namespace Driver
|
|||||||
|
|
||||||
if (DrvHdr->Type == FexFormatType::FexFormatType_Driver)
|
if (DrvHdr->Type == FexFormatType::FexFormatType_Driver)
|
||||||
{
|
{
|
||||||
FexExtended *DrvExtHdr = (FexExtended *)((uint64_t)DrvHdr + EXTENDED_SECTION_ADDRESS);
|
FexExtended *DrvExtHdr = (FexExtended *)((uintptr_t)DrvHdr + EXTENDED_SECTION_ADDRESS);
|
||||||
debug("Name: \"%s\"; Type: %d; Callback: %#lx", DrvExtHdr->Driver.Name, DrvExtHdr->Driver.Type, DrvExtHdr->Driver.Callback);
|
debug("Name: \"%s\"; Type: %d; Callback: %#lx", DrvExtHdr->Driver.Name, DrvExtHdr->Driver.Type, DrvExtHdr->Driver.Callback);
|
||||||
|
|
||||||
if (DrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI)
|
if (DrvExtHdr->Driver.Bind.Type == DriverBindType::BIND_PCI)
|
||||||
@ -171,7 +171,7 @@ namespace Driver
|
|||||||
cwk_path_get_extension(driver->Name, &extension, nullptr);
|
cwk_path_get_extension(driver->Name, &extension, nullptr);
|
||||||
if (!strcmp(extension, ".fex") || !strcmp(extension, ".elf"))
|
if (!strcmp(extension, ".fex") || !strcmp(extension, ".elf"))
|
||||||
{
|
{
|
||||||
uint64_t ret = this->LoadDriver(driver->Address, driver->Length);
|
uintptr_t ret = this->LoadDriver(driver->Address, driver->Length);
|
||||||
char RetString[128];
|
char RetString[128];
|
||||||
if (ret == DriverCode::OK)
|
if (ret == DriverCode::OK)
|
||||||
strncpy(RetString, "\e058C19OK", 64);
|
strncpy(RetString, "\e058C19OK", 64);
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
Memory::Tracker *Tracker = new Memory::Tracker;
|
Memory::Tracker *Tracker = new Memory::Tracker;
|
||||||
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
||||||
memcpy(fex, (void *)DriverAddress, Size);
|
memcpy(fex, (void *)DriverAddress, Size);
|
||||||
FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS);
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size);
|
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
uint8_t *result = md5File((uint8_t *)fex, Size);
|
uint8_t *result = md5File((uint8_t *)fex, Size);
|
||||||
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
@ -47,7 +47,7 @@ namespace Driver
|
|||||||
KCallback->RawPtr = nullptr;
|
KCallback->RawPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
KCallback->Reason = CallbackReason::ConfigurationReason;
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback);
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
delete Tracker;
|
delete Tracker;
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
Memory::Tracker *Tracker = new Memory::Tracker;
|
Memory::Tracker *Tracker = new Memory::Tracker;
|
||||||
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
||||||
memcpy(fex, (void *)DriverAddress, Size);
|
memcpy(fex, (void *)DriverAddress, Size);
|
||||||
FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS);
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size);
|
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
uint8_t *result = md5File((uint8_t *)fex, Size);
|
uint8_t *result = md5File((uint8_t *)fex, Size);
|
||||||
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
@ -79,7 +79,7 @@ namespace Driver
|
|||||||
|
|
||||||
KCallback->RawPtr = nullptr;
|
KCallback->RawPtr = nullptr;
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
KCallback->Reason = CallbackReason::ConfigurationReason;
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback);
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
||||||
@ -111,7 +111,7 @@ namespace Driver
|
|||||||
DriverInterruptHook *InterruptHook = nullptr;
|
DriverInterruptHook *InterruptHook = nullptr;
|
||||||
if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] != 0)
|
if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] != 0)
|
||||||
InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] + 32, // x86
|
InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0] + 32, // x86
|
||||||
(void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex),
|
(void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex),
|
||||||
KCallback);
|
KCallback);
|
||||||
|
|
||||||
for (unsigned long i = 0; i < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0]); i++)
|
for (unsigned long i = 0; i < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[0]); i++)
|
||||||
@ -119,14 +119,14 @@ namespace Driver
|
|||||||
if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] == 0)
|
if (((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] == 0)
|
||||||
break;
|
break;
|
||||||
// InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] + 32, // x86
|
// InterruptHook = new DriverInterruptHook(((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i] + 32, // x86
|
||||||
// (void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex),
|
// (void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex),
|
||||||
// KCallback);
|
// KCallback);
|
||||||
fixme("TODO: MULTIPLE BIND INTERRUPT VECTORS %d", ((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i]);
|
fixme("TODO: MULTIPLE BIND INTERRUPT VECTORS %d", ((FexExtended *)DrvExtHdr)->Driver.Bind.Interrupt.Vector[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
KCallback->RawPtr = nullptr;
|
KCallback->RawPtr = nullptr;
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
KCallback->Reason = CallbackReason::ConfigurationReason;
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback);
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
for (unsigned long Vidx = 0; Vidx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[0]); Vidx++)
|
for (unsigned long Vidx = 0; Vidx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[0]); Vidx++)
|
||||||
for (unsigned long Didx = 0; Didx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[0]); Didx++)
|
for (unsigned long Didx = 0; Didx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[0]); Didx++)
|
||||||
@ -34,8 +34,8 @@ namespace Driver
|
|||||||
Memory::Tracker *Tracker = new Memory::Tracker();
|
Memory::Tracker *Tracker = new Memory::Tracker();
|
||||||
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
Fex *fex = (Fex *)Tracker->RequestPages(TO_PAGES(Size));
|
||||||
memcpy(fex, (void *)DriverAddress, Size);
|
memcpy(fex, (void *)DriverAddress, Size);
|
||||||
FexExtended *fexExtended = (FexExtended *)((uint64_t)fex + EXTENDED_SECTION_ADDRESS);
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
debug("Driver allocated at %#lx-%#lx", fex, (uint64_t)fex + Size);
|
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
uint8_t *result = md5File((uint8_t *)fex, Size);
|
uint8_t *result = md5File((uint8_t *)fex, Size);
|
||||||
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
@ -60,21 +60,21 @@ namespace Driver
|
|||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15));
|
((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15));
|
||||||
|
|
||||||
if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) != 0)
|
if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) != 0)
|
||||||
if (!Memory::Virtual().Check((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3))))
|
if (!Memory::Virtual().Check((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3))))
|
||||||
{
|
{
|
||||||
debug("IO base (BAR1 & ~3) is not mapped");
|
debug("IO base (BAR1 & ~3) is not mapped");
|
||||||
Memory::Virtual().Map((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), (void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), (void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR1 & (~3)), Memory::PTFlag::RW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) == 0)
|
if ((((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 1) == 0)
|
||||||
if (!Memory::Virtual().Check((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15))))
|
if (!Memory::Virtual().Check((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15))))
|
||||||
{
|
{
|
||||||
debug("Memory base (BAR0 & ~15) is not mapped");
|
debug("Memory base (BAR0 & ~15) is not mapped");
|
||||||
Memory::Virtual().Map((void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), (void *)(uint64_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), (void *)(uintptr_t)(((PCI::PCIHeader0 *)PCIDevice)->BAR0 & (~15)), Memory::PTFlag::RW);
|
||||||
|
|
||||||
uint64_t original = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
uintptr_t original = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = 0xFFFFFFFF;
|
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = 0xFFFFFFFF;
|
||||||
uint64_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 0xFFFFFFF0;
|
uintptr_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0 & 0xFFFFFFF0;
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = original;
|
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = original;
|
||||||
debug("Size: %#lx (%ld pages)", size, TO_PAGES(size));
|
debug("Size: %#lx (%ld pages)", size, TO_PAGES(size));
|
||||||
fixme("TODO: [BUG] Mapping is broken!!!!!!");
|
fixme("TODO: [BUG] Mapping is broken!!!!!!");
|
||||||
@ -97,12 +97,12 @@ namespace Driver
|
|||||||
case FexDriverType::FexDriverType_Network:
|
case FexDriverType::FexDriverType_Network:
|
||||||
{
|
{
|
||||||
DriverInterruptHook *InterruptHook = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)devices[0])->InterruptLine) + 32, // x86
|
DriverInterruptHook *InterruptHook = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)devices[0])->InterruptLine) + 32, // x86
|
||||||
(void *)((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex),
|
(void *)((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex),
|
||||||
KCallback);
|
KCallback);
|
||||||
|
|
||||||
KCallback->RawPtr = PCIDevice;
|
KCallback->RawPtr = PCIDevice;
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
KCallback->Reason = CallbackReason::ConfigurationReason;
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback);
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
||||||
@ -134,7 +134,7 @@ namespace Driver
|
|||||||
{
|
{
|
||||||
KCallback->RawPtr = PCIDevice;
|
KCallback->RawPtr = PCIDevice;
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
KCallback->Reason = CallbackReason::ConfigurationReason;
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uint64_t)fexExtended->Driver.Callback + (uint64_t)fex))(KCallback);
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
{
|
{
|
||||||
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
error("Driver %s does not implement the configuration callback", fexExtended->Driver.Name);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
fixme("Process driver: %s", ((FexExtended *)DrvExtHdr)->Driver.Name);
|
fixme("Process driver: %s", ((FexExtended *)DrvExtHdr)->Driver.Name);
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
@ -49,8 +49,8 @@ namespace Interrupts
|
|||||||
CPU::x64::wrmsr(CPU::x64::MSR_SHADOW_GS_BASE, (uint64_t)CoreData);
|
CPU::x64::wrmsr(CPU::x64::MSR_SHADOW_GS_BASE, (uint64_t)CoreData);
|
||||||
CoreData->ID = Core;
|
CoreData->ID = Core;
|
||||||
CoreData->IsActive = true;
|
CoreData->IsActive = true;
|
||||||
CoreData->SystemCallStack = (uint8_t *)((uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE);
|
CoreData->SystemCallStack = (uint8_t *)((uintptr_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE);
|
||||||
CoreData->Stack = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE;
|
CoreData->Stack = (uintptr_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE;
|
||||||
if (CoreData->Checksum != CPU_DATA_CHECKSUM)
|
if (CoreData->Checksum != CPU_DATA_CHECKSUM)
|
||||||
{
|
{
|
||||||
KPrint("CPU %d checksum mismatch! %x != %x", Core, CoreData->Checksum, CPU_DATA_CHECKSUM);
|
KPrint("CPU %d checksum mismatch! %x != %x", Core, CoreData->Checksum, CPU_DATA_CHECKSUM);
|
||||||
|
@ -6,10 +6,10 @@ namespace Xalloc
|
|||||||
{
|
{
|
||||||
struct SpinLockData
|
struct SpinLockData
|
||||||
{
|
{
|
||||||
uint64_t LockData = 0x0;
|
uintptr_t LockData = 0x0;
|
||||||
const char *CurrentHolder = "(null)";
|
const char *CurrentHolder = "(null)";
|
||||||
const char *AttemptingToGet = "(null)";
|
const char *AttemptingToGet = "(null)";
|
||||||
uint64_t Count = 0;
|
size_t Count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void DeadLock(SpinLockData Lock)
|
void DeadLock(SpinLockData Lock)
|
||||||
|
@ -45,9 +45,9 @@ __no_instrument_function void MapFromZero(PageTable4 *PT, BootInfo *Info)
|
|||||||
void *NullAddress = KernelAllocator.RequestPage();
|
void *NullAddress = KernelAllocator.RequestPage();
|
||||||
memset(NullAddress, 0, PAGE_SIZE); // TODO: If the CPU instruction pointer hits this page, there should be function to handle it. (memcpy assembly code?)
|
memset(NullAddress, 0, PAGE_SIZE); // TODO: If the CPU instruction pointer hits this page, there should be function to handle it. (memcpy assembly code?)
|
||||||
va.Map((void *)0, (void *)NullAddress, PTFlag::RW | PTFlag::US);
|
va.Map((void *)0, (void *)NullAddress, PTFlag::RW | PTFlag::US);
|
||||||
uint64_t VirtualOffsetNormalVMA = NORMAL_VMA_OFFSET;
|
uintptr_t VirtualOffsetNormalVMA = NORMAL_VMA_OFFSET;
|
||||||
uint64_t MemSize = Info->Memory.Size;
|
size_t MemSize = Info->Memory.Size;
|
||||||
for (uint64_t t = 0; t < MemSize; t += PAGE_SIZE)
|
for (size_t t = 0; t < MemSize; t += PAGE_SIZE)
|
||||||
{
|
{
|
||||||
va.Map((void *)t, (void *)t, PTFlag::RW /* | PTFlag::US */);
|
va.Map((void *)t, (void *)t, PTFlag::RW /* | PTFlag::US */);
|
||||||
va.Map((void *)VirtualOffsetNormalVMA, (void *)t, PTFlag::RW /* | PTFlag::US */);
|
va.Map((void *)VirtualOffsetNormalVMA, (void *)t, PTFlag::RW /* | PTFlag::US */);
|
||||||
@ -70,8 +70,8 @@ __no_instrument_function void MapFramebuffer(PageTable4 *PT, BootInfo *Info)
|
|||||||
if (!Info->Framebuffer[itrfb].BaseAddress)
|
if (!Info->Framebuffer[itrfb].BaseAddress)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for (uint64_t fb_base = (uint64_t)Info->Framebuffer[itrfb].BaseAddress;
|
for (uintptr_t fb_base = (uintptr_t)Info->Framebuffer[itrfb].BaseAddress;
|
||||||
fb_base < ((uint64_t)Info->Framebuffer[itrfb].BaseAddress + ((Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height) + PAGE_SIZE));
|
fb_base < ((uintptr_t)Info->Framebuffer[itrfb].BaseAddress + ((Info->Framebuffer[itrfb].Pitch * Info->Framebuffer[itrfb].Height) + PAGE_SIZE));
|
||||||
fb_base += PAGE_SIZE)
|
fb_base += PAGE_SIZE)
|
||||||
va.Map((void *)fb_base, (void *)fb_base, PTFlag::RW | PTFlag::US | PTFlag::G);
|
va.Map((void *)fb_base, (void *)fb_base, PTFlag::RW | PTFlag::US | PTFlag::G);
|
||||||
itrfb++;
|
itrfb++;
|
||||||
@ -84,14 +84,14 @@ __no_instrument_function void MapKernel(PageTable4 *PT, BootInfo *Info)
|
|||||||
Kernel Start & Text Start ------ Text End ------ Kernel Rodata End ------ Kernel Data End & Kernel End
|
Kernel Start & Text Start ------ Text End ------ Kernel Rodata End ------ Kernel Data End & Kernel End
|
||||||
*/
|
*/
|
||||||
Virtual va = Virtual(PT);
|
Virtual va = Virtual(PT);
|
||||||
uint64_t KernelStart = (uint64_t)&_kernel_start;
|
uintptr_t KernelStart = (uintptr_t)&_kernel_start;
|
||||||
uint64_t KernelTextEnd = (uint64_t)&_kernel_text_end;
|
uintptr_t KernelTextEnd = (uintptr_t)&_kernel_text_end;
|
||||||
uint64_t KernelDataEnd = (uint64_t)&_kernel_data_end;
|
uintptr_t KernelDataEnd = (uintptr_t)&_kernel_data_end;
|
||||||
uint64_t KernelRoDataEnd = (uint64_t)&_kernel_rodata_end;
|
uintptr_t KernelRoDataEnd = (uintptr_t)&_kernel_rodata_end;
|
||||||
uint64_t KernelEnd = (uint64_t)&_kernel_end;
|
uintptr_t KernelEnd = (uintptr_t)&_kernel_end;
|
||||||
|
|
||||||
uint64_t BaseKernelMapAddress = (uint64_t)Info->Kernel.PhysicalBase;
|
uintptr_t BaseKernelMapAddress = (uintptr_t)Info->Kernel.PhysicalBase;
|
||||||
uint64_t k;
|
uintptr_t k;
|
||||||
|
|
||||||
for (k = KernelStart; k < KernelTextEnd; k += PAGE_SIZE)
|
for (k = KernelStart; k < KernelTextEnd; k += PAGE_SIZE)
|
||||||
{
|
{
|
||||||
@ -130,9 +130,9 @@ __no_instrument_function void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
for (uint64_t i = 0; i < Info->Memory.Entries; i++)
|
for (uint64_t i = 0; i < Info->Memory.Entries; i++)
|
||||||
{
|
{
|
||||||
uint64_t Base = reinterpret_cast<uint64_t>(Info->Memory.Entry[i].BaseAddress);
|
uintptr_t Base = reinterpret_cast<uintptr_t>(Info->Memory.Entry[i].BaseAddress);
|
||||||
uint64_t Length = Info->Memory.Entry[i].Length;
|
uintptr_t Length = Info->Memory.Entry[i].Length;
|
||||||
uint64_t End = Base + Length;
|
uintptr_t End = Base + Length;
|
||||||
const char *Type = "Unknown";
|
const char *Type = "Unknown";
|
||||||
|
|
||||||
switch (Info->Memory.Entry[i].Type)
|
switch (Info->Memory.Entry[i].Type)
|
||||||
@ -233,7 +233,7 @@ __no_instrument_function void InitializeMemoryManagement(BootInfo *Info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *HeapMalloc(uint64_t Size)
|
void *HeapMalloc(size_t Size)
|
||||||
{
|
{
|
||||||
switch (AllocatorType)
|
switch (AllocatorType)
|
||||||
{
|
{
|
||||||
@ -256,7 +256,7 @@ void *HeapMalloc(uint64_t Size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *HeapCalloc(uint64_t n, uint64_t Size)
|
void *HeapCalloc(size_t n, size_t Size)
|
||||||
{
|
{
|
||||||
switch (AllocatorType)
|
switch (AllocatorType)
|
||||||
{
|
{
|
||||||
@ -279,7 +279,7 @@ void *HeapCalloc(uint64_t n, uint64_t Size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *HeapRealloc(void *Address, uint64_t Size)
|
void *HeapRealloc(void *Address, size_t Size)
|
||||||
{
|
{
|
||||||
switch (AllocatorType)
|
switch (AllocatorType)
|
||||||
{
|
{
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
Virtual::PageMapIndexer::PageMapIndexer(uint64_t VirtualAddress)
|
Virtual::PageMapIndexer::PageMapIndexer(uintptr_t VirtualAddress)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
uint64_t Address = VirtualAddress;
|
uintptr_t Address = VirtualAddress;
|
||||||
Address >>= 12;
|
Address >>= 12;
|
||||||
this->PTEIndex = Address & 0x1FF;
|
this->PTEIndex = Address & 0x1FF;
|
||||||
Address >>= 9;
|
Address >>= 9;
|
||||||
@ -15,7 +15,7 @@ namespace Memory
|
|||||||
Address >>= 9;
|
Address >>= 9;
|
||||||
this->PMLIndex = Address & 0x1FF;
|
this->PMLIndex = Address & 0x1FF;
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
uint64_t Address = VirtualAddress;
|
uintptr_t Address = VirtualAddress;
|
||||||
Address >>= 12;
|
Address >>= 12;
|
||||||
this->PTEIndex = Address & 0x3FF;
|
this->PTEIndex = Address & 0x3FF;
|
||||||
Address >>= 10;
|
Address >>= 10;
|
||||||
|
@ -34,10 +34,10 @@ namespace Memory
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Physical::SwapPages(void *Address, uint64_t PageCount)
|
bool Physical::SwapPages(void *Address, size_t PageCount)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < PageCount; i++)
|
for (size_t i = 0; i < PageCount; i++)
|
||||||
if (!this->SwapPage((void *)((uint64_t)Address + (i * PAGE_SIZE))))
|
if (!this->SwapPage((void *)((uintptr_t)Address + (i * PAGE_SIZE))))
|
||||||
return false;
|
return false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -48,10 +48,10 @@ namespace Memory
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Physical::UnswapPages(void *Address, uint64_t PageCount)
|
bool Physical::UnswapPages(void *Address, size_t PageCount)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < PageCount; i++)
|
for (size_t i = 0; i < PageCount; i++)
|
||||||
if (!this->UnswapPage((void *)((uint64_t)Address + (i * PAGE_SIZE))))
|
if (!this->UnswapPage((void *)((uintptr_t)Address + (i * PAGE_SIZE))))
|
||||||
return false;
|
return false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ namespace Memory
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Physical::RequestPages(uint64_t Count)
|
void *Physical::RequestPages(size_t Count)
|
||||||
{
|
{
|
||||||
SmartLock(this->MemoryLock);
|
SmartLock(this->MemoryLock);
|
||||||
for (; PageBitmapIndex < PageBitmap.Size * 8; PageBitmapIndex++)
|
for (; PageBitmapIndex < PageBitmap.Size * 8; PageBitmapIndex++)
|
||||||
@ -91,7 +91,7 @@ namespace Memory
|
|||||||
if (PageBitmap[Index] == true)
|
if (PageBitmap[Index] == true)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Count; i++)
|
for (size_t i = 0; i < Count; i++)
|
||||||
if (PageBitmap[Index + i] == true)
|
if (PageBitmap[Index + i] == true)
|
||||||
goto NextPage;
|
goto NextPage;
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ namespace Memory
|
|||||||
warn("Null pointer passed to FreePage.");
|
warn("Null pointer passed to FreePage.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t Index = (uint64_t)Address / PAGE_SIZE;
|
size_t Index = (size_t)Address / PAGE_SIZE;
|
||||||
if (unlikely(PageBitmap[Index] == false))
|
if (unlikely(PageBitmap[Index] == false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::FreePages(void *Address, uint64_t Count)
|
void Physical::FreePages(void *Address, size_t Count)
|
||||||
{
|
{
|
||||||
if (unlikely(Address == nullptr || Count == 0))
|
if (unlikely(Address == nullptr || Count == 0))
|
||||||
{
|
{
|
||||||
@ -144,8 +144,8 @@ namespace Memory
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint64_t t = 0; t < Count; t++)
|
for (size_t t = 0; t < Count; t++)
|
||||||
this->FreePage((void *)((uint64_t)Address + (t * PAGE_SIZE)));
|
this->FreePage((void *)((uintptr_t)Address + (t * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::LockPage(void *Address)
|
void Physical::LockPage(void *Address)
|
||||||
@ -153,7 +153,7 @@ namespace Memory
|
|||||||
if (unlikely(Address == nullptr))
|
if (unlikely(Address == nullptr))
|
||||||
warn("Trying to lock null address.");
|
warn("Trying to lock null address.");
|
||||||
|
|
||||||
uint64_t Index = (uint64_t)Address / PAGE_SIZE;
|
uintptr_t Index = (uintptr_t)Address / PAGE_SIZE;
|
||||||
if (unlikely(PageBitmap[Index] == true))
|
if (unlikely(PageBitmap[Index] == true))
|
||||||
return;
|
return;
|
||||||
if (PageBitmap.Set(Index, true))
|
if (PageBitmap.Set(Index, true))
|
||||||
@ -163,13 +163,13 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::LockPages(void *Address, uint64_t PageCount)
|
void Physical::LockPages(void *Address, size_t PageCount)
|
||||||
{
|
{
|
||||||
if (unlikely(Address == nullptr || PageCount == 0))
|
if (unlikely(Address == nullptr || PageCount == 0))
|
||||||
warn("Trying to lock %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
warn("Trying to lock %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
||||||
|
|
||||||
for (uint64_t i = 0; i < PageCount; i++)
|
for (size_t i = 0; i < PageCount; i++)
|
||||||
this->LockPage((void *)((uint64_t)Address + (i * PAGE_SIZE)));
|
this->LockPage((void *)((uintptr_t)Address + (i * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::ReservePage(void *Address)
|
void Physical::ReservePage(void *Address)
|
||||||
@ -177,7 +177,7 @@ namespace Memory
|
|||||||
if (unlikely(Address == nullptr))
|
if (unlikely(Address == nullptr))
|
||||||
warn("Trying to reserve null address.");
|
warn("Trying to reserve null address.");
|
||||||
|
|
||||||
uint64_t Index = (uint64_t)Address / PAGE_SIZE;
|
uintptr_t Index = (uintptr_t)Address / PAGE_SIZE;
|
||||||
if (unlikely(PageBitmap[Index] == true))
|
if (unlikely(PageBitmap[Index] == true))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -188,13 +188,13 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::ReservePages(void *Address, uint64_t PageCount)
|
void Physical::ReservePages(void *Address, size_t PageCount)
|
||||||
{
|
{
|
||||||
if (unlikely(Address == nullptr || PageCount == 0))
|
if (unlikely(Address == nullptr || PageCount == 0))
|
||||||
warn("Trying to reserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
warn("Trying to reserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
||||||
|
|
||||||
for (uint64_t t = 0; t < PageCount; t++)
|
for (size_t t = 0; t < PageCount; t++)
|
||||||
this->ReservePage((void *)((uint64_t)Address + (t * PAGE_SIZE)));
|
this->ReservePage((void *)((uintptr_t)Address + (t * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::UnreservePage(void *Address)
|
void Physical::UnreservePage(void *Address)
|
||||||
@ -202,7 +202,7 @@ namespace Memory
|
|||||||
if (unlikely(Address == nullptr))
|
if (unlikely(Address == nullptr))
|
||||||
warn("Trying to unreserve null address.");
|
warn("Trying to unreserve null address.");
|
||||||
|
|
||||||
uint64_t Index = (uint64_t)Address / PAGE_SIZE;
|
uintptr_t Index = (uintptr_t)Address / PAGE_SIZE;
|
||||||
if (unlikely(PageBitmap[Index] == false))
|
if (unlikely(PageBitmap[Index] == false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -215,13 +215,13 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::UnreservePages(void *Address, uint64_t PageCount)
|
void Physical::UnreservePages(void *Address, size_t PageCount)
|
||||||
{
|
{
|
||||||
if (unlikely(Address == nullptr || PageCount == 0))
|
if (unlikely(Address == nullptr || PageCount == 0))
|
||||||
warn("Trying to unreserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
warn("Trying to unreserve %s%s.", Address ? "null address" : "", PageCount ? "0 pages" : "");
|
||||||
|
|
||||||
for (uint64_t t = 0; t < PageCount; t++)
|
for (size_t t = 0; t < PageCount; t++)
|
||||||
this->UnreservePage((void *)((uint64_t)Address + (t * PAGE_SIZE)));
|
this->UnreservePage((void *)((uintptr_t)Address + (t * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physical::Init(BootInfo *Info)
|
void Physical::Init(BootInfo *Info)
|
||||||
@ -253,14 +253,14 @@ namespace Memory
|
|||||||
CPU::Stop();
|
CPU::Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t BitmapSize = (MemorySize / PAGE_SIZE) / 8 + 1;
|
size_t BitmapSize = (MemorySize / PAGE_SIZE) / 8 + 1;
|
||||||
trace("Initializing Bitmap at %llp-%llp (%lld Bytes)",
|
trace("Initializing Bitmap at %llp-%llp (%lld Bytes)",
|
||||||
LargestFreeMemorySegment,
|
LargestFreeMemorySegment,
|
||||||
(void *)((uint64_t)LargestFreeMemorySegment + BitmapSize),
|
(void *)((uintptr_t)LargestFreeMemorySegment + BitmapSize),
|
||||||
BitmapSize);
|
BitmapSize);
|
||||||
PageBitmap.Size = BitmapSize;
|
PageBitmap.Size = BitmapSize;
|
||||||
PageBitmap.Buffer = (uint8_t *)LargestFreeMemorySegment;
|
PageBitmap.Buffer = (uint8_t *)LargestFreeMemorySegment;
|
||||||
for (uint64_t i = 0; i < BitmapSize; i++)
|
for (size_t i = 0; i < BitmapSize; i++)
|
||||||
*(uint8_t *)(PageBitmap.Buffer + i) = 0;
|
*(uint8_t *)(PageBitmap.Buffer + i) = 0;
|
||||||
|
|
||||||
trace("Reserving pages...");
|
trace("Reserving pages...");
|
||||||
|
@ -13,18 +13,18 @@ namespace Memory
|
|||||||
void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE));
|
void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE));
|
||||||
debug("AllocatedStack: %p", AllocatedStack);
|
debug("AllocatedStack: %p", AllocatedStack);
|
||||||
memset(AllocatedStack, 0, USER_STACK_SIZE);
|
memset(AllocatedStack, 0, USER_STACK_SIZE);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++)
|
for (size_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++)
|
||||||
{
|
{
|
||||||
Virtual(Table).Map((void *)(USER_STACK_BASE + (i * PAGE_SIZE)),
|
Virtual(Table).Map((void *)(USER_STACK_BASE + (i * PAGE_SIZE)),
|
||||||
(void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)),
|
(void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)),
|
||||||
PTFlag::RW | PTFlag::US);
|
PTFlag::RW | PTFlag::US);
|
||||||
debug("Mapped %p to %p", (void *)(USER_STACK_BASE + (i * PAGE_SIZE)),
|
debug("Mapped %p to %p", (void *)(USER_STACK_BASE + (i * PAGE_SIZE)),
|
||||||
(void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)));
|
(void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
this->StackBottom = (void *)USER_STACK_BASE;
|
this->StackBottom = (void *)USER_STACK_BASE;
|
||||||
this->StackTop = (void *)(USER_STACK_BASE + USER_STACK_SIZE);
|
this->StackTop = (void *)(USER_STACK_BASE + USER_STACK_SIZE);
|
||||||
this->StackPhyiscalBottom = AllocatedStack;
|
this->StackPhyiscalBottom = AllocatedStack;
|
||||||
this->StackPhyiscalTop = (void *)((uint64_t)AllocatedStack + USER_STACK_SIZE);
|
this->StackPhyiscalTop = (void *)((uintptr_t)AllocatedStack + USER_STACK_SIZE);
|
||||||
this->Size = USER_STACK_SIZE;
|
this->Size = USER_STACK_SIZE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -33,7 +33,7 @@ namespace Memory
|
|||||||
this->StackPhyiscalBottom = this->StackBottom;
|
this->StackPhyiscalBottom = this->StackBottom;
|
||||||
debug("StackBottom: %p", this->StackBottom);
|
debug("StackBottom: %p", this->StackBottom);
|
||||||
memset(this->StackBottom, 0, STACK_SIZE);
|
memset(this->StackBottom, 0, STACK_SIZE);
|
||||||
this->StackTop = (void *)((uint64_t)this->StackBottom + STACK_SIZE);
|
this->StackTop = (void *)((uintptr_t)this->StackBottom + STACK_SIZE);
|
||||||
this->StackPhyiscalTop = this->StackTop;
|
this->StackPhyiscalTop = this->StackTop;
|
||||||
this->Size = STACK_SIZE;
|
this->Size = STACK_SIZE;
|
||||||
}
|
}
|
||||||
@ -47,12 +47,12 @@ namespace Memory
|
|||||||
// debug("Freed stack at %p", this->StackBottom);
|
// debug("Freed stack at %p", this->StackBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StackGuard::Expand(uint64_t FaultAddress)
|
bool StackGuard::Expand(uintptr_t FaultAddress)
|
||||||
{
|
{
|
||||||
if (this->UserMode)
|
if (this->UserMode)
|
||||||
{
|
{
|
||||||
if (FaultAddress < (uint64_t)this->StackBottom - USER_STACK_SIZE ||
|
if (FaultAddress < (uintptr_t)this->StackBottom - USER_STACK_SIZE ||
|
||||||
FaultAddress > (uint64_t)this->StackTop)
|
FaultAddress > (uintptr_t)this->StackTop)
|
||||||
{
|
{
|
||||||
return false; // It's not about the stack.
|
return false; // It's not about the stack.
|
||||||
}
|
}
|
||||||
@ -61,12 +61,12 @@ namespace Memory
|
|||||||
void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE));
|
void *AllocatedStack = KernelAllocator.RequestPages(TO_PAGES(USER_STACK_SIZE));
|
||||||
debug("AllocatedStack: %p", AllocatedStack);
|
debug("AllocatedStack: %p", AllocatedStack);
|
||||||
memset(AllocatedStack, 0, USER_STACK_SIZE);
|
memset(AllocatedStack, 0, USER_STACK_SIZE);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++)
|
for (uintptr_t i = 0; i < TO_PAGES(USER_STACK_SIZE); i++)
|
||||||
{
|
{
|
||||||
Virtual(this->Table).Map((void *)((uint64_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)), PTFlag::RW | PTFlag::US);
|
Virtual(this->Table).Map((void *)((uintptr_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)), PTFlag::RW | PTFlag::US);
|
||||||
debug("Mapped %p to %p", (void *)((uint64_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uint64_t)AllocatedStack + (i * PAGE_SIZE)));
|
debug("Mapped %p to %p", (void *)((uintptr_t)this->StackBottom - (i * PAGE_SIZE)), (void *)((uintptr_t)AllocatedStack + (i * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
this->StackBottom = (void *)((uint64_t)this->StackBottom - USER_STACK_SIZE);
|
this->StackBottom = (void *)((uintptr_t)this->StackBottom - USER_STACK_SIZE);
|
||||||
this->Size += USER_STACK_SIZE;
|
this->Size += USER_STACK_SIZE;
|
||||||
info("Stack expanded to %p", this->StackBottom);
|
info("Stack expanded to %p", this->StackBottom);
|
||||||
return true;
|
return true;
|
||||||
|
@ -11,22 +11,22 @@ namespace Memory
|
|||||||
return FROM_PAGES(Size);
|
return FROM_PAGES(Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Tracker::RequestPages(uint64_t Count)
|
void *Tracker::RequestPages(size_t Count)
|
||||||
{
|
{
|
||||||
void *Address = KernelAllocator.RequestPages(Count);
|
void *Address = KernelAllocator.RequestPages(Count);
|
||||||
for (uint64_t i = 0; i < Count; i++)
|
for (size_t i = 0; i < Count; i++)
|
||||||
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
AllocatedPagesList.push_back({Address, Count});
|
AllocatedPagesList.push_back({Address, Count});
|
||||||
return Address;
|
return Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tracker::FreePages(void *Address, uint64_t Count)
|
void Tracker::FreePages(void *Address, size_t Count)
|
||||||
{
|
{
|
||||||
KernelAllocator.FreePages(Address, Count);
|
KernelAllocator.FreePages(Address, Count);
|
||||||
for (uint64_t i = 0; i < Count; i++)
|
for (size_t i = 0; i < Count; i++)
|
||||||
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
||||||
|
|
||||||
for (uint64_t i = 0; i < AllocatedPagesList.size(); i++)
|
for (uintptr_t i = 0; i < AllocatedPagesList.size(); i++)
|
||||||
if (AllocatedPagesList[i].Address == Address)
|
if (AllocatedPagesList[i].Address == Address)
|
||||||
{
|
{
|
||||||
AllocatedPagesList.remove(i);
|
AllocatedPagesList.remove(i);
|
||||||
@ -48,8 +48,8 @@ namespace Memory
|
|||||||
foreach (auto var in AllocatedPagesList)
|
foreach (auto var in AllocatedPagesList)
|
||||||
{
|
{
|
||||||
KernelAllocator.FreePages(var.Address, var.PageCount);
|
KernelAllocator.FreePages(var.Address, var.PageCount);
|
||||||
for (uint64_t i = 0; i < var.PageCount; i++)
|
for (size_t i = 0; i < var.PageCount; i++)
|
||||||
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)var.Address + (i * PAGE_SIZE)), (void *)((uint64_t)var.Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
Memory::Virtual(this->PageTable).Remap((void *)((uintptr_t)var.Address + (i * PAGE_SIZE)), (void *)((uintptr_t)var.Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
||||||
}
|
}
|
||||||
debug("Tracker destroyed.");
|
debug("Tracker destroyed.");
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ namespace Memory
|
|||||||
bool Virtual::Check(void *VirtualAddress, PTFlag Flag)
|
bool Virtual::Check(void *VirtualAddress, PTFlag Flag)
|
||||||
{
|
{
|
||||||
// 0x1000 aligned
|
// 0x1000 aligned
|
||||||
uint64_t Address = (uint64_t)VirtualAddress;
|
uintptr_t Address = (uintptr_t)VirtualAddress;
|
||||||
Address &= 0xFFFFFFFFFFFFF000;
|
Address &= 0xFFFFFFFFFFFFF000;
|
||||||
|
|
||||||
PageMapIndexer Index = PageMapIndexer((uint64_t)Address);
|
PageMapIndexer Index = PageMapIndexer(Address);
|
||||||
PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex];
|
PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex];
|
||||||
|
|
||||||
PageDirectoryPointerTableEntryPtr *PDPTE = nullptr;
|
PageDirectoryPointerTableEntryPtr *PDPTE = nullptr;
|
||||||
@ -20,15 +20,15 @@ namespace Memory
|
|||||||
|
|
||||||
if ((PML4.raw & Flag) > 0)
|
if ((PML4.raw & Flag) > 0)
|
||||||
{
|
{
|
||||||
PDPTE = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12);
|
PDPTE = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
|
||||||
if (PDPTE)
|
if (PDPTE)
|
||||||
if ((PDPTE->Entries[Index.PDPTEIndex].Present))
|
if ((PDPTE->Entries[Index.PDPTEIndex].Present))
|
||||||
{
|
{
|
||||||
PDE = (PageDirectoryEntryPtr *)((uint64_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
PDE = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
|
||||||
if (PDE)
|
if (PDE)
|
||||||
if ((PDE->Entries[Index.PDEIndex].Present))
|
if ((PDE->Entries[Index.PDEIndex].Present))
|
||||||
{
|
{
|
||||||
PTE = (PageTableEntryPtr *)((uint64_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
PTE = (PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
|
||||||
if (PTE)
|
if (PTE)
|
||||||
if ((PTE->Entries[Index.PTEIndex].Present))
|
if ((PTE->Entries[Index.PTEIndex].Present))
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ namespace Memory
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PageMapIndexer Index = PageMapIndexer((uint64_t)VirtualAddress);
|
PageMapIndexer Index = PageMapIndexer((uintptr_t)VirtualAddress);
|
||||||
// Clear any flags that are not 1 << 0 (Present) - 1 << 5 (Accessed) because rest are for page table entries only
|
// Clear any flags that are not 1 << 0 (Present) - 1 << 5 (Accessed) because rest are for page table entries only
|
||||||
uint64_t DirectoryFlags = Flags & 0x3F;
|
uint64_t DirectoryFlags = Flags & 0x3F;
|
||||||
|
|
||||||
@ -60,10 +60,10 @@ namespace Memory
|
|||||||
PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)KernelAllocator.RequestPage();
|
PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)KernelAllocator.RequestPage();
|
||||||
memset(PDPTEPtr, 0, PAGE_SIZE);
|
memset(PDPTEPtr, 0, PAGE_SIZE);
|
||||||
PML4.Present = true;
|
PML4.Present = true;
|
||||||
PML4.SetAddress((uint64_t)PDPTEPtr >> 12);
|
PML4.SetAddress((uintptr_t)PDPTEPtr >> 12);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.GetAddress() << 12);
|
PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
|
||||||
PML4.raw |= DirectoryFlags;
|
PML4.raw |= DirectoryFlags;
|
||||||
this->Table->Entries[Index.PMLIndex] = PML4;
|
this->Table->Entries[Index.PMLIndex] = PML4;
|
||||||
|
|
||||||
@ -74,10 +74,10 @@ namespace Memory
|
|||||||
PDEPtr = (PageDirectoryEntryPtr *)KernelAllocator.RequestPage();
|
PDEPtr = (PageDirectoryEntryPtr *)KernelAllocator.RequestPage();
|
||||||
memset(PDEPtr, 0, PAGE_SIZE);
|
memset(PDEPtr, 0, PAGE_SIZE);
|
||||||
PDPTE.Present = true;
|
PDPTE.Present = true;
|
||||||
PDPTE.SetAddress((uint64_t)PDEPtr >> 12);
|
PDPTE.SetAddress((uintptr_t)PDEPtr >> 12);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PDEPtr = (PageDirectoryEntryPtr *)((uint64_t)PDPTE.GetAddress() << 12);
|
PDEPtr = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE.GetAddress() << 12);
|
||||||
PDPTE.raw |= DirectoryFlags;
|
PDPTE.raw |= DirectoryFlags;
|
||||||
PDPTEPtr->Entries[Index.PDPTEIndex] = PDPTE;
|
PDPTEPtr->Entries[Index.PDPTEIndex] = PDPTE;
|
||||||
|
|
||||||
@ -88,17 +88,17 @@ namespace Memory
|
|||||||
PTEPtr = (PageTableEntryPtr *)KernelAllocator.RequestPage();
|
PTEPtr = (PageTableEntryPtr *)KernelAllocator.RequestPage();
|
||||||
memset(PTEPtr, 0, PAGE_SIZE);
|
memset(PTEPtr, 0, PAGE_SIZE);
|
||||||
PDE.Present = true;
|
PDE.Present = true;
|
||||||
PDE.SetAddress((uint64_t)PTEPtr >> 12);
|
PDE.SetAddress((uintptr_t)PTEPtr >> 12);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PTEPtr = (PageTableEntryPtr *)((uint64_t)PDE.GetAddress() << 12);
|
PTEPtr = (PageTableEntryPtr *)((uintptr_t)PDE.GetAddress() << 12);
|
||||||
PDE.raw |= DirectoryFlags;
|
PDE.raw |= DirectoryFlags;
|
||||||
PDEPtr->Entries[Index.PDEIndex] = PDE;
|
PDEPtr->Entries[Index.PDEIndex] = PDE;
|
||||||
|
|
||||||
PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex];
|
PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex];
|
||||||
PTE.Present = true;
|
PTE.Present = true;
|
||||||
PTE.raw |= Flags;
|
PTE.raw |= Flags;
|
||||||
PTE.SetAddress((uint64_t)PhysicalAddress >> 12);
|
PTE.SetAddress((uintptr_t)PhysicalAddress >> 12);
|
||||||
PTEPtr->Entries[Index.PTEIndex] = PTE;
|
PTEPtr->Entries[Index.PTEIndex] = PTE;
|
||||||
|
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
@ -133,10 +133,10 @@ namespace Memory
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags)
|
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, size_t PageCount, uint64_t Flags)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < PageCount; i++)
|
for (size_t i = 0; i < PageCount; i++)
|
||||||
this->Map((void *)((uint64_t)VirtualAddress + (i * PAGE_SIZE)), (void *)((uint64_t)PhysicalAddress + (i * PAGE_SIZE)), Flags);
|
this->Map((void *)((uintptr_t)VirtualAddress + (i * PAGE_SIZE)), (void *)((uintptr_t)PhysicalAddress + (i * PAGE_SIZE)), Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Unmap(void *VirtualAddress)
|
void Virtual::Unmap(void *VirtualAddress)
|
||||||
@ -148,28 +148,28 @@ namespace Memory
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PageMapIndexer Index = PageMapIndexer((uint64_t)VirtualAddress);
|
PageMapIndexer Index = PageMapIndexer((uintptr_t)VirtualAddress);
|
||||||
PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex];
|
PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex];
|
||||||
if (!PML4.Present)
|
if (!PML4.Present)
|
||||||
{
|
{
|
||||||
error("Page not present");
|
error("Page not present");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PageDirectoryPointerTableEntryPtr *PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uint64_t)PML4.Address << 12);
|
PageDirectoryPointerTableEntryPtr *PDPTEPtr = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.Address << 12);
|
||||||
PageDirectoryPointerTableEntry PDPTE = PDPTEPtr->Entries[Index.PDPTEIndex];
|
PageDirectoryPointerTableEntry PDPTE = PDPTEPtr->Entries[Index.PDPTEIndex];
|
||||||
if (!PDPTE.Present)
|
if (!PDPTE.Present)
|
||||||
{
|
{
|
||||||
error("Page not present");
|
error("Page not present");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PageDirectoryEntryPtr *PDEPtr = (PageDirectoryEntryPtr *)((uint64_t)PDPTE.Address << 12);
|
PageDirectoryEntryPtr *PDEPtr = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE.Address << 12);
|
||||||
PageDirectoryEntry PDE = PDEPtr->Entries[Index.PDEIndex];
|
PageDirectoryEntry PDE = PDEPtr->Entries[Index.PDEIndex];
|
||||||
if (!PDE.Present)
|
if (!PDE.Present)
|
||||||
{
|
{
|
||||||
error("Page not present");
|
error("Page not present");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PageTableEntryPtr *PTEPtr = (PageTableEntryPtr *)((uint64_t)PDE.Address << 12);
|
PageTableEntryPtr *PTEPtr = (PageTableEntryPtr *)((uintptr_t)PDE.Address << 12);
|
||||||
PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex];
|
PageTableEntry PTE = PTEPtr->Entries[Index.PTEIndex];
|
||||||
if (!PTE.Present)
|
if (!PTE.Present)
|
||||||
{
|
{
|
||||||
@ -195,10 +195,10 @@ namespace Memory
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Unmap(void *VirtualAddress, uint64_t PageCount)
|
void Virtual::Unmap(void *VirtualAddress, size_t PageCount)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < PageCount; i++)
|
for (size_t i = 0; i < PageCount; i++)
|
||||||
this->Unmap((void *)((uint64_t)VirtualAddress + (i * PAGE_SIZE)));
|
this->Unmap((void *)((uintptr_t)VirtualAddress + (i * PAGE_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Remap(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags)
|
void Virtual::Remap(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags)
|
||||||
|
@ -772,10 +772,10 @@ namespace PCI
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void PCI::EnumerateFunction(uint64_t DeviceAddress, uint64_t Function)
|
void PCI::EnumerateFunction(uintptr_t DeviceAddress, uintptr_t Function)
|
||||||
{
|
{
|
||||||
uint64_t Offset = Function << 12;
|
uintptr_t Offset = Function << 12;
|
||||||
uint64_t FunctionAddress = DeviceAddress + Offset;
|
uintptr_t FunctionAddress = DeviceAddress + Offset;
|
||||||
Memory::Virtual().Map((void *)FunctionAddress, (void *)FunctionAddress, Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)FunctionAddress, (void *)FunctionAddress, Memory::PTFlag::RW);
|
||||||
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)FunctionAddress;
|
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)FunctionAddress;
|
||||||
if (PCIDeviceHdr->DeviceID == 0)
|
if (PCIDeviceHdr->DeviceID == 0)
|
||||||
@ -788,24 +788,24 @@ namespace PCI
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCI::EnumerateDevice(uint64_t BusAddress, uint64_t Device)
|
void PCI::EnumerateDevice(uintptr_t BusAddress, uintptr_t Device)
|
||||||
{
|
{
|
||||||
uint64_t Offset = Device << 15;
|
uintptr_t Offset = Device << 15;
|
||||||
uint64_t DeviceAddress = BusAddress + Offset;
|
uintptr_t DeviceAddress = BusAddress + Offset;
|
||||||
Memory::Virtual().Map((void *)DeviceAddress, (void *)DeviceAddress, Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)DeviceAddress, (void *)DeviceAddress, Memory::PTFlag::RW);
|
||||||
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)DeviceAddress;
|
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)DeviceAddress;
|
||||||
if (PCIDeviceHdr->DeviceID == 0)
|
if (PCIDeviceHdr->DeviceID == 0)
|
||||||
return;
|
return;
|
||||||
if (PCIDeviceHdr->DeviceID == 0xFFFF)
|
if (PCIDeviceHdr->DeviceID == 0xFFFF)
|
||||||
return;
|
return;
|
||||||
for (uint64_t Function = 0; Function < 8; Function++)
|
for (uintptr_t Function = 0; Function < 8; Function++)
|
||||||
EnumerateFunction(DeviceAddress, Function);
|
EnumerateFunction(DeviceAddress, Function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCI::EnumerateBus(uint64_t BaseAddress, uint64_t Bus)
|
void PCI::EnumerateBus(uintptr_t BaseAddress, uintptr_t Bus)
|
||||||
{
|
{
|
||||||
uint64_t Offset = Bus << 20;
|
uintptr_t Offset = Bus << 20;
|
||||||
uint64_t BusAddress = BaseAddress + Offset;
|
uintptr_t BusAddress = BaseAddress + Offset;
|
||||||
Memory::Virtual().Map((void *)BusAddress, (void *)BusAddress, Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)BusAddress, (void *)BusAddress, Memory::PTFlag::RW);
|
||||||
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)BusAddress;
|
PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)BusAddress;
|
||||||
if (Bus != 0) // TODO: VirtualBox workaround (UNTESTED ON REAL HARDWARE!)
|
if (Bus != 0) // TODO: VirtualBox workaround (UNTESTED ON REAL HARDWARE!)
|
||||||
@ -820,7 +820,7 @@ namespace PCI
|
|||||||
PCIDeviceHdr->CacheLineSize, PCIDeviceHdr->Class, PCIDeviceHdr->Command,
|
PCIDeviceHdr->CacheLineSize, PCIDeviceHdr->Class, PCIDeviceHdr->Command,
|
||||||
PCIDeviceHdr->HeaderType, PCIDeviceHdr->LatencyTimer, PCIDeviceHdr->ProgIF,
|
PCIDeviceHdr->HeaderType, PCIDeviceHdr->LatencyTimer, PCIDeviceHdr->ProgIF,
|
||||||
PCIDeviceHdr->RevisionID, PCIDeviceHdr->Status, PCIDeviceHdr->Subclass);
|
PCIDeviceHdr->RevisionID, PCIDeviceHdr->Status, PCIDeviceHdr->Subclass);
|
||||||
for (uint64_t Device = 0; Device < 32; Device++)
|
for (uintptr_t Device = 0; Device < 32; Device++)
|
||||||
EnumerateDevice(BusAddress, Device);
|
EnumerateDevice(BusAddress, Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,11 +848,11 @@ namespace PCI
|
|||||||
int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig);
|
int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig);
|
||||||
for (int t = 0; t < Entries; t++)
|
for (int t = 0; t < Entries; t++)
|
||||||
{
|
{
|
||||||
DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uint64_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t));
|
DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uintptr_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t));
|
||||||
Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW);
|
||||||
trace("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress,
|
trace("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress,
|
||||||
NewDeviceConfig->StartBus, NewDeviceConfig->EndBus);
|
NewDeviceConfig->StartBus, NewDeviceConfig->EndBus);
|
||||||
for (uint64_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++)
|
for (uintptr_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++)
|
||||||
EnumerateBus(NewDeviceConfig->BaseAddress, Bus);
|
EnumerateBus(NewDeviceConfig->BaseAddress, Bus);
|
||||||
}
|
}
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
|
@ -52,7 +52,7 @@ typedef struct
|
|||||||
|
|
||||||
namespace SymbolResolver
|
namespace SymbolResolver
|
||||||
{
|
{
|
||||||
Symbols::Symbols(uint64_t ImageAddress)
|
Symbols::Symbols(uintptr_t ImageAddress)
|
||||||
{
|
{
|
||||||
debug("Solving symbols for address: %#llx", ImageAddress);
|
debug("Solving symbols for address: %#llx", ImageAddress);
|
||||||
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
|
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
|
||||||
@ -68,7 +68,7 @@ namespace SymbolResolver
|
|||||||
Elf64_Sym *ElfSymbols = nullptr;
|
Elf64_Sym *ElfSymbols = nullptr;
|
||||||
char *strtab = nullptr;
|
char *strtab = nullptr;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Header->e_shnum; i++)
|
for (uint16_t i = 0; i < Header->e_shnum; i++)
|
||||||
switch (ElfSections[i].sh_type)
|
switch (ElfSections[i].sh_type)
|
||||||
{
|
{
|
||||||
case SHT_SYMTAB:
|
case SHT_SYMTAB:
|
||||||
@ -83,7 +83,7 @@ namespace SymbolResolver
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strtab = (char *)(uint64_t)ImageAddress + ElfSections[i].sh_offset;
|
strtab = (char *)(ImageAddress + ElfSections[i].sh_offset);
|
||||||
debug("String table found, %d entries", ElfSections[i].sh_size);
|
debug("String table found, %d entries", ElfSections[i].sh_size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -91,8 +91,8 @@ namespace SymbolResolver
|
|||||||
|
|
||||||
if (ElfSymbols != nullptr && strtab != nullptr)
|
if (ElfSymbols != nullptr && strtab != nullptr)
|
||||||
{
|
{
|
||||||
size_t Index, MinimumIndex;
|
uintptr_t Index, MinimumIndex;
|
||||||
for (size_t i = 0; i < this->TotalEntries - 1; i++)
|
for (uintptr_t i = 0; i < this->TotalEntries - 1; i++)
|
||||||
{
|
{
|
||||||
MinimumIndex = i;
|
MinimumIndex = i;
|
||||||
for (Index = i + 1; Index < this->TotalEntries; Index++)
|
for (Index = i + 1; Index < this->TotalEntries; Index++)
|
||||||
@ -114,7 +114,7 @@ namespace SymbolResolver
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
trace("Symbol table loaded, %d entries (%ldKB)", this->TotalEntries, TO_KB(this->TotalEntries * sizeof(SymbolTable)));
|
trace("Symbol table loaded, %d entries (%ldKB)", this->TotalEntries, TO_KB(this->TotalEntries * sizeof(SymbolTable)));
|
||||||
for (size_t i = 0, g = this->TotalEntries; i < g; i++)
|
for (uintptr_t i = 0, g = this->TotalEntries; i < g; i++)
|
||||||
{
|
{
|
||||||
this->SymTable[i].Address = ElfSymbols[i].st_value;
|
this->SymTable[i].Address = ElfSymbols[i].st_value;
|
||||||
this->SymTable[i].FunctionName = &strtab[ElfSymbols[i].st_name];
|
this->SymTable[i].FunctionName = &strtab[ElfSymbols[i].st_name];
|
||||||
@ -133,10 +133,10 @@ namespace SymbolResolver
|
|||||||
|
|
||||||
Symbols::~Symbols() {}
|
Symbols::~Symbols() {}
|
||||||
|
|
||||||
const __no_instrument_function char *Symbols::GetSymbolFromAddress(uint64_t Address)
|
const __no_instrument_function char *Symbols::GetSymbolFromAddress(uintptr_t Address)
|
||||||
{
|
{
|
||||||
Symbols::SymbolTable Result{0, (char *)"<unknown>"};
|
Symbols::SymbolTable Result{0, (char *)"<unknown>"};
|
||||||
for (size_t i = 0; i < this->TotalEntries; i++)
|
for (uintptr_t i = 0; i < this->TotalEntries; i++)
|
||||||
if (this->SymTable[i].Address <= Address && this->SymTable[i].Address > Result.Address)
|
if (this->SymTable[i].Address <= Address && this->SymTable[i].Address > Result.Address)
|
||||||
Result = this->SymTable[i];
|
Result = this->SymTable[i];
|
||||||
return Result.FunctionName;
|
return Result.FunctionName;
|
||||||
|
@ -38,16 +38,16 @@ namespace SMBIOS
|
|||||||
SMBIOSEntryPoint *Header = (SMBIOSEntryPoint *)bInfo->SMBIOSPtr;
|
SMBIOSEntryPoint *Header = (SMBIOSEntryPoint *)bInfo->SMBIOSPtr;
|
||||||
debug("Getting SMBIOS header for type %d", Type);
|
debug("Getting SMBIOS header for type %d", Type);
|
||||||
|
|
||||||
struct SMBIOSHeader *hdr = (SMBIOSHeader *)(uint64_t)Header->TableAddress;
|
struct SMBIOSHeader *hdr = (SMBIOSHeader *)(uintptr_t)Header->TableAddress;
|
||||||
for (int i = 0; i <= 11; i++)
|
for (int i = 0; i <= 11; i++)
|
||||||
{
|
{
|
||||||
if (hdr < (void *)(uint64_t)(Header->TableAddress + Header->TableLength))
|
if (hdr < (void *)(uintptr_t)(Header->TableAddress + Header->TableLength))
|
||||||
if (hdr->Type == Type)
|
if (hdr->Type == Type)
|
||||||
{
|
{
|
||||||
debug("Found SMBIOS header for type %d at %#lx", Type, hdr);
|
debug("Found SMBIOS header for type %d at %#lx", Type, hdr);
|
||||||
return hdr;
|
return hdr;
|
||||||
}
|
}
|
||||||
hdr = (struct SMBIOSHeader *)((uint64_t)hdr + SMBIOSTableLength(hdr));
|
hdr = (struct SMBIOSHeader *)((uintptr_t)hdr + SMBIOSTableLength(hdr));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
namespace Time
|
namespace Time
|
||||||
{
|
{
|
||||||
void time::Sleep(uint64_t Milliseconds)
|
void time::Sleep(uintptr_t Milliseconds)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__) || defined(__i386__)
|
#if defined(__amd64__) || defined(__i386__)
|
||||||
uint64_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000) / clk;
|
uintptr_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000) / clk;
|
||||||
while (mminq(&((HPET *)hpet)->MainCounterValue) < Target)
|
while (mminq(&((HPET *)hpet)->MainCounterValue) < Target)
|
||||||
CPU::Pause();
|
CPU::Pause();
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
|
@ -138,7 +138,7 @@ namespace UniversalAsynchronousReceiverTransmitter
|
|||||||
|
|
||||||
SafeFunction __no_instrument_function Events::~Events()
|
SafeFunction __no_instrument_function Events::~Events()
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < RegisteredEvents.size(); i++)
|
for (uintptr_t i = 0; i < RegisteredEvents.size(); i++)
|
||||||
if (RegisteredEvents[i] == this)
|
if (RegisteredEvents[i] == this)
|
||||||
{
|
{
|
||||||
RegisteredEvents.remove(i);
|
RegisteredEvents.remove(i);
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include <uart.hpp>
|
#include <uart.hpp>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
extern uint64_t _binary_Files_ter_powerline_v12n_psf_start;
|
extern uintptr_t _binary_Files_ter_powerline_v12n_psf_start;
|
||||||
extern uint64_t _binary_Files_ter_powerline_v12n_psf_end;
|
extern uintptr_t _binary_Files_ter_powerline_v12n_psf_end;
|
||||||
extern uint64_t _binary_Files_ter_powerline_v12n_psf_size;
|
extern uintptr_t _binary_Files_ter_powerline_v12n_psf_size;
|
||||||
|
|
||||||
NewLock(PrintLock);
|
NewLock(PrintLock);
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ namespace Video
|
|||||||
|
|
||||||
for (unsigned long Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + fonthdrHeight; Y++)
|
for (unsigned long Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + fonthdrHeight; Y++)
|
||||||
for (unsigned long X = this->Buffers[Index]->CursorX - fonthdrWidth; X < this->Buffers[Index]->CursorX; X++)
|
for (unsigned long X = this->Buffers[Index]->CursorX - fonthdrWidth; X < this->Buffers[Index]->CursorX; X++)
|
||||||
*(uint32_t *)((uint64_t)this->Buffers[Index]->Buffer +
|
*(uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer +
|
||||||
(Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = 0;
|
(Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ namespace Video
|
|||||||
{
|
{
|
||||||
for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + fonthdrWidth; X++)
|
for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + fonthdrWidth; X++)
|
||||||
if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0)
|
if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0)
|
||||||
*(uint32_t *)((uint64_t)this->Buffers[Index]->Buffer +
|
*(uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer +
|
||||||
(Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = this->Buffers[Index]->Color;
|
(Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = this->Buffers[Index]->Color;
|
||||||
|
|
||||||
FontPtr += BytesPerLine;
|
FontPtr += BytesPerLine;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Video
|
namespace Video
|
||||||
{
|
{
|
||||||
Font::Font(uint64_t *Start, uint64_t *End, FontType Type)
|
Font::Font(uintptr_t *Start, uintptr_t *End, FontType Type)
|
||||||
{
|
{
|
||||||
trace("Initializing font with start %#llx and end %#llx Type: %d", Start, End, Type);
|
trace("Initializing font with start %#llx and end %#llx Type: %d", Start, End, Type);
|
||||||
this->Info.StartAddress = Start;
|
this->Info.StartAddress = Start;
|
||||||
@ -14,9 +14,9 @@ namespace Video
|
|||||||
{
|
{
|
||||||
this->Info.PSF2Font = new PSF2_FONT;
|
this->Info.PSF2Font = new PSF2_FONT;
|
||||||
|
|
||||||
uint64_t FontDataLength = End - Start;
|
uintptr_t FontDataLength = End - Start;
|
||||||
PSF2_HEADER *font2 = (PSF2_HEADER *)KernelAllocator.RequestPages(FontDataLength / PAGE_SIZE + 1);
|
PSF2_HEADER *font2 = (PSF2_HEADER *)KernelAllocator.RequestPages(FontDataLength / PAGE_SIZE + 1);
|
||||||
for (uint64_t i = 0; i < FontDataLength / PAGE_SIZE + 1; i++)
|
for (uintptr_t i = 0; i < FontDataLength / PAGE_SIZE + 1; i++)
|
||||||
Memory::Virtual().Map((void *)(font2 + (i * PAGE_SIZE)), (void *)(font2 + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
Memory::Virtual().Map((void *)(font2 + (i * PAGE_SIZE)), (void *)(font2 + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
||||||
memcpy((void *)font2, Start, FontDataLength);
|
memcpy((void *)font2, Start, FontDataLength);
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace Video
|
|||||||
error("Font2 magic mismatch.");
|
error("Font2 magic mismatch.");
|
||||||
|
|
||||||
this->Info.PSF2Font->Header = font2;
|
this->Info.PSF2Font->Header = font2;
|
||||||
this->Info.PSF2Font->GlyphBuffer = reinterpret_cast<void *>(reinterpret_cast<uint64_t>(Start) + sizeof(PSF2_HEADER));
|
this->Info.PSF2Font->GlyphBuffer = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(Start) + sizeof(PSF2_HEADER));
|
||||||
}
|
}
|
||||||
else if (Type == FontType::PCScreenFont1)
|
else if (Type == FontType::PCScreenFont1)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ namespace Video
|
|||||||
uint32_t glyphBufferSize = font1->charsize * 256;
|
uint32_t glyphBufferSize = font1->charsize * 256;
|
||||||
if (font1->mode == 1) // 512 glyph mode
|
if (font1->mode == 1) // 512 glyph mode
|
||||||
glyphBufferSize = font1->charsize * 512;
|
glyphBufferSize = font1->charsize * 512;
|
||||||
void *glyphBuffer = reinterpret_cast<void *>(reinterpret_cast<uint64_t>(Start) + sizeof(PSF1_HEADER));
|
void *glyphBuffer = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(Start) + sizeof(PSF1_HEADER));
|
||||||
this->Info.PSF1Font->Header = font1;
|
this->Info.PSF1Font->Header = font1;
|
||||||
this->Info.PSF1Font->GlyphBuffer = glyphBuffer;
|
this->Info.PSF1Font->GlyphBuffer = glyphBuffer;
|
||||||
UNUSED(glyphBufferSize); // TODO: Use this in the future?
|
UNUSED(glyphBufferSize); // TODO: Use this in the future?
|
||||||
|
@ -71,7 +71,7 @@ namespace Execute
|
|||||||
|
|
||||||
/* Originally from https://wiki.osdev.org/ELF_Tutorial */
|
/* Originally from https://wiki.osdev.org/ELF_Tutorial */
|
||||||
|
|
||||||
static inline Elf64_Shdr *GetElfSheader(Elf64_Ehdr *Header) { return (Elf64_Shdr *)((uint64_t)Header + Header->e_shoff); }
|
static inline Elf64_Shdr *GetElfSheader(Elf64_Ehdr *Header) { return (Elf64_Shdr *)((uintptr_t)Header + Header->e_shoff); }
|
||||||
static inline Elf64_Shdr *GetElfSection(Elf64_Ehdr *Header, uint64_t Index) { return &GetElfSheader(Header)[Index]; }
|
static inline Elf64_Shdr *GetElfSection(Elf64_Ehdr *Header, uint64_t Index) { return &GetElfSheader(Header)[Index]; }
|
||||||
|
|
||||||
static inline char *GetElfStringTable(Elf64_Ehdr *Header)
|
static inline char *GetElfStringTable(Elf64_Ehdr *Header)
|
||||||
@ -81,7 +81,7 @@ namespace Execute
|
|||||||
return (char *)Header + GetElfSection(Header, Header->e_shstrndx)->sh_offset;
|
return (char *)Header + GetElfSection(Header, Header->e_shstrndx)->sh_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char *elf_lookup_string(Elf64_Ehdr *Header, uint64_t Offset)
|
static inline char *elf_lookup_string(Elf64_Ehdr *Header, uintptr_t Offset)
|
||||||
{
|
{
|
||||||
char *StringTable = GetElfStringTable(Header);
|
char *StringTable = GetElfStringTable(Header);
|
||||||
if (StringTable == nullptr)
|
if (StringTable == nullptr)
|
||||||
@ -111,17 +111,17 @@ namespace Execute
|
|||||||
if (SymbolTable == nullptr || StringTable == nullptr)
|
if (SymbolTable == nullptr || StringTable == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < (SymbolTable->sh_size / sizeof(Elf64_Sym)); i++)
|
for (size_t i = 0; i < (SymbolTable->sh_size / sizeof(Elf64_Sym)); i++)
|
||||||
{
|
{
|
||||||
Symbol = (Elf64_Sym *)((uint64_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym)));
|
Symbol = (Elf64_Sym *)((uintptr_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym)));
|
||||||
String = (char *)((uint64_t)Header + StringTable->sh_offset + Symbol->st_name);
|
String = (char *)((uintptr_t)Header + StringTable->sh_offset + Symbol->st_name);
|
||||||
if (strcmp(String, Name) == 0)
|
if (strcmp(String, Name) == 0)
|
||||||
return (void *)Symbol->st_value;
|
return (void *)Symbol->st_value;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint32_t Index)
|
static uintptr_t ELFGetSymbolValue(Elf64_Ehdr *Header, uint64_t Table, uint32_t Index)
|
||||||
{
|
{
|
||||||
if (Table == SHN_UNDEF || Index == SHN_UNDEF)
|
if (Table == SHN_UNDEF || Index == SHN_UNDEF)
|
||||||
return 0;
|
return 0;
|
||||||
@ -154,14 +154,14 @@ namespace Execute
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (uint64_t)Target;
|
return (uintptr_t)Target;
|
||||||
}
|
}
|
||||||
else if (Symbol->st_shndx == SHN_ABS)
|
else if (Symbol->st_shndx == SHN_ABS)
|
||||||
return Symbol->st_value;
|
return Symbol->st_value;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Elf64_Shdr *Target = GetElfSection(Header, Symbol->st_shndx);
|
Elf64_Shdr *Target = GetElfSection(Header, Symbol->st_shndx);
|
||||||
return (uint64_t)Header + Symbol->st_value + Target->sh_offset;
|
return (uintptr_t)Header + Symbol->st_value + Target->sh_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,8 +181,8 @@ namespace Execute
|
|||||||
memset(Buffer, 0, Section->sh_size);
|
memset(Buffer, 0, Section->sh_size);
|
||||||
|
|
||||||
Memory::Virtual pva = Memory::Virtual(/* TODO TODO TODO TODO TODO TODO */);
|
Memory::Virtual pva = Memory::Virtual(/* TODO TODO TODO TODO TODO TODO */);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(Section->sh_size); i++)
|
for (size_t i = 0; i < TO_PAGES(Section->sh_size); i++)
|
||||||
pva.Map((void *)((uint64_t)Buffer + (i * PAGE_SIZE)), (void *)((uint64_t)Buffer + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
pva.Map((void *)((uintptr_t)Buffer + (i * PAGE_SIZE)), (void *)((uintptr_t)Buffer + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
|
|
||||||
Section->sh_offset = (uint64_t)Buffer - (uint64_t)Header;
|
Section->sh_offset = (uint64_t)Buffer - (uint64_t)Header;
|
||||||
debug("Section %ld", Section->sh_size);
|
debug("Section %ld", Section->sh_size);
|
||||||
@ -190,17 +190,17 @@ namespace Execute
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Header->e_shnum; i++)
|
for (size_t i = 0; i < Header->e_shnum; i++)
|
||||||
{
|
{
|
||||||
Elf64_Shdr *Section = &shdr[i];
|
Elf64_Shdr *Section = &shdr[i];
|
||||||
if (Section->sh_type == SHT_REL)
|
if (Section->sh_type == SHT_REL)
|
||||||
{
|
{
|
||||||
for (uint64_t Index = 0; Index < Section->sh_size / Section->sh_entsize; Index++)
|
for (size_t Index = 0; Index < Section->sh_size / Section->sh_entsize; Index++)
|
||||||
{
|
{
|
||||||
Elf64_Rel *RelTable = &((Elf64_Rel *)((uint64_t)Header + Section->sh_offset))[Index];
|
Elf64_Rel *RelTable = &((Elf64_Rel *)((uintptr_t)Header + Section->sh_offset))[Index];
|
||||||
Elf64_Shdr *Target = GetElfSection(Header, Section->sh_info);
|
Elf64_Shdr *Target = GetElfSection(Header, Section->sh_info);
|
||||||
|
|
||||||
uint64_t *RelAddress = (uint64_t *)(((uint64_t)Header + Target->sh_offset) + RelTable->r_offset);
|
uintptr_t *RelAddress = (uintptr_t *)(((uintptr_t)Header + Target->sh_offset) + RelTable->r_offset);
|
||||||
uint64_t SymbolValue = 0;
|
uint64_t SymbolValue = 0;
|
||||||
|
|
||||||
if (ELF64_R_SYM(RelTable->r_info) != SHN_UNDEF)
|
if (ELF64_R_SYM(RelTable->r_info) != SHN_UNDEF)
|
||||||
@ -218,7 +218,7 @@ namespace Execute
|
|||||||
*RelAddress = DO_64_64(SymbolValue, *RelAddress);
|
*RelAddress = DO_64_64(SymbolValue, *RelAddress);
|
||||||
break;
|
break;
|
||||||
case R_386_PC32:
|
case R_386_PC32:
|
||||||
*RelAddress = DO_64_PC32(SymbolValue, *RelAddress, (uint64_t)RelAddress);
|
*RelAddress = DO_64_PC32(SymbolValue, *RelAddress, (uintptr_t)RelAddress);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Unsupported relocation type: %d", ELF64_R_TYPE(RelTable->r_info));
|
error("Unsupported relocation type: %d", ELF64_R_TYPE(RelTable->r_info));
|
||||||
|
@ -43,7 +43,7 @@ namespace Execute
|
|||||||
|
|
||||||
Memory::Virtual pva = Memory::Virtual(Process->PageTable);
|
Memory::Virtual pva = Memory::Virtual(Process->PageTable);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++)
|
for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++)
|
||||||
pva.Map((void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), (void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
pva.Map((void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), (void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
|
|
||||||
Vector<AuxiliaryVector> auxv; // TODO!
|
Vector<AuxiliaryVector> auxv; // TODO!
|
||||||
|
|
||||||
@ -76,13 +76,13 @@ namespace Execute
|
|||||||
|
|
||||||
void *BaseImage = KernelAllocator.RequestPages(TO_PAGES(ExFile->Node->Length));
|
void *BaseImage = KernelAllocator.RequestPages(TO_PAGES(ExFile->Node->Length));
|
||||||
memcpy(BaseImage, (void *)ExFile->Node->Address, ExFile->Node->Length);
|
memcpy(BaseImage, (void *)ExFile->Node->Address, ExFile->Node->Length);
|
||||||
debug("Image Size: %#lx - %#lx (length: %ld)", BaseImage, (uint64_t)BaseImage + ExFile->Node->Length, ExFile->Node->Length);
|
debug("Image Size: %#lx - %#lx (length: %ld)", BaseImage, (uintptr_t)BaseImage + ExFile->Node->Length, ExFile->Node->Length);
|
||||||
|
|
||||||
PCB *Process = TaskManager->CreateProcess(TaskManager->GetCurrentProcess(), BaseName, TaskTrustLevel::User, BaseImage);
|
PCB *Process = TaskManager->CreateProcess(TaskManager->GetCurrentProcess(), BaseName, TaskTrustLevel::User, BaseImage);
|
||||||
|
|
||||||
Memory::Virtual pva = Memory::Virtual(Process->PageTable);
|
Memory::Virtual pva = Memory::Virtual(Process->PageTable);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++)
|
for (uint64_t i = 0; i < TO_PAGES(ExFile->Node->Length); i++)
|
||||||
pva.Remap((void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), (void *)((uint64_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
pva.Remap((void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), (void *)((uintptr_t)BaseImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
|
|
||||||
Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)BaseImage;
|
Elf64_Ehdr *ELFHeader = (Elf64_Ehdr *)BaseImage;
|
||||||
|
|
||||||
@ -158,8 +158,8 @@ namespace Execute
|
|||||||
memset(MemoryImage, 0, ElfAppSize);
|
memset(MemoryImage, 0, ElfAppSize);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++)
|
for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++)
|
||||||
{
|
{
|
||||||
pva.Remap((void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), (void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
pva.Remap((void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), (void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
debug("Mapping: %#lx -> %#lx", (uint64_t)MemoryImage + (i * PAGE_SIZE), (uint64_t)MemoryImage + (i * PAGE_SIZE));
|
debug("Mapping: %#lx -> %#lx", (uintptr_t)MemoryImage + (i * PAGE_SIZE), (uintptr_t)MemoryImage + (i * PAGE_SIZE));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -172,10 +172,10 @@ namespace Execute
|
|||||||
memset(MemoryImage, 0, ElfAppSize);
|
memset(MemoryImage, 0, ElfAppSize);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++)
|
for (uint64_t i = 0; i < TO_PAGES(ElfAppSize); i++)
|
||||||
{
|
{
|
||||||
uint64_t Address = (uint64_t)ProgramHeader->p_vaddr;
|
uintptr_t Address = (uintptr_t)ProgramHeader->p_vaddr;
|
||||||
Address &= 0xFFFFFFFFFFFFF000;
|
Address &= 0xFFFFFFFFFFFFF000;
|
||||||
pva.Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
pva.Remap((void *)((uintptr_t)Address + (i * PAGE_SIZE)), (void *)((uintptr_t)MemoryImage + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
||||||
debug("Mapping: %#lx -> %#lx", (uint64_t)Address + (i * PAGE_SIZE), (uint64_t)MemoryImage + (i * PAGE_SIZE));
|
debug("Mapping: %#lx -> %#lx", (uintptr_t)Address + (i * PAGE_SIZE), (uintptr_t)MemoryImage + (i * PAGE_SIZE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@ namespace FileSystem
|
|||||||
.Read = USTAR_Read,
|
.Read = USTAR_Read,
|
||||||
};
|
};
|
||||||
|
|
||||||
USTAR::USTAR(uint64_t Address, Virtual *vfs)
|
USTAR::USTAR(uintptr_t Address, Virtual *vfs)
|
||||||
{
|
{
|
||||||
trace("Initializing USTAR with address %#llx", Address);
|
trace("Initializing USTAR with address %#llx", Address);
|
||||||
|
|
||||||
if (memcmp(((FileHeader *)Address)->signature, "ustar", 5) != 0)
|
if (memcmp(((FileHeader *)(uintptr_t)Address)->signature, "ustar", 5) != 0)
|
||||||
{
|
{
|
||||||
error("ustar signature invalid!");
|
error("ustar signature invalid!");
|
||||||
return;
|
return;
|
||||||
@ -41,9 +41,9 @@ namespace FileSystem
|
|||||||
|
|
||||||
vfs->CreateRoot(&ustar, "/");
|
vfs->CreateRoot(&ustar, "/");
|
||||||
|
|
||||||
uint64_t errorsallowed = 20;
|
int ErrorsAllowed = 20;
|
||||||
|
|
||||||
for (uint64_t i = 0;; i++)
|
for (size_t i = 0;; i++)
|
||||||
{
|
{
|
||||||
FileHeader *header = (FileHeader *)Address;
|
FileHeader *header = (FileHeader *)Address;
|
||||||
if (memcmp(((FileHeader *)Address)->signature, "ustar", 5) != 0)
|
if (memcmp(((FileHeader *)Address)->signature, "ustar", 5) != 0)
|
||||||
@ -51,7 +51,7 @@ namespace FileSystem
|
|||||||
memmove(header->name, header->name + 1, strlen(header->name));
|
memmove(header->name, header->name + 1, strlen(header->name));
|
||||||
if (header->name[strlen(header->name) - 1] == '/')
|
if (header->name[strlen(header->name) - 1] == '/')
|
||||||
header->name[strlen(header->name) - 1] = 0;
|
header->name[strlen(header->name) - 1] = 0;
|
||||||
uint64_t size = getsize(header->size);
|
size_t size = getsize(header->size);
|
||||||
FileSystemNode *node = nullptr;
|
FileSystemNode *node = nullptr;
|
||||||
|
|
||||||
if (!isempty((char *)header->name))
|
if (!isempty((char *)header->name))
|
||||||
@ -63,9 +63,9 @@ namespace FileSystem
|
|||||||
debug("Added node: %s", node->Name);
|
debug("Added node: %s", node->Name);
|
||||||
if (node == nullptr)
|
if (node == nullptr)
|
||||||
{
|
{
|
||||||
if (errorsallowed > 0)
|
if (ErrorsAllowed > 0)
|
||||||
{
|
{
|
||||||
errorsallowed--;
|
ErrorsAllowed--;
|
||||||
goto NextFileAddress;
|
goto NextFileAddress;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -133,7 +133,7 @@ namespace FileSystem
|
|||||||
FileStatus RemoveChild(FileSystemNode *Parent, const char *Name)
|
FileStatus RemoveChild(FileSystemNode *Parent, const char *Name)
|
||||||
{
|
{
|
||||||
vfsdbg("RemoveChild( Parent: \"%s\" Name: \"%s\" )", Parent->Name, Name);
|
vfsdbg("RemoveChild( Parent: \"%s\" Name: \"%s\" )", Parent->Name, Name);
|
||||||
for (uint64_t i = 0; i < Parent->Children.size(); i++)
|
for (uintptr_t i = 0; i < Parent->Children.size(); i++)
|
||||||
if (strcmp(Parent->Children[i]->Name, Name) == 0)
|
if (strcmp(Parent->Children[i]->Name, Name) == 0)
|
||||||
{
|
{
|
||||||
Parent->Children.remove(i);
|
Parent->Children.remove(i);
|
||||||
@ -414,7 +414,7 @@ namespace FileSystem
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Virtual::Read(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
|
size_t Virtual::Read(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(!File))
|
if (unlikely(!File))
|
||||||
@ -437,7 +437,7 @@ namespace FileSystem
|
|||||||
return File->Node->Operator->Read(File->Node, Offset, Size, Buffer);
|
return File->Node->Operator->Read(File->Node, Offset, Size, Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Virtual::Write(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
|
size_t Virtual::Write(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size)
|
||||||
{
|
{
|
||||||
SmartLock(VFSLock);
|
SmartLock(VFSLock);
|
||||||
if (unlikely(!File))
|
if (unlikely(!File))
|
||||||
|
@ -25,7 +25,7 @@ void KernelMainThread()
|
|||||||
|
|
||||||
KPrint("Initializing Filesystem...");
|
KPrint("Initializing Filesystem...");
|
||||||
vfs = new FileSystem::Virtual;
|
vfs = new FileSystem::Virtual;
|
||||||
new FileSystem::USTAR((uint64_t)bInfo->Modules[0].Address, vfs); // TODO: Detect initrd
|
new FileSystem::USTAR((uintptr_t)bInfo->Modules[0].Address, vfs); // TODO: Detect initrd
|
||||||
KPrint("Initializing Disk Manager...");
|
KPrint("Initializing Disk Manager...");
|
||||||
DiskManager = new Disk::Manager;
|
DiskManager = new Disk::Manager;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ void KernelMainThread()
|
|||||||
if (DriverManager->GetDrivers().size() > 0)
|
if (DriverManager->GetDrivers().size() > 0)
|
||||||
{
|
{
|
||||||
foreach (auto Driver in DriverManager->GetDrivers())
|
foreach (auto Driver in DriverManager->GetDrivers())
|
||||||
if (((FexExtended *)((uint64_t)Driver->Address + EXTENDED_SECTION_ADDRESS))->Driver.Type == FexDriverType::FexDriverType_Storage)
|
if (((FexExtended *)((uintptr_t)Driver->Address + EXTENDED_SECTION_ADDRESS))->Driver.Type == FexDriverType::FexDriverType_Storage)
|
||||||
DiskManager->FetchDisks(Driver->DriverUID);
|
DiskManager->FetchDisks(Driver->DriverUID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -49,7 +49,7 @@ void KernelMainThread()
|
|||||||
"TERM=tty",
|
"TERM=tty",
|
||||||
"HOME=/",
|
"HOME=/",
|
||||||
"USER=root",
|
"USER=root",
|
||||||
"SHELL=/system/bin/sh",
|
"SHELL=/system/sh",
|
||||||
"PWD=/",
|
"PWD=/",
|
||||||
"LANG=en_US.UTF-8",
|
"LANG=en_US.UTF-8",
|
||||||
"TZ=UTC",
|
"TZ=UTC",
|
||||||
|
24
Kernel.cpp
24
Kernel.cpp
@ -13,6 +13,24 @@
|
|||||||
|
|
||||||
#include "Core/smbios.hpp"
|
#include "Core/smbios.hpp"
|
||||||
|
|
||||||
|
#ifdef __amd64__
|
||||||
|
#if UINTPTR_MAX != UINT64_MAX
|
||||||
|
#error "uintptr_t is not 64-bit!"
|
||||||
|
#endif // UINTPTR_MAX != UINT64_MAX
|
||||||
|
#endif // __amd64__
|
||||||
|
|
||||||
|
#ifdef __i386__
|
||||||
|
#if UINTPTR_MAX != UINT32_MAX
|
||||||
|
#error "uintptr_t is not 32-bit!"
|
||||||
|
#endif // UINTPTR_MAX != UINT32_MAX
|
||||||
|
#endif // __i386__
|
||||||
|
|
||||||
|
#ifdef __aarch64__
|
||||||
|
#if UINTPTR_MAX != UINT64_MAX
|
||||||
|
#error "uintptr_t is not 64-bit!"
|
||||||
|
#endif // UINTPTR_MAX != UINT64_MAX
|
||||||
|
#endif // __aarch64__
|
||||||
|
|
||||||
NewLock(KernelLock);
|
NewLock(KernelLock);
|
||||||
|
|
||||||
BootInfo *bInfo = nullptr;
|
BootInfo *bInfo = nullptr;
|
||||||
@ -45,7 +63,7 @@ EXTERNC void KPrint(const char *Format, ...)
|
|||||||
Display->SetBuffer(0);
|
Display->SetBuffer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERNC __no_instrument_function void PostEntry(BootInfo *Info)
|
EXTERNC __no_instrument_function void AfterEntry(BootInfo *Info)
|
||||||
{
|
{
|
||||||
BootClock = Time::ReadClock();
|
BootClock = Time::ReadClock();
|
||||||
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
|
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
|
||||||
@ -63,7 +81,7 @@ EXTERNC __no_instrument_function void PostEntry(BootInfo *Info)
|
|||||||
KPrint("Initializing CPU Features");
|
KPrint("Initializing CPU Features");
|
||||||
CPU::InitializeFeatures();
|
CPU::InitializeFeatures();
|
||||||
KPrint("Loading Kernel Symbols");
|
KPrint("Loading Kernel Symbols");
|
||||||
KernelSymbolTable = new SymbolResolver::Symbols((uint64_t)Info->Kernel.FileBase);
|
KernelSymbolTable = new SymbolResolver::Symbols((uintptr_t)Info->Kernel.FileBase);
|
||||||
KPrint("Reading Kernel Parameters");
|
KPrint("Reading Kernel Parameters");
|
||||||
Config = ParseConfig((char *)bInfo->Kernel.CommandLine);
|
Config = ParseConfig((char *)bInfo->Kernel.CommandLine);
|
||||||
KPrint("Initializing Power Manager");
|
KPrint("Initializing Power Manager");
|
||||||
@ -181,7 +199,7 @@ EXTERNC __no_stack_protector __no_instrument_function void Entry(BootInfo *Info)
|
|||||||
|
|
||||||
InitializeMemoryManagement(Info);
|
InitializeMemoryManagement(Info);
|
||||||
EnableProfiler = true;
|
EnableProfiler = true;
|
||||||
PostEntry(Info);
|
AfterEntry(Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERNC __no_stack_protector __no_instrument_function void BeforeShutdown()
|
EXTERNC __no_stack_protector __no_instrument_function void BeforeShutdown()
|
||||||
|
@ -404,7 +404,7 @@ static int cag_option_find_next(cag_option_context *context)
|
|||||||
// Grab a pointer to the string and verify that it is not the end. If it is
|
// Grab a pointer to the string and verify that it is not the end. If it is
|
||||||
// the end, we have to return false to indicate that we finished.
|
// the end, we have to return false to indicate that we finished.
|
||||||
c = context->argv[next_option_index];
|
c = context->argv[next_option_index];
|
||||||
if (context->forced_end || c == NULL || (uint64_t)c == (uint64_t)0xfffffffffffff000 /* TODO: workaround */)
|
if (context->forced_end || c == NULL || (uintptr_t)c == (uintptr_t)0xfffffffffffff000 /* TODO: workaround */)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_enter(void
|
|||||||
Level - 1,
|
Level - 1,
|
||||||
Level,
|
Level,
|
||||||
' ',
|
' ',
|
||||||
KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function),
|
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)Function),
|
||||||
KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite));
|
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)CallSite));
|
||||||
Wait = false;
|
Wait = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_exit(void
|
|||||||
Level - 1,
|
Level - 1,
|
||||||
Level,
|
Level,
|
||||||
' ',
|
' ',
|
||||||
KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function),
|
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)Function),
|
||||||
KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite));
|
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)CallSite));
|
||||||
Wait = false;
|
Wait = false;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "../kernel.h"
|
#include "../kernel.h"
|
||||||
|
|
||||||
|
typedef __INT32_TYPE__ mode_t;
|
||||||
|
|
||||||
#define internal_unimpl(a, b, c, d, e, f, g) \
|
#define internal_unimpl(a, b, c, d, e, f, g) \
|
||||||
{ \
|
{ \
|
||||||
fixme("Unimplemented Syscall: %lld %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f, g); \
|
fixme("Unimplemented Syscall: %lld %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f, g); \
|
||||||
@ -15,31 +17,31 @@
|
|||||||
fixme("( %lld %lld %lld %lld %lld %lld %lld ) stub", a, b, c, d, e, f, g); \
|
fixme("( %lld %lld %lld %lld %lld %lld %lld ) stub", a, b, c, d, e, f, g); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_read(unsigned int fd, char *buf, size_t count)
|
static ssize_t sys_read(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
fixme("read( %p %p %ld )", fd, buf, count);
|
fixme("read( %p %p %ld )", fd, buf, count);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_write(unsigned int fd, const char *buf, size_t count)
|
static ssize_t sys_write(int fd, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
fixme("write( %p %p %ld )", fd, buf, count);
|
fixme("write( %p %p %ld )", fd, buf, count);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_open(const char *filename, int flags, unsigned short mode)
|
static ssize_t sys_open(const char *filename, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
fixme("open( %s %d %d )", filename, flags, mode);
|
fixme("open( %s %d %d )", filename, flags, mode);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_close(unsigned int fd)
|
static ssize_t sys_close(int fd)
|
||||||
{
|
{
|
||||||
fixme("close( %d )", fd);
|
fixme("close( %d )", fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_stat(const char *filename, void *statbuf)
|
static ssize_t sys_stat(const char *filename, void *statbuf)
|
||||||
{
|
{
|
||||||
fixme("stat( %s %p )", filename, statbuf);
|
fixme("stat( %s %p )", filename, statbuf);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "../syscalls.h"
|
#include "../syscalls.h"
|
||||||
#include "../kernel.h"
|
#include "../kernel.h"
|
||||||
|
|
||||||
static uint64_t sys_exit(SyscallsFrame *Frame, uint64_t code)
|
static int sys_exit(SyscallsFrame *Frame, int code)
|
||||||
{
|
{
|
||||||
trace("Userspace thread %s(%lld) exited with code %#llx", TaskManager->GetCurrentThread()->Name, TaskManager->GetCurrentThread()->ID, code);
|
trace("Userspace thread %s(%lld) exited with code %#llx", TaskManager->GetCurrentThread()->Name, TaskManager->GetCurrentThread()->ID, code);
|
||||||
TaskManager->GetCurrentThread()->ExitCode = code;
|
TaskManager->GetCurrentThread()->ExitCode = code;
|
||||||
@ -23,18 +23,18 @@ static int sys_print(SyscallsFrame *Frame, char Char, int Index)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_request_pages(SyscallsFrame *Frame, uint64_t Count)
|
static uintptr_t sys_request_pages(SyscallsFrame *Frame, size_t Count)
|
||||||
{
|
{
|
||||||
return (uint64_t)TaskManager->GetCurrentThread()->Memory->RequestPages(Count);
|
return (uintptr_t)TaskManager->GetCurrentThread()->Memory->RequestPages(Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_free_pages(SyscallsFrame *Frame, uint64_t Address, uint64_t Count)
|
static int sys_free_pages(SyscallsFrame *Frame, uintptr_t Address, size_t Count)
|
||||||
{
|
{
|
||||||
TaskManager->GetCurrentThread()->Memory->FreePages((void *)Address, Count);
|
TaskManager->GetCurrentThread()->Memory->FreePages((void *)Address, Count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t sys_kernelctl(SyscallsFrame *Frame, uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4)
|
static int sys_kernelctl(SyscallsFrame *Frame, int Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4)
|
||||||
{
|
{
|
||||||
fixme("KernelCTL: %lld", Command);
|
fixme("KernelCTL: %lld", Command);
|
||||||
return 0;
|
return 0;
|
||||||
@ -50,7 +50,7 @@ static void *NativeSyscallsTable[] = {
|
|||||||
[_KernelCTL] = (void *)sys_kernelctl,
|
[_KernelCTL] = (void *)sys_kernelctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t HandleNativeSyscalls(SyscallsFrame *Frame)
|
uintptr_t HandleNativeSyscalls(SyscallsFrame *Frame)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
// debug("rax: %#llx, rbx: %#llx, rcx: %#llx, rdx: %#llx, rsi: %#llx, rdi: %#llx, rbp: %#llx, r8: %#llx, r9: %#llx, r10: %#llx, r11: %#llx, r12: %#llx, r13: %#llx, r14: %#llx, r15: %#llx", Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi, Frame->rbp, Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13, Frame->r14, Frame->r15);
|
// debug("rax: %#llx, rbx: %#llx, rcx: %#llx, rdx: %#llx, rsi: %#llx, rdi: %#llx, rbp: %#llx, r8: %#llx, r9: %#llx, r10: %#llx, r11: %#llx, r12: %#llx, r13: %#llx, r14: %#llx, r15: %#llx", Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi, Frame->rbp, Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13, Frame->r14, Frame->r15);
|
||||||
@ -60,14 +60,14 @@ uint64_t HandleNativeSyscalls(SyscallsFrame *Frame)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t (*call)(uint64_t, ...) = reinterpret_cast<uint64_t (*)(uint64_t, ...)>(NativeSyscallsTable[Frame->rax]);
|
uintptr_t (*call)(uintptr_t, ...) = reinterpret_cast<uintptr_t (*)(uintptr_t, ...)>(NativeSyscallsTable[Frame->rax]);
|
||||||
if (!call)
|
if (!call)
|
||||||
{
|
{
|
||||||
error("Syscall %#llx failed.", Frame->rax);
|
error("Syscall %#llx failed.", Frame->rax);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
debug("[%#lx]->( %#lx %#lx %#lx %#lx %#lx %#lx )", Frame->rax, Frame->rdi, Frame->rsi, Frame->rdx, Frame->rcx, Frame->r8, Frame->r9);
|
debug("[%#lx]->( %#lx %#lx %#lx %#lx %#lx %#lx )", Frame->rax, Frame->rdi, Frame->rsi, Frame->rdx, Frame->rcx, Frame->r8, Frame->r9);
|
||||||
uint64_t ret = call((uint64_t)Frame, Frame->rdi, Frame->rsi, Frame->rdx, Frame->r10, Frame->r8, Frame->r9);
|
uintptr_t ret = call((uintptr_t)Frame, Frame->rdi, Frame->rsi, Frame->rdx, Frame->r10, Frame->r8, Frame->r9);
|
||||||
Frame->rax = ret;
|
Frame->rax = ret;
|
||||||
return ret;
|
return ret;
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "../kernel.h"
|
#include "../kernel.h"
|
||||||
|
|
||||||
extern "C" uint64_t SystemCallsHandler(SyscallsFrame *Frame)
|
extern "C" uintptr_t SystemCallsHandler(SyscallsFrame *Frame)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
switch (TaskManager->GetCurrentThread()->Info.Compatibility)
|
switch (TaskManager->GetCurrentThread()->Info.Compatibility)
|
||||||
|
@ -29,7 +29,7 @@ namespace InterProcessCommunication
|
|||||||
handle->Operation = IPCOperationNone;
|
handle->Operation = IPCOperationNone;
|
||||||
handle->Listening = 0;
|
handle->Listening = 0;
|
||||||
handle->Error = IPCUnknown;
|
handle->Error = IPCUnknown;
|
||||||
pcb->IPCHandles->AddNode(Port, (uint64_t)handle);
|
pcb->IPCHandles->AddNode(Port, (uintptr_t)handle);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ namespace InterProcessCommunication
|
|||||||
|
|
||||||
Vector<Tasking::PCB *> Processes = TaskManager->GetProcessList();
|
Vector<Tasking::PCB *> Processes = TaskManager->GetProcessList();
|
||||||
|
|
||||||
for (uint64_t i = 0; i < Processes.size(); i++)
|
for (size_t i = 0; i < Processes.size(); i++)
|
||||||
{
|
{
|
||||||
Tasking::PCB *pcb = Processes[i];
|
Tasking::PCB *pcb = Processes[i];
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace Tasking
|
|||||||
Security::~Security()
|
Security::~Security()
|
||||||
{
|
{
|
||||||
trace("Destroying Tasking Security");
|
trace("Destroying Tasking Security");
|
||||||
for (uint64_t i = 0; i < Tokens.size(); i++)
|
for (size_t i = 0; i < Tokens.size(); i++)
|
||||||
Tokens.remove(i);
|
Tokens.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace Tasking
|
|||||||
|
|
||||||
SafeFunction __no_instrument_function void Task::RemoveThread(TCB *Thread)
|
SafeFunction __no_instrument_function void Task::RemoveThread(TCB *Thread)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < Thread->Parent->Threads.size(); i++)
|
for (size_t i = 0; i < Thread->Parent->Threads.size(); i++)
|
||||||
if (Thread->Parent->Threads[i] == Thread)
|
if (Thread->Parent->Threads[i] == Thread)
|
||||||
{
|
{
|
||||||
trace("Thread \"%s\"(%d) removed from process \"%s\"(%d)",
|
trace("Thread \"%s\"(%d) removed from process \"%s\"(%d)",
|
||||||
@ -116,7 +116,7 @@ namespace Tasking
|
|||||||
foreach (PCB *process in Process->Children)
|
foreach (PCB *process in Process->Children)
|
||||||
RemoveProcess(process);
|
RemoveProcess(process);
|
||||||
|
|
||||||
for (uint64_t i = 0; i < ListProcess.size(); i++)
|
for (size_t i = 0; i < ListProcess.size(); i++)
|
||||||
{
|
{
|
||||||
if (ListProcess[i] == Process)
|
if (ListProcess[i] == Process)
|
||||||
{
|
{
|
||||||
@ -232,20 +232,20 @@ namespace Tasking
|
|||||||
{
|
{
|
||||||
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
|
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < CurrentCPU->CurrentProcess->Threads.size(); i++)
|
for (size_t i = 0; i < CurrentCPU->CurrentProcess->Threads.size(); i++)
|
||||||
{
|
{
|
||||||
// Loop until we find the current thread from the process thread list.
|
// Loop until we find the current thread from the process thread list.
|
||||||
if (CurrentCPU->CurrentProcess->Threads[i] == CurrentCPU->CurrentThread)
|
if (CurrentCPU->CurrentProcess->Threads[i] == CurrentCPU->CurrentThread)
|
||||||
{
|
{
|
||||||
// Check if the next thread is valid. If not, we search until we find, but if we reach the end of the list, we go to the next process.
|
// Check if the next thread is valid. If not, we search until we find, but if we reach the end of the list, we go to the next process.
|
||||||
uint64_t tmpidx = i;
|
size_t TempIndex = i;
|
||||||
RetryAnotherThread:
|
RetryAnotherThread:
|
||||||
TCB *thread = CurrentCPU->CurrentProcess->Threads[tmpidx + 1];
|
TCB *thread = CurrentCPU->CurrentProcess->Threads[TempIndex + 1];
|
||||||
if (InvalidTCB(thread))
|
if (InvalidTCB(thread))
|
||||||
{
|
{
|
||||||
if (tmpidx > CurrentCPU->CurrentProcess->Threads.size())
|
if (TempIndex > CurrentCPU->CurrentProcess->Threads.size())
|
||||||
break;
|
break;
|
||||||
tmpidx++;
|
TempIndex++;
|
||||||
goto RetryAnotherThread;
|
goto RetryAnotherThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,20 +272,20 @@ namespace Tasking
|
|||||||
{
|
{
|
||||||
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
|
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < ListProcess.size(); i++)
|
for (size_t i = 0; i < ListProcess.size(); i++)
|
||||||
{
|
{
|
||||||
// Loop until we find the current process from the process list.
|
// Loop until we find the current process from the process list.
|
||||||
if (ListProcess[i] == CurrentCPU->CurrentProcess)
|
if (ListProcess[i] == CurrentCPU->CurrentProcess)
|
||||||
{
|
{
|
||||||
// Check if the next process is valid. If not, we search until we find.
|
// Check if the next process is valid. If not, we search until we find.
|
||||||
uint64_t tmpidx = i;
|
size_t TempIndex = i;
|
||||||
RetryAnotherProcess:
|
RetryAnotherProcess:
|
||||||
PCB *pcb = ListProcess[tmpidx + 1];
|
PCB *pcb = ListProcess[TempIndex + 1];
|
||||||
if (InvalidPCB(pcb))
|
if (InvalidPCB(pcb))
|
||||||
{
|
{
|
||||||
if (tmpidx > ListProcess.size())
|
if (TempIndex > ListProcess.size())
|
||||||
break;
|
break;
|
||||||
tmpidx++;
|
TempIndex++;
|
||||||
goto RetryAnotherProcess;
|
goto RetryAnotherProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ namespace Tasking
|
|||||||
goto RetryAnotherProcess;
|
goto RetryAnotherProcess;
|
||||||
|
|
||||||
// Everything good, now search for a thread.
|
// Everything good, now search for a thread.
|
||||||
for (uint64_t j = 0; j < pcb->Threads.size(); j++)
|
for (size_t j = 0; j < pcb->Threads.size(); j++)
|
||||||
{
|
{
|
||||||
TCB *tcb = pcb->Threads[j];
|
TCB *tcb = pcb->Threads[j];
|
||||||
if (InvalidTCB(tcb))
|
if (InvalidTCB(tcb))
|
||||||
@ -368,7 +368,7 @@ namespace Tasking
|
|||||||
schedbg("================================================================");
|
schedbg("================================================================");
|
||||||
schedbg("Status: 0-ukn | 1-rdy | 2-run | 3-wait | 4-term");
|
schedbg("Status: 0-ukn | 1-rdy | 2-run | 3-wait | 4-term");
|
||||||
schedbg("Technical Informations on regs %#lx", Frame->InterruptNumber);
|
schedbg("Technical Informations on regs %#lx", Frame->InterruptNumber);
|
||||||
uint64_t ds;
|
size_t ds;
|
||||||
asmv("mov %%ds, %0"
|
asmv("mov %%ds, %0"
|
||||||
: "=r"(ds));
|
: "=r"(ds));
|
||||||
schedbg("FS=%#lx GS=%#lx SS=%#lx CS=%#lx DS=%#lx",
|
schedbg("FS=%#lx GS=%#lx SS=%#lx CS=%#lx DS=%#lx",
|
||||||
@ -506,7 +506,7 @@ namespace Tasking
|
|||||||
CurrentCPU->CurrentThread->RIPHistory[127] = Frame->rip;
|
CurrentCPU->CurrentThread->RIPHistory[127] = Frame->rip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalDescriptorTable::SetKernelStack((void *)((uint64_t)CurrentCPU->CurrentThread->Stack->GetStackTop()));
|
GlobalDescriptorTable::SetKernelStack((void *)((uintptr_t)CurrentCPU->CurrentThread->Stack->GetStackTop()));
|
||||||
CPU::x64::writecr3({.raw = (uint64_t)CurrentCPU->CurrentProcess->PageTable});
|
CPU::x64::writecr3({.raw = (uint64_t)CurrentCPU->CurrentProcess->PageTable});
|
||||||
// Not sure if this is needed, but it's better to be safe than sorry.
|
// Not sure if this is needed, but it's better to be safe than sorry.
|
||||||
asmv("movq %cr3, %rax");
|
asmv("movq %cr3, %rax");
|
||||||
@ -752,8 +752,8 @@ namespace Tasking
|
|||||||
Thread->Registers.rflags.AlwaysOne = 1;
|
Thread->Registers.rflags.AlwaysOne = 1;
|
||||||
Thread->Registers.rflags.IF = 1;
|
Thread->Registers.rflags.IF = 1;
|
||||||
Thread->Registers.rflags.ID = 1;
|
Thread->Registers.rflags.ID = 1;
|
||||||
Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop());
|
Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop());
|
||||||
POKE(uint64_t, Thread->Registers.rsp) = (uint64_t)ThreadDoExit;
|
POKE(uintptr_t, Thread->Registers.rsp) = (uintptr_t)ThreadDoExit;
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#endif
|
#endif
|
||||||
@ -775,14 +775,14 @@ namespace Tasking
|
|||||||
// Thread->Registers.rflags.IOPL = 3;
|
// Thread->Registers.rflags.IOPL = 3;
|
||||||
Thread->Registers.rflags.IF = 1;
|
Thread->Registers.rflags.IF = 1;
|
||||||
Thread->Registers.rflags.ID = 1;
|
Thread->Registers.rflags.ID = 1;
|
||||||
Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop());
|
Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop());
|
||||||
|
|
||||||
uint64_t ArgvSize = 0;
|
size_t ArgvSize = 0;
|
||||||
if (argv)
|
if (argv)
|
||||||
while (argv[ArgvSize] != nullptr)
|
while (argv[ArgvSize] != nullptr)
|
||||||
ArgvSize++;
|
ArgvSize++;
|
||||||
|
|
||||||
uint64_t EnvpSize = 0;
|
size_t EnvpSize = 0;
|
||||||
if (envp)
|
if (envp)
|
||||||
while (envp[EnvpSize] != nullptr)
|
while (envp[EnvpSize] != nullptr)
|
||||||
EnvpSize++;
|
EnvpSize++;
|
||||||
@ -799,40 +799,40 @@ namespace Tasking
|
|||||||
char *StackStringsVirtual = (char *)Thread->Stack->GetStackTop();
|
char *StackStringsVirtual = (char *)Thread->Stack->GetStackTop();
|
||||||
|
|
||||||
// Store string pointers for later
|
// Store string pointers for later
|
||||||
uint64_t ArgvStrings[ArgvSize];
|
uintptr_t ArgvStrings[ArgvSize];
|
||||||
uint64_t EnvpStrings[EnvpSize];
|
uintptr_t EnvpStrings[EnvpSize];
|
||||||
|
|
||||||
for (uint64_t i = 0; i < ArgvSize; i++)
|
for (size_t i = 0; i < ArgvSize; i++)
|
||||||
{
|
{
|
||||||
// Subtract the length of the string and the null terminator
|
// Subtract the length of the string and the null terminator
|
||||||
StackStrings -= strlen(argv[i]) + 1;
|
StackStrings -= strlen(argv[i]) + 1;
|
||||||
StackStringsVirtual -= strlen(argv[i]) + 1;
|
StackStringsVirtual -= strlen(argv[i]) + 1;
|
||||||
// Store the pointer to the string
|
// Store the pointer to the string
|
||||||
ArgvStrings[i] = (uint64_t)StackStringsVirtual;
|
ArgvStrings[i] = (uintptr_t)StackStringsVirtual;
|
||||||
// Copy the string to the stack
|
// Copy the string to the stack
|
||||||
strcpy(StackStrings, argv[i]);
|
strcpy(StackStrings, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint64_t i = 0; i < EnvpSize; i++)
|
for (size_t i = 0; i < EnvpSize; i++)
|
||||||
{
|
{
|
||||||
// Subtract the length of the string and the null terminator
|
// Subtract the length of the string and the null terminator
|
||||||
StackStrings -= strlen(envp[i]) + 1;
|
StackStrings -= strlen(envp[i]) + 1;
|
||||||
StackStringsVirtual -= strlen(envp[i]) + 1;
|
StackStringsVirtual -= strlen(envp[i]) + 1;
|
||||||
// Store the pointer to the string
|
// Store the pointer to the string
|
||||||
EnvpStrings[i] = (uint64_t)StackStringsVirtual;
|
EnvpStrings[i] = (uintptr_t)StackStringsVirtual;
|
||||||
// Copy the string to the stack
|
// Copy the string to the stack
|
||||||
strcpy(StackStrings, envp[i]);
|
strcpy(StackStrings, envp[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align the stack to 16 bytes
|
// Align the stack to 16 bytes
|
||||||
StackStrings -= (uint64_t)StackStrings & 0xF;
|
StackStrings -= (uintptr_t)StackStrings & 0xF;
|
||||||
// Set "Stack" to the new stack pointer
|
// Set "Stack" to the new stack pointer
|
||||||
Stack = (char *)StackStrings;
|
Stack = (char *)StackStrings;
|
||||||
// If argv and envp sizes are odd then we need to align the stack
|
// If argv and envp sizes are odd then we need to align the stack
|
||||||
Stack -= (ArgvSize + EnvpSize) % 2;
|
Stack -= (ArgvSize + EnvpSize) % 2;
|
||||||
|
|
||||||
// We need 8 bit pointers for the stack from here
|
// We need 8 bit pointers for the stack from here
|
||||||
uint64_t *Stack64 = (uint64_t *)Stack;
|
uintptr_t *Stack64 = (uintptr_t *)Stack;
|
||||||
|
|
||||||
// Store the null terminator
|
// Store the null terminator
|
||||||
Stack64--;
|
Stack64--;
|
||||||
@ -842,7 +842,7 @@ namespace Tasking
|
|||||||
foreach (AuxiliaryVector var in auxv)
|
foreach (AuxiliaryVector var in auxv)
|
||||||
{
|
{
|
||||||
// Subtract the size of the auxillary vector
|
// Subtract the size of the auxillary vector
|
||||||
Stack64 -= sizeof(Elf64_auxv_t) / sizeof(uint64_t);
|
Stack64 -= sizeof(Elf64_auxv_t) / sizeof(uintptr_t);
|
||||||
// Store the auxillary vector
|
// Store the auxillary vector
|
||||||
POKE(Elf64_auxv_t, Stack64) = var.archaux;
|
POKE(Elf64_auxv_t, Stack64) = var.archaux;
|
||||||
// TODO: Store strings to the stack
|
// TODO: Store strings to the stack
|
||||||
@ -854,9 +854,9 @@ namespace Tasking
|
|||||||
|
|
||||||
// Store EnvpStrings[] to the stack
|
// Store EnvpStrings[] to the stack
|
||||||
Stack64 -= EnvpSize; // (1 Stack64 = 8 bits; Stack64 = 8 * EnvpSize)
|
Stack64 -= EnvpSize; // (1 Stack64 = 8 bits; Stack64 = 8 * EnvpSize)
|
||||||
for (uint64_t i = 0; i < EnvpSize; i++)
|
for (size_t i = 0; i < EnvpSize; i++)
|
||||||
{
|
{
|
||||||
*(Stack64 + i) = (uint64_t)EnvpStrings[i];
|
*(Stack64 + i) = (uintptr_t)EnvpStrings[i];
|
||||||
debug("EnvpStrings[%d]: %#lx", i, EnvpStrings[i]);
|
debug("EnvpStrings[%d]: %#lx", i, EnvpStrings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -866,9 +866,9 @@ namespace Tasking
|
|||||||
|
|
||||||
// Store ArgvStrings[] to the stack
|
// Store ArgvStrings[] to the stack
|
||||||
Stack64 -= ArgvSize; // (1 Stack64 = 8 bits; Stack64 = 8 * ArgvSize)
|
Stack64 -= ArgvSize; // (1 Stack64 = 8 bits; Stack64 = 8 * ArgvSize)
|
||||||
for (uint64_t i = 0; i < ArgvSize; i++)
|
for (size_t i = 0; i < ArgvSize; i++)
|
||||||
{
|
{
|
||||||
*(Stack64 + i) = (uint64_t)ArgvStrings[i];
|
*(Stack64 + i) = (uintptr_t)ArgvStrings[i];
|
||||||
debug("ArgvStrings[%d]: %#lx", i, ArgvStrings[i]);
|
debug("ArgvStrings[%d]: %#lx", i, ArgvStrings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,20 +881,20 @@ namespace Tasking
|
|||||||
|
|
||||||
/* We need the virtual address but because we are in the kernel we can't use the process page table.
|
/* We need the virtual address but because we are in the kernel we can't use the process page table.
|
||||||
So we modify the physical address and store how much we need to subtract to get the virtual address for RSP. */
|
So we modify the physical address and store how much we need to subtract to get the virtual address for RSP. */
|
||||||
uint64_t SubtractStack = (uint64_t)Thread->Stack->GetStackPhysicalTop() - (uint64_t)Stack;
|
uintptr_t SubtractStack = (uintptr_t)Thread->Stack->GetStackPhysicalTop() - (uintptr_t)Stack;
|
||||||
debug("SubtractStack: %#lx", SubtractStack);
|
debug("SubtractStack: %#lx", SubtractStack);
|
||||||
|
|
||||||
// Set the stack pointer to the new stack
|
// Set the stack pointer to the new stack
|
||||||
Thread->Registers.rsp = ((uint64_t)Thread->Stack->GetStackTop() - SubtractStack);
|
Thread->Registers.rsp = ((uintptr_t)Thread->Stack->GetStackTop() - SubtractStack);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DumpData("Stack Data", (void *)((uint64_t)Thread->Stack->GetStackPhysicalTop() - (uint64_t)SubtractStack), SubtractStack);
|
DumpData("Stack Data", (void *)((uintptr_t)Thread->Stack->GetStackPhysicalTop() - (uintptr_t)SubtractStack), SubtractStack);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thread->Registers.rdi = (uint64_t)ArgvSize; // argc
|
Thread->Registers.rdi = (uintptr_t)ArgvSize; // argc
|
||||||
Thread->Registers.rsi = (uint64_t)(Thread->Registers.rsp + 8); // argv
|
Thread->Registers.rsi = (uintptr_t)(Thread->Registers.rsp + 8); // argv
|
||||||
Thread->Registers.rcx = (uint64_t)EnvpSize; // envc
|
Thread->Registers.rcx = (uintptr_t)EnvpSize; // envc
|
||||||
Thread->Registers.rdx = (uint64_t)(Thread->Registers.rsp + 8 + (8 * ArgvSize) + 8); // envp
|
Thread->Registers.rdx = (uintptr_t)(Thread->Registers.rsp + 8 + (8 * ArgvSize) + 8); // envp
|
||||||
|
|
||||||
/* We need to leave the libc's crt to make a syscall when the Thread is exited or we are going to get GPF or PF exception. */
|
/* We need to leave the libc's crt to make a syscall when the Thread is exited or we are going to get GPF or PF exception. */
|
||||||
|
|
||||||
@ -973,7 +973,7 @@ namespace Tasking
|
|||||||
Process->Security.TrustLevel = TrustLevel;
|
Process->Security.TrustLevel = TrustLevel;
|
||||||
// Process->Security.UniqueToken = SecurityManager.CreateToken();
|
// Process->Security.UniqueToken = SecurityManager.CreateToken();
|
||||||
|
|
||||||
Process->IPCHandles = new HashMap<InterProcessCommunication::IPCPort, uint64_t>;
|
Process->IPCHandles = new HashMap<InterProcessCommunication::IPCPort, uintptr_t>;
|
||||||
|
|
||||||
switch (TrustLevel)
|
switch (TrustLevel)
|
||||||
{
|
{
|
||||||
@ -997,7 +997,7 @@ namespace Tasking
|
|||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
Process->PageTable = (Memory::PageTable4 *)KernelAllocator.RequestPages(TO_PAGES(PAGE_SIZE));
|
Process->PageTable = (Memory::PageTable4 *)KernelAllocator.RequestPages(TO_PAGES(PAGE_SIZE));
|
||||||
memcpy(Process->PageTable, (void *)UserspaceKernelOnlyPageTable, PAGE_SIZE);
|
memcpy(Process->PageTable, (void *)UserspaceKernelOnlyPageTable, PAGE_SIZE);
|
||||||
for (uint64_t i = 0; i < TO_PAGES(PAGE_SIZE); i++)
|
for (size_t i = 0; i < TO_PAGES(PAGE_SIZE); i++)
|
||||||
Memory::Virtual(Process->PageTable).Map((void *)Process->PageTable, (void *)Process->PageTable, Memory::PTFlag::RW); // Make sure the page table is mapped.
|
Memory::Virtual(Process->PageTable).Map((void *)Process->PageTable, (void *)Process->PageTable, Memory::PTFlag::RW); // Make sure the page table is mapped.
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
@ -1037,7 +1037,7 @@ namespace Tasking
|
|||||||
if (Image)
|
if (Image)
|
||||||
{
|
{
|
||||||
// TODO: Check if it's ELF
|
// TODO: Check if it's ELF
|
||||||
Process->ELFSymbolTable = new SymbolResolver::Symbols((uint64_t)Image);
|
Process->ELFSymbolTable = new SymbolResolver::Symbols((uintptr_t)Image);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug("No image provided for process \"%s\"(%d)", Process->Name, Process->ID);
|
debug("No image provided for process \"%s\"(%d)", Process->Name, Process->ID);
|
||||||
@ -1093,7 +1093,7 @@ namespace Tasking
|
|||||||
for (int i = 0; i < SMP::CPUCores; i++)
|
for (int i = 0; i < SMP::CPUCores; i++)
|
||||||
{
|
{
|
||||||
Vector<AuxiliaryVector> auxv;
|
Vector<AuxiliaryVector> auxv;
|
||||||
IdleThread = CreateThread(IdleProcess, reinterpret_cast<uint64_t>(IdleProcessLoop), nullptr, nullptr, auxv);
|
IdleThread = CreateThread(IdleProcess, reinterpret_cast<uintptr_t>(IdleProcessLoop), nullptr, nullptr, auxv);
|
||||||
char IdleName[16];
|
char IdleName[16];
|
||||||
sprintf_(IdleName, "Idle Thread %d", i);
|
sprintf_(IdleName, "Idle Thread %d", i);
|
||||||
IdleThread->Rename(IdleName);
|
IdleThread->Rename(IdleName);
|
||||||
|
@ -53,7 +53,7 @@ __constructor void TestRandom()
|
|||||||
uint16_t Seeds16[16];
|
uint16_t Seeds16[16];
|
||||||
uint32_t Seeds32[16];
|
uint32_t Seeds32[16];
|
||||||
uint64_t Seeds64[16];
|
uint64_t Seeds64[16];
|
||||||
for (uint64_t i = 0; i < 16; i++)
|
for (short i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
Seeds16[i] = Random::rand16();
|
Seeds16[i] = Random::rand16();
|
||||||
Seeds32[i] = Random::rand32();
|
Seeds32[i] = Random::rand32();
|
||||||
|
@ -6,7 +6,7 @@ class Bitmap
|
|||||||
public:
|
public:
|
||||||
size_t Size;
|
size_t Size;
|
||||||
uint8_t *Buffer;
|
uint8_t *Buffer;
|
||||||
bool operator[](uint64_t index);
|
bool operator[](uintptr_t index);
|
||||||
bool Set(uint64_t index, bool value);
|
bool Set(uintptr_t index, bool value);
|
||||||
bool Get(uint64_t index);
|
bool Get(uintptr_t index);
|
||||||
};
|
};
|
||||||
|
@ -86,16 +86,16 @@ namespace Disk
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char Label[72] = "Unidentified Partition";
|
char Label[72] = "Unidentified Partition";
|
||||||
uint64_t StartLBA = 0xdeadbeef;
|
size_t StartLBA = 0xdeadbeef;
|
||||||
uint64_t EndLBA = 0xdeadbeef;
|
size_t EndLBA = 0xdeadbeef;
|
||||||
uint64_t Sectors = 0xdeadbeef;
|
size_t Sectors = 0xdeadbeef;
|
||||||
uint64_t Flags = 0xdeadbeef;
|
size_t Flags = 0xdeadbeef;
|
||||||
unsigned char Port = 0;
|
unsigned char Port = 0;
|
||||||
PartitionStyle Style = PartitionStyle::Unknown;
|
PartitionStyle Style = PartitionStyle::Unknown;
|
||||||
size_t Index = 0;
|
size_t Index = 0;
|
||||||
|
|
||||||
uint64_t Read(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; }
|
size_t Read(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; }
|
||||||
uint64_t Write(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; }
|
size_t Write(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; }
|
||||||
Partition() {}
|
Partition() {}
|
||||||
~Partition() {}
|
~Partition() {}
|
||||||
};
|
};
|
||||||
@ -109,10 +109,10 @@ namespace Disk
|
|||||||
PartitionStyle Style = PartitionStyle::Unknown;
|
PartitionStyle Style = PartitionStyle::Unknown;
|
||||||
Vector<Partition *> Partitions;
|
Vector<Partition *> Partitions;
|
||||||
bool MechanicalDisk = false;
|
bool MechanicalDisk = false;
|
||||||
uint64_t UniqueIdentifier = 0xdeadbeef;
|
size_t UniqueIdentifier = 0xdeadbeef;
|
||||||
|
|
||||||
uint64_t Read(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; }
|
size_t Read(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; }
|
||||||
uint64_t Write(uint64_t Offset, uint64_t Count, uint8_t *Buffer) { return 0; }
|
size_t Write(size_t Offset, size_t Count, uint8_t *Buffer) { return 0; }
|
||||||
Drive()
|
Drive()
|
||||||
{ // TODO: Allocate buffer
|
{ // TODO: Allocate buffer
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ namespace Video
|
|||||||
|
|
||||||
struct FontInfo
|
struct FontInfo
|
||||||
{
|
{
|
||||||
uint64_t *StartAddress;
|
uintptr_t *StartAddress;
|
||||||
uint64_t *EndAddress;
|
uintptr_t *EndAddress;
|
||||||
PSF1_FONT *PSF1Font;
|
PSF1_FONT *PSF1Font;
|
||||||
PSF2_FONT *PSF2Font;
|
PSF2_FONT *PSF2Font;
|
||||||
uint32_t Width, Height;
|
uint32_t Width, Height;
|
||||||
@ -72,7 +72,7 @@ namespace Video
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
FontInfo GetInfo() { return Info; }
|
FontInfo GetInfo() { return Info; }
|
||||||
Font(uint64_t *Start, uint64_t *End, FontType Type);
|
Font(uintptr_t *Start, uintptr_t *End, FontType Type);
|
||||||
~Font();
|
~Font();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ namespace Video
|
|||||||
{
|
{
|
||||||
void *Buffer = nullptr;
|
void *Buffer = nullptr;
|
||||||
uint32_t Width, Height;
|
uint32_t Width, Height;
|
||||||
uint64_t Size;
|
size_t Size;
|
||||||
uint32_t Color;
|
uint32_t Color;
|
||||||
uint32_t CursorX, CursorY;
|
uint32_t CursorX, CursorY;
|
||||||
long Checksum;
|
long Checksum;
|
||||||
@ -107,7 +107,7 @@ namespace Video
|
|||||||
debug("No width and height specified, using %ldx%lld", Width, Height);
|
debug("No width and height specified, using %ldx%lld", Width, Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Size = this->framebuffer.Pitch * Height;
|
size_t Size = this->framebuffer.Pitch * Height;
|
||||||
if (!this->Buffers[Index])
|
if (!this->Buffers[Index])
|
||||||
{
|
{
|
||||||
if (this->Buffers[Index]->Checksum != 0xDEAD5C9EE7)
|
if (this->Buffers[Index]->Checksum != 0xDEAD5C9EE7)
|
||||||
@ -160,7 +160,7 @@ namespace Video
|
|||||||
X = this->Buffers[Index]->Width - 1;
|
X = this->Buffers[Index]->Width - 1;
|
||||||
if (Y >= this->Buffers[Index]->Height)
|
if (Y >= this->Buffers[Index]->Height)
|
||||||
Y = this->Buffers[Index]->Height - 1;
|
Y = this->Buffers[Index]->Height - 1;
|
||||||
uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
||||||
*Pixel = Color;
|
*Pixel = Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ namespace Video
|
|||||||
{
|
{
|
||||||
if (X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height)
|
if (X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height)
|
||||||
return 0;
|
return 0;
|
||||||
uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
||||||
return *Pixel;
|
return *Pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +58,17 @@ namespace Driver
|
|||||||
unsigned long DriverUIDs = 0;
|
unsigned long DriverUIDs = 0;
|
||||||
|
|
||||||
DriverCode CallDriverEntryPoint(void *fex, void *KAPIAddress);
|
DriverCode CallDriverEntryPoint(void *fex, void *KAPIAddress);
|
||||||
DriverCode DriverLoadBindPCI(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false);
|
DriverCode DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||||
DriverCode DriverLoadBindInterrupt(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false);
|
DriverCode DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||||
DriverCode DriverLoadBindInput(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false);
|
DriverCode DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||||
DriverCode DriverLoadBindProcess(void *DrvExtHdr, uint64_t DriverAddress, uint64_t Size, bool IsElf = false);
|
DriverCode DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Vector<DriverFile *> GetDrivers() { return Drivers; }
|
Vector<DriverFile *> GetDrivers() { return Drivers; }
|
||||||
void UnloadAllDrivers();
|
void UnloadAllDrivers();
|
||||||
bool UnloadDriver(unsigned long DUID);
|
bool UnloadDriver(unsigned long DUID);
|
||||||
int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB);
|
int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB);
|
||||||
DriverCode LoadDriver(uint64_t DriverAddress, uint64_t Size);
|
DriverCode LoadDriver(uintptr_t DriverAddress, size_t Size);
|
||||||
DriverCode StartDrivers();
|
DriverCode StartDrivers();
|
||||||
Driver();
|
Driver();
|
||||||
~Driver();
|
~Driver();
|
||||||
|
@ -20,24 +20,24 @@ namespace FileSystem
|
|||||||
|
|
||||||
struct FileSystemNode;
|
struct FileSystemNode;
|
||||||
|
|
||||||
typedef uint64_t (*OperationMount)(const char *, unsigned long, const void *);
|
typedef size_t (*OperationMount)(const char *, unsigned long, const void *);
|
||||||
typedef uint64_t (*OperationUmount)(int);
|
typedef size_t (*OperationUmount)(int);
|
||||||
typedef uint64_t (*OperationRead)(FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer);
|
typedef size_t (*OperationRead)(FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer);
|
||||||
typedef uint64_t (*OperationWrite)(FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer);
|
typedef size_t (*OperationWrite)(FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer);
|
||||||
typedef void (*OperationOpen)(FileSystemNode *Node, uint8_t Mode, uint8_t Flags);
|
typedef void (*OperationOpen)(FileSystemNode *Node, uint8_t Mode, uint8_t Flags);
|
||||||
typedef void (*OperationClose)(FileSystemNode *Node);
|
typedef void (*OperationClose)(FileSystemNode *Node);
|
||||||
typedef uint64_t (*OperationSync)(void);
|
typedef size_t (*OperationSync)(void);
|
||||||
typedef void (*OperationCreate)(FileSystemNode *Node, char *Name, uint16_t NameLength);
|
typedef void (*OperationCreate)(FileSystemNode *Node, char *Name, uint16_t NameLength);
|
||||||
typedef void (*OperationMkdir)(FileSystemNode *Node, char *Name, uint16_t NameLength);
|
typedef void (*OperationMkdir)(FileSystemNode *Node, char *Name, uint16_t NameLength);
|
||||||
|
|
||||||
#define MountFSFunction(name) uint64_t name(const char *unknown0, unsigned long unknown1, const uint8_t *unknown2)
|
#define MountFSFunction(name) size_t name(const char *unknown0, unsigned long unknown1, const uint8_t *unknown2)
|
||||||
#define UMountFSFunction(name) uint64_t name(int unknown0)
|
#define UMountFSFunction(name) size_t name(int unknown0)
|
||||||
|
|
||||||
#define ReadFSFunction(name) uint64_t name(FileSystem::FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer)
|
#define ReadFSFunction(name) size_t name(FileSystem::FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer)
|
||||||
#define WriteFSFunction(name) uint64_t name(FileSystem::FileSystemNode *Node, uint64_t Offset, uint64_t Size, uint8_t *Buffer)
|
#define WriteFSFunction(name) size_t name(FileSystem::FileSystemNode *Node, size_t Offset, size_t Size, uint8_t *Buffer)
|
||||||
#define OpenFSFunction(name) void name(FileSystem::FileSystemNode *Node, uint8_t Mode, uint8_t Flags)
|
#define OpenFSFunction(name) void name(FileSystem::FileSystemNode *Node, uint8_t Mode, uint8_t Flags)
|
||||||
#define CloseFSFunction(name) void name(FileSystem::FileSystemNode *Node)
|
#define CloseFSFunction(name) void name(FileSystem::FileSystemNode *Node)
|
||||||
#define SyncFSFunction(name) uint64_t name(void)
|
#define SyncFSFunction(name) size_t name(void)
|
||||||
#define CreateFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength)
|
#define CreateFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength)
|
||||||
#define MkdirFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength)
|
#define MkdirFSFunction(name) void name(FileSystem::FileSystemNode *Node, char *Name, uint16_t NameLength)
|
||||||
|
|
||||||
@ -108,10 +108,10 @@ namespace FileSystem
|
|||||||
uint64_t IndexNode = 0;
|
uint64_t IndexNode = 0;
|
||||||
uint64_t Mask = 0;
|
uint64_t Mask = 0;
|
||||||
uint64_t Mode = 0;
|
uint64_t Mode = 0;
|
||||||
uint64_t Flags = NodeFlags::FS_ERROR;
|
int Flags = NodeFlags::FS_ERROR;
|
||||||
uint64_t UserIdentifier = 0, GroupIdentifier = 0;
|
uint64_t UserIdentifier = 0, GroupIdentifier = 0;
|
||||||
uint64_t Address = 0;
|
uintptr_t Address = 0;
|
||||||
uint64_t Length = 0;
|
size_t Length = 0;
|
||||||
FileSystemNode *Parent = nullptr;
|
FileSystemNode *Parent = nullptr;
|
||||||
FileSystemOperations *Operator = nullptr;
|
FileSystemOperations *Operator = nullptr;
|
||||||
/* For root node:
|
/* For root node:
|
||||||
@ -153,8 +153,8 @@ namespace FileSystem
|
|||||||
FILE *Mount(FileSystemOperations *Operator, const char *Path);
|
FILE *Mount(FileSystemOperations *Operator, const char *Path);
|
||||||
FileStatus Unmount(FILE *File);
|
FileStatus Unmount(FILE *File);
|
||||||
FILE *Open(const char *Path, FileSystemNode *Parent = nullptr);
|
FILE *Open(const char *Path, FileSystemNode *Parent = nullptr);
|
||||||
uint64_t Read(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
size_t Read(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size);
|
||||||
uint64_t Write(FILE *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
size_t Write(FILE *File, size_t Offset, uint8_t *Buffer, size_t Size);
|
||||||
FileStatus Close(FILE *File);
|
FileStatus Close(FILE *File);
|
||||||
FileSystemNode *CreateRoot(FileSystemOperations *Operator, const char *RootName);
|
FileSystemNode *CreateRoot(FileSystemOperations *Operator, const char *RootName);
|
||||||
FileSystemNode *Create(FileSystemNode *Parent, const char *Path);
|
FileSystemNode *Create(FileSystemNode *Parent, const char *Path);
|
||||||
|
@ -23,7 +23,7 @@ namespace FileSystem
|
|||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Initrd(uint64_t Address);
|
Initrd(uintptr_t Address);
|
||||||
~Initrd();
|
~Initrd();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ namespace FileSystem
|
|||||||
class FB
|
class FB
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void SetFrameBufferData(uint64_t Address, uint64_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine);
|
void SetFrameBufferData(uintptr_t Address, size_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine);
|
||||||
FB();
|
FB();
|
||||||
~FB();
|
~FB();
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ namespace FileSystem
|
|||||||
private:
|
private:
|
||||||
uint32_t getsize(const char *s)
|
uint32_t getsize(const char *s)
|
||||||
{
|
{
|
||||||
uint64_t ret = 0;
|
uint32_t ret = 0;
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
ret *= 8;
|
ret *= 8;
|
||||||
@ -63,7 +63,7 @@ namespace FileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
USTAR(uint64_t Address, Virtual *vfs);
|
USTAR(uintptr_t Address, Virtual *vfs);
|
||||||
~USTAR();
|
~USTAR();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
uint8_t Result = *(volatile uint8_t *)Address;
|
uint8_t Result = *(volatile uint8_t *)(uintptr_t)Address;
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
return Result;
|
return Result;
|
||||||
@ -71,7 +71,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
uint16_t Result = *(volatile uint16_t *)Address;
|
uint16_t Result = *(volatile uint16_t *)(uintptr_t)Address;
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
return Result;
|
return Result;
|
||||||
@ -81,7 +81,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
uint32_t Result = *(volatile uint32_t *)Address;
|
uint32_t Result = *(volatile uint32_t *)(uintptr_t)Address;
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
return Result;
|
return Result;
|
||||||
@ -91,7 +91,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
uint64_t Result = *(volatile uint64_t *)Address;
|
uint64_t Result = *(volatile uint64_t *)(uintptr_t)Address;
|
||||||
asmv("" ::
|
asmv("" ::
|
||||||
: "memory");
|
: "memory");
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -13,7 +13,7 @@ class LockClass
|
|||||||
uint64_t LockData = 0x0;
|
uint64_t LockData = 0x0;
|
||||||
const char *CurrentHolder = "(nul)";
|
const char *CurrentHolder = "(nul)";
|
||||||
const char *AttemptingToGet = "(nul)";
|
const char *AttemptingToGet = "(nul)";
|
||||||
uint64_t Count = 0;
|
size_t Count = 0;
|
||||||
long Core = 0;
|
long Core = 0;
|
||||||
};
|
};
|
||||||
void DeadLock(SpinLockData Lock);
|
void DeadLock(SpinLockData Lock);
|
||||||
|
@ -11,7 +11,7 @@ START_EXTERNC
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint64_t size; // Size of input in bytes
|
size_t size; // Size of input in bytes
|
||||||
uint32_t buffer[4]; // Current accumulation of hash
|
uint32_t buffer[4]; // Current accumulation of hash
|
||||||
uint8_t input[64]; // Input to be used in the next step
|
uint8_t input[64]; // Input to be used in the next step
|
||||||
uint8_t digest[16]; // Result of algorithm
|
uint8_t digest[16]; // Result of algorithm
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
extern uint64_t _kernel_start, _kernel_end;
|
extern uintptr_t _kernel_start, _kernel_end;
|
||||||
extern uint64_t _kernel_text_end, _kernel_data_end, _kernel_rodata_end;
|
extern uintptr_t _kernel_text_end, _kernel_data_end, _kernel_rodata_end;
|
||||||
|
|
||||||
// kilobyte
|
// kilobyte
|
||||||
#define TO_KB(d) (d / 1024)
|
#define TO_KB(d) (d / 1024)
|
||||||
@ -177,7 +177,7 @@ namespace Memory
|
|||||||
uint64_t raw;
|
uint64_t raw;
|
||||||
|
|
||||||
/** @brief Set Address */
|
/** @brief Set Address */
|
||||||
void SetAddress(uint64_t _Address)
|
void SetAddress(uintptr_t _Address)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
_Address &= 0x000000FFFFFFFFFF;
|
_Address &= 0x000000FFFFFFFFFF;
|
||||||
@ -195,7 +195,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Get Address */
|
/** @brief Get Address */
|
||||||
uint64_t GetAddress()
|
uintptr_t GetAddress()
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
||||||
@ -232,7 +232,7 @@ namespace Memory
|
|||||||
uint64_t raw;
|
uint64_t raw;
|
||||||
|
|
||||||
/** @brief Set PageTableEntryPtr address */
|
/** @brief Set PageTableEntryPtr address */
|
||||||
void SetAddress(uint64_t _Address)
|
void SetAddress(uintptr_t _Address)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
_Address &= 0x000000FFFFFFFFFF;
|
_Address &= 0x000000FFFFFFFFFF;
|
||||||
@ -250,7 +250,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Get PageTableEntryPtr address */
|
/** @brief Get PageTableEntryPtr address */
|
||||||
uint64_t GetAddress()
|
uintptr_t GetAddress()
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
||||||
@ -287,7 +287,7 @@ namespace Memory
|
|||||||
uint64_t raw;
|
uint64_t raw;
|
||||||
|
|
||||||
/** @brief Set PageDirectoryEntryPtr address */
|
/** @brief Set PageDirectoryEntryPtr address */
|
||||||
void SetAddress(uint64_t _Address)
|
void SetAddress(uintptr_t _Address)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
_Address &= 0x000000FFFFFFFFFF;
|
_Address &= 0x000000FFFFFFFFFF;
|
||||||
@ -305,7 +305,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Get PageDirectoryEntryPtr address */
|
/** @brief Get PageDirectoryEntryPtr address */
|
||||||
uint64_t GetAddress()
|
uintptr_t GetAddress()
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
||||||
@ -342,7 +342,7 @@ namespace Memory
|
|||||||
uint64_t raw;
|
uint64_t raw;
|
||||||
|
|
||||||
/** @brief Set PageDirectoryPointerTableEntryPtr address */
|
/** @brief Set PageDirectoryPointerTableEntryPtr address */
|
||||||
void SetAddress(uint64_t _Address)
|
void SetAddress(uintptr_t _Address)
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
_Address &= 0x000000FFFFFFFFFF;
|
_Address &= 0x000000FFFFFFFFFF;
|
||||||
@ -360,7 +360,7 @@ namespace Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Get PageDirectoryPointerTableEntryPtr address */
|
/** @brief Get PageDirectoryPointerTableEntryPtr address */
|
||||||
uint64_t GetAddress()
|
uintptr_t GetAddress()
|
||||||
{
|
{
|
||||||
#if defined(__amd64__)
|
#if defined(__amd64__)
|
||||||
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
return (this->raw & 0x000FFFFFFFFFF000) >> 12;
|
||||||
@ -400,9 +400,9 @@ namespace Memory
|
|||||||
Bitmap PageBitmap;
|
Bitmap PageBitmap;
|
||||||
|
|
||||||
void ReservePage(void *Address);
|
void ReservePage(void *Address);
|
||||||
void ReservePages(void *Address, uint64_t PageCount);
|
void ReservePages(void *Address, size_t PageCount);
|
||||||
void UnreservePage(void *Address);
|
void UnreservePage(void *Address);
|
||||||
void UnreservePages(void *Address, uint64_t PageCount);
|
void UnreservePages(void *Address, size_t PageCount);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bitmap GetPageBitmap() { return PageBitmap; }
|
Bitmap GetPageBitmap() { return PageBitmap; }
|
||||||
@ -447,7 +447,7 @@ namespace Memory
|
|||||||
* @return true if swap was successful
|
* @return true if swap was successful
|
||||||
* @return false if swap was unsuccessful
|
* @return false if swap was unsuccessful
|
||||||
*/
|
*/
|
||||||
bool SwapPages(void *Address, uint64_t PageCount);
|
bool SwapPages(void *Address, size_t PageCount);
|
||||||
/**
|
/**
|
||||||
* @brief Unswap page
|
* @brief Unswap page
|
||||||
*
|
*
|
||||||
@ -464,7 +464,7 @@ namespace Memory
|
|||||||
* @return true if unswap was successful
|
* @return true if unswap was successful
|
||||||
* @return false if unswap was unsuccessful
|
* @return false if unswap was unsuccessful
|
||||||
*/
|
*/
|
||||||
bool UnswapPages(void *Address, uint64_t PageCount);
|
bool UnswapPages(void *Address, size_t PageCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Lock page
|
* @brief Lock page
|
||||||
@ -478,7 +478,7 @@ namespace Memory
|
|||||||
* @param Address Address of the pages
|
* @param Address Address of the pages
|
||||||
* @param PageCount Number of pages
|
* @param PageCount Number of pages
|
||||||
*/
|
*/
|
||||||
void LockPages(void *Address, uint64_t PageCount);
|
void LockPages(void *Address, size_t PageCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request page
|
* @brief Request page
|
||||||
@ -492,7 +492,7 @@ namespace Memory
|
|||||||
* @param PageCount Number of pages
|
* @param PageCount Number of pages
|
||||||
* @return void* Allocated pages address
|
* @return void* Allocated pages address
|
||||||
*/
|
*/
|
||||||
void *RequestPages(uint64_t Count);
|
void *RequestPages(size_t Count);
|
||||||
/**
|
/**
|
||||||
* @brief Free page
|
* @brief Free page
|
||||||
*
|
*
|
||||||
@ -505,7 +505,7 @@ namespace Memory
|
|||||||
* @param Address Address of the pages
|
* @param Address Address of the pages
|
||||||
* @param PageCount Number of pages
|
* @param PageCount Number of pages
|
||||||
*/
|
*/
|
||||||
void FreePages(void *Address, uint64_t Count);
|
void FreePages(void *Address, size_t Count);
|
||||||
/** @brief Do not use. */
|
/** @brief Do not use. */
|
||||||
void Init(BootInfo *Info);
|
void Init(BootInfo *Info);
|
||||||
/** @brief Do not use. */
|
/** @brief Do not use. */
|
||||||
@ -524,11 +524,11 @@ namespace Memory
|
|||||||
class PageMapIndexer
|
class PageMapIndexer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint64_t PMLIndex = 0;
|
uintptr_t PMLIndex = 0;
|
||||||
uint64_t PDPTEIndex = 0;
|
uintptr_t PDPTEIndex = 0;
|
||||||
uint64_t PDEIndex = 0;
|
uintptr_t PDEIndex = 0;
|
||||||
uint64_t PTEIndex = 0;
|
uintptr_t PTEIndex = 0;
|
||||||
PageMapIndexer(uint64_t VirtualAddress);
|
PageMapIndexer(uintptr_t VirtualAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -558,7 +558,7 @@ namespace Memory
|
|||||||
* @param PageCount Number of pages.
|
* @param PageCount Number of pages.
|
||||||
* @param Flags Flags of the page. Check PTFlag enum.
|
* @param Flags Flags of the page. Check PTFlag enum.
|
||||||
*/
|
*/
|
||||||
void Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags);
|
void Map(void *VirtualAddress, void *PhysicalAddress, size_t PageCount, uint64_t Flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unmap page.
|
* @brief Unmap page.
|
||||||
@ -573,7 +573,7 @@ namespace Memory
|
|||||||
* @param VirtualAddress First virtual address of the page.
|
* @param VirtualAddress First virtual address of the page.
|
||||||
* @param PageCount Number of pages.
|
* @param PageCount Number of pages.
|
||||||
*/
|
*/
|
||||||
void Unmap(void *VirtualAddress, uint64_t PageCount);
|
void Unmap(void *VirtualAddress, size_t PageCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remap page.
|
* @brief Remap page.
|
||||||
@ -619,7 +619,7 @@ namespace Memory
|
|||||||
/** @brief For general info */
|
/** @brief For general info */
|
||||||
void *GetStackPhysicalTop() { return StackPhyiscalTop; }
|
void *GetStackPhysicalTop() { return StackPhyiscalTop; }
|
||||||
/** @brief Called by exception handler */
|
/** @brief Called by exception handler */
|
||||||
bool Expand(uint64_t FaultAddress);
|
bool Expand(uintptr_t FaultAddress);
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Stack Guard object
|
* @brief Construct a new Stack Guard object
|
||||||
* @param User Stack for user mode?
|
* @param User Stack for user mode?
|
||||||
@ -640,7 +640,7 @@ namespace Memory
|
|||||||
struct AllocatedPages
|
struct AllocatedPages
|
||||||
{
|
{
|
||||||
void *Address;
|
void *Address;
|
||||||
uint64_t PageCount;
|
size_t PageCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<AllocatedPages> AllocatedPagesList;
|
Vector<AllocatedPages> AllocatedPagesList;
|
||||||
@ -648,8 +648,8 @@ namespace Memory
|
|||||||
public:
|
public:
|
||||||
uint64_t GetAllocatedMemorySize();
|
uint64_t GetAllocatedMemorySize();
|
||||||
|
|
||||||
void *RequestPages(uint64_t Count);
|
void *RequestPages(size_t Count);
|
||||||
void FreePages(void *Address, uint64_t Count);
|
void FreePages(void *Address, size_t Count);
|
||||||
|
|
||||||
Tracker(PageTable4 *PageTable = nullptr);
|
Tracker(PageTable4 *PageTable = nullptr);
|
||||||
~Tracker();
|
~Tracker();
|
||||||
@ -686,9 +686,9 @@ extern Memory::PageTable4 *UserspaceKernelOnlyPageTable;
|
|||||||
|
|
||||||
extern void *KPT;
|
extern void *KPT;
|
||||||
|
|
||||||
EXTERNC void *HeapMalloc(uint64_t Size);
|
EXTERNC void *HeapMalloc(size_t Size);
|
||||||
EXTERNC void *HeapCalloc(uint64_t n, uint64_t Size);
|
EXTERNC void *HeapCalloc(size_t n, size_t Size);
|
||||||
EXTERNC void *HeapRealloc(void *Address, uint64_t Size);
|
EXTERNC void *HeapRealloc(void *Address, size_t Size);
|
||||||
EXTERNC void HeapFree(void *Address);
|
EXTERNC void HeapFree(void *Address);
|
||||||
|
|
||||||
#define kmalloc(Size) HeapMalloc(Size)
|
#define kmalloc(Size) HeapMalloc(Size)
|
||||||
|
@ -129,7 +129,7 @@ namespace PCI
|
|||||||
|
|
||||||
struct DeviceConfig
|
struct DeviceConfig
|
||||||
{
|
{
|
||||||
uint64_t BaseAddress;
|
uintptr_t BaseAddress;
|
||||||
uint16_t PCISegGroup;
|
uint16_t PCISegGroup;
|
||||||
uint8_t StartBus;
|
uint8_t StartBus;
|
||||||
uint8_t EndBus;
|
uint8_t EndBus;
|
||||||
@ -143,9 +143,9 @@ namespace PCI
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Vector<PCIDeviceHeader *> &GetDevices() { return Devices; }
|
Vector<PCIDeviceHeader *> &GetDevices() { return Devices; }
|
||||||
void EnumerateFunction(uint64_t DeviceAddress, uint64_t Function);
|
void EnumerateFunction(uintptr_t DeviceAddress, uint64_t Function);
|
||||||
void EnumerateDevice(uint64_t BusAddress, uint64_t Device);
|
void EnumerateDevice(uintptr_t BusAddress, uint64_t Device);
|
||||||
void EnumerateBus(uint64_t BaseAddress, uint64_t Bus);
|
void EnumerateBus(uintptr_t BaseAddress, uint64_t Bus);
|
||||||
Vector<PCIDeviceHeader *> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
Vector<PCIDeviceHeader *> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
||||||
Vector<PCIDeviceHeader *> FindPCIDevice(int VendorID, int DeviceID);
|
Vector<PCIDeviceHeader *> FindPCIDevice(int VendorID, int DeviceID);
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ struct CPUData
|
|||||||
/** @brief Used by syscall handler */
|
/** @brief Used by syscall handler */
|
||||||
uint8_t *SystemCallStack; /* gs+0x0 */
|
uint8_t *SystemCallStack; /* gs+0x0 */
|
||||||
/** @brief Used by syscall handler */
|
/** @brief Used by syscall handler */
|
||||||
uint64_t TempStack; /* gs+0x8 */
|
uintptr_t TempStack; /* gs+0x8 */
|
||||||
/** @brief Used by CPU */
|
/** @brief Used by CPU */
|
||||||
uint64_t Stack;
|
uintptr_t Stack;
|
||||||
/** @brief CPU ID. */
|
/** @brief CPU ID. */
|
||||||
long ID;
|
long ID;
|
||||||
/** @brief Local CPU error code. */
|
/** @brief Local CPU error code. */
|
||||||
|
@ -8,17 +8,17 @@ namespace SymbolResolver
|
|||||||
private:
|
private:
|
||||||
struct SymbolTable
|
struct SymbolTable
|
||||||
{
|
{
|
||||||
uint64_t Address;
|
uintptr_t Address;
|
||||||
char *FunctionName;
|
char *FunctionName;
|
||||||
};
|
};
|
||||||
|
|
||||||
SymbolTable SymTable[0x10000];
|
SymbolTable SymTable[0x10000];
|
||||||
uint64_t TotalEntries = 0;
|
uintptr_t TotalEntries = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Symbols(uint64_t ImageAddress);
|
Symbols(uintptr_t ImageAddress);
|
||||||
~Symbols();
|
~Symbols();
|
||||||
const char *GetSymbolFromAddress(uint64_t Address);
|
const char *GetSymbolFromAddress(uintptr_t Address);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,14 +10,14 @@ typedef struct SyscallsFrame
|
|||||||
uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax;
|
uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax;
|
||||||
uint64_t InterruptNumber, ErrorCode, rip, cs, rflags, rsp, ss;
|
uint64_t InterruptNumber, ErrorCode, rip, cs, rflags, rsp, ss;
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
uint64_t ebp, edi, esi, edx, ecx, ebx, eax;
|
uint32_t ebp, edi, esi, edx, ecx, ebx, eax;
|
||||||
uint64_t InterruptNumber, ErrorCode, eip, cs, eflags, esp, ss;
|
uint32_t InterruptNumber, ErrorCode, eip, cs, eflags, esp, ss;
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#endif
|
#endif
|
||||||
} SyscallsFrame;
|
} SyscallsFrame;
|
||||||
|
|
||||||
uint64_t HandleNativeSyscalls(SyscallsFrame *Frame);
|
uintptr_t HandleNativeSyscalls(SyscallsFrame *Frame);
|
||||||
uint64_t HandleLinuxSyscalls(SyscallsFrame *Frame);
|
uintptr_t HandleLinuxSyscalls(SyscallsFrame *Frame);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize syscalls for the current CPU. (Function is available on x32, x64 & aarch64)
|
* @brief Initialize syscalls for the current CPU. (Function is available on x32, x64 & aarch64)
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
namespace Tasking
|
namespace Tasking
|
||||||
{
|
{
|
||||||
typedef unsigned long IP;
|
typedef unsigned long IP;
|
||||||
typedef unsigned long IPOffset;
|
typedef __UINTPTR_TYPE__ IPOffset;
|
||||||
typedef unsigned long UPID;
|
typedef unsigned long UPID;
|
||||||
typedef unsigned long UTID;
|
typedef unsigned long UTID;
|
||||||
typedef unsigned long Token;
|
typedef __UINTPTR_TYPE__ Token;
|
||||||
|
|
||||||
enum TaskArchitecture
|
enum TaskArchitecture
|
||||||
{
|
{
|
||||||
@ -165,7 +165,7 @@ namespace Tasking
|
|||||||
TaskInfo Info;
|
TaskInfo Info;
|
||||||
Vector<TCB *> Threads;
|
Vector<TCB *> Threads;
|
||||||
Vector<PCB *> Children;
|
Vector<PCB *> Children;
|
||||||
HashMap<InterProcessCommunication::IPCPort, uint64_t> *IPCHandles;
|
HashMap<InterProcessCommunication::IPCPort, uintptr_t> *IPCHandles;
|
||||||
Memory::PageTable4 *PageTable;
|
Memory::PageTable4 *PageTable;
|
||||||
SymbolResolver::Symbols *ELFSymbolTable;
|
SymbolResolver::Symbols *ELFSymbolTable;
|
||||||
};
|
};
|
||||||
|
@ -46,7 +46,7 @@ typedef __builtin_va_list va_list;
|
|||||||
#define va_end(v) __builtin_va_end(v)
|
#define va_end(v) __builtin_va_end(v)
|
||||||
#define va_arg(v, l) __builtin_va_arg(v, l)
|
#define va_arg(v, l) __builtin_va_arg(v, l)
|
||||||
|
|
||||||
#define ALIGN_UP(x, align) ((__typeof__(x))(((uint64_t)(x) + ((align)-1)) & (~((align)-1))))
|
#define ALIGN_UP(x, align) ((__typeof__(x))(((uintptr_t)(x) + ((align)-1)) & (~((align)-1))))
|
||||||
#define ALIGN_DOWN(x, align) ((__typeof__(x))((x) & (~((align)-1))))
|
#define ALIGN_DOWN(x, align) ((__typeof__(x))((x) & (~((align)-1))))
|
||||||
|
|
||||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||||
@ -107,6 +107,7 @@ typedef __INT8_TYPE__ int8_t;
|
|||||||
typedef __INT16_TYPE__ int16_t;
|
typedef __INT16_TYPE__ int16_t;
|
||||||
typedef __INT32_TYPE__ int32_t;
|
typedef __INT32_TYPE__ int32_t;
|
||||||
typedef __INT64_TYPE__ int64_t;
|
typedef __INT64_TYPE__ int64_t;
|
||||||
|
|
||||||
typedef __UINT8_TYPE__ uint8_t;
|
typedef __UINT8_TYPE__ uint8_t;
|
||||||
typedef __UINT16_TYPE__ uint16_t;
|
typedef __UINT16_TYPE__ uint16_t;
|
||||||
typedef __UINT32_TYPE__ uint32_t;
|
typedef __UINT32_TYPE__ uint32_t;
|
||||||
@ -116,6 +117,7 @@ typedef __INT_LEAST8_TYPE__ int_least8_t;
|
|||||||
typedef __INT_LEAST16_TYPE__ int_least16_t;
|
typedef __INT_LEAST16_TYPE__ int_least16_t;
|
||||||
typedef __INT_LEAST32_TYPE__ int_least32_t;
|
typedef __INT_LEAST32_TYPE__ int_least32_t;
|
||||||
typedef __INT_LEAST64_TYPE__ int_least64_t;
|
typedef __INT_LEAST64_TYPE__ int_least64_t;
|
||||||
|
|
||||||
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
|
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
|
||||||
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
|
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
|
||||||
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
|
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
|
||||||
@ -125,6 +127,7 @@ typedef __INT_FAST8_TYPE__ int_fast8_t;
|
|||||||
typedef __INT_FAST16_TYPE__ int_fast16_t;
|
typedef __INT_FAST16_TYPE__ int_fast16_t;
|
||||||
typedef __INT_FAST32_TYPE__ int_fast32_t;
|
typedef __INT_FAST32_TYPE__ int_fast32_t;
|
||||||
typedef __INT_FAST64_TYPE__ int_fast64_t;
|
typedef __INT_FAST64_TYPE__ int_fast64_t;
|
||||||
|
|
||||||
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
|
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
|
||||||
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
|
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
|
||||||
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
|
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
|
||||||
@ -138,6 +141,11 @@ typedef __UINTMAX_TYPE__ uintmax_t;
|
|||||||
|
|
||||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||||
typedef __SIZE_TYPE__ size_t;
|
typedef __SIZE_TYPE__ size_t;
|
||||||
|
// typedef __WCHAR_TYPE__ wchar_t;
|
||||||
|
typedef __WINT_TYPE__ wint_t;
|
||||||
|
typedef __SIG_ATOMIC_TYPE__ sig_atomic_t;
|
||||||
|
// TODO: ssize_t
|
||||||
|
typedef intptr_t ssize_t;
|
||||||
|
|
||||||
#define INT8_MAX __INT8_MAX__
|
#define INT8_MAX __INT8_MAX__
|
||||||
#define INT8_MIN (-INT8_MAX - 1)
|
#define INT8_MIN (-INT8_MAX - 1)
|
||||||
|
@ -6,8 +6,8 @@ template <class T>
|
|||||||
class Vector
|
class Vector
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint64_t VectorSize = 0;
|
size_t VectorSize = 0;
|
||||||
uint64_t VectorCapacity = 0;
|
size_t VectorCapacity = 0;
|
||||||
T *VectorBuffer = nullptr;
|
T *VectorBuffer = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -23,7 +23,7 @@ public:
|
|||||||
VectorBuffer = 0;
|
VectorBuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function Vector(uint64_t Size)
|
__no_instrument_function Vector(size_t Size)
|
||||||
{
|
{
|
||||||
VectorCapacity = Size;
|
VectorCapacity = Size;
|
||||||
VectorSize = Size;
|
VectorSize = Size;
|
||||||
@ -33,7 +33,7 @@ public:
|
|||||||
VectorBuffer = new T[Size];
|
VectorBuffer = new T[Size];
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function Vector(uint64_t Size, const T &Initial)
|
__no_instrument_function Vector(size_t Size, const T &Initial)
|
||||||
{
|
{
|
||||||
VectorSize = Size;
|
VectorSize = Size;
|
||||||
VectorCapacity = Size;
|
VectorCapacity = Size;
|
||||||
@ -41,7 +41,7 @@ public:
|
|||||||
debug("VECTOR INIT: Vector( %lld %llx )", Size, Initial);
|
debug("VECTOR INIT: Vector( %lld %llx )", Size, Initial);
|
||||||
#endif
|
#endif
|
||||||
VectorBuffer = new T[Size];
|
VectorBuffer = new T[Size];
|
||||||
for (uint64_t i = 0; i < Size; i++)
|
for (size_t i = 0; i < Size; i++)
|
||||||
VectorBuffer[i] = Initial;
|
VectorBuffer[i] = Initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
debug("VECTOR INIT: Vector( <vector> )->Size: %lld", VectorSize);
|
debug("VECTOR INIT: Vector( <vector> )->Size: %lld", VectorSize);
|
||||||
#endif
|
#endif
|
||||||
VectorBuffer = new T[VectorSize];
|
VectorBuffer = new T[VectorSize];
|
||||||
for (uint64_t i = 0; i < VectorSize; i++)
|
for (size_t i = 0; i < VectorSize; i++)
|
||||||
VectorBuffer[i] = Vector.VectorBuffer[i];
|
VectorBuffer[i] = Vector.VectorBuffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,21 +65,21 @@ public:
|
|||||||
delete[] VectorBuffer;
|
delete[] VectorBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function void remove(uint64_t Position)
|
__no_instrument_function void remove(size_t Position)
|
||||||
{
|
{
|
||||||
if (Position >= VectorSize)
|
if (Position >= VectorSize)
|
||||||
return;
|
return;
|
||||||
memset(&*(VectorBuffer + Position), 0, sizeof(T));
|
memset(&*(VectorBuffer + Position), 0, sizeof(T));
|
||||||
for (uint64_t i = 0; i < VectorSize - 1; i++)
|
for (size_t i = 0; i < VectorSize - 1; i++)
|
||||||
{
|
{
|
||||||
*(VectorBuffer + Position + i) = *(VectorBuffer + Position + i + 1);
|
*(VectorBuffer + Position + i) = *(VectorBuffer + Position + i + 1);
|
||||||
}
|
}
|
||||||
VectorSize--;
|
VectorSize--;
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function uint64_t capacity() const { return VectorCapacity; }
|
__no_instrument_function size_t capacity() const { return VectorCapacity; }
|
||||||
|
|
||||||
__no_instrument_function uint64_t size() const { return VectorSize; }
|
__no_instrument_function size_t size() const { return VectorSize; }
|
||||||
|
|
||||||
__no_instrument_function bool empty() const;
|
__no_instrument_function bool empty() const;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (VectorSize <= 1)
|
if (VectorSize <= 1)
|
||||||
return;
|
return;
|
||||||
for (uint64_t i = 0, j = VectorSize - 1; i < j; i++, j--)
|
for (size_t i = 0, j = VectorSize - 1; i < j; i++, j--)
|
||||||
{
|
{
|
||||||
T c = *(VectorBuffer + i);
|
T c = *(VectorBuffer + i);
|
||||||
*(VectorBuffer + i) = *(VectorBuffer + j);
|
*(VectorBuffer + i) = *(VectorBuffer + j);
|
||||||
@ -112,7 +112,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function void reserve(uint64_t Capacity)
|
__no_instrument_function void reserve(size_t Capacity)
|
||||||
{
|
{
|
||||||
if (VectorBuffer == 0)
|
if (VectorBuffer == 0)
|
||||||
{
|
{
|
||||||
@ -122,25 +122,25 @@ public:
|
|||||||
#ifdef DEBUG_MEM_ALLOCATION
|
#ifdef DEBUG_MEM_ALLOCATION
|
||||||
debug("VECTOR ALLOCATION: reverse( %lld )", Capacity);
|
debug("VECTOR ALLOCATION: reverse( %lld )", Capacity);
|
||||||
#endif
|
#endif
|
||||||
T *Newbuffer = new T[Capacity];
|
T *NewBuffer = new T[Capacity];
|
||||||
uint64_t _Size = Capacity < VectorSize ? Capacity : VectorSize;
|
size_t _Size = Capacity < VectorSize ? Capacity : VectorSize;
|
||||||
for (uint64_t i = 0; i < _Size; i++)
|
for (size_t i = 0; i < _Size; i++)
|
||||||
Newbuffer[i] = VectorBuffer[i];
|
NewBuffer[i] = VectorBuffer[i];
|
||||||
VectorCapacity = Capacity;
|
VectorCapacity = Capacity;
|
||||||
#ifdef DEBUG_MEM_ALLOCATION
|
#ifdef DEBUG_MEM_ALLOCATION
|
||||||
debug("VECTOR ALLOCATION: reverse( <Capacity> )->Buffer:~%lld", VectorBuffer);
|
debug("VECTOR ALLOCATION: reverse( <Capacity> )->Buffer:~%lld", VectorBuffer);
|
||||||
#endif
|
#endif
|
||||||
delete[] VectorBuffer;
|
delete[] VectorBuffer;
|
||||||
VectorBuffer = Newbuffer;
|
VectorBuffer = NewBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function void resize(uint64_t Size)
|
__no_instrument_function void resize(size_t Size)
|
||||||
{
|
{
|
||||||
reserve(Size);
|
reserve(Size);
|
||||||
VectorSize = Size;
|
VectorSize = Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function T &operator[](uint64_t Index) { return VectorBuffer[Index]; }
|
__no_instrument_function T &operator[](size_t Index) { return VectorBuffer[Index]; }
|
||||||
|
|
||||||
__no_instrument_function Vector<T> &operator=(const Vector<T> &Vector)
|
__no_instrument_function Vector<T> &operator=(const Vector<T> &Vector)
|
||||||
{
|
{
|
||||||
@ -151,7 +151,7 @@ public:
|
|||||||
debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%lld", VectorSize);
|
debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%lld", VectorSize);
|
||||||
#endif
|
#endif
|
||||||
VectorBuffer = new T[VectorSize];
|
VectorBuffer = new T[VectorSize];
|
||||||
for (uint64_t i = 0; i < VectorSize; i++)
|
for (size_t i = 0; i < VectorSize; i++)
|
||||||
VectorBuffer[i] = Vector.VectorBuffer[i];
|
VectorBuffer[i] = Vector.VectorBuffer[i];
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user