diff --git a/BUGS b/BUGS index b0b2abe..d268065 100644 --- a/BUGS +++ b/BUGS @@ -2,4 +2,3 @@ Bugs: -1) Problems in ubthread.... no doing propper mutex diff --git a/TODO b/TODO index 579da05..782b792 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,8 @@ IMPORTANT FIRST THINGS TO DO +Kernel Modules - Start on this for drivers and the like + Bring in ufs to kernel Set up an installer Make sure libc works @@ -26,6 +28,9 @@ $Log$ +Revision 1.3 2004/07/15 12:10:57 reddawg +Updated things todo + Revision 1.2 2004/07/09 02:50:36 reddawg no message diff --git a/src/Makefile.inc b/src/Makefile.inc index d95264c..c30c9f5 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -2,8 +2,8 @@ # Global 'Source' Options # allow you to change your default compiler without affecting your other work -CC = gcc295 -CXX = g++295 +CC = gcc +CXX = g++ LD = ld AR = ar REMOVE = rm -rf diff --git a/src/sys/Makefile b/src/sys/Makefile index 4a96314..3a03b8c 100644 --- a/src/sys/Makefile +++ b/src/sys/Makefile @@ -1,7 +1,7 @@ # $Id$ # Kernel Makefile (C) 2002 The UbixOS Project -all: net-code sde-code pci-code ubixfs-code vfs-code isa-code kernel-code lib-code vmm-code sys-code boot-code init-code devfs-code mpi-code kernel-img +all: net-code sde-code pci-code ubixfs-code vfs-code isa-code kernel-code lib-code vmm-code sys-code boot-code init-code devfs-code mpi-code kmods-code kernel-img boot-code: boot (cd boot;make) @@ -51,6 +51,9 @@ mpi-code: mpi (cd mpi;make) +kmods-code: kmods + (cd kmods;make) + kernel-img: compile (/bin/echo "/* " > ./compile/null.c) (date >> ./compile/null.c) @@ -77,4 +80,5 @@ (cd devfs;make clean) (cd net;make clean) (cd mpi;make clean) + (cd kmods;make clean) (cd ../tools/;make clean) diff --git a/src/sys/include/ubixos/kmod.h b/src/sys/include/ubixos/kmod.h new file mode 100644 index 0000000..d436427 --- /dev/null +++ b/src/sys/include/ubixos/kmod.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + 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 _KMOD_H +#define _KMOD_H + +#include + +#define LD_START 0x1000000 + +uInt32 kmod_load(const char *); + +#endif + +/*** + $Log$ + END + ***/ diff --git a/src/sys/kmods/Makefile b/src/sys/kmods/Makefile new file mode 100644 index 0000000..ba50da0 --- /dev/null +++ b/src/sys/kmods/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = kmod.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/kmods/kmod.c b/src/sys/kmods/kmod.c new file mode 100644 index 0000000..2eed7e5 --- /dev/null +++ b/src/sys/kmods/kmod.c @@ -0,0 +1,176 @@ +/***************************************************************************************** + 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 +#include +#include +#include +#include + +uInt32 kmod_load(const char *kmod_file) { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + int sym = 0x0; + char *newLoc = 0x0; + char *shStr = 0x0; + char *dynStr = 0x0; + uInt32 *reMap = 0x0; + fileDescriptor *kmod_fd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynSym *relSymTab = 0x0; + elfPltInfo *elfRel = 0x0; + + kmod_fd = fopen(kmod_file,"rb"); + + if (kmod_fd == 0x0) { + kprintf("Can not open ld.so\n"); + } + + fseek(kmod_fd,0x0,0x0); + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + assert(binaryHeader); + fread(binaryHeader,sizeof(elfHeader),1,kmod_fd); + + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + assert(programHeader); + fseek(kmod_fd,binaryHeader->ePhoff,0); + fread(programHeader,sizeof(elfSectionHeader),binaryHeader->ePhnum,kmod_fd); + + sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + assert(sectionHeader); + fseek(kmod_fd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,kmod_fd); + + shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); + fseek(kmod_fd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); + fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,kmod_fd); + + for (i=0;iePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + case PT_DYNAMIC: + newLoc = (char *)programHeader[i].phVaddr + LD_START; + /* + 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) { + /* 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); + } + /* Now Load Section To Memory */ + fseek(kmod_fd,programHeader[i].phOffset,0x0); + fread(newLoc,programHeader[i].phFilesz,1,kmod_fd); + break; + case PT_GNU_STACK: + /* Tells us if the stack should be executable. Failsafe to executable + until we add checking */ + break; + case PT_PAX_FLAGS: + /* Not sure... */ + break; + default: + kprintf("Unhandled Header : %08x\n", programHeader[i].phType); + break; + } + } + + for (i=0x0;ieShnum;i++) { + switch (sectionHeader[i].shType) { + case 3: + if (!strcmp((shStr + sectionHeader[i].shName),".dynstr")) { + dynStr = (char *)kmalloc(sectionHeader[i].shSize); + fseek(kmod_fd,sectionHeader[i].shOffset,0x0); + fread(dynStr,sectionHeader[i].shSize,1,kmod_fd); + } + break; + case 9: + elfRel = (elfPltInfo *)kmalloc(sectionHeader[i].shSize); + fseek(kmod_fd,sectionHeader[i].shOffset,0x0); + fread(elfRel,sectionHeader[i].shSize,1,kmod_fd); + + for (x=0x0;xeEntry + LD_START; + + kfree(dynStr); + kfree(shStr); + kfree(relSymTab); + kfree(sectionHeader); + kfree(programHeader); + kfree(binaryHeader); + fclose(kmod_fd); + + return((uInt32)i); + } + +/*** + $Log$ + END + ***/ +