Some cleanup

This commit is contained in:
Adrien Bourmault 2020-02-12 17:51:14 +01:00
parent 23362604f9
commit f1ae002ded
No known key found for this signature in database
GPG Key ID: AFEE5788AEE3F4EC
6 changed files with 31 additions and 17 deletions

View File

@ -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(),
VGA_COLOR_LIGHT_GREY,
regs->intNo,
"Unknown ISR Exception");
KeSendEOItoPIC(regs->intNo);

View File

@ -54,7 +54,7 @@ void DebugLog(const char *fmt, ...)
va_start(ap, fmt);
if (ticks) {
BPrintOnBuf(BStdDbg, "[%C%9d%C]\t",
BPrintOnBuf(BStdDbg, "[%C%8d%C]\t",
VGA_COLOR_LIGHT_BROWN,
ticks,
VGA_COLOR_LIGHT_GREY);

View File

@ -70,7 +70,8 @@ static void GetTimeFromRTC(void)
IoWriteByteOnPort(0x70, 0x32);
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 {
lastTime.sec = OriginTime.sec;
lastTime.min = OriginTime.min;
@ -212,7 +213,7 @@ void KeEnableRTC(void)
KeRestoreIRQs(flags);
KeEnableNMI();
srand(KeGetTimeStamp()); // Initializes the kernel number generator
srand(KeGetTimeStamp()); // init number generator
DebugLog("RTC interrupt frequency set to %d Hz\n",
32768 >> (RTC_RATE - 1));
}

View File

@ -158,7 +158,6 @@ bool MmIsBusyZone(void *start)
(ulong)start < ((ulong)memoryMap.entry[i].addr +
(ulong)memoryMap.entry[i].length)
) {
//KernLog("Non free because %d type : %p\n", memoryMap.entry[i].type, start);
return 1;
}
}

View File

@ -219,7 +219,8 @@ void MmInitPaging(void)
MmLoadPML4((void *)MmPageMapLevel4);
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 (void*)(((ulong)*page & 0xFFFFFFFFFF000)+ ((ulong)virtualAddr - (ulong)virtAddrPage));
return (void*)(((ulong)*page & 0xFFFFFFFFFF000)+
((ulong)virtualAddr - (ulong)virtAddrPage));
}
void *MmTransPhyToVirtAddr(void* physicalAddr)
@ -409,7 +411,8 @@ static void PagingHandler(ISRFrame_t *regs)
{
ulong StackGuardOne = (ulong)MmGetStackGuards(0);
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,
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Underflow\n\n"
" Page Fault Error code : %#x (%b)\n"
@ -420,7 +423,9 @@ static void PagingHandler(ISRFrame_t *regs)
regs->ErrorCode,
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,
"\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Stack Overflow\n\n"
" Page Fault Error code : %#x (%b)\n"
@ -455,7 +460,8 @@ static void PagingHandler(ISRFrame_t *regs)
);
} else {
//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)",
VGA_COLOR_LIGHT_RED,

View File

@ -40,7 +40,9 @@ enum
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 ulong MmPhysLastKernAddress;
@ -112,7 +114,8 @@ ulong MmGetTotalPageSize(void)
((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 *prevBusyPage = NULL;
@ -179,7 +182,8 @@ ulong MmAllocPageFrame(size_t size, bool contiguous)
DebugLog("Allocating %d pages (%u o)...\n", pageNumber, size);
// 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) {
busyLastAddr = isPageBusy(curPage);
@ -263,7 +267,8 @@ error_t MmMapPageFrame(ulong id, void *virtAddr, ulong flags)
busyPage = busyPage->next;
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)) {
return EADDRINUSE;
}
@ -290,7 +295,8 @@ error_t MmUnmapPageFrame(ulong id)
busyPage = busyPage->next;
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);
//DebugLog("Map %p at %p\n", addr, virtAddr);
if (actualPhys && id == busyPage->id) {