diff --git a/src/Makefile.inc b/src/Makefile.inc index c30c9f5..c772176 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -2,8 +2,9 @@ # Global 'Source' Options # allow you to change your default compiler without affecting your other work -CC = gcc -CXX = g++ +CFLAGS = -march=pentium4 +CC = gcc -march=pentium4 +CXX = g++ -march=pentium4 LD = ld AR = ar REMOVE = rm -rf diff --git a/src/bin/Makefile b/src/bin/Makefile index d792e50..aeae246 100644 --- a/src/bin/Makefile +++ b/src/bin/Makefile @@ -82,4 +82,4 @@ (cd ld;make clean) (cd edit;make clean) (cd ttyd;make clean) - (Cd stat;make clean) \ No newline at end of file + (cd stat;make clean) diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 60c6384..8c15029 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -81,7 +81,8 @@ int main() { /* Set up counter for startup routine */ int i = 0x0; - + uInt32 *sysTask; + /* Do A Clear Screen Just To Make The TEXT Buffer Nice And Empty */ clearScreen(); @@ -102,20 +103,28 @@ /* Initialize the system */ kprintf("Free Pages: [%i]\n",systemVitals->freePages); + kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); - kprintf("Starting Os\n"); + kprintf("Starting OS\n"); - execThread(systemTask,(uInt32)kmalloc(0x2000)+0x2000,0x0); - execFile("sys:/init",0x0,0x0,0x0); /* OS Initializer */ - execFile("sys:/stat",0x0,0x0,0x1); /* OS Status Monitor */ - irqEnable(0x0); + sysTask = kmalloc(0x2000); + if(sysTask == 0x0 || sysTask == NULL) + kprintf("OS: Unable to allocate memory\n"); + + execThread(systemTask, (uInt32)sysTask+0x2000,0x0); + //execThread(systemTask,(uInt32)kmalloc(0x2000)+0x2000,0x0); + + execFile("sys:/init",0x0,0x0,0x0); /* OS Initializer */ + execFile("sys:/stat",0x0,0x0,0x1); /* OS Status Monitor */ + + irqEnable(0x0); - while (0x1) - asm("hlt"); /* Keep haulting until the scheduler reacts */ + while (0x1) + asm("hlt"); /* Keep haulting until the scheduler reacts */ - /* Return to start however we should never get this far */ - return(0x0); - } + /* Return to start however we should never get this far */ + return(0x0); +} /*** END diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 393d4e7..058459e 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -68,6 +68,8 @@ int sched_init() { taskList = (kTask_t *)kmalloc(sizeof(kTask_t)); + if(taskList == 0x0) + kpanic("Unable to create task list"); taskList->id = nextID++; @@ -90,6 +92,7 @@ tmpTask = _current->next; //outportByte(0xE9,_current->id + '0'); schedStart: + /* Yield the next task from the current prio queue */ for (;tmpTask != 0x0; tmpTask = tmpTask->next) { if (tmpTask->state > 0x0) { diff --git a/src/sys/kmods/kmod.c b/src/sys/kmods/kmod.c index 5e164ae..8d81082 100644 --- a/src/sys/kmods/kmod.c +++ b/src/sys/kmods/kmod.c @@ -74,11 +74,18 @@ kmod_fd = fopen(kmod_file,"rb"); if (kmod_fd == 0x0) { kprintf("Can not open %s\n",kmod_file); + return 0x0; } /* load module header */ fseek(kmod_fd,0x0,0x0); binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + if(binaryHeader == 0x0) + { + kprintf("kmod: out of memory\n"); + return 0x0; + } + assert(binaryHeader); fread(binaryHeader,sizeof(elfHeader),1,kmod_fd); diff --git a/src/sys/lib/assert.c b/src/sys/lib/assert.c index ce59502..957803e 100644 --- a/src/sys/lib/assert.c +++ b/src/sys/lib/assert.c @@ -33,11 +33,11 @@ void __assert(const char *func,const char *file,int line,const char *failedexpr) { if (func == NULL) - (void)kprintf( + kprintf( "Assertion failed: (%s), file %s, line %d.\n", failedexpr, file, line); else - (void)kprintf( + kprintf( "Assertion failed: (%s), function %s, file %s, line %d.\n", failedexpr, func, file, line); kpanic("Asserted\n"); @@ -45,6 +45,9 @@ /*** $Log$ + Revision 1.1 2004/07/20 22:29:55 reddawg + assert: remade assert + END ***/ diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 5c5a1fd..f659a05 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -347,11 +347,11 @@ void kfree(void *baseAddr) { struct memDescriptor *tmpDesc = 0x0; - spinLock(&mallocSpinLock); assert(baseAddr); assert(usedKernDesc); + spinLock(&mallocSpinLock); for (tmpDesc = usedKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { @@ -381,13 +381,16 @@ return; } } - kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); spinUnlock(&mallocSpinLock); + kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); return; } /*** $Log$ + Revision 1.32 2004/09/28 21:50:04 reddawg + kmalloc: now when we kfree memory is filled with 0xBE so it is easy to debug if we continue to use free'd memory + Revision 1.31 2004/09/19 16:17:25 reddawg fixed memory leak we now lose no memory.... diff --git a/src/sys/sys/device.c b/src/sys/sys/device.c index c49ec5a..8aecb20 100644 --- a/src/sys/sys/device.c +++ b/src/sys/sys/device.c @@ -50,7 +50,6 @@ int device_add(int minor,char type,struct device_interface *devInfo) { struct device_node *tmpDev = 0x0; - spinLock(&deviceSpinLock); tmpDev = (struct device_node *)kmalloc(sizeof(struct device_node)); assert(tmpDev); @@ -60,6 +59,8 @@ tmpDev->type = type; tmpDev->devInfo = devInfo; tmpDev->next = devices; + + spinLock(&deviceSpinLock); devices = tmpDev; spinUnlock(&deviceSpinLock); @@ -109,10 +110,10 @@ { struct device_node *current, *previous; -spinLock(&deviceSpinLock); current = devices; previous=NULL; +spinLock(&deviceSpinLock); while(current != NULL) { if(current==deviceToDelete) break; @@ -122,11 +123,17 @@ current = current->next; } } - if(current == NULL) return 1; + if(current == NULL) + { + spinUnlock(&deviceSpinLock); + return 1; + } else { - if(current == devices) devices = devices->next; - else previous->next = current->next; + if(current == devices) + devices = devices->next; + else + previous->next = current->next; kfree(current); spinUnlock(&deviceSpinLock); return 1; diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index 9b88ce9..cafe6c1 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -189,9 +189,7 @@ //kprintf("fd->fileName: %s:%i\n",fd->fileName,_current->id); assert(fd->mp); assert(fd->mp->fs); - spinLock(&fdTable_lock); fd->mp->fs->vfsRead(fd,ptr,fd->offset,size * nmemb); - spinUnlock(&fdTable_lock); fd->offset += size * nmemb; return(size * nmemb); } @@ -251,10 +249,8 @@ int ch = 0x0; /* If Found Return Next Char */ if (fd != 0x0) { - spinLock(&fdTable_lock); fd->mp->fs->vfsRead(fd,(char *)&ch,fd->offset,1); fd->offset++; - spinUnlock(&fdTable_lock); return(ch); } @@ -279,16 +275,14 @@ char fileName[1024]; fileDescriptor *tmpFd = 0x0; - spinLock(&fdTable_lock); /* Allocate Memory For File Descriptor */ - if ((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { - kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); - spinUnlock(&fdTable_lock); - return(0x0); + if((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { + kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + return(NULL); } - sprintf(fileName,file); + sprintf(fileName,"%s",file); if (strstr(fileName,":")) { mountPoint = (char *)strtok((char *)&fileName,":"); @@ -299,7 +293,7 @@ } if (path[0] == '/') { - sprintf(tmpFd->fileName,path); + sprintf(tmpFd->fileName,"%s", path); } else { sprintf(tmpFd->fileName,"/%s",path); @@ -315,13 +309,12 @@ if (tmpFd->mp == 0x0) { kprintf("Mount Point Bad\n"); - spinUnlock(&fdTable_lock); return(0x0); } /* This Will Set Up The Descriptor Modes */ - tmpFd->mode = 0x0; - for (i = 0x0;'\0' != flags[i];i++) { + tmpFd->mode = 0; + for (i = 0; '\0' != flags[i] ;i++ ) { switch(flags[i]) { case 'w': case 'W': @@ -340,43 +333,64 @@ tmpFd->mode |= fileAppend; break; default: + kprintf("Invalid mode '%c' for fopen\n", flags[i]); break; } } + /* Search For The File */ if (tmpFd->mp->fs->vfsOpenFile(tmpFd->fileName,tmpFd) == 0x1) { /* If The File Is Found Then Set Up The Descriptor */ - tmpFd->buffer = (char *)kmalloc(0x1000); - + + + /* in order to save resources we will allocate the buffer later when it is needed */ +/* + tmpFd->buffer = (char *)kmalloc(4096); + if(tmpFd->buffer == 0x0) + { + kfree(tmpFd); + kprintf("Error: tmpFd->buffer == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + spinUnlock(&fdTable_lock); + return 0x1; + } +*/ /* Set Its Status To Open */ tmpFd->status = fdOpen; /* Initial File Offset Is Zero */ - tmpFd->offset = 0x0; + tmpFd->offset = 0; + tmpFd->prev = 0x0; + + /* we do not want to be in a spinlock longer than we need to, so + it has been moved to here. */ + spinLock(&fdTable_lock); /* Increment Number Of Open Files */ systemVitals->openFiles++; - tmpFd->prev = 0x0; tmpFd->next = fdTable; if (fdTable != 0x0) fdTable->prev = tmpFd; + + fdTable = tmpFd; + + spinUnlock(&fdTable_lock); - fdTable = tmpFd; /* Return The FD */ - spinUnlock(&fdTable_lock); return(tmpFd); } else { - /* If The File Was Not Found Free The Memory */ - kfree(tmpFd); + kfree(tmpFd->buffer); + kfree(tmpFd); + spinUnlock(&fdTable_lock); + + return (NULL); } - /* Return NULL */ - spinUnlock(&fdTable_lock); - return(0x0); + /* Return NULL */ + return(0x0); } /************************************************************************ @@ -401,10 +415,9 @@ if (tmpFd == fdTable) fdTable = tmpFd->next; - + spinUnlock(&fdTable_lock); kfree(tmpFd->buffer); kfree(tmpFd); - spinUnlock(&fdTable_lock); return(0x0); } } diff --git a/src/tools/Makefile b/src/tools/Makefile index 574ae02..46be4f3 100644 --- a/src/tools/Makefile +++ b/src/tools/Makefile @@ -39,6 +39,7 @@ format-dsk: (cp ../sys/compile/ubix.elf ./) (cp ../bin/init/init ./) + (cp ../bin/stat/stat ./) (cp ../bin/login/login ./) (cp ../bin/shell/shell ./) (cp ../bin/ls/ls ./) @@ -52,11 +53,11 @@ (cp ../bin/ld/ld.so ./) #(cp /lib/libc.so.5 ./) (cp ../bin/ttyd/ttyd ./) - (./format 50 2000 ${FD_DEVICE} ubix.elf 0 login 3754 ROM8X14.DPF 3754 init 3754 ubistry 3754 shell 3754 userdb 3754 ls 3754 motd 3754 fdisk 3754 cp 3754 clock 3754 libc_old.so 3754 ld.so 3754 ttyd 3754 mbr 3754) + (./format 50 2000 ${FD_DEVICE} ubix.elf 0 login 3754 init 3754 stat 3754 ubistry 3754 shell 3754 userdb 3754 ls 3754 motd 3754 fdisk 3754 cp 3754 clock 3754 libc_old.so 3754 ld.so 3754 ttyd 3754 ) # (./format 50 2000 ${FD_DEVICE} ubix.elf 0 login 3754 init 3754 ubistry 3754 shell 3754 userdb 3754 motd 3754 libc_old.so 3754 ld.so 3754 test 3754 libc.so.5 3754) #(./format 263 204361 /dev/md1 ubix.elf 0 format 3754 fdisk 3754 ROM8X14.DPF 3754 init 3754 login 3754 shell 3754 userdb 3754 ls 3754 motd 3754 cp 3754) - (./format 1064 2000 ${FD_DEVICE} shell 3754 clock 3754) + #(./format 1064 2000 ${FD_DEVICE} shell 3754 clock 3754) #(./format 200 2000 /dev/md1 ubix.elf 0 shell 3754 motd 3754 libc_old.so 3754) (rm -fr ubix.elf) (rm -fr login) @@ -68,7 +69,7 @@ (rm -fr cp) (rm -fr fdisk) #(rm -fr format) - (rm -fr mbr) + (rm -fr ubistry) (rm -fr ld.so) (rm -fr libc.so.5)