diff --git a/src/bin/cat/Makefile b/src/bin/cat/Makefile index 34c2c0a..500e8c1 100755 --- a/src/bin/cat/Makefile +++ b/src/bin/cat/Makefile @@ -29,8 +29,8 @@ # Link The Binary $(BINARY) : $(OBJS) - $(GCC) -nostdlib -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) -# ld -o $@ $(STARTUP) ../../lib/libc/libc.so $(OBJS) +# $(GCC) -nostdlib -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + ld -o $@ $(STARTUP) ../../lib/libc/libc.so $(OBJS) # Compile the source files .cc.o: diff --git a/src/sys/boot/Makefile b/src/sys/boot/Makefile index c84b742..10a6044 100755 --- a/src/sys/boot/Makefile +++ b/src/sys/boot/Makefile @@ -2,27 +2,9 @@ FDDEVICE = "/dev/fd0" #FDDEVICE = /dev/fd1 -NASM = nasm -#NASM = /usr/local/bin/nasm +all: -all: writeimg format - -writeimg: writeimg.c - gcc writeimg.c -o writeimg - -format: format.c - gcc format.c -o format - -install: writeimg - ($(NASM) bootsec.asm -o bootsec) - (cat ../compile/ubix.elf >>bootsec) - (dd if=/dev/zero of=./buf bs=512 count=10) - (cat buf >>bootsec) - (rm -f buf) -# (./writeimg $(FDDEVICE)) - -formatdsk: format - (./format 60 2 bin help.txt readme.txt) +install: clean: (rm -f writeimg format bootsec *.core) diff --git a/src/sys/include/ubixfs/file.h b/src/sys/include/ubixfs/file.h index fe90b2f..479f1be 100755 --- a/src/sys/include/ubixfs/file.h +++ b/src/sys/include/ubixfs/file.h @@ -41,7 +41,7 @@ uShort length; uLong start; uChar fileName[22]; - uChar buffer[512]; + uChar *buffer; } fileDescriptor; typedef struct userFileDescriptorStruct { diff --git a/src/sys/include/ubixos/elf.h b/src/sys/include/ubixos/elf.h index fc51d71..49d13b5 100755 --- a/src/sys/include/ubixos/elf.h +++ b/src/sys/include/ubixos/elf.h @@ -82,5 +82,10 @@ uLong dynInfo; } elfDynsym; +typedef struct { + uLong a; + uLong b; + } elfDynamic; + #endif \ No newline at end of file diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 2608544..632c362 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -102,12 +102,14 @@ unmapPage((0x7C0000 + (0x1000 * i)),0); } //Now Lets Make A Clean Stack - newLoc = (char *)0x5DC000; + newLoc = (char *)0x5DA000; + remapPage(findFreePage(_current->id),0x5DA000); + setPageAttribute(0x5DA000,(pageDefault | pageStack)); remapPage(findFreePage(_current->id),0x5DB000); setPageAttribute(0x5DB000,(pageDefault | pageStack)); remapPage(findFreePage(_current->id),0x5DC000); setPageAttribute(0x5DC000,(pageDefault | pageStack)); - for (i=0;i<4096;i++) { + for (i=0;i<(4096 * 3);i++) { newLoc[i] = 0x0; } i = 0x5DC000+4095; @@ -192,15 +194,29 @@ ************************************************************************/ void sysExec() { - int i = 0,x = 0; - int *status; - uLong eStart = 0; + int i = 0,x = 0,y = 0x0; + int *status = 0x0; + int fdSize = 0x0; + uLong eStart = 0x0; char *binarySpace = (char *)0x7C0000; - char *newLoc; - char *file; + char *librarySpace = (char *)0x6400000; + char *newLoc = 0x0; + char *file = 0x0; + char *binDynStr = 0x0; + char *libDynStr = 0x0; + fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = (elfHeader *)0x7C0000; - elfProgramheader *programHeader; + fileDescriptor *libFd = 0x0; + + elfHeader *binaryHeader = (elfHeader *)0x7C0000; + elfHeader *libraryHeader = (elfHeader *)0x6400000; + elfProgramheader *programHeader = 0x0; + elfSectionheader *sectionHeader = 0x0; + elfProgramheader *libProgramHeader = 0x0; + elfSectionheader *libSectionHeader = 0x0; + elfDynsym *libDynSym = 0x0; + elfDynsym *binDynSym = 0x0; + asm("":"=b"(file),"=c"(status)); asm("sti"); tmpFd = fopen(file,"r"); @@ -216,11 +232,14 @@ //Load The Binary Into Memory Byte For Byte I Should Find A Faster Way for (i=0;feof(tmpFd) == 0;i++) { binarySpace[i] = fgetc(tmpFd); + fdSize = i; } //Close The File fclose(tmpFd); //Set programHeader To Point To Loaded Binary So We Can Gather Info programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); + //Set sectionHeader To Point To Loaded Binary To We Can Gather Info + sectionHeader = (elfSectionheader *)(0x7C0000 + binaryHeader->eShoff); //Loop Through The Header And Load Sections Which Need To Be Loaded for (i=0;iePhnum;i++) { if (programHeader[i].phType == 1) { @@ -239,17 +258,49 @@ } } else if (programHeader[i].phType == 3) { - //kprintf("Interpreter Requiredbn"); + binDynStr = (void *)binarySpace + sectionHeader[4].shOffset; + binDynSym = (void *)binarySpace + sectionHeader[3].shOffset; + libFd = fopen("libc.so","r"); + for (x=0;x<((libFd->size+4095)/4096);x++) { + remapPage(findFreePage(_current->id),((void *)librarySpace + (0x1000 * x))); + } + for (x=0;feof(libFd) == 0;x++) { + librarySpace[x] = fgetc(libFd); + } + kprintf("Size: [%i]\n",x); + fclose(libFd); + libProgramHeader = (void *)((void *)librarySpace + libraryHeader->ePhoff); + libSectionHeader = (void *)((void *)librarySpace + libraryHeader->eShoff); + kprintf("Interpreter: [%s] Required.\n",(char *)(binarySpace + programHeader[i].phOffset)); + kprintf("Library [%s] Required.\n",(char *)(binDynStr + 1)); + libDynStr = (void *)((void *)librarySpace + libSectionHeader[3].shOffset); + libDynSym = (void *)((void *)librarySpace + libSectionHeader[2].shOffset); + for (x=0;x<(libSectionHeader[2].shSize/sizeof(elfDynsym));x++) { + if (libDynSym[x].dynValue > 0x0) { + libDynSym[x].dynValue += (void *)librarySpace; + } + } + for (x=0;x<(sectionHeader[3].shSize/sizeof(elfDynsym));x++) { + if (binDynSym[x].dynInfo == 0x12) { + kprintf("Relocating: [%s]",(void *)binDynStr+binDynSym[x].dynName); + for (y=0;y<(libSectionHeader[2].shSize/sizeof(elfDynsym));y++) { + if (!kstrcmp((void *)binDynStr+binDynSym[x].dynName,(void *)libDynStr+libDynSym[y].dynName)) { + binDynSym[x].dynValue=libDynSym[y].dynValue; + kprintf("Got A Match\n"); + } + } + } + } } } //Get The Starting Point eStart = binaryHeader->eEntry; //Now That We Relocated The Binary We Can Unmap And Free Old Pages - for (i=0;i<((tmpFd->size+4095)/4096);i++) { + for (i=0;i<((fdSize+4095)/4096);i++) { unmapPage((0x7C0000 + (0x1000 * i)),0); } //Set Up Args - + //argv = //Jump To Start Of New Binary asm( "pushl %0\n" diff --git a/src/sys/ubixfs/file.c b/src/sys/ubixfs/file.c index 57e8d76..258f5d4 100755 --- a/src/sys/ubixfs/file.c +++ b/src/sys/ubixfs/file.c @@ -48,6 +48,7 @@ //Search For The File if (findFile((char *)file,tmpFd) == 1) { //If The File Is Found Then Set Up The Descriptor + tmpFd->buffer = (uChar *)0x1000;//(uChar *)kmalloc(sizeof(uChar)*512); sprintf(tmpFd->fileName,"%s",file); //This Will Set Up The Descriptor Modes while (flags[0]) { @@ -123,6 +124,7 @@ //If Fd Is The First FD Then Reset fdTable if (tmpFd == fdTable) { fdTable = tmpFd->next; +// kfree(fd->buffer); kfree(fd); systemVitals->openFiles--; return(1); @@ -131,6 +133,7 @@ else if (tmpFd == lastFd) { prevFd->next = 0x0; lastFd = prevFd; +// kfree(fd->buffer); kfree(fd); systemVitals->openFiles--; return(1); @@ -165,6 +168,7 @@ //If Found Return Next Char if (tmpFd == fd) { ch = getFileByte(tmpFd,tmpFd->offset); + //kprintf("[%i]",ch); tmpFd->offset++; return(ch); } diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c index 8fb7fa0..8856dd7 100755 --- a/src/sys/ubixfs/ubixfs.c +++ b/src/sys/ubixfs/ubixfs.c @@ -87,21 +87,24 @@ batIndex = blockAllocationTable[batIndex].nextBlock; } //Calculate Which Block Sector We Should Load - bSect = ((offset - ((i-1)*4096))/512); +// bSect = ((offset - ((i-1)*4096))/512); // kprintf("bSect: [%i],realSector: [%i]\n",bSect,blockAllocationTable[batIndex].realSector); //Fix FD Status So We Dont Load A Sector Again - if ((offset%512 == 0) && (fd->status == fdRead)) { + // if ((offset%512 == 0) && (fd->status == fdRead)) { + if ((offset%4096 == 0) && (fd->status == fdRead)) { fd->status = fdOpen; } //If The Offset Is Less Then The File Size Return The Char At It if (offset < fd->size) { //If FD Status Is Not fdRead Then Load A Sector From Disk if (fd->status != fdRead) { - readBlock(diskLabel->partitions[0].p_offset+blockAllocationTable[batIndex].realSector+bSect,fd->buffer,1); + //readBlock(diskLabel->partitions[0].p_offset+blockAllocationTable[batIndex].realSector+bSect,fd->buffer,1); + readBlock(diskLabel->partitions[0].p_offset+blockAllocationTable[batIndex].realSector+bSect,fd->buffer,8); fd->status = fdRead; } //This Sets The Char To Return - ch = fd->buffer[offset-(bSect*512)]; + //ch = fd->buffer[offset-(bSect*512)-(blockCount*4096)]; + ch = fd->buffer[offset-(blockCount*4096)]; } else { //Set File EOF If There Is Nothing To Do diff --git a/src/tools/Makefile b/src/tools/Makefile index 02a2a8f..819f870 100755 --- a/src/tools/Makefile +++ b/src/tools/Makefile @@ -51,7 +51,8 @@ (cp ../bin/pwd/pwd ./) (cp ../bin/login/login ./) (cp ../bin/cat/cat ./) - (./format 50 2000 ubix.elf init shell test ls pwd userdb login cat) + (cp ../lib/libc/libc.so ./) + (./format 50 2000 ubix.elf init shell test ls userdb login cat libc.so pwd) (rm ubix.elf) (rm init) (rm shell) @@ -60,3 +61,4 @@ (rm pwd) (rm cat) (rm login) + (rm libc.so)