diff --git a/src/bin/shell/commands.c b/src/bin/shell/commands.c index 6b5101b..d6009d3 100644 --- a/src/bin/shell/commands.c +++ b/src/bin/shell/commands.c @@ -45,6 +45,7 @@ return(1); } else if (memcmp(data->args->arg,"stress", 6) == 0) { + //for (i=0x0;i<100;i++) { while (1) { printf("Starting Clock\n"); cPid = fork(); diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index d6f9ad0..65b2c10 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -58,10 +58,8 @@ pit_init, atkbd_init, time_init, - /* - net_init, - ne2k_init, - */ + /*net_init,*/ + /*ne2k_init, */ devfs_init, ubixfs_init, fdc_init, @@ -73,6 +71,9 @@ /*** $Log$ + Revision 1.21 2004/07/22 17:32:25 reddawg + I broke it hopefully + Revision 1.20 2004/07/21 23:05:05 reddawg last round of fixed main.c: removed kernel stack diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index 3571e8f..1bfecfa 100644 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -58,7 +58,7 @@ void *vmmGetPhysicalAddr(uInt32); void *vmmCreateVirtualSpace(pidType); void *vmmGetFreeVirtualPage(pidType,int); -void vmm_pageFault(uInt32); +void vmm_pageFault(uInt32,uInt32); void _vmm_pageFault(); extern uInt32 *kernelPageDirectory; @@ -67,6 +67,9 @@ /*** $Log$ + Revision 1.4 2004/07/24 20:00:51 reddawg + Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. + Revision 1.3 2004/07/22 17:32:25 reddawg I broke it hopefully diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index 82a1aac..68d3261 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -45,7 +45,7 @@ void endTask(pidType pid) { vmmFreeProcessPages(pid); if (_current->imageFd) - fclose(_current->imageFd); + fclose(_current->imageFd); kprintf("FreePage: [0x%X]\n",systemVitals->freePages); sched_setStatus(_current->id,DEAD); schedYield(); @@ -54,6 +54,18 @@ /*** $Log$ + Revision 1.9 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + Revision 1.8 2004/07/19 02:31:17 reddawg We do some propper task cleanup now when they exit... such as close open FD for LD and delete task from the task list diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 67ffcc4..f4b8103 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -291,7 +292,6 @@ elfSectionHeader *sectionHeader = 0x0; elfDynamic *elfDynamicS = 0x0; - tmpFd = fopen(file,"r"); _current->imageFd = tmpFd; @@ -307,8 +307,10 @@ } /* Load ELF Header */ - binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); - assert(binaryHeader); + + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + endTask(_current->id); + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ @@ -333,12 +335,16 @@ } /* Load The Program Header(s) */ - programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) + endTask(_current->id); + assert(programHeader); fseek(tmpFd,binaryHeader->ePhoff,0); fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); - sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + if ((sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum)) == 0x0) + endTask(_current->id); + assert(sectionHeader); fseek(tmpFd,binaryHeader->eShoff,0); fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd); @@ -397,6 +403,9 @@ /*** $Log$ + Revision 1.48 2004/07/22 19:27:36 reddawg + Did i forget to commit + Revision 1.47 2004/07/22 19:18:14 reddawg Fixed some pointer arithmatic which isn't causing any troubles marky mark who can't code rock hard diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 3ba4f2b..dfaadd0 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -87,10 +87,12 @@ ************************************************************************/ static void *getEmptyDesc() { int i = 0x0; - struct memDescriptor *tmpDesc = emptyKernDesc; + struct memDescriptor *tmpDesc = 0x0; spinLock(&emptyDescSpinLock); + tmpDesc = emptyKernDesc; + if (tmpDesc != 0x0) { emptyKernDesc = tmpDesc->next; emptyKernDesc->prev = 0x0; @@ -99,7 +101,7 @@ spinUnlock(&emptyDescSpinLock); return(tmpDesc); } - + kprintf("out of descriptors\n"); if ((emptyKernDesc = (struct memDescriptor *)vmmGetFreeKernelPage(sysID,4)) == 0x0) kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); @@ -194,7 +196,8 @@ return; //Loop The Free Descriptors See If We Can Merge Them - for (tmpDesc1=freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + mergeStart: + for (tmpDesc1=freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { /* Compare The Base Addr With The Other Descriptors If You Find The One That You Are Looking For Lets Merge Them @@ -226,7 +229,8 @@ tmpDesc1->next = 0x0; kprintf("mergememBlocks: [%i]\n",tmpDesc1->limit); insertFreeDesc(tmpDesc1); - tmpDesc1 = freeKernDesc; + //tmpDesc1 = freeKernDesc; + goto mergeStart; break; } } @@ -261,11 +265,11 @@ len = MALLOC_ALIGN(len); if (len == 0x0) { - kpanic("Malloc of Size 0 Requested\n"); spinUnlock(&mallocSpinLock); return(0x0); } - for (tmpDesc1 = freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + for (tmpDesc1 = freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { + assert(tmpDesc1); if (tmpDesc1->limit >= len) { if (tmpDesc1->prev != 0x0) { tmpDesc1->prev->next = tmpDesc1->next; @@ -288,7 +292,7 @@ tmpDesc2->next = 0x0; tmpDesc2->prev = 0x0; if (tmpDesc2->limit <= 0x0) - kprintf("kmalloc-1 tmpDesc2: [%i]\n",tmpDesc2->limit); + kprintf("kmalloc-1 tmpDesc2: [%i:%i:%i]\n",tmpDesc2->limit,tmpDesc1->limit,len); insertFreeDesc(tmpDesc2); } buf = (char *)tmpDesc1->baseAddr; @@ -305,8 +309,9 @@ tmpDesc1->limit = len; tmpDesc1->next = kernDesc; tmpDesc1->prev = 0x0; + kernDesc->prev = tmpDesc1; kernDesc = tmpDesc1; - kernDesc->next->prev = tmpDesc1; + if ((len%0x1000) > 0) { tmpDesc2 = getEmptyDesc(); assert(tmpDesc2); @@ -375,13 +380,25 @@ return; } } - kprintf("Error Freeing Descriptor! [0x%X]\n",baseAddr); + kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); spinUnlock(&mallocSpinLock); return; } /*** $Log$ + Revision 1.16 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + Revision 1.15 2004/07/20 23:20:50 reddawg kmalloc: forgot to remove an assert diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c index 1d854cd..de57b37 100644 --- a/src/sys/ubixfs/ubixfs.c +++ b/src/sys/ubixfs/ubixfs.c @@ -248,7 +248,7 @@ int i = 0x0; char *buffer = 0x0; struct ubixFSInfo *fsInfo = NULL; - struct cacheNode * cacheNode = NULL; + struct cacheNode *cacheNode = NULL; assert(fd); assert(fd->mp); @@ -265,7 +265,7 @@ for (i=0x0; i fd->size) { /* Set File EOF If There Is Nothing To Do */ - data[i] = '\0'; + /* data[i] = '\0'; Is this safe? */ fd->status = fdEof; return(size); } @@ -276,58 +276,6 @@ return(size); } -/************************************************************************ - -Function: int readUbixFS(fileDescriptor *fd,char *data,long offset,long size) -Description: Read File Into Data -Notes: - -************************************************************************/ -static int readUbixFS_old(fileDescriptor *fd,char *data,long offset,long size) { - int blockCount = 0x0; - int batIndex; - long i = 0x0; - struct ubixFSInfo *fsInfo = NULL; - - assert(fd); - assert(fd->mp); - assert(fd->mp->fsInfo); - - fsInfo = fd->mp->fsInfo; - batIndex = fd->start; - - blockCount = ((offset)/4096); - /* Find The Starting Block */ - for (i=1;i<=blockCount;i++) { - batIndex = fsInfo->blockAllocationTable[batIndex].nextBlock; - if (batIndex == 0x0) { - /* sysErr(log, "Invalid File Offset"); */ - return(0); - } - } - /* If The File Size Is Greater Then The Offset Lets Goto Work */ - fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); - for (i=0x0; i fd->size) { - /* Set File EOF If There Is Nothing To Do */ - data[i] = '\0'; - fd->status = fdEof; - return(size); - } - /* Copy Data From Buffer To Data */ - data[i] = fd->buffer[offset-(blockCount*4096)]; - offset++; - if (offset%4096 == 0 && offset != size) { - batIndex = fsInfo->blockAllocationTable[batIndex].nextBlock; - fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); - blockCount++; - } - } - /* Return */ - return(size); - } - - /************************************************************************ @@ -578,6 +526,11 @@ /*** $Log$ + Revision 1.33 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + Revision 1.32 2004/07/22 23:01:51 reddawg Ok checking in before I sleep diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c index 6b66d4c..5fdbca9 100644 --- a/src/sys/vmm/getfreepage.c +++ b/src/sys/vmm/getfreepage.c @@ -50,16 +50,16 @@ for (x = 768; x < 1024; x++) { /* Set Page Table Address */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * x)); + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); for (y = 0x0; y < 1024; y++) { /* Loop Through The Page Table Find An UnAllocated Page */ if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { /* Map A Physical Page To The Virtual Page */ - vmmRemapPage(vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + vmmRemapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000))); /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); /* Return The Address Of The Newly Allocate Page */ - return ((void *)((x * (1024 * 4096)) + (y * 4096))); + return ((void *)((x * 0x400000) + (y * 0x1000))); } } } @@ -69,6 +69,9 @@ /*** $Log$ + Revision 1.2 2004/07/20 22:29:55 reddawg + assert: remade assert + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg UbixOS v1.0 diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index 49c8414..adc36e5 100644 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -36,7 +36,8 @@ #include static uInt32 freePages = 0; -static spinLock_t vmmSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t vmmSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t vmmCowSpinLock = SPIN_LOCK_INITIALIZER; int numPages = 0x0; @@ -225,7 +226,7 @@ int freePage(uInt32 pageAddr) { int pageIndex = 0x0; - //spinLock(&vmmSpinLock); + spinLock(&vmmSpinLock); /* Find The Page Index To The Memory Map */ pageIndex = (pageAddr / 4096); @@ -242,7 +243,7 @@ /* Adjust The COW Counter */ adjustCowCounter(((uInt32) vmmMemoryMap[pageIndex].pageAddr), -1); } - //spinUnlock(&vmmSpinLock); + spinUnlock(&vmmSpinLock); /* Return */ return (0); } @@ -261,7 +262,7 @@ ************************************************************************/ int adjustCowCounter(uInt32 baseAddr, int adjustment) { int vmmMemoryMapIndex = (baseAddr / 4096); - //spinLock(&vmmSpinLock); + spinLock(&vmmCowSpinLock); /* Adjust COW Counter */ vmmMemoryMap[vmmMemoryMapIndex].cowCounter += adjustment; @@ -275,7 +276,7 @@ vmmMemoryMap[vmmMemoryMapIndex].pid = vmmID; freePages++; } - //spinUnlock(&vmmSpinLock); + spinUnlock(&vmmCowSpinLock); /* Return */ return (0); } @@ -295,7 +296,7 @@ int i=0,x=0; uInt32 *tmpPageTable = 0x0; uInt32 *tmpPageDir = (uInt32 *)parentPageDirAddr; - //spinLock(&vmmSpinLock); + spinLock(&vmmSpinLock); /* Check Page Directory For An Avail Page Table */ for (i=0;i<=0x300;i++) { if (tmpPageDir[i] != 0) { @@ -328,12 +329,15 @@ } } /* Return */ - //spinUnlock(&vmmSpinLock); + spinUnlock(&vmmSpinLock); return; } /*** $Log$ + Revision 1.8 2004/07/24 17:47:28 reddawg + vmm_pageFault: deadlock resolved thanks to a propper solution suggested by geist + Revision 1.7 2004/07/19 02:04:32 reddawg memory.c: added spinlocks to vmmFindFreePage and vmmFreePage to prevent two tasks from possibly allocating the same page diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index f5a1011..c026d97 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -47,7 +47,7 @@ A Paging System Also Start To Add Security Levels ************************************************************************/ -void vmm_pageFault(uInt32 memAddr) { +void vmm_pageFault(uInt32 memAddr,uInt32 eip) { uInt32 i = 0, pageTableIndex = 0,pageDirectoryIndex = 0; uInt32 *pageDir = 0x0,*pageTable = 0x0; uInt32 *src = 0x0,*dst = 0x0; @@ -55,21 +55,25 @@ spinLock(&pageFaultSpinLock); pageDir = (uInt32 *)parentPageDirAddr; + //Calculate The Page Directory Index - pageDirectoryIndex = (memAddr/(1024*4096)); + pageDirectoryIndex = (memAddr >> 22); + //Calculate The Page Table Index - pageTableIndex = ((memAddr-(pageDirectoryIndex*(1024*4096)))/4096); + pageTableIndex = ((memAddr >> 12) & 0x3FF); + if (pageDir[pageDirectoryIndex] == 0x0) { //Creat A Routine For Non Mapped Memory - kprintf("Segfault At Address: [0x%X][0x%X][%i], Not A Valid Page Table\n",memAddr,_current->tss.esp,_current->id); - while (1); + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X], Not A Valid Page Table\n",memAddr,_current->tss.esp,_current->id,eip); + spinUnlock(&pageFaultSpinLock); + endTask(_current->id); } else { //Set pageTable To Point To Virtual Address Of Page Table - pageTable = (uInt32 *)(tablesBaseAddress + (4096 * pageDirectoryIndex)); + pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); if (((uInt32)pageTable[pageTableIndex] & pageCow) == pageCow) { //Set Src To Base Address Of Page To Copy - src = (uInt32 *) ((1024*4096*pageDirectoryIndex) + (4096*pageTableIndex)); + src = memAddr & 0xFFFFF000; //Allocate A Free Page For Destination dst = (uInt32 *) vmmGetFreePage(_current->id); //Copy Memory @@ -87,11 +91,12 @@ kprintf("pageTable: [0x%X]\n",pageTable[pageTableIndex]); } else { - //Need To Create A Routine For Attempting To Access Non Mapped Memory - kprintf("Segfault At Address: [0x%X][0x%X][%i] Non Mapped\n",memAddr,_current->tss.esp,_current->id); - _current->state = DEAD; spinUnlock(&pageFaultSpinLock); - sched(); + //Need To Create A Routine For Attempting To Access Non Mapped Memory + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X] Non Mapped\n",memAddr,_current->tss.esp,_current->id,eip); + endTask(_current->id); + //_current->state = DEAD; + //sched(); } } asm volatile( @@ -100,44 +105,12 @@ ); spinUnlock(&pageFaultSpinLock); } - -/************************************************************************ - -Function: void _pageFault() -Description: This Is The ASM Code That Calls The pageFault() Function -Notes: - -************************************************************************/ -/* -asm( - ".global _vmmPageFault \n" - "_vmmPageFault: \n" - " xchgl %eax,(%esp) \n" - " movl 4(%esp),%eax \n" - " pushl %ecx \n" - " pushl %edx \n" - " push %ds \n" - " push %es \n" - " push %fs \n" - " pushl %eax \n" - "movl %cr2,%eax \n" - "sti \n" - "pushl %eax \n" - "call vmmPageFault \n" - "popl %eax \n" - "popl %eax \n" - "pop %fs \n" - "pop %es \n" - "pop %ds \n" - "popl %edx \n" - "popl %ecx \n" - "popl %eax \n" - "iret \n" - ); -*/ /*** $Log$ + Revision 1.5 2004/07/24 20:00:51 reddawg + Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. + Revision 1.4 2004/07/24 17:47:28 reddawg vmm_pageFault: deadlock resolved thanks to a propper solution suggested by geist