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

View File

@ -54,14 +54,14 @@ 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);
} else { } else {
BPrintOnBuf(BStdDbg, "[%C%s%C]\t", BPrintOnBuf(BStdDbg, "[%C%s%C]\t",
VGA_COLOR_GREEN, VGA_COLOR_GREEN,
" ok", " ok",
VGA_COLOR_LIGHT_GREY); VGA_COLOR_LIGHT_GREY);
} }

View File

@ -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));
} }

View File

@ -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;
} }
} }

View File

@ -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"
@ -443,7 +448,7 @@ static void PagingHandler(ISRFrame_t *regs)
); );
} else if (regs->cr2 >= MmVirtLastAddress || regs->cr2 <= 0) { } else if (regs->cr2 >= MmVirtLastAddress || regs->cr2 <= 0) {
bprintf(BStdOut, bprintf(BStdOut,
"\n\n%CPANIC\n[ISR 0x8] Out of bound of the address space at %p !\n\n" "\n\n%CPANIC\n[ISR 0x8] Out of bound of the address space at %p !\n\n"
" End of the address space : %p\n" " End of the address space : %p\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,

View File

@ -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) {