diff --git a/src/sys/Makefile b/src/sys/Makefile index 959cd34..0e9f7c5 100644 --- a/src/sys/Makefile +++ b/src/sys/Makefile @@ -2,7 +2,7 @@ # # $Id$ -all: kernel-code vmm-code lib-code sys-code init-code kernel-img +all: mpi-code kernel-code vmm-code lib-code sys-code init-code kernel-img vmm-code: vmm (cd vmm;make) @@ -18,6 +18,9 @@ kernel-code: kernel (cd kernel;make) + +mpi-code: mpi + (cd mpi;make) kernel-img: compile (/bin/echo "/* " > ./compile/null.c) @@ -35,5 +38,6 @@ (cd sys;make clean) (cd init;make clean) (cd kernel;make clean) + (cd mpi;make clean) (cd compile;make clean) (cd ../tools/;make clean) diff --git a/src/sys/include/assert.h b/src/sys/include/assert.h new file mode 100644 index 0000000..e6c3f51 --- /dev/null +++ b/src/sys/include/assert.h @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/assert.h,v 1.4 2002/03/23 17:24:53 imp Exp $ + */ + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#undef assert +#undef _assert + +#ifdef NDEBUG +#define assert(e) ((void)0) +#define _assert(e) ((void)0) +#else +#define _assert(e) assert(e) + +#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \ + __LINE__, #e)) +#endif /* NDEBUG */ + +__BEGIN_DECLS +void __assert(const char *, const char *, int, const char *); +__END_DECLS diff --git a/src/sys/include/lib/kmalloc.h b/src/sys/include/lib/kmalloc.h new file mode 100644 index 0000000..1b3d101 --- /dev/null +++ b/src/sys/include/lib/kmalloc.h @@ -0,0 +1,56 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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$ + +*****************************************************************************************/ + +#ifndef _KMALLOC_H +#define _KMALLOC_H + +#include + +#define sysID -2 +#define MALLOC_ALIGN_SIZE 32 +#define MALLOC_ALIGN(size) (size + ((((size) % (MALLOC_ALIGN_SIZE)) == 0)? 0 : ((MALLOC_ALIGN_SIZE) - ((size) % (MALLOC_ALIGN_SIZE))))) + +struct memDescriptor { + struct memDescriptor *prev; //4 + struct memDescriptor *next; //4 + void *baseAddr; //4 + uInt32 limit; //4 + /*uInt8 status; //1 */ + /*char reserved[11]; //11 */ + }; + +void kfree(void *baseAddr); +void *kmalloc(uInt32 len); + +#endif + +/*** + END + ***/ + diff --git a/src/sys/include/string.h b/src/sys/include/string.h new file mode 100644 index 0000000..2fc1c63 --- /dev/null +++ b/src/sys/include/string.h @@ -0,0 +1,48 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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$ + +*****************************************************************************************/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +void * memcpy(void * dst, const void * src, size_t length); +void *memset(void * dst, int c, size_t length); +int strlen(const char * string); +int strcmp(const char *,const char *); + +int sprintf(char * str, const char * format, ...); + +long strtol(const char * __restrict nptr, char ** __restrict endptr, int base); + +#endif + +/*** + END + ***/ diff --git a/src/sys/include/vmm/vmm.h b/src/sys/include/vmm/vmm.h index 917d974..e522dc0 100644 --- a/src/sys/include/vmm/vmm.h +++ b/src/sys/include/vmm/vmm.h @@ -60,6 +60,7 @@ int cowCounter; } mMap; +void *vmm_getFreeMallocPage(u_int16_t); int vmm_clearVirtualPage(u_int32_t); void vmm_pageFault(); void _vmm_pageFault(); diff --git a/src/sys/lib/Makefile b/src/sys/lib/Makefile index e86bb43..8ed9f64 100644 --- a/src/sys/lib/Makefile +++ b/src/sys/lib/Makefile @@ -7,7 +7,7 @@ include ../Makefile.inc # Objects -OBJS = memset.o string.o vsprintf.o kprintf.o +OBJS = assert.o kmalloc.o memset.o string.o vsprintf.o kprintf.o all: $(OBJS) diff --git a/src/sys/lib/assert.c b/src/sys/lib/assert.c new file mode 100644 index 0000000..bd9158f --- /dev/null +++ b/src/sys/lib/assert.c @@ -0,0 +1,49 @@ +/***************************************************************************************** + 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 +#include +#include + +void __assert(const char *func,const char *file,int line,const char *failedexpr) { + if (func == NULL) + (void)kprintf( + "Assertion failed: (%s), file %s, line %d.\n", failedexpr, + file, line); + else + (void)kprintf( + "Assertion failed: (%s), function %s, file %s, line %d.\n", + failedexpr, func, file, line); + kpanic("Asserted\n"); + } + +/*** + END + ***/ + diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c new file mode 100644 index 0000000..47c806a --- /dev/null +++ b/src/sys/lib/kmalloc.c @@ -0,0 +1,513 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 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 +#include +#include +#include +#include +#include +#include + +/* + Set up three descriptor tables: + + kernDesc - The inuse descriptor table + freeKernDesc - The free descriptor table (descriptors with memory backing just not in use) + emptyKernDesc - The empty descriptor table (descriptors with out a memory backing) + +*/ +static struct memDescriptor *usedKernDesc = 0x0; +static struct memDescriptor *freeKernDesc = 0x0; +static struct memDescriptor *emptyKernDesc = 0x0; + +/* + Set up our spinlocks so we do not corrupt linked lists if we have re-entrancy +*/ +static spinLock_t mallocSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t emptyDescSpinLock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + +Function: void *getEmptyDesc() +Description: Find An Empty Descriptor + +Notes: + +02/17/03 - Is This Efficient? + +************************************************************************/ +static void *getEmptyDesc() { + int i = 0x0; + struct memDescriptor *tmpDesc = 0x0; + + spinLock(&emptyDescSpinLock); + + tmpDesc = emptyKernDesc; + + if (tmpDesc != 0x0) { + emptyKernDesc = tmpDesc->next; + if (emptyKernDesc != 0x0) + emptyKernDesc->prev = 0x0; + + + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + spinUnlock(&emptyDescSpinLock); + return(tmpDesc); + } + + if ((emptyKernDesc = (struct memDescriptor *)vmm_getFreeMallocPage(4)) == 0x0) + kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); + + /* zero out the memory so we know there is no garbage */ + memset(emptyKernDesc,0x0,0x4000); + + emptyKernDesc[0].next = &emptyKernDesc[1]; + + for (i = 0x1;i < ((0x4000/sizeof(struct memDescriptor)));i++) { + 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[0]; + + emptyKernDesc = tmpDesc->next; + emptyKernDesc->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + spinUnlock(&emptyDescSpinLock); + return(tmpDesc); + } + +/************************************************************************ + +Function: void insertFreeDesc(struct memDescriptor *freeDesc) +Description: This Function Inserts A Free Descriptor On The List Which Is + Kept In Size Order + +Notes: + +02/17/03 - This Was Inspired By TCA's Great Wisdom - + "[20:20:59] You should just insert it in order" + +************************************************************************/ +static int insertFreeDesc(struct memDescriptor *freeDesc) { + struct memDescriptor *tmpDesc = 0x0; + assert(freeDesc); + + if (freeDesc->limit <= 0x0) + kpanic("Inserting Descriptor with no limit\n"); + + if (freeKernDesc != 0x0) { + + #if 0 + freeDesc->next = freeKernDesc; + freeDesc->prev = 0x0; + freeKernDesc->prev = freeDesc; + freeKernDesc = freeDesc; + #endif + + for (tmpDesc = freeKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { + if (freeDesc->limit <= tmpDesc->limit) { + + freeDesc->prev = tmpDesc->prev; + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = freeDesc; + + + tmpDesc->prev = freeDesc; + freeDesc->next = tmpDesc; + + if (tmpDesc == freeKernDesc) + freeKernDesc = freeDesc; + return(0x0); + } + if (tmpDesc->next == 0x0) { + tmpDesc->next = freeDesc; + freeDesc->prev = tmpDesc; + freeDesc->next = 0x0; + return(0x0); + } + } + kpanic("didnt Insert\n"); + return(0x0); + } + else { + freeDesc->prev = 0x0; + freeDesc->next = 0x0; + freeKernDesc = freeDesc; + return(0x0); + } + + return(0x1); + } + +/************************************************************************ + +Function: void mergeMemBlocks() +Description: This Function Will Merge Free Blocks And Free Pages + +Notes: + +03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 + +************************************************************************/ +static void mergeMemBlocks() { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + uInt32 baseAddr = 0x0; + + return; + + //Loop The Free Descriptors See If We Can Merge Them + 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 + */ + if (tmpDesc1->limit != 0x0) { + baseAddr = (uInt32)tmpDesc1->baseAddr + (uInt32)tmpDesc1->limit; + for (tmpDesc2=freeKernDesc;tmpDesc2;tmpDesc2=tmpDesc2->next) { + if ((uInt32)tmpDesc2->baseAddr == baseAddr) { + tmpDesc1->limit += tmpDesc2->limit; + tmpDesc2->baseAddr = 0x0; + tmpDesc2->limit = 0x0; + if (tmpDesc2->prev) { + tmpDesc2->prev->next = tmpDesc2->next; + } + if (tmpDesc2->next) { + tmpDesc2->next->prev = tmpDesc2->prev; + } + tmpDesc2->prev = 0x0; + tmpDesc2->next = emptyKernDesc; + emptyKernDesc->prev = tmpDesc2; + emptyKernDesc = tmpDesc2; + if (tmpDesc1->prev) { + tmpDesc1->prev->next = tmpDesc1->next; + } + if (tmpDesc1->next) { + tmpDesc1->next->prev = tmpDesc1->prev; + } + tmpDesc1->prev = 0x0; + tmpDesc1->next = 0x0; + kprintf("mergememBlocks: [%i]\n",tmpDesc1->limit); + insertFreeDesc(tmpDesc1); + //tmpDesc1 = freeKernDesc; + goto mergeStart; + break; + } + } + } + } + return; + } + + +/************************************************************************ + +Function: void *kmalloc(uInt32 len) +Description: Allocate Kernel Memory + +Notes: + +02/17/03 - Do I Still Need To Pass In The Pid? + +************************************************************************/ +void *kmalloc(uInt32 len) { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + char *buf = 0x0; + int i = 0x0; + uInt16 pages = 0x0; + + spinLock(&mallocSpinLock); + + len = MALLOC_ALIGN(len); + + if (len == 0x0) { + spinUnlock(&mallocSpinLock); + return(0x0); + } + for (tmpDesc1 = freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { + assert(tmpDesc1); + if (tmpDesc1->limit >= len) { + if (tmpDesc1->prev != 0x0) + tmpDesc1->prev->next = tmpDesc1->next; + if (tmpDesc1->next != 0x0) + tmpDesc1->next->prev = tmpDesc1->prev; + + if (tmpDesc1 == freeKernDesc) + freeKernDesc = tmpDesc1->next; + + tmpDesc1->prev = 0x0; + tmpDesc1->next = usedKernDesc; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + if (tmpDesc1->limit > len) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->limit = tmpDesc1->limit - len; + tmpDesc1->limit = len; + tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; + tmpDesc2->next = 0x0; + tmpDesc2->prev = 0x0; + insertFreeDesc(tmpDesc2); + } + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + (char)buf[i] = (char)0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("m1[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + return(tmpDesc1->baseAddr); + } + } + tmpDesc1 = getEmptyDesc(); + //kprintf("no empty desc\n"); + if (tmpDesc1 != 0x0) { + pages = ((len + 4095)/4096); + tmpDesc1->baseAddr = (struct memDescriptor *)vmm_getFreeMallocPage(pages); + tmpDesc1->limit = len; + tmpDesc1->next = usedKernDesc; + tmpDesc1->prev = 0x0; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + + if (((pages * 4096)-len) > 0x0) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; + tmpDesc2->limit = ((pages * 4096)-len); + tmpDesc2->prev = 0x0; + tmpDesc2->next = 0x0; + if (tmpDesc2->limit <= 0x0) + kprintf("kmalloc-2 tmpDesc2: [%i]\n",tmpDesc2->limit); + insertFreeDesc(tmpDesc2); + } + + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + (char)buf[i] = (char)0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); + //kprintf("m2[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + return(tmpDesc1->baseAddr); + } + //Return Null If Unable To Malloc + spinUnlock(&mallocSpinLock); + //kprintf("baseAddr3[0x0]"); + return(0x0); + } + +/************************************************************************ + +Function: void kfree(void *baseAddr) +Description: This Will Find The Descriptor And Free It + +Notes: + +02/17/03 - I need To Make It Join Descriptors + +************************************************************************/ +void kfree(void *baseAddr) { + struct memDescriptor *tmpDesc = 0x0; + + spinLock(&mallocSpinLock); + + assert(baseAddr); + + assert(usedKernDesc); + + for (tmpDesc = usedKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { + + if (tmpDesc->baseAddr == baseAddr) { + memset(tmpDesc->baseAddr,0xBE,tmpDesc->limit); + + if (usedKernDesc == tmpDesc) + usedKernDesc = tmpDesc->next; + + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = tmpDesc->next; + + if (tmpDesc->next != 0x0) + tmpDesc->next->prev = tmpDesc->prev; + + + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + + if (tmpDesc->limit <= 0x0) + kprintf("kfree tmpDesc1: [%i]\n",tmpDesc->limit); + //kprintf("{0x%X}",tmpDesc->baseAddr); + insertFreeDesc(tmpDesc); + + // mergeMemBlocks(); + spinUnlock(&mallocSpinLock); + return; + } + } + kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); + spinUnlock(&mallocSpinLock); + 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.... + + Revision 1.30 2004/09/14 21:51:24 reddawg + Debug info + + Revision 1.29 2004/09/11 23:39:31 reddawg + ok time for bed + + Revision 1.28 2004/09/11 23:21:26 reddawg + run now do you get fegfaults with BB? + + Revision 1.27 2004/09/11 22:49:28 reddawg + pat look at lines 276-285 does the math seem right? + + Revision 1.26 2004/09/11 22:33:13 reddawg + minor changes + + Revision 1.25 2004/09/11 12:11:11 reddawg + Cleaning up the VFS more changes to follow... + + Revision 1.24 2004/09/08 23:19:58 reddawg + hmm + + Revision 1.23 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + + Revision 1.22 2004/08/26 22:51:18 reddawg + TCA touched me :( i think he likes men.... + + + sched.h: kTask_t added parentPid + endtask.c: fixed term back to parentPid + exec.c: cleaned warnings + fork.c: fixed term to childPid + sched.c: clean up for dead tasks + systemtask.c: clean up dead tasks + kmalloc.c: cleaned up warnings + udp.c: cleaned up warnings + bot.c: cleaned up warnings + shell.c: cleaned up warnings + tcpdump.c: took a dump + hd.c: cleaned up warnings + ubixfs.c: stopped prning debug info + + Revision 1.21 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + 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 + + Revision 1.18 2004/07/26 16:52:45 reddawg + here we go + + Revision 1.17 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + + 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 + + Revision 1.14 2004/07/20 23:18:11 reddawg + Made malloc a little more robust but we have a serious memory leak somewhere + + Revision 1.13 2004/07/20 22:29:55 reddawg + assert: remade assert + + Revision 1.12 2004/07/20 18:58:24 reddawg + Few fixes + + Revision 1.11 2004/07/18 05:24:15 reddawg + Fixens + + Revision 1.10 2004/07/17 18:00:47 reddawg + kmalloc: added assert() + + Revision 1.9 2004/07/17 15:54:52 reddawg + kmalloc: added assert() + bioscall: fixed some potential problem by not making 16bit code + paging: added assert() + + Revision 1.8 2004/06/17 14:50:32 reddawg + kmalloc: converted some variables to static + + Revision 1.7 2004/06/17 02:54:54 flameshadow + chg: fixed cast + + Revision 1.6 2004/05/26 11:56:51 reddawg + kmalloc: fixed memrgeMemBlocks hopefully it will prevent future segfault issues + by not having any more overlapping blocks + + Revision 1.5 2004/05/25 14:01:14 reddawg + Implimented Better Spinlocking No More Issues With KMALLOC which actually + was causing bizzare problems + + END + ***/ + diff --git a/src/sys/mpi/mpi.c b/src/sys/mpi/mpi.c index 6d0b9d9..964f273 100644 --- a/src/sys/mpi/mpi.c +++ b/src/sys/mpi/mpi.c @@ -29,7 +29,7 @@ #include -#if 0 + #include #include @@ -40,7 +40,7 @@ /***************************************************************************************** - Function: static mpiMbox_t * mpiFindMbox(char *name) + Function: static mpiMbox_t * mpi_findMbox(char *name) Description: This function will find a mail box that matches the supplied name @@ -58,7 +58,7 @@ return(0x0); } - + /***************************************************************************************** Function: int mpiCreateMbox(char *name) @@ -81,7 +81,7 @@ mbox = (mpi_mbox_t *)kmalloc(sizeof(mpi_mbox_t)); sprintf(mbox->name,name); - mbox->pid = _current->id; + // UBUmbox->pid = _current->id; if (mboxList == 0x0) { mbox->prev = 0x0; @@ -160,7 +160,7 @@ message->header = msg->header; memcpy(message->data,msg->data,MESSAGE_LENGTH); - message->pid = _current->id; + // UBU message->pid = _current->id; message->next = 0x0; if (mbox->msg == 0x0) { @@ -207,10 +207,11 @@ return(-1); } - if (mbox->pid != _current->id) { + /* UBU if (mbox->pid != _current->id) { spinUnlock(&mpiSpinLock); return(-1); } + */ msg->header = mbox->msg->header; memcpy(msg->data,mbox->msg->data,MESSAGE_LENGTH); @@ -241,10 +242,12 @@ for (mbox = mboxList;mbox;mbox=mbox->next) { if (!strcmp(mbox->name,name)) { + /* UBU if (mbox->pid != _current->id) { spinUnlock(&mpiSpinLock); return(-1); } + */ mbox->prev->next = mbox->next; mbox->next->prev = mbox->prev; kfree(mbox); @@ -257,10 +260,7 @@ return(-1); } -#endif - /*** - $Log$ - END ***/ + diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 496e0ef..cbe0013 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -225,7 +225,7 @@ } /***************************************************************************************** - Function: void *vmmGetFreeKernelPage(pidType pid); + Function: void *vmm_getFreeKernelPage(pidType pid); Description: Returns A Free Page Mapped To The VM Space @@ -282,15 +282,14 @@ return (0x0); } -/************************************************************************ +/***************************************************************************************** + Function: int vmm_clearVirtualPage(u_int32_t pageAddr) -Function: void vmmClearVirtualPage(uInt32 pageAddr); + Description: This function will set a virtual page to all NULL -Description: This Will Null Out A Page Of Memory + Notes: -Notes: - -************************************************************************/ +*****************************************************************************************/ int vmm_clearVirtualPage(u_int32_t pageAddr) { u_int32_t *src = 0x0; int counter = 0x0; @@ -307,6 +306,60 @@ return (0x0); } +/***************************************************************************************** + Function: void *vmm_getFreeMallocPage(u_int16_t count) + + Description: This function will allocate a free page for malloc + + Notes: + +*****************************************************************************************/ +void *vmm_getFreeMallocPage(u_int16_t count) { + u_int16_t x = 0x0, y = 0x0; + int c = 0x0; + u_int32_t *pageTableSrc = 0x0; + + spinLock(&fkpSpinLock); + /* Lets Search For A Free Page */ + for (x = 960; x < 1024; x++) { + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (VMM_TABLESBASEADDR + (0x1000 * x)); + for (y = 0; y < 1024; y++) { + /* 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 (y + c < 1024) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + vmm_remapPage((uInt32) vmm_findFreePage(VMM_SYS_ID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT,VMM_SYS_ID); + vmm_clearVirtualPage((uInt32) ((x * 0x400000) + ((y + c) * 0x1000))); + } + spinUnlock(&fkpSpinLock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } else { + /* Map A Physical Page To The Virtual Page */ + vmm_remapPage((uInt32) vmm_findFreePage(VMM_SYS_ID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT,VMM_SYS_ID); + /* Clear This Page So No Garbage Is There */ + vmm_clearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&fkpSpinLock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fkpSpinLock); + return (0x0); +} /*** END