diff --git a/src/bin/login/main.c b/src/bin/login/main.c index f466e01..70d2e7f 100644 --- a/src/bin/login/main.c +++ b/src/bin/login/main.c @@ -74,17 +74,22 @@ } printf("Starting Login Daemon\n"); - + fd = fopen("sys:/userdb","r"); + if (fd->fd == 0x0) { + printf("file not foun!!!\n"); + while (1); + } +/* if (!(fd = fopen("sys:/userdb","r"))) { printf("Error Opening File"); memcpy(data[0].username,"root",4); memcpy(data[0].password,"user",4); memcpy(data[0].shell,"sys:/shell", 10); - } - else { - fread(data,4096,1,fd); - fclose(fd); - } + */ + + fread(data,4096,1,fd); + fclose(fd); + if ((data2 = (char *)malloc(384)) == 0x0) { printf("Malloc Failed\n"); exit(0x1); diff --git a/src/bin/shell/commands.c b/src/bin/shell/commands.c index a7c24d9..5a119b9 100644 --- a/src/bin/shell/commands.c +++ b/src/bin/shell/commands.c @@ -62,7 +62,6 @@ printf("Starting Clock\n"); cPid = fork(); if (cPid == 0x0) { - printf("Pid: [%i]\n",cPid); exec("clock",0x0,0x0); exit(0x1); } diff --git a/src/lib/libc_old/stdio/fopen.c b/src/lib/libc_old/stdio/fopen.c index e45efe0..6d472e5 100644 --- a/src/lib/libc_old/stdio/fopen.c +++ b/src/lib/libc_old/stdio/fopen.c @@ -32,7 +32,7 @@ FILE *fopen(const char *file,const char *mode) { FILE *fp = malloc(sizeof(FILE)); - fp->fd = -1; + fp->fd = 0x0; asm volatile( "int %0\n" : : "i" (0x80),"a" (8),"b" (file),"c" (mode),"d" (fp) @@ -42,6 +42,9 @@ /*** $Log$ + Revision 1.3 2004/06/17 15:16:02 reddawg + Made asm statements volatile + Revision 1.2 2004/06/16 19:38:26 reddawg Updated CW Cleaned Out Dead Code diff --git a/src/sys/include/vfs/file.h b/src/sys/include/vfs/file.h index 285f226..83c5f4f 100644 --- a/src/sys/include/vfs/file.h +++ b/src/sys/include/vfs/file.h @@ -44,8 +44,8 @@ uInt32 size; uInt16 length; uInt32 start; - uInt8 fileName[512]; - char *buffer; + char fileName[512]; + char *buffer; struct cacheNode *cacheNode; uInt32 perms; } fileDescriptor; diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index ac632a7..7b6afdf 100644 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -35,33 +35,35 @@ #define pageLength 0x00000400 #define pageSize 4096 #define pageEntries (pageSize/4) -#define pagePresent 0x00000001 -#define pageWrite 0x00000002 -#define pageUser 0x00000004 #define pageCow 0x00000200 -#define pageStack 0x00000400 -#define pageDefault (pagePresent|pageWrite|pageUser) -#define kernelPageDefault (pagePresent|pageWrite) -#define tablesBaseAddress 0xBFC00000 -#define parentPageDirAddr 0x100000 +#define tablesBaseAddress 0xBFC00000 +#define parentPageDirAddr 0x100000 -int vmmPagingInit(); +#define PAGE_STACK 0x00000400 +#define PAGE_PRESENT 0x00000001 +#define PAGE_WRITE 0x00000002 +#define PAGE_USER 0x00000004 +#define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER) +#define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE) + int vmmClearVirtualPage(uInt32 pageAddr); -int vmmRemapPage(const uInt32,const uInt32); + void vmmUnmapPage(uInt32,int); void vmmUnmapPages(void *,uInt32); -void vmmSetPageAttribute(uInt32,int); void *vmmMapFromTask(pidType,void *,uInt32); void *vmmCopyVirtualSpace(pidType); void *vmmGetFreePage(pidType); void *vmmGetFreeKernelPage(pidType pid,uInt16 count); -void *vmmGetPhysicalAddr(uInt32); void *vmmCreateVirtualSpace(pidType); void *vmmGetFreeVirtualPage(pidType,int); -void *vmm_getFreeMallocPage(uInt16 count); -void vmm_pageFault(uInt32,uInt32); -void _vmm_pageFault(); +uInt32 vmm_getPhysicalAddr(uInt32); +int vmm_setPageAttributes(uInt32,uInt16); +int vmm_remapPage(uInt32,uInt32,uInt16); +int vmm_pagingInit(); +void *vmm_getFreeMallocPage(uInt16 count); +void vmm_pageFault(uInt32,uInt32); +void _vmm_pageFault(); extern uInt32 *kernelPageDirectory; @@ -69,6 +71,9 @@ /*** $Log$ + Revision 1.6 2004/07/26 19:15:49 reddawg + test code, fixes and the like + Revision 1.5 2004/07/24 23:04:44 reddawg Changes... mark let me know if you fault at pid 185 when you type stress diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index 68d3261..a60eefe 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -46,7 +46,7 @@ vmmFreeProcessPages(pid); if (_current->imageFd) fclose(_current->imageFd); - kprintf("FreePage: [0x%X]\n",systemVitals->freePages); + //kprintf("FreePage: [0x%X]\n",systemVitals->freePages); sched_setStatus(_current->id,DEAD); schedYield(); return; @@ -54,6 +54,9 @@ /*** $Log$ + Revision 1.10 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + Revision 1.9 2004/07/21 10:02:09 reddawg devfs: renamed functions device system: renamed functions diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index f4c5ab4..ab14306 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -201,16 +201,22 @@ Allocate Memory Im Going To Have To Make This Load Memory With Correct Settings so it helps us in the future */ - for (x=0;x<=(programHeader[i].phMemsz+4095);x += 0x1000) { - if (vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)) == 0x0) { + for (x = 0x0;x < (programHeader[i].phMemsz+4095);x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) kpanic("Error: vmmFindFreePage Failed\n"); - } memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); /* Now Load Section To Memory */ fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0;x < (programHeader[i].phMemsz+4095);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n",__FILE__,__LINE__); + } + } } } @@ -218,16 +224,12 @@ _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); /* Task Stack 0x2000 bytes long */ - vmmRemapPage(vmmFindFreePage(_current->id),0x5DC000); - vmmSetPageAttribute(0x5DC000,(pageDefault | pageStack)); - vmmRemapPage(vmmFindFreePage(_current->id),0x5DB000); - vmmSetPageAttribute(0x5DB000,(pageDefault | pageStack)); + vmm_remapPage(vmmFindFreePage(_current->id),0x5DC000,PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmmFindFreePage(_current->id),0x5DB000,PAGE_DEFAULT | PAGE_STACK); /* Kernel Stack 0x2000 bytes long */ - vmmRemapPage(vmmFindFreePage(_current->id),0x5D1000); - vmmSetPageAttribute(0x5D1000,(pageDefault | pageStack)); - vmmRemapPage(vmmFindFreePage(_current->id),0x5D0000); - vmmSetPageAttribute(0x5D0000,(pageDefault | pageStack)); + vmm_remapPage(vmmFindFreePage(_current->id),0x5D1000,KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmmFindFreePage(_current->id),0x5D0000,KERNEL_PAGE_DEFAULT | PAGE_STACK); /* Set All The Proper Information For The Task */ _current->tss.back_link = 0x0; @@ -293,6 +295,8 @@ elfProgramHeader *programHeader = 0x0; elfSectionHeader *sectionHeader = 0x0; elfDynamic *elfDynamicS = 0x0; + + //tmp = (uInt32 *)0x5D1FA0; tmpFd = fopen(file,"r"); _current->imageFd = tmpFd; @@ -357,15 +361,22 @@ Allocate Memory Im Going To Have To Make This Load Memory With Correct Settings so it helps us in the future */ - for (x=0;x<(programHeader[i].phMemsz+4095);x+=0x1000) { - if ((vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x))) == 0x0) - kpanic("vmmRemapPage failed: exec-2\n"); + for (x=0;x<(programHeader[i].phMemsz+4095);x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + kpanic("Error: vmmFindFreePage Failed\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); /* Now Load Section To Memory */ fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0;x < (programHeader[i].phMemsz+4095);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n",__FILE__,__LINE__); + } + } } else if (programHeader[i].phType == 2) { //newLoc = (char *)programHeader[i].phVaddr; @@ -409,6 +420,9 @@ /*** $Log$ + Revision 1.54 2004/07/28 00:24:20 reddawg + removed debug code + Revision 1.53 2004/07/28 00:17:05 reddawg Major: Disconnected page 0x0 from the system... Unfortunately this broke many things diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c index 678b0b8..ea17d6b 100644 --- a/src/sys/kernel/file.c +++ b/src/sys/kernel/file.c @@ -137,7 +137,10 @@ Notes: ************************************************************************/ -void sysFopen(char *file,char *flags,userFileDescriptor *userFd) { +void sysFopen(const char *file,char *flags,userFileDescriptor *userFd) { + if (userFd == 0x0) + kpanic("Error: userFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + userFd->fd = fopen(file,flags); if (userFd->fd != 0x0) { userFd->fdSize = userFd->fd->size; @@ -269,6 +272,15 @@ /*** $Log$ + Revision 1.8 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.7 2004/07/05 23:06:32 reddawg Fixens diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c index cceabfc..03aee45 100644 --- a/src/sys/kernel/ld.c +++ b/src/sys/kernel/ld.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,8 @@ Settings so it helps us in the future */ for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { - if ((vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START))) == 0x0) + /* make r/w or ro */ + if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: ld\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); } @@ -162,6 +164,15 @@ /*** $Log$ + Revision 1.32 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.31 2004/07/22 19:32:42 reddawg absolute path diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index ae9c6b6..fdf0ee2 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -50,6 +50,7 @@ asm( ".globl _sysCallNew \n" "_sysCallNew: \n" + " pusha \n" " cmpl totalCalls,%eax \n" " jae invalidSysCallNew \n" " mov %esp,%ebx \n" @@ -61,6 +62,7 @@ "invalidSysCallNew: \n" " call invalidCall \n" "doneNew: \n" + " popa \n" " iret \n" ); @@ -205,6 +207,9 @@ /*** $Log$ + Revision 1.22 2004/07/21 21:03:03 reddawg + we now check all the pointers + Revision 1.21 2004/07/21 20:55:10 reddawg fixed invalidSyscall diff --git a/src/sys/lib/Makefile b/src/sys/lib/Makefile index 0f6f061..a3a1422 100644 --- a/src/sys/lib/Makefile +++ b/src/sys/lib/Makefile @@ -8,7 +8,7 @@ INCLUDES += -I../../lib/objgfx40/ # Objects -OBJS = assert.o ogprintf.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o +OBJS = memset.o assert.o ogprintf.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o all: $(OBJS) diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 5d449e6..7e43b00 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -83,7 +83,7 @@ spinUnlock(&emptyDescSpinLock); return(tmpDesc); } - kprintf("out of descriptors\n"); + if ((emptyKernDesc = (struct memDescriptor *)vmm_getFreeMallocPage(4)) == 0x0) kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); @@ -93,11 +93,14 @@ emptyKernDesc[0].next = &emptyKernDesc[1]; for (i = 0x1;i < ((0x4000/sizeof(struct memDescriptor)));i++) { - emptyKernDesc[i].next = &emptyKernDesc[i+1]; + if (i+1 < (0x4000/sizeof(struct memDescriptor))) + emptyKernDesc[i].next = &emptyKernDesc[i+1]; + else + emptyKernDesc[i].next = 0x0; emptyKernDesc[i].prev = &emptyKernDesc[i-1]; } - tmpDesc = emptyKernDesc; + tmpDesc = &emptyKernDesc[0]; emptyKernDesc = tmpDesc->next; emptyKernDesc->prev = 0x0; @@ -242,8 +245,8 @@ void *kmalloc(uInt32 len) { struct memDescriptor *tmpDesc1 = 0x0; struct memDescriptor *tmpDesc2 = 0x0; - char *buf = 0x0; - int i = 0x0; + char *buf = 0x0; + int i = 0x0; spinLock(&mallocSpinLock); @@ -301,11 +304,11 @@ usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; - if ((len%0x1000) > 0) { + if ((len%0x1000) > 0x0) { tmpDesc2 = getEmptyDesc(); assert(tmpDesc2); tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; - tmpDesc2->limit = ((len + 4095)/4096)*4096 - tmpDesc1->limit; + tmpDesc2->limit = ((len + 4095)/0x1000)*0x1000 - tmpDesc1->limit; tmpDesc2->prev = 0x0; tmpDesc2->next = 0x0; if (tmpDesc2->limit <= 0x0) @@ -358,7 +361,6 @@ tmpDesc1->next->prev = tmpDesc1->prev; - tmpDesc1->next = 0x0; tmpDesc1->prev = 0x0; @@ -378,6 +380,15 @@ /*** $Log$ + Revision 1.20 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.19 2004/07/26 19:15:49 reddawg test code, fixes and the like diff --git a/src/sys/lib/string.c b/src/sys/lib/string.c index 78da9cf..7f230c0 100644 --- a/src/sys/lib/string.c +++ b/src/sys/lib/string.c @@ -84,21 +84,6 @@ } -void *memset(void * dst, int c, size_t length) { - size_t x = length >> 2; - size_t y = length & 0xf; - size_t i; - - unsigned int newC = (c << 24) | (c << 16) | (c << 8) | (c); - - for (i = 0; i < x; i++) - ((unsigned long *)dst)[i] = newC; - - for (i = 0; i < y; i++) - ((char *) dst)[length-y+i] = c; - return dst; - } - int strlen(const char * string) { int i = 0; @@ -168,6 +153,10 @@ /*** $Log$ + Revision 1.5 2004/07/20 18:42:41 flameshadow + add: strcpy() + chg: modified dirCache.c to use strcpy() + Revision 1.4 2004/07/05 23:06:32 reddawg Fixens diff --git a/src/sys/sde/ogDisplay_UbixOS.cc b/src/sys/sde/ogDisplay_UbixOS.cc index 453e382..5b3c519 100755 --- a/src/sys/sde/ogDisplay_UbixOS.cc +++ b/src/sys/sde/ogDisplay_UbixOS.cc @@ -24,6 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Log$ + Revision 1.2 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg UbixOS v1.0 @@ -47,6 +50,7 @@ #include #include #include + #include } /* @@ -184,8 +188,8 @@ printOff = 0; for (i = 0x0; i < ((size)/4096); i++) { - vmmRemapPage(modeInfo->physBasePtr + (i * 0x1000), - modeInfo->physBasePtr + (i * 0x1000)); + if ((vmm_remapPage(modeInfo->physBasePtr + (i * 0x1000),modeInfo->physBasePtr + (i * 0x1000),KERNEL_PAGE_DEFAULT)) == 0x0) + kpanic("Error: vmm_remapPage failed\n"); } // for i owner = this; diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index e5b3975..7d94ceb 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -91,15 +91,17 @@ setVector(_int5, 5, dPresent + dInt + dDpl3); setVector(_int6, 6, dPresent + dInt + dDpl3); setVector(_int7,7,dPresent + dInt + dDpl3); + //setVector(_int8,8,dPresent + dInt + dDpl3); + setTaskVector(8,dPresent + dTask + dDpl3, 0x38); setVector(_int9, 9, dPresent + dInt + dDpl3); setVector(_int10, 10, dPresent + dInt + dDpl3); setVector(_int11, 11, dPresent + dInt + dDpl3); setVector(_int12, 12, dPresent + dInt + dDpl3); setTaskVector(13, dPresent + dTask + dDpl3, 0x38); - setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl3); + setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); setVector(_sysCall, 128, dPresent + dTrap + dDpl3); setVector(_sysCallNew, 0x90, dPresent + dTrap + dDpl3); - setVector(timerInt, 0x68, (dInt + dPresent + dDpl3)); + setVector(timerInt, 0x68, (dInt + dPresent + dDpl0)); gpfTSS->back_link = 0x0; @@ -219,7 +221,6 @@ void _int8() { kprintf("int8: Double Fault! [%i]\n",_current->id); endTask(_current->id); - schedYield(); } void _int9() { @@ -255,7 +256,32 @@ uInt8 *ip = 0x0; uInt16 *stack = 0x0, *ivt = 0x0; uInt32 *stack32 = 0x0; + uInt32 memAddr = 0x0; bool isOperand32 = FALSE, isAddress32 = FALSE; + + + /* UBU */ + uInt32 *pageDir = 0x0,*pageTable = 0x0; + uInt32 i = 0, pageTableIndex = 0,pageDirectoryIndex = 0; + + asm( + "movl %%cr2,%0\n" + : "=g" (memAddr) + ); + + pageDir = parentPageDirAddr; + //Calculate The Page Directory Index + pageDirectoryIndex = (memAddr >> 22); + + //Calculate The Page Table Index + pageTableIndex = ((memAddr >> 12) & 0x3FF); + + pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + asm("cli"); + + kprintf("Page Table Addr: [0x%X]\n",pageDir[pageDirectoryIndex]); + kpanic("gpf [%i][0x%X][0x%X][0x%X][0x%X]\n",_current->id,_current->tss.eip,_current->tss.esp,_current->tss.esp0,memAddr); + endTask(_current->id); irqDisable(0x0); @@ -429,6 +455,15 @@ /*** $Log$ + Revision 1.22 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.21 2004/07/25 05:32:58 reddawg fixed diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index 3fda578..a63f4bb 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -163,42 +163,46 @@ int i = 0; fileDescriptor *tmpFd = 0x0; char *path = 0x0,*mountPoint = 0x0; - /* Allocate Memory For File Descriptor */ - tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor)); + /* Allocate Memory For File Descriptor */ + if ((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { + kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + } path = tmpFd->fileName; + if (strstr(file,":")) { - mountPoint = (char *)strtok((char *)file,":"); - sprintf(path,strtok(NULL,"\n")); + sprintf(tmpFd->fileName,file); + mountPoint = (char *)strtok((char *)tmpFd->fileName,":"); + path = strtok(NULL,"\n"); } else { - if (file[0] == '/') - sprintf(path,file); - else - sprintf(path,"/%s",file); + if (file[0] == '/') { + sprintf(tmpFd->fileName,file); + } + else { + sprintf(tmpFd->fileName,"/%s",file); + } } i = strlen(path); if (i > 2) { if (path[i-1] == '/') path[i-1] = '\0'; - } - i = 0; + } if (mountPoint == 0x0) { - tmpFd->mp = vfs_findMount("sys"); /* _current->oInfo.container; */ + tmpFd->mp = vfs_findMount("sys"); } else { tmpFd->mp = vfs_findMount(mountPoint); } if (tmpFd->mp == 0x0) { - //kpanic("Mount Point Bad"); kprintf("Mount Point Bad\n"); return(0x0); } /* This Will Set Up The Descriptor Modes */ tmpFd->mode = 0x0; - while ('\0' != flags[i]) { + for (i = 0x0;'\0' != flags[i];i++) { switch(flags[i]) { case 'w': case 'W': @@ -219,7 +223,6 @@ default: break; } - i++; } /* Search For The File */ @@ -256,12 +259,16 @@ /* If The File Was Not Found Free The Memory */ kfree(tmpFd); } + /* Return NULL */ return(0x0); } /*** $Log$ + Revision 1.15 2004/07/27 19:24:31 flameshadow + chg: reduced the number of debugging statements in the kernel. + Revision 1.14 2004/07/27 04:05:20 flameshadow chg: kinda fixed it. Added bunches of debug info diff --git a/src/sys/vmm/copyvirtualspace.c b/src/sys/vmm/copyvirtualspace.c index 023f9e4..2c4b6fd 100644 --- a/src/sys/vmm/copyvirtualspace.c +++ b/src/sys/vmm/copyvirtualspace.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include static spinLock_t cvsSpinLock = SPIN_LOCK_INITIALIZER; @@ -61,17 +63,20 @@ /* Set Address Of Parent Page Directory */ parentPageDirectory = (uInt32 *) parentPageDirAddr; /* Allocate A New Page For The New Page Directory */ - newPageDirectory = (uInt32 *) vmmGetFreeKernelPage(pid,1); + if ((newPageDirectory = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ - newPageDirectoryAddress = vmmGetPhysicalAddr((uInt32) newPageDirectory); + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); + /* First Set Up A Flushed Page Directory */ - for (x = 0x0; x < pageEntries; x++) { - newPageDirectory[x] = (uInt32) 0x0; - } + memset(newPageDirectory,0x0,0x1000); + /* Map The Top 1GB Region Of The VM Space */ for (x = 768; x < pageEntries; x++) { newPageDirectory[x] = parentPageDirectory[x]; - } + } + /* * Now For The Fun Stuff For Page Tables 1-766 We Must Map These And Set * The Permissions On Every Mapped Pages To COW This Will Conserve Memory @@ -81,30 +86,36 @@ /* If Page Table Exists Map It */ if (parentPageDirectory[x] != 0) { /* Set Parent To Propper Page Table */ - parentPageTable = (uInt32 *) (tablesBaseAddress + (4096 * x)); + parentPageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); /* Allocate A New Page Table */ - newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1); + if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* Set Parent And New Pages To COW */ for (i = 0; i < pageEntries; i++) { + /* If Page Is Mapped */ - if (parentPageTable[i] != 0x0) { + if ((parentPageTable[i] & 0xFFFFF000) != 0x0) { /* Check To See If Its A Stack Page */ - if (((uInt32) parentPageTable[i] & pageStack) == pageStack) { + if (((uInt32) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { /* Alloc A New Page For This Stack Page */ - newStackPage = (uInt32 *) vmmGetFreeKernelPage(pid,1); + if ((newStackPage = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* Set Pointer To Parents Stack Page */ parentStackPage = (uInt32 *) (((1024 * 4096) * x) + (4096 * i)); + /* Copy The Tack Byte For Byte (I Should Find A Faster Way) */ - for (s = 0; s < pageEntries; s++) { + for (s = 0x0; s < pageEntries; s++) { newStackPage[s] = parentStackPage[s]; - } + } /* Insert New Stack Into Page Table */ - newPageTable[i] = ((uInt32) vmmGetPhysicalAddr((uInt32) newStackPage) | pageDefault | pageStack); + newPageTable[i] = (vmm_getPhysicalAddr((uInt32) newStackPage) | PAGE_DEFAULT | PAGE_STACK); /* Unmap From Kernel Space */ vmmUnmapPage((uInt32) newStackPage, 1); } else { /* Set Page To COW In Parent And Child Space */ - newPageTable[i] = (((uInt32) parentPageTable[i] & 0xFFFFF000) | (pagePresent | pageCow)); + newPageTable[i] = (((uInt32) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | pageCow)); /* Increment The COW Counter For This Page */ if (((uInt32) parentPageTable[i] & pageCow) == pageCow) { adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 1); @@ -118,7 +129,7 @@ } } /* Put New Page Table Into New Page Directory */ - newPageDirectory[x] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + newPageDirectory[x] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ vmmUnmapPage((uInt32) newPageTable, 1); } else { @@ -129,13 +140,14 @@ * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region */ - newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1); + if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* Flush The Page From Garbage In Memory */ - for (x = 0; x < pageEntries; x++) { - newPageTable[x] = (uInt32) 0x0; - } + memset(newPageTable,0x0,0x1000); + /* Map This Into The Page Directory */ - newPageDirectory[0] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ parentPageTable = (uInt32 *) tablesBaseAddress; /* Map The First 1MB Worth Of Pages */ @@ -145,9 +157,9 @@ /* Map The Next 3MB Worth Of Pages But Make Them COW */ for (x = (pageEntries / 4) + 1; x < pageEntries; x++) { /* If Page Is Avaiable Map It */ - if (parentPageTable[x] != 0) { + if ((parentPageTable[x] & 0xFFFFF000) != 0x0) { /* Set Pages To COW */ - newPageTable[x] = (((uInt32) parentPageTable[x] & 0xFFFFF000) | (pagePresent | pageCow)); + newPageTable[x] = (((uInt32) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | pageCow)); /* Increment The COW Counter For This Page */ if (((uInt32) parentPageTable[x] & pageCow) == pageCow) { adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 1); @@ -160,7 +172,7 @@ } } /* Set Virtual Mapping For Page Directory */ - newPageTable[256] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageDirectory) | pageDefault); + newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); /* * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have @@ -170,9 +182,10 @@ /* First Lets Unmap The Previously Allocated Page Table */ vmmUnmapPage((uInt32) newPageTable, 1); /* Allocate A New Page Table */ - newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1); + if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* First Set Our Page Directory To Contain This */ - newPageDirectory[767] = (uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault; + newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; /* Now Lets Build The Page Table */ for (x = 0; x < pageEntries; x++) { newPageTable[x] = newPageDirectory[x]; @@ -190,6 +203,9 @@ /*** $Log$ + Revision 1.6 2004/07/26 19:15:49 reddawg + test code, fixes and the like + Revision 1.5 2004/07/25 06:04:00 reddawg Last of my fixes for the morning diff --git a/src/sys/vmm/createvirtualspace.c b/src/sys/vmm/createvirtualspace.c index 8a282cb..76b5876 100644 --- a/src/sys/vmm/createvirtualspace.c +++ b/src/sys/vmm/createvirtualspace.c @@ -24,6 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Log$ + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + Revision 1.8 2004/04/13 16:36:34 reddawg Changed our copyright, it is all now under a BSD-Style license @@ -72,7 +75,7 @@ /* Allocate A New Page For The New Page Directory */ newPageDirectory = (uInt32 *) vmmGetFreePage(pid); /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ - newPageDirectoryAddress = vmmGetPhysicalAddr((uInt32) newPageDirectory); + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); /* First Set Up A Flushed Page Directory */ for (x = 0; x < pageEntries; x++) { (uInt32) newPageDirectory[x] = (uInt32) 0x0; @@ -91,7 +94,7 @@ (uInt32) newPageTable[x] = (uInt32) 0x0; } /* Map This Into The Page Directory */ - newPageDirectory[0] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ parentPageTable = (uInt32 *) tablesBaseAddress; /* Map The First 1MB Worth Of Pages */ @@ -99,7 +102,7 @@ newPageTable[x] = parentPageTable[x]; } /* Set Virtual Mapping For Page Directory */ - newPageTable[256] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageDirectory) | pageDefault); + newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); /* * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have @@ -111,7 +114,7 @@ /* Allocate A New Page Table */ newPageTable = (uInt32 *) vmmGetFreePage(pid); /* First Set Our Page Directory To Contain This */ - newPageDirectory[767] = (uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault; + newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; /* Now Lets Build The Page Table */ for (x = 0; x < pageEntries; x++) { newPageTable[x] = newPageDirectory[x]; diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c index 0626887..b3ded2c 100644 --- a/src/sys/vmm/getfreepage.c +++ b/src/sys/vmm/getfreepage.c @@ -28,6 +28,7 @@ *****************************************************************************************/ #include +#include /************************************************************************ @@ -55,7 +56,7 @@ /* Loop Through The Page Table Find An UnAllocated Page */ if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { /* Map A Physical Page To The Virtual Page */ - if ((vmmRemapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)))) == 0x0) + if ((vmm_remapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: vmmGetFreePage\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); @@ -70,6 +71,15 @@ /*** $Log$ + Revision 1.4 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.3 2004/07/24 23:04:44 reddawg Changes... mark let me know if you fault at pid 185 when you type stress diff --git a/src/sys/vmm/getfreevirtualpage.c b/src/sys/vmm/getfreevirtualpage.c index 02a99cd..fc6f799 100644 --- a/src/sys/vmm/getfreevirtualpage.c +++ b/src/sys/vmm/getfreevirtualpage.c @@ -29,6 +29,7 @@ #include #include +#include #include static spinLock_t fvpSpinLock = SPIN_LOCK_INITIALIZER; @@ -58,9 +59,9 @@ kpanic("Invalid vmStart\n"); for (x = (_current->oInfo.vmStart / (1024 * 4096)); x < 1024; x++) { /* Set Page Table Address */ - if ((pageDir[x] & pagePresent) != pagePresent) { + if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { /* If Page Table Is Non Existant Then Set It Up */ - pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | pageDefault; + pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; /* Also Add It To Virtual Space So We Can Make Changes Later */ pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); pageTableSrc[x] = pageDir[x]; @@ -81,15 +82,17 @@ /* Loop Through The Page Table Find An UnAllocated Page */ if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { if (count > 0x1) { - for (c = 0; c < count; c++) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { - c = -1; - break; - } - } + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } if (c != -1) { for (c = 0; c < count; c++) { - if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)))) == 0x0) + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } @@ -103,7 +106,7 @@ * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) * ,pid); */ - if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)))) == 0x0) + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); @@ -121,6 +124,15 @@ /*** $Log$ + Revision 1.3 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.2 2004/07/24 23:21:25 reddawg ok last of my commits for the night I'm going to bed diff --git a/src/sys/vmm/getphysicaladdr.c b/src/sys/vmm/getphysicaladdr.c index b2c4393..f7759e2 100644 --- a/src/sys/vmm/getphysicaladdr.c +++ b/src/sys/vmm/getphysicaladdr.c @@ -35,7 +35,7 @@ Notes: ************************************************************************/ -void *vmmGetPhysicalAddr(uInt32 pageAddr) { +uInt32 vmm_getPhysicalAddr(uInt32 pageAddr) { int pageDirectoryIndex = 0x0, pageTableIndex = 0x0; uInt32 *pageTable = 0x0; @@ -48,11 +48,14 @@ /* Set pageTable To The Virtual Address Of Table */ pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); /* Return The Physical Address Of The Page */ - return ((void *)(pageTable[pageTableIndex] & 0xFFFFF000)); + return ((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); } /*** $Log$ + Revision 1.3 2004/07/26 19:15:49 reddawg + test code, fixes and the like + Revision 1.2 2004/06/16 12:52:51 reddawg Fixed bug with & diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index 9e65d87..2d17938 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -78,7 +78,7 @@ pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); if (((uInt32)pageTable[pageTableIndex] & pageCow) == pageCow) { //Set Src To Base Address Of Page To Copy - src = memAddr & 0xFFFFF000; + src = (uInt32 *)(memAddr & 0xFFFFF000); //Allocate A Free Page For Destination dst = (uInt32 *) vmmGetFreeVirtualPage(_current->id,1); //Copy Memory @@ -88,11 +88,12 @@ //Adjust The COW Counter For Physical Page adjustCowCounter(((uInt32)pageTable[pageTableIndex] & 0xFFFFF000),-1); //Remap In New Page - pageTable[pageTableIndex] = (uInt32)((uInt32)vmmGetPhysicalAddr((uInt32)dst)|pageDefault); + pageTable[pageTableIndex] = (uInt32)(vmm_getPhysicalAddr((uInt32)dst)|(memAddr & 0xFFF)); //Unlink From Memory Map Allocated Page vmmUnmapPage((uInt32)dst,1); } else if (pageTable[pageTableIndex] != 0x0) { + kprintf("Security failed pagetable not user permission\n"); kprintf("pageTable: [0x%X:0x%X:0x%X:0x%X]\n",pageTable[pageTableIndex],pageTableIndex,pageDirectoryIndex,eip); kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X] Non Mapped\n",memAddr,_current->tss.esp,_current->id,eip); spinUnlock(&pageFaultSpinLock); @@ -119,6 +120,9 @@ /*** $Log$ + Revision 1.10 2004/07/28 00:22:56 reddawg + bah + Revision 1.9 2004/07/28 00:17:05 reddawg Major: Disconnected page 0x0 from the system... Unfortunately this broke many things diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 4a7f82f..12203f3 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -34,6 +34,7 @@ #include #include #include +#include #include uInt32 *kernelPageDirectory = 0x0; @@ -43,22 +44,20 @@ static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; -/************************************************************************ +/***************************************************************************************** + Function: int vmm_pagingInit(); -Function: int vmmPagingInit() -Description: This Function Will Initialize The Operating Systems Paging + Description: This Function Will Initialize The Operating Systems Paging Abilities. -Notes: + Notes: + 02/20/2004 - Looked Over Code And Have Approved Its Quality + 07/28/3004 - All pages are set for ring-0 only no more user accessable -02/20/2004 - Looked Over Code And Have Approved Its Quality +*****************************************************************************************/ -************************************************************************/ - -int -vmmPagingInit() -{ - uInt32 i = 0x0, x = 0x0; +int vmm_pagingInit(){ + uInt32 i = 0x0; uInt32 *pageTable = 0x0; /* Allocate A Page Of Memory For Kernels Page Directory */ @@ -66,78 +65,77 @@ if (kernelPageDirectory == 0x0) { kpanic("Error: vmmFindFreePage Failed"); return (0x1); - } + } /* end if */ + /* Clear The Memory To Ensure There Is No Garbage */ for (i = 0; i < pageEntries; i++) { (uInt32) kernelPageDirectory[i] = (uInt32) 0x0; - } - /* Allocate A Page For The First 4MB Of Memory */ - pageTable = (uInt32 *) vmmFindFreePage(sysID); - if (pageTable == 0x0) { + } /* end for */ + + /* Allocate a page for the first 4MB of memory */ + if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) kpanic("Error: vmmFindFreePage Failed"); - return (0x1); - } - kernelPageDirectory[0] = (uInt32) ((uInt32) (pageTable) | pagePresent | pageWrite | pageUser); + kernelPageDirectory[0] = (uInt32) ((uInt32) (pageTable) | KERNEL_PAGE_DEFAULT); + /* Make Sure The Page Table Is Clean */ - for (i = 0; i < pageEntries; i++) { - (uInt32) pageTable[i] = (uInt32) 0x0; - } - /* Map The First 1MB Of Memory To The Kernel VM Space */ - /* pageTable[0] = (uInt32) (0x0 | pagePresent | pageUser); */ - for (i = 1; i < (pageEntries / 4); i++) { - pageTable[i] = (uInt32) ((i * 0x1000) | pagePresent | pageWrite | pageUser); - } + memset(pageTable,0x0,0x1000); + + /* + * Map the first 1MB of Memory to the kernel MM space because our kernel starts + * at 0x30000 + * Do not map page at address 0x0 this is reserved for null... + */ + for (i = 0x1; i < (pageEntries / 0x4); i++) { + pageTable[i] = (uInt32) ((i * 0x1000) | KERNEL_PAGE_DEFAULT); + } /* end for */ /* - * Create Page Tables For The Top 1GB Of VM Space This Is To Be Shared With - * All VM Spaces + * Create page tables for the top 1GB of VM space. This space is set aside + * for kernel space and will be shared with each process */ for (i = 768; i < pageEntries; i++) { - pageTable = (uInt32 *) vmmFindFreePage(sysID); - if (pageTable == 0x0) { + if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) kpanic("Error: vmmFindFreePage Failed"); - return (0x1); - } + /* Make Sure The Page Table Is Clean */ - for (x = 0; x < pageEntries; x++) { - (uInt32) pageTable[x] = (uInt32) 0x0; - } + memset(pageTable,0x0,0x1000); + /* Map In The Page Directory */ - kernelPageDirectory[i] = (uInt32) ((uInt32) (pageTable) | pagePresent | pageWrite); - } + kernelPageDirectory[i] = (uInt32) ((uInt32) (pageTable) | KERNEL_PAGE_DEFAULT); + } /* end for */ + /* Set Up Memory To Be All The Allocated Page Directories */ - pageTable = (uInt32 *) vmmFindFreePage(sysID); - if (pageTable == 0x0) { + if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) kpanic("Error: vmmFindFreePage Failed"); - return (0x1); - } + /* Clean Page Table */ - for (x = 0; x < pageEntries; x++) { - (uInt32) pageTable[x] = (uInt32) 0x0; - } - kernelPageDirectory[767] = ((uInt32) pageTable | pagePresent | pageWrite); + memset(pageTable,0x0,0x1000); + + kernelPageDirectory[767] = ((uInt32) pageTable | KERNEL_PAGE_DEFAULT); for (i = 0; i < pageEntries; i++) { pageTable[i] = kernelPageDirectory[i]; - } + } /* end for */ + /* Also Set Up Page Directory To Be The The First Page In 0xE0400000 */ pageTable = (uInt32 *) (kernelPageDirectory[0] & 0xFFFFF000); - pageTable[256] = (uInt32) ((uInt32) (kernelPageDirectory) | pagePresent | pageWrite); + pageTable[256] = (uInt32) ((uInt32) (kernelPageDirectory) | KERNEL_PAGE_DEFAULT); /* Now Lets Turn On Paging With This Initial Page Table */ asm volatile( - "movl %0,%%eax \n" - "movl %%eax,%%cr3 \n" - "movl %%cr0,%%eax \n" - "orl $0x80010000,%%eax \n" /* Flags To Enable Paging With - * Protection */ - "movl %%eax,%%cr0 \n" -: : "d"((uInt32 *) (kernelPageDirectory)) + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + "movl %%cr0,%%eax \n" + "orl $0x80010000,%%eax \n" /* Turn on memory protection */ + "movl %%eax,%%cr0 \n" + : + : "d"((uInt32 *) (kernelPageDirectory)) ); /* Remap The Memory List */ for (i = 0x101000; i <= (0x101000 + (numPages * sizeof(mMap))); i += 0x1000) { - vmmRemapPage(i, (vmmMemoryMapAddr + (i - 0x101000))); - } + if ((vmm_remapPage(i, (vmmMemoryMapAddr + (i - 0x101000)),KERNEL_PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage failed\n"); + } /* Set New Address For Memory Map Since Its Relocation */ vmmMemoryMap = (mMap *) vmmMemoryMapAddr; @@ -146,51 +144,56 @@ /* Return so we know everything went well */ return (0x0); -} + } /* END */ -/************************************************************************ +/***************************************************************************************** + Function: int vmmRemapPage(Physical Source,Virtual Destination) + + Description: This Function Will Remap A Physical Page Into Virtual Space + + Notes: + 07/29/02 - Rewrote This To Work With Our New Paging System + 07/30/02 - Changed Address Of Page Tables And Page Directory + 07/28/04 - If perms == 0x0 set to PAGE_DEFAULT -Function: int vmmRemapPage(Physical Source,Virtual Destination) -Description: This Function Will Remap A Physical Page Into Virtual Space -Notes: - -07/29/02 - Rewrote This To Work With Our New Paging System - -07/30/02 - Changed Address Of Page Tables And Page Directory - -************************************************************************/ -int -vmmRemapPage(const uInt32 source,const uInt32 dest) +*****************************************************************************************/ +int vmm_remapPage(uInt32 source,uInt32 dest,uInt16 perms) { - uInt16 destPageDirectoryIndex = 0, destPageTableIndex = 0; + uInt16 destPageDirectoryIndex = 0x0, destPageTableIndex = 0x0; uInt32 *pageDir = 0x0, *pageTable = 0x0; short i = 0x0; spinLock(&rmpSpinLock); + + if (perms == 0x0) + perms = KERNEL_PAGE_DEFAULT; + /* * Set Pointer pageDirectory To Point To The Virtual Mapping Of The Page * Directory */ pageDir = (uInt32 *) parentPageDirAddr; /* Check To See If Page Table Exists */ - //assert(dest); if (dest == 0x0) return(0x0); /* Get Index Into The Page Directory */ destPageDirectoryIndex = (dest / 0x400000); - if ((pageDir[destPageDirectoryIndex] & pagePresent) != pagePresent) { + if ((pageDir[destPageDirectoryIndex] & PAGE_PRESENT) != PAGE_PRESENT) { /* If Page Table Is Non Existant Then Set It Up */ - pageDir[destPageDirectoryIndex] = (uInt32) vmmFindFreePage(_current->id) | pageDefault; + /* UBU Why does the page table need to be user writable? */ + pageDir[destPageDirectoryIndex] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; /* Also Add It To Virtual Space So We Can Make Changes Later */ pageTable = (uInt32 *) (tablesBaseAddress + 0x2FF000); pageTable[destPageDirectoryIndex] = pageDir[destPageDirectoryIndex]; /* Reload Page Directory */ asm volatile( + "push %eax \n" "mov %cr3,%eax \n" "mov %eax,%cr3 \n" + "pop %eax \n" ); pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); for (i = 0x0;i < pageEntries;i++) @@ -200,18 +203,21 @@ pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); /* Get The Index To The Page Table */ - destPageTableIndex = ((dest - (destPageDirectoryIndex * 0x400000)) / 4096); + destPageTableIndex = ((dest - (destPageDirectoryIndex * 0x400000)) / 0x1000); /* If The Page Is Mapped In Free It Before We Remap */ - if ((pageTable[destPageTableIndex] & pagePresent) == pagePresent) { + if ((pageTable[destPageTableIndex] & PAGE_PRESENT) == PAGE_PRESENT) { /* Clear The Page First For Security Reasons */ freePage(((uInt32) pageTable[destPageTableIndex] & 0xFFFFF000)); } /* Set The Source Address In The Destination */ - pageTable[destPageTableIndex] = (uInt32) (source | pageDefault); + pageTable[destPageTableIndex] = (uInt32) (source | perms); + //kprintf("[0x%X]",pageTable[destPageTableIndex]); /* Reload The Page Table; */ asm volatile( + "push %eax \n" "movl %cr3,%eax\n" "movl %eax,%cr3\n" + "pop %eax \n" ); /* Return */ spinUnlock(&rmpSpinLock); @@ -242,15 +248,17 @@ /* Loop Through The Page Table Find An UnAllocated Page */ if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { if (count > 1) { - for (c = 0; c < count; c++) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { - c = -1; - break; - } - } + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } if (c != -1) { for (c = 0; c < count; c++) { - if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)))) == 0x0) + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage failed: gfkp-1\n"); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } @@ -260,11 +268,7 @@ } else { /* Map A Physical Page To The Virtual Page */ - /* - * vmmRemapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*409 - * 6)),pid); - */ - if ((vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)))) == 0x0) + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage failed: gfkp-2\n"); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); @@ -323,9 +327,9 @@ //Calculate The Page Table Index And Page Directory Index dI = (baseAddr/(1024*4096)); tI = ((baseAddr-(dI*(1024*4096)))/4096); - vmmRemapPage(child->tss.cr3,0x5A00000); + vmm_remapPage(child->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT); for (i=0;i<0x1000;i++) { - vmmRemapPage(childPageDir[i],0x5A01000 + (i * 0x1000)); + vmm_remapPage(childPageDir[i],0x5A01000 + (i * 0x1000),KERNEL_PAGE_DEFAULT); } for (x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++) { pageTableSrc = (uInt32 *)(tablesBaseAddress + (4096*x)); @@ -346,7 +350,7 @@ tI = 0-c; } childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); - vmmRemapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096))); + vmm_remapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096)),KERNEL_PAGE_DEFAULT); } vmmUnmapPage(0x5A00000,1); for (i=0;i<0x1000;i++) { @@ -358,7 +362,7 @@ else { //Map A Physical Page To The Virtual Page childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); - vmmRemapPage(childPageTable[tI],((x*(1024*4096))+(y*4096))); + vmm_remapPage(childPageTable[tI],((x*(1024*4096))+(y*4096)),KERNEL_PAGE_DEFAULT); //Return The Address Of The Mapped In Memory vmmUnmapPage(0x5A00000,1); for (i=0;i<0x1000;i++) { @@ -396,7 +400,7 @@ } if (c != -1) { for (c = 0; c < count; c++) { - vmmRemapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000))); + vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT); vmmClearVirtualPage((uInt32) ((x * 0x400000) + ((y + c) * 0x1000))); } spinUnlock(&fkpSpinLock); @@ -404,7 +408,7 @@ } } else { /* Map A Physical Page To The Virtual Page */ - vmmRemapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + (y * 0x1000))); + vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT); /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); /* Return The Address Of The Newly Allocate Page */ @@ -421,6 +425,15 @@ /*** $Log$ + Revision 1.15 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + Revision 1.14 2004/07/27 12:02:01 reddawg chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much diff --git a/src/sys/vmm/setpageattributes.c b/src/sys/vmm/setpageattributes.c index 705a3aa..17c29d8 100644 --- a/src/sys/vmm/setpageattributes.c +++ b/src/sys/vmm/setpageattributes.c @@ -28,6 +28,7 @@ *****************************************************************************************/ #include +#include /************************************************************************ @@ -37,33 +38,40 @@ Notes: ************************************************************************/ -void -vmmSetPageAttribute(uInt32 pageAddr, int attributes) -{ - uInt16 directoryIndex, tableIndex; - uInt32 *pageTable; +int vmm_setPageAttributes(uInt32 memAddr,uInt16 attributes) { + uInt16 directoryIndex = 0x0, tableIndex = 0x0; + uInt32 *pageTable = 0x0; - /* Get Index To Page Directory */ - directoryIndex = (pageAddr / (1024 * 0x1000)); - /* Get Index To Page Table */ - tableIndex = ((pageAddr - (directoryIndex * (1024 * 0x1000))) / 0x1000); + /* Calculate The Page Directory Index */ + directoryIndex = (memAddr >> 22); + + /* Calculate The Page Table Index */ + tableIndex = ((memAddr >> 12) & 0x3FF); + /* Set Table Pointer */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * directoryIndex)); + if ((pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * directoryIndex))) == 0x0) + kpanic("Error: pageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* Set Attribute If Page Is Mapped */ - if (pageTable[tableIndex] != 0) { + if (pageTable[tableIndex] != 0x0) pageTable[tableIndex] = ((pageTable[tableIndex] & 0xFFFFF000) | attributes); - } + /* Reload The Page Table; */ asm volatile( + "push %eax \n" "movl %cr3,%eax\n" "movl %eax,%cr3\n" + "pop %eax \n" ); /* Return */ - return; -} + return(0x0); + } /*** $Log$ + Revision 1.3 2004/07/20 22:29:55 reddawg + assert: remade assert + Revision 1.2 2004/06/10 22:23:56 reddawg Volatiles diff --git a/src/sys/vmm/vmminit.c b/src/sys/vmm/vmminit.c index e227123..68fc9f0 100644 --- a/src/sys/vmm/vmminit.c +++ b/src/sys/vmm/vmminit.c @@ -30,7 +30,6 @@ #include /***************************************************************************************** - Function: int vmm_init() Description: Initializes the vmm subsystem @@ -42,7 +41,7 @@ if (vmmMemMapInit() != 0x0) { return (0x1); } - if (vmmPagingInit() != 0x0) { + if (vmm_pagingInit() != 0x0) { return (0x1); } return (0x0); @@ -50,6 +49,9 @@ /*** $Log$ + Revision 1.3 2004/07/09 12:18:19 reddawg + Updating Initialization Procedures + Revision 1.2 2004/05/21 14:36:55 reddawg Cleaned up