diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 1cf92d6..f1ecf9d 100755 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c @@ -94,8 +94,9 @@ if (tmpDesc->limit >= len) { if (tmpDesc->limit > len+4) { newDesc = findFreeDesc(); - newDesc->base = tmpDesc->base+tmpDesc->limit + 1; - newDesc->limit = tmpDesc->limit - len; + newDesc->page = tmpDesc->page; + newDesc->base = tmpDesc->base + len + 1; + newDesc->limit = tmpDesc->limit - len - 1; } tmpDesc->counter = 1; ret = tmpDesc->base; @@ -108,8 +109,8 @@ tmpDesc->counter = 1; newDesc = findFreeDesc(); newDesc->page = tmpDesc->page; - newDesc->base = tmpDesc->base + tmpDesc->limit + 1; - newDesc->limit = 4096 - tmpDesc->limit; + newDesc->base = tmpDesc->base + len + 1; + newDesc->limit = 4096 - tmpDesc->limit - 1; ret = tmpDesc->base; break; } diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 249c3b0..18b72be 100755 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -40,10 +40,11 @@ descriptorTable(GDT,5) { {dummy:0}, - standardDescriptor(0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), - standardDescriptor(0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), - standardDescriptor(0, 0xFFFFF, (dLdt)), - standardDescriptor(100000, (sizeof(struct tssStruct)-1), (dTss)), + standardDescriptor(0x0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), + standardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), + standardDescriptor(0x0, 0xFFFFF, (dLdt)), + standardDescriptor(100000, sizeof(struct tssStruct), (dTss)), +// standardDescriptor(0x4000, sizeof(struct tssStruct), (dTss)), }; struct { @@ -166,15 +167,13 @@ initVitals(); //Initialize Vitals Tracking init8259(); //Initialize PIC initIdt(); //Initialize IDT - initKeyboard(); //Initialize Keyboard - initScheduler(); //Initialize Scheduler - initFloppy(); //Initialize Floppy Controller - initUbixFS(); //Initialize File System - a = kmalloc(512); - b = kmalloc(37); + initKeyboard(); //Initialize Keyboar + /* + a = kmalloc(3); + b = kmalloc(5); kprintf("[%x][%x]\n",a,b); - memset(a,'\0',512); - memset(b,'\0',37); + memset(b,'\0',5); + memset(a,'\0',3); a[0] = 'P'; a[1] = 'a'; a[2] = 't'; @@ -183,7 +182,13 @@ b[2] = 'c'; b[3] = 'k'; b[4] = 's'; - kprintf("[%s][%s]\n",a,b); + kprintf("[%s]",a); + kprintf("[%s]",b); + kprintf("\n"); + */ + initScheduler(); //Initialize Scheduler + initFloppy(); //Initialize Floppy Controller + initUbixFS(); //Initialize File System /* kprintf("PhysBasePtr: [%i]\n",testVesa->PhysBasePtr); kprintf("BytesPerLine: [%i]\n",testVesa->BytesPerLine); @@ -234,6 +239,11 @@ execThread(idleThread,0xAFFF,"Idle Thread"); execFile("init"); kprintf("Free Pages: [%i]\n",freePages); + /* + outportByte(0x43,0x3C); + outportByte(0x40,((1193180/1000) & 0xFF)); + outportByte(0x40,(((1193180/1000) << 8) & 0xFF)); + */ enableIrq(0); while (1); } diff --git a/src/sys/kernel/Makefile b/src/sys/kernel/Makefile index d618def..2dae65d 100755 --- a/src/sys/kernel/Makefile +++ b/src/sys/kernel/Makefile @@ -14,7 +14,7 @@ REMOVE = rm -fr # Objects -OBJS = io.o version.o kprintf.o vsprintf.o idt.o schedule.o exec.o dma.o idlethread.o syscall.o fork.o kmalloc.o spinlock.o vitals.o +OBJS = io.o version.o kprintf.o vsprintf.o idt.o schedule.o exec.o dma.o idlethread.o syscall.o fork.o kmalloc.o spinlock.o vitals.o panic.o all: $(OBJS) diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index eb5d8e4..9e0ce55 100755 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -40,11 +40,11 @@ ************************************************************************/ void sysFork() { //Lets Find A New Task - kTask_t * newProcess = findTask(); + kTask_t *newProcess = findTask(); int *ret = 0x0; //Set Up Pointer to Return Value asm("":"=b" (ret)); - //Set Up New Tasks Information + //Set Up New Tasks Information newProcess->tss.back_link = 0x0; newProcess->tss.esp0 = _current->tss.esp0; newProcess->tss.ss0 = 0x10; diff --git a/src/sys/kernel/idlethread.c b/src/sys/kernel/idlethread.c index dd4d503..d5a344d 100755 --- a/src/sys/kernel/idlethread.c +++ b/src/sys/kernel/idlethread.c @@ -27,9 +27,10 @@ #include void idleThread() { - while (1); + uLong ticks = 0x0; while (1) { - kprintf("B"); + ticks++; + if (!ticks%1000) { kprintf("[%i]\n",ticks); } //checkTasks(); /* Looks for run away proccesses and kills thems */ } } diff --git a/src/sys/kernel/kmalloc.c b/src/sys/kernel/kmalloc.c index 9c725d8..8a8093c 100755 --- a/src/sys/kernel/kmalloc.c +++ b/src/sys/kernel/kmalloc.c @@ -86,7 +86,6 @@ } void *kmalloc(uInt len) { - void *ret = 0x0; struct memDescriptor *tmpDesc = 0x0,*newDesc = 0x0; if (!kernDesc) { initMalloc(); @@ -94,30 +93,33 @@ for(tmpDesc=kernDesc;tmpDesc;tmpDesc=tmpDesc->next) { if (tmpDesc->counter == 0) { if (tmpDesc->limit >= len) { + kprintf("Had Page\n"); if (tmpDesc->limit > len+4) { newDesc = findFreeDesc(); - newDesc->base = tmpDesc->base+tmpDesc->limit + 1; + newDesc->page = tmpDesc->page; + newDesc->base = tmpDesc->base + len + 1; newDesc->limit = tmpDesc->limit - len; } tmpDesc->counter = 1; - ret = tmpDesc->base; - break; + kprintf("[0x%x][0x%x][%i]\n",tmpDesc->page,tmpDesc->base,tmpDesc->limit); + return(tmpDesc->base); } - if (tmpDesc->page == 0x0) { + else if (tmpDesc->page == 0x0) { + kprintf("Had To Alloc Page\n"); tmpDesc->page = (void *)getFreePage(_current->id); tmpDesc->base = tmpDesc->page; tmpDesc->limit = len; tmpDesc->counter = 1; newDesc = findFreeDesc(); newDesc->page = tmpDesc->page; - newDesc->base = tmpDesc->base + tmpDesc->limit + 1; + newDesc->base = tmpDesc->base + len + 1; newDesc->limit = 4096 - tmpDesc->limit; - ret = tmpDesc->base; - break; + kprintf("[0x%x][0x%x][%i]\n",tmpDesc->page,tmpDesc->base,tmpDesc->limit); + return(tmpDesc->base); } } } - return(ret); + return(0x0); } diff --git a/src/sys/kernel/panic.c b/src/sys/kernel/panic.c new file mode 100755 index 0000000..1bd9fc2 --- /dev/null +++ b/src/sys/kernel/panic.c @@ -0,0 +1,29 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#include + +void panic() { + kprintf("System Panic!\nHalting Machine\n"); + while (1) { asm("hlt"); } + } \ No newline at end of file diff --git a/src/sys/kernel/schedule.c b/src/sys/kernel/schedule.c index 337d4f2..6e08b27 100755 --- a/src/sys/kernel/schedule.c +++ b/src/sys/kernel/schedule.c @@ -43,7 +43,7 @@ int currentProc = -1; int lastPid = -1; kTask_t *taskList = (kTask_t *)0xE0800000; -kTask_t *_current,*_usedMath = 0x0; +kTask_t *_current = 0x0,*_usedMath = 0x0; extern union descriptorTableunion GDT[7]; extern int testVal; diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index 29e19bc..23823bf 100755 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -139,6 +139,7 @@ uLong findFreePage(pid_t pid) { int i=0; //Lets Look For A Free Page + if (pid < -1) { pid = -1; } for (i=0;i<=numPages;i++) { /* If We Found A Free Page Set It To Not Available diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 1e1566d..8f9aa57 100755 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -626,6 +626,9 @@ kprintf("Segfault At Address: [0x%x][%i]\n",memAddr,_current->id); freeProcessPages(_current->id); _current->status = EMPTY; + if (_current->id < -1) { + panic(); + } schedule(); while (1); } @@ -653,6 +656,9 @@ kprintf("Segfault At Address: [0x%x][%i]\n",memAddr,_current->id); freeProcessPages(_current->id); _current->status = EMPTY; + if (_current->id < -1) { + panic(); + } schedule(); while(1); } diff --git a/ubixos.kdevprj b/ubixos.kdevprj index 0ec1fd9..54009c6 100755 --- a/ubixos.kdevprj +++ b/ubixos.kdevprj @@ -852,7 +852,7 @@ type=DATA [src/sys/kernel/Makefile.am] -files=src/sys/kernel/Makefile,src/sys/kernel/io.c,src/sys/kernel/version.c,src/sys/kernel/kprintf.c,src/sys/kernel/vsprintf.c,src/sys/kernel/idt.c,src/sys/kernel/exec.c,src/sys/kernel/schedule.c,src/sys/kernel/dma.c,src/sys/kernel/idlethread.c,src/sys/kernel/syscall.c,src/sys/kernel/fork.c,src/sys/kernel/kmalloc.c,src/sys/kernel/spinlock.c,src/sys/kernel/bios32.c,src/sys/kernel/vitals.c +files=src/sys/kernel/Makefile,src/sys/kernel/io.c,src/sys/kernel/version.c,src/sys/kernel/kprintf.c,src/sys/kernel/vsprintf.c,src/sys/kernel/idt.c,src/sys/kernel/exec.c,src/sys/kernel/schedule.c,src/sys/kernel/dma.c,src/sys/kernel/idlethread.c,src/sys/kernel/syscall.c,src/sys/kernel/fork.c,src/sys/kernel/kmalloc.c,src/sys/kernel/spinlock.c,src/sys/kernel/bios32.c,src/sys/kernel/vitals.c,src/sys/kernel/panic.c sub_dirs= type=static_library @@ -910,6 +910,12 @@ install_location= type=SOURCE +[src/sys/kernel/panic.c] +dist=true +install=false +install_location= +type=SOURCE + [src/sys/kernel/schedule.c] dist=true install=false