diff --git a/src/bin/Makefile b/src/bin/Makefile index d374f73..8bb9fee 100755 --- a/src/bin/Makefile +++ b/src/bin/Makefile @@ -1,7 +1,7 @@ # $Id$ # The System Makefile (C) 2002 The UbixOS Project -all: init-bin shell-bin +all: init-bin shell-bin test-bin init-bin: init (cd init;make) @@ -9,6 +9,10 @@ shell-bin: shell (cd shell;make) +test-bin: test + (cd test;make) + clean: (cd init;make clean) (cd shell;make clean) + (cd test;make clean) diff --git a/src/bin/shell/main.c b/src/bin/shell/main.c index c355989..1decfc6 100755 --- a/src/bin/shell/main.c +++ b/src/bin/shell/main.c @@ -42,13 +42,34 @@ } buffer[count] = '\0'; } + +int checkPid(int pid) { + asm( + "int %0\n" + : : "i" (0x80),"a" (6),"b" (&pid) + ); + return(pid); + } int main() { - unsigned char buffer[256]; + unsigned char buffer[256],*tmp; + int cPid = 0; + tmp = &buffer; + printf("Shell Start\n"); while (1) { printf("\nUbixOS: "); gets(&buffer); if (0 == memcmp(buffer, "uname", 5)) printf("\nUbixOS v0.01a " __DATE__" " __TIME__ " \n"); + if (memcmp(buffer,"exec", 4) == 0) { + tmp += 5; + cPid = fork(); + if (!cPid) { + exec(tmp); + } + else { + while (checkPid(cPid)); + } + } } } diff --git a/src/bin/test/Makefile b/src/bin/test/Makefile new file mode 100755 index 0000000..231b1d9 --- /dev/null +++ b/src/bin/test/Makefile @@ -0,0 +1,43 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + + +#Compiler +GCC = gcc +G++ = gcc + +#Linker +LD = ld + +#Kernel File Name +BINARY = test + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +# Link the kernel statically with fixed text+data address @1M +$(BINARY) : $(OBJS) + $(LD) -o $@ ../../lib/libc/stdio/*.o ../../lib/libc/stdlib/*.o ../../lib/libc/sys/*.o $(OBJS) #-Ttext 0x08048000 #-Ttext 0x1200000 + +# Compile the source files +.cc.o: + $(G++) -Wall -fomit-frame-pointer -O -I../../lib/libc/include -c -o $@ $< + +.cc.s: + $(G++) -Wall -fomit-frame-pointer -O -I../../lib/libc/include -S -o $@ $< + +.c.o: + $(GCC) -Wall -O -I../../lib/libc/include -c -o $@ $< + +.c.s: + $(GCC) -Wall -fomit-frame-pointer -O -I../../lib/libc/include -S -o $@ $< + +.S.o: + $(GCC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/test/main.c b/src/bin/test/main.c new file mode 100755 index 0000000..b75c81a --- /dev/null +++ b/src/bin/test/main.c @@ -0,0 +1,36 @@ +/************************************************************************************** + 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$ + +**************************************************************************************/ + +int main(); + +#include + +void _start() { + main(); + } + +int main() { + while (1) { + printf("A"); + } + } diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h index daa3dab..cb88338 100755 --- a/src/sys/include/ubixos/syscalls.h +++ b/src/sys/include/ubixos/syscalls.h @@ -30,11 +30,12 @@ void sysExec(); void sysFork(); void sysFgetc(); +void sysCheckPid(); typedef void (*functionPTR)(); functionPTR systemCalls[] = { - sysFwrite,sysGetpid,sysExit,sysExec,sysFork,sysFgetc + sysFwrite,sysGetpid,sysExit,sysExec,sysFork,sysFgetc,sysCheckPid }; int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 322fa65..9f4a6a2 100755 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -89,18 +89,16 @@ elfProgramheader *programHeader; asm("":"=b"(file)); asm("sti"); - kprintf("test"); fd = (int)fopen(file,1); - kprintf("FD: [%i]\n",fd); for (i=0;feof(fd) == 0;i++) { binarySpace[i] = fgetc(fd); } + fclose(fd); programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); newLoc = (char *)programHeader->phVaddr; for (x=0;x<=i;x++) { newLoc[x] = binarySpace[x]; } - kprintf("La [%i]\n",i); asm( "jmp *%0\n" : @@ -116,4 +114,15 @@ if (fd == 0) { ptr[0] = getch(); } + } + +void sysCheckPid() { + int *ptr; + asm("": "=b" (ptr)); + if (taskList[*ptr].status = ACTIVE) { + *ptr = 1; + } + else { + *ptr = 0; + } } \ No newline at end of file diff --git a/src/tools/Makefile b/src/tools/Makefile index 55b63a9..2f814f6 100755 --- a/src/tools/Makefile +++ b/src/tools/Makefile @@ -45,6 +45,8 @@ format-dsk: (cp ../bin/init/init ./) (cp ../bin/shell/shell ./) - (./format 101 init shell) + (cp ../bin/test/test ./) + (./format 101 init shell test) (rm init) (rm shell) + (rm test)