diff --git a/src/sys/Makefile b/src/sys/Makefile index c7f5437..959cd34 100644 --- a/src/sys/Makefile +++ b/src/sys/Makefile @@ -2,7 +2,7 @@ # # $Id$ -all: vmm-code lib-code sys-code init-code kernel-img +all: kernel-code vmm-code lib-code sys-code init-code kernel-img vmm-code: vmm (cd vmm;make) @@ -15,6 +15,9 @@ init-code: init (cd init;make) + +kernel-code: kernel + (cd kernel;make) kernel-img: compile (/bin/echo "/* " > ./compile/null.c) @@ -31,5 +34,6 @@ (cd lib;make clean) (cd sys;make clean) (cd init;make clean) + (cd kernel;make clean) (cd compile;make clean) (cd ../tools/;make clean) diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile index 9deb702..c6bb980 100644 --- a/src/sys/compile/Makefile +++ b/src/sys/compile/Makefile @@ -10,7 +10,7 @@ OBJS = null.o #Kernel Parts -KPARTS = ../vmm/*.o ../lib/*.o ../sys/*.o ../init/*.o +KPARTS = ../kernel/*.o ../vmm/*.o ../lib/*.o ../sys/*.o ../init/*.o # Link the kernel statically with fixed text+data address @1M $(KERNEL) : $(OBJS) diff --git a/src/sys/include/sys/kpanic.h b/src/sys/include/sys/kpanic.h new file mode 100644 index 0000000..3586136 --- /dev/null +++ b/src/sys/include/sys/kpanic.h @@ -0,0 +1,40 @@ +/***************************************************************************************** + 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 _KPANIC_H +#define _KPANIC_H + +void kpanic(const char *fmt, ...); + +#endif + +/*** + END + ***/ + diff --git a/src/sys/include/vmm/vmm.h b/src/sys/include/vmm/vmm.h index 264c480..917d974 100644 --- a/src/sys/include/vmm/vmm.h +++ b/src/sys/include/vmm/vmm.h @@ -60,6 +60,7 @@ int cowCounter; } mMap; +int vmm_clearVirtualPage(u_int32_t); void vmm_pageFault(); void _vmm_pageFault(); int vmm_pagingInit(); @@ -71,7 +72,6 @@ int vmm_buildMemoryMap(); int vmm_init(); - extern uInt32 vmm_numPages; extern mMap *vmm_memoryMap; diff --git a/src/sys/kernel/Makefile b/src/sys/kernel/Makefile new file mode 100644 index 0000000..d2937a6 --- /dev/null +++ b/src/sys/kernel/Makefile @@ -0,0 +1,28 @@ +# (C) 2002-2004 The UbixOS Project +# +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = kpanic.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/kernel/kpanic.c b/src/sys/kernel/kpanic.c new file mode 100644 index 0000000..af840c8 --- /dev/null +++ b/src/sys/kernel/kpanic.c @@ -0,0 +1,63 @@ +/***************************************************************************************** + 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 + + +/************************************************************************ + +Function: void kpanic(const char *fmt, ...) + +Description: This function is used to cause a kernel panic + +Notes: + +************************************************************************/ +void kpanic(const char *fmt, ...) { + char buf[512]; + vaList args; + + vaStart(args, fmt); + vsprintf(buf, fmt, args); + vaEnd(args); + + kprintf("kPanic: %s", buf); + + /* Halt The System */ + asm("cli"); + while (1) + asm("hlt"); + } + +/*** + END + ***/ diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index f679dcf..496e0ef 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -34,11 +34,13 @@ #include #include #include +#include #include #include static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; -static uInt32 *kernelPageDirectory = 0x0; +static spinLock_t fkpSpinLock = SPIN_LOCK_INITIALIZER; +static u_int32_t *kernelPageDirectory = 0x0; /***************************************************************************************** @@ -65,7 +67,7 @@ } /* end if */ /* Clear The Memory To Ensure There Is No Garbage */ - for (i = 0; i < VMM_PAGEENTRIES; i++) { + for (i = 0x0; i < VMM_PAGEENTRIES; i++) { (uInt32) kernelPageDirectory[i] = (uInt32) 0x0; } /* end for */ @@ -222,6 +224,90 @@ return (source); } +/***************************************************************************************** + Function: void *vmmGetFreeKernelPage(pidType pid); + + Description: Returns A Free Page Mapped To The VM Space + + Notes: + 07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel + +*****************************************************************************************/ +void *vmm_getFreeKernelPage(pidType pid, u_int16_t count) { + int x = 0, y = 0, c = 0; + u_int32_t *pageTableSrc = 0x0; + + spinLock(&fkpSpinLock); + /* Lets Search For A Free Page */ + for (x = 768; x < 1024; x++) { + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (VMM_TABLESBASEADDR + (4096 * 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++) { + if ((vmm_remapPage((uInt32) vmm_findFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT,pid)) == 0x0) + kpanic("vmmRemapPage failed: gfkp-1\n"); + vmm_clearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + spinUnlock(&fkpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } else { + /* Map A Physical Page To The Virtual Page */ + + if ((vmm_remapPage((uInt32) vmm_findFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),KERNEL_PAGE_DEFAULT,pid)) == 0x0) + kpanic("vmmRemapPage failed: gfkp-2\n"); + /* Clear This Page So No Garbage Is There */ + vmm_clearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&fkpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fkpSpinLock); + return (0x0); +} + +/************************************************************************ + +Function: void vmmClearVirtualPage(uInt32 pageAddr); + +Description: This Will Null Out A Page Of Memory + +Notes: + +************************************************************************/ +int vmm_clearVirtualPage(u_int32_t pageAddr) { + u_int32_t *src = 0x0; + int counter = 0x0; + + /* Set Source Pointer To Virtual Page Address */ + src = (uInt32 *) pageAddr; + + /* Clear Out The Page */ + for (counter = 0x0; counter < VMM_PAGEENTRIES; counter++) { + (uInt32) src[counter] = (uInt32) 0x0; + } + + /* Return */ + return (0x0); +} + + /*** END ***/