diff --git a/src/bin/init/Makefile b/src/bin/init/Makefile index 3ac0dee..619accb 100755 --- a/src/bin/init/Makefile +++ b/src/bin/init/Makefile @@ -20,7 +20,7 @@ # Link the kernel statically with fixed text+data address @1M $(BINARY) : $(OBJS) - $(LD) -o $@ ../../lib/libc/stdio/*.o ../../lib/libc/sys/*.o $(OBJS) + $(LD) -o $@ ../../lib/libc/stdio/*.o ../../lib/libc/stdlib/*.o ../../lib/libc/sys/*.o $(OBJS) # Compile the source files .cc.o: diff --git a/src/bin/init/main.c b/src/bin/init/main.c index 695f0ba..6640b01 100755 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -10,6 +10,7 @@ **************************************************************************************/ #include +#include #include int main(); @@ -20,20 +21,15 @@ int main() { int i=0; - char data[32]; i = getpid(); printf("This is my pid: [%i]\n",i); for (i=0;i<5;i++) { printf("Init Code [%i]\n",i); } - data[0] = 'T'; - data[1] = 'e'; - data[2] = 's'; - data[3] = 't'; - data[10] = 'Y'; - data[11] = '0'; - data[31] = '\n'; - fwrite(data,sizeof(data),stdout); + if (getpid() != 0) { + printf("Sorry This Program Must Be Started By The Kernel!!!!\n"); + exit(1); + } while(1); - exit(); + exit(1); } \ No newline at end of file diff --git a/src/lib/libc/Makefile b/src/lib/libc/Makefile index f2e2a3c..ed763d8 100755 --- a/src/lib/libc/Makefile +++ b/src/lib/libc/Makefile @@ -21,6 +21,7 @@ lib.so: $(OBJS) (cd stdio;make) + (cd stdlib;make) (cd sys;make) $(LD) -o $(OUTPUT) $(OBJS) ./stdio/*.o ./sys/*.o @@ -45,3 +46,4 @@ $(REMOVE) $(OBJS) $(OUTPUT) (cd stdio;make clean) (cd sys;make clean) + (cd stdlib;make clean) \ No newline at end of file diff --git a/src/lib/libc/include/stdarg.h b/src/lib/libc/include/stdarg.h index 0903960..6dd7906 100755 --- a/src/lib/libc/include/stdarg.h +++ b/src/lib/libc/include/stdarg.h @@ -1,12 +1,16 @@ /************************************************************************************** - Copyright (c) 2002 - The UbixOS Project + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. $Id$ + **************************************************************************************/ -#ifndef _ULIBC_STDARG_H -#define _ULIBC_STDARG_H +#ifndef _STDARG_H +#define _STDARG_H typedef char *vaList; diff --git a/src/lib/libc/include/stdlib.h b/src/lib/libc/include/stdlib.h new file mode 100755 index 0000000..d8f23b6 --- /dev/null +++ b/src/lib/libc/include/stdlib.h @@ -0,0 +1,17 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#ifndef _STDLIB_H +#define _STDLIB_H + +void exit(int); + +#endif \ No newline at end of file diff --git a/src/lib/libc/stdlib/Makefile b/src/lib/libc/stdlib/Makefile new file mode 100755 index 0000000..dd4eb84 --- /dev/null +++ b/src/lib/libc/stdlib/Makefile @@ -0,0 +1,41 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + + +#Compiler +GCC = gcc +G++ = gcc + +#Linker +LD = ld -Bshareable +AR = ar + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = exit.o +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(G++) -Wall -nostdinc -O -I../include -c -o $@ $< + +.cc.s: + $(G++) -Wall -nostdinc -O -I../include -S -o $@ $< + +.c.o: + $(GCC) -Wall -nostdinc -O -I../include -c $< + +.c.s: + $(GCC) -Wall -nostdinc -O -I../include -S -o $@ $< + +.S.o: + $(GCC) -Wall -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c new file mode 100755 index 0000000..371ef58 --- /dev/null +++ b/src/lib/libc/stdlib/exit.c @@ -0,0 +1,17 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +void exit(int status) { + asm( + "int %0\n" + : : "i" (0x80),"a" (2),"b" (status) + ); + } \ No newline at end of file diff --git a/src/lib/libc/sys/getpid.c b/src/lib/libc/sys/getpid.c index 0ef3f17..796e584 100755 --- a/src/lib/libc/sys/getpid.c +++ b/src/lib/libc/sys/getpid.c @@ -12,14 +12,10 @@ #include uShort getpid(void) { - int pid = -1; - uShort *pidPtr; - pidPtr = pid; + char pid[1]; asm( -// "movl %2,%%ebx \n" - "int %0 \n" - : - : "i" (0x80),"a" (1),"b" (pidPtr) + "int %0\n" + : : "i" (0x80),"a" (1),"b" (pid) ); - return(pidPtr); + return(pid[0]); } \ No newline at end of file diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h index 31219f3..31640c1 100755 --- a/src/sys/include/ubixos/syscalls.h +++ b/src/sys/include/ubixos/syscalls.h @@ -14,11 +14,12 @@ void sysFwrite(); void sysGetpid(); +void sysExit(); typedef void (*functionPTR)(); functionPTR systemCalls[] = { - sysFwrite,sysGetpid + sysFwrite,sysGetpid,sysExit }; int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); diff --git a/src/sys/include/vmm/memory.h b/src/sys/include/vmm/memory.h index 5ab60c5..18ead4b 100755 --- a/src/sys/include/vmm/memory.h +++ b/src/sys/include/vmm/memory.h @@ -24,5 +24,6 @@ unsigned long findFreepage(int pid); void initMmap(); void freePage(unsigned long pageAddr); +void freeProcesspages(int pid); #endif \ No newline at end of file diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 3432f8e..6b33096 100755 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -62,12 +62,17 @@ } void sysGetpid() { - int *pid; + char *pid; asm ( - "movl %%ebx,%0\n" - : "=g" (pid) + "" + : "=b" (pid) ); - kprintf("First: [%i]\n",pid); - pid = _current->id; - kprintf("Real: [%i]\n",pid); + pid[0] = _current->id; + } + +void sysExit() { + int *status; + asm("":"=b" (status)); + freeProcesspages(_current->id); + kprintf("Status: [%i]\n",status); } \ No newline at end of file diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index 4acc898..5a68fdd 100755 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -107,4 +107,13 @@ int i=0; i = (pageAddr/4096); memoryMap[i].status = memAvail; + } + +void freeProcesspages(int pid) { + int i=0; + for (i=0;i