Some cleanup
This commit is contained in:
parent
23362604f9
commit
f1ae002ded
|
@ -332,8 +332,10 @@ void _KeHandleISR(ISRFrame_t *regs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bprintf(BStdDbg, "[%d]\tISR 0x%x %s\n",
|
bprintf(BStdDbg, "[%C%8d%C]\tISR 0x%x %s\n",
|
||||||
|
VGA_COLOR_BROWN,
|
||||||
KeGetTicks(),
|
KeGetTicks(),
|
||||||
|
VGA_COLOR_LIGHT_GREY,
|
||||||
regs->intNo,
|
regs->intNo,
|
||||||
"Unknown ISR Exception");
|
"Unknown ISR Exception");
|
||||||
KeSendEOItoPIC(regs->intNo);
|
KeSendEOItoPIC(regs->intNo);
|
||||||
|
|
|
@ -54,7 +54,7 @@ void DebugLog(const char *fmt, ...)
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
if (ticks) {
|
if (ticks) {
|
||||||
BPrintOnBuf(BStdDbg, "[%C%9d%C]\t",
|
BPrintOnBuf(BStdDbg, "[%C%8d%C]\t",
|
||||||
VGA_COLOR_LIGHT_BROWN,
|
VGA_COLOR_LIGHT_BROWN,
|
||||||
ticks,
|
ticks,
|
||||||
VGA_COLOR_LIGHT_GREY);
|
VGA_COLOR_LIGHT_GREY);
|
||||||
|
|
|
@ -70,7 +70,8 @@ static void GetTimeFromRTC(void)
|
||||||
IoWriteByteOnPort(0x70, 0x32);
|
IoWriteByteOnPort(0x70, 0x32);
|
||||||
OriginTime.century = IoReadByteFromPort(0x71);
|
OriginTime.century = IoReadByteFromPort(0x71);
|
||||||
|
|
||||||
// Now while we don't get the same value, read the registers (ensure data are valid)
|
// Now while we don't get the same value,
|
||||||
|
// read the registers (ensure data are valid)
|
||||||
do {
|
do {
|
||||||
lastTime.sec = OriginTime.sec;
|
lastTime.sec = OriginTime.sec;
|
||||||
lastTime.min = OriginTime.min;
|
lastTime.min = OriginTime.min;
|
||||||
|
@ -212,7 +213,7 @@ void KeEnableRTC(void)
|
||||||
KeRestoreIRQs(flags);
|
KeRestoreIRQs(flags);
|
||||||
KeEnableNMI();
|
KeEnableNMI();
|
||||||
|
|
||||||
srand(KeGetTimeStamp()); // Initializes the kernel number generator
|
srand(KeGetTimeStamp()); // init number generator
|
||||||
DebugLog("RTC interrupt frequency set to %d Hz\n",
|
DebugLog("RTC interrupt frequency set to %d Hz\n",
|
||||||
32768 >> (RTC_RATE - 1));
|
32768 >> (RTC_RATE - 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,6 @@ bool MmIsBusyZone(void *start)
|
||||||
(ulong)start < ((ulong)memoryMap.entry[i].addr +
|
(ulong)start < ((ulong)memoryMap.entry[i].addr +
|
||||||
(ulong)memoryMap.entry[i].length)
|
(ulong)memoryMap.entry[i].length)
|
||||||
) {
|
) {
|
||||||
//KernLog("Non free because %d type : %p\n", memoryMap.entry[i].type, start);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,8 @@ void MmInitPaging(void)
|
||||||
MmLoadPML4((void *)MmPageMapLevel4);
|
MmLoadPML4((void *)MmPageMapLevel4);
|
||||||
MmEnableWriteProtect();
|
MmEnableWriteProtect();
|
||||||
|
|
||||||
DebugLog("Page table size : %u MB\n", (lastDirectoryAddr - firstDirectoryAddr + phDirSize)/MB);
|
DebugLog("Page table size : %u MB\n",
|
||||||
|
(lastDirectoryAddr - firstDirectoryAddr + phDirSize)/MB);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -311,7 +312,8 @@ void *MmTransVirtToPhyAddr(void* virtualAddr)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (void*)(((ulong)*page & 0xFFFFFFFFFF000)+ ((ulong)virtualAddr - (ulong)virtAddrPage));
|
return (void*)(((ulong)*page & 0xFFFFFFFFFF000)+
|
||||||
|
((ulong)virtualAddr - (ulong)virtAddrPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *MmTransPhyToVirtAddr(void* physicalAddr)
|
void *MmTransPhyToVirtAddr(void* physicalAddr)
|
||||||
|
@ -409,7 +411,8 @@ static void PagingHandler(ISRFrame_t *regs)
|
||||||
{
|
{
|
||||||
ulong StackGuardOne = (ulong)MmGetStackGuards(0);
|
ulong StackGuardOne = (ulong)MmGetStackGuards(0);
|
||||||
ulong StackGuardTwo = (ulong)MmGetStackGuards(1);
|
ulong StackGuardTwo = (ulong)MmGetStackGuards(1);
|
||||||
if ((regs->cr2 >= StackGuardOne) && (regs->cr2 <= StackGuardOne + KPAGESIZE) && (regs->rsp <= regs->cr2)) {
|
if ((regs->cr2 >= StackGuardOne) && (regs->cr2 <= StackGuardOne + KPAGESIZE)
|
||||||
|
&& (regs->rsp <= regs->cr2)) {
|
||||||
bprintf(BStdOut,
|
bprintf(BStdOut,
|
||||||
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Underflow\n\n"
|
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Underflow\n\n"
|
||||||
" Page Fault Error code : %#x (%b)\n"
|
" Page Fault Error code : %#x (%b)\n"
|
||||||
|
@ -420,7 +423,9 @@ static void PagingHandler(ISRFrame_t *regs)
|
||||||
regs->ErrorCode,
|
regs->ErrorCode,
|
||||||
StackGuardOne
|
StackGuardOne
|
||||||
);
|
);
|
||||||
} else if ((regs->cr2 >= StackGuardTwo) && (regs->cr2 <= StackGuardTwo + KPAGESIZE) && (regs->rsp >= regs->cr2)) {
|
} else if ((regs->cr2 >= StackGuardTwo)
|
||||||
|
&& (regs->cr2 <= StackGuardTwo + KPAGESIZE)
|
||||||
|
&& (regs->rsp >= regs->cr2)) {
|
||||||
bprintf(BStdOut,
|
bprintf(BStdOut,
|
||||||
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Overflow\n\n"
|
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Overflow\n\n"
|
||||||
" Page Fault Error code : %#x (%b)\n"
|
" Page Fault Error code : %#x (%b)\n"
|
||||||
|
@ -455,7 +460,8 @@ static void PagingHandler(ISRFrame_t *regs)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//XXX page fault
|
//XXX page fault
|
||||||
bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x8] Irrecoverable Page Fault at %p\n\n"
|
bprintf(BStdOut,
|
||||||
|
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Page Fault at %p\n\n"
|
||||||
" Error code : 0x%x (%b)",
|
" Error code : 0x%x (%b)",
|
||||||
|
|
||||||
VGA_COLOR_LIGHT_RED,
|
VGA_COLOR_LIGHT_RED,
|
||||||
|
|
|
@ -40,7 +40,9 @@ enum
|
||||||
Whatever2 = 1UL << 62
|
Whatever2 = 1UL << 62
|
||||||
};
|
};
|
||||||
|
|
||||||
static AllocatedPage_t busyPagesList = { (void*)0, (void*)0, 0, (AllocatedPage_t*)0 };
|
static AllocatedPage_t busyPagesList =
|
||||||
|
{ (void*)0, (void*)0, 0, (AllocatedPage_t*)0 };
|
||||||
|
|
||||||
extern MemoryMap_t memoryMap;
|
extern MemoryMap_t memoryMap;
|
||||||
extern ulong MmPhysLastKernAddress;
|
extern ulong MmPhysLastKernAddress;
|
||||||
|
|
||||||
|
@ -112,7 +114,8 @@ ulong MmGetTotalPageSize(void)
|
||||||
((MmPhysLastKernAddress + KPAGESIZE) & 0xFFFFFFFFFF000));
|
((MmPhysLastKernAddress + KPAGESIZE) & 0xFFFFFFFFFF000));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addPageToBusyList(void *phyPageAddrBegin, void *phyPageAddrEnd, ulong id)
|
static void addPageToBusyList(void *phyPageAddrBegin,
|
||||||
|
void *phyPageAddrEnd, ulong id)
|
||||||
{
|
{
|
||||||
AllocatedPage_t *busyPage = &busyPagesList;
|
AllocatedPage_t *busyPage = &busyPagesList;
|
||||||
AllocatedPage_t *prevBusyPage = NULL;
|
AllocatedPage_t *prevBusyPage = NULL;
|
||||||
|
@ -179,7 +182,8 @@ ulong MmAllocPageFrame(size_t size, bool contiguous)
|
||||||
DebugLog("Allocating %d pages (%u o)...\n", pageNumber, size);
|
DebugLog("Allocating %d pages (%u o)...\n", pageNumber, size);
|
||||||
|
|
||||||
// Through the pages in physical memory...
|
// Through the pages in physical memory...
|
||||||
for (void *curPage = (void*)((MmPhysLastKernAddress + KPAGESIZE) & 0xFFFFFFFFFF000);
|
for (void *curPage =
|
||||||
|
(void*)((MmPhysLastKernAddress + KPAGESIZE) & 0xFFFFFFFFFF000);
|
||||||
curPage < (void*)(phRamSize & 0xFFFFFFFFFF000); curPage += KPAGESIZE) {
|
curPage < (void*)(phRamSize & 0xFFFFFFFFFF000); curPage += KPAGESIZE) {
|
||||||
busyLastAddr = isPageBusy(curPage);
|
busyLastAddr = isPageBusy(curPage);
|
||||||
|
|
||||||
|
@ -263,7 +267,8 @@ error_t MmMapPageFrame(ulong id, void *virtAddr, ulong flags)
|
||||||
busyPage = busyPage->next;
|
busyPage = busyPage->next;
|
||||||
|
|
||||||
if (id == busyPage->id) {
|
if (id == busyPage->id) {
|
||||||
for (void *addr = busyPage->phyAddressBegin; addr <= busyPage->phyAddressEnd; addr += KPAGESIZE) {
|
for (void *addr = busyPage->phyAddressBegin;
|
||||||
|
addr <= busyPage->phyAddressEnd; addr += KPAGESIZE) {
|
||||||
if (MmTransPhyToVirtAddr(addr)) {
|
if (MmTransPhyToVirtAddr(addr)) {
|
||||||
return EADDRINUSE;
|
return EADDRINUSE;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +295,8 @@ error_t MmUnmapPageFrame(ulong id)
|
||||||
busyPage = busyPage->next;
|
busyPage = busyPage->next;
|
||||||
|
|
||||||
if (id == busyPage->id) {
|
if (id == busyPage->id) {
|
||||||
for (void *addr = busyPage->phyAddressBegin; addr <= busyPage->phyAddressEnd; addr += KPAGESIZE) {
|
for (void *addr = busyPage->phyAddressBegin;
|
||||||
|
addr <= busyPage->phyAddressEnd; addr += KPAGESIZE) {
|
||||||
actualPhys = MmTransPhyToVirtAddr(addr);
|
actualPhys = MmTransPhyToVirtAddr(addr);
|
||||||
//DebugLog("Map %p at %p\n", addr, virtAddr);
|
//DebugLog("Map %p at %p\n", addr, virtAddr);
|
||||||
if (actualPhys && id == busyPage->id) {
|
if (actualPhys && id == busyPage->id) {
|
||||||
|
|
Loading…
Reference in New Issue