diff --git a/src/bin/shell/Makefile b/src/bin/shell/Makefile index d222b38..2f58303 100755 --- a/src/bin/shell/Makefile +++ b/src/bin/shell/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/stdlib/*.o ../../lib/libc/sys/*.o $(OBJS) #-Ttext 0x1200000 + $(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: diff --git a/src/sys/include/ubixos/schedule.h b/src/sys/include/ubixos/schedule.h index ea58439..e5203dd 100755 --- a/src/sys/include/ubixos/schedule.h +++ b/src/sys/include/ubixos/schedule.h @@ -90,9 +90,10 @@ uShort uid; uShort gid; uLong pageDirectory; + char fileImage[256]; }; -extern struct taskStruct taskList[numTasks]; +extern struct taskStruct *taskList; extern struct taskStruct *_current,*_usedMath; extern int currentProc; diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index 8f4861c..4a91a89 100755 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -24,6 +24,8 @@ #ifndef _PAGING_H #define _PAGING_H +#include + #define pageLength 0x00000400 #define pageSize 4096 #define pagePresent 0x00000001 @@ -36,6 +38,7 @@ void initPaging(); unsigned int allocPage(); +void remapPage(uInt source,uInt dest); void pageFault(); void _pageFault(); diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 96455e4..a7ef9ed 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -40,6 +40,7 @@ } programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); newLoc = (char *)programHeader->phVaddr; + kprintf("[%i]\n",programHeader->phOffset); for (x=0;x #include +#include void idleThread() { + unsigned char *testBuf = (char *)0x1000000; + unsigned char *testBuf2 = (char *)0xB8000; /* This thread is for maintinance */ + remapPage(0xB8000,0x1000000); while (1) { + //if (testBuf[0] != 'c') { remapPage(0xB8000,0x1000000); } + testBuf[0] = 'c'; + testBuf[1] = printColor; + testBuf2[2] = 'd'; + testBuf2[3] = printColor; + //kprintf("M[%i]R[%i]\n",testBuf[0],testBuf2[0]); + //remapPage(0xB8000,0x1000000); //checkTasks(); /* Looks for run away proccesses and kills thems */ } } \ No newline at end of file diff --git a/src/sys/kernel/schedule.c b/src/sys/kernel/schedule.c index 1bc09d3..8c59565 100755 --- a/src/sys/kernel/schedule.c +++ b/src/sys/kernel/schedule.c @@ -28,7 +28,7 @@ #include int currentProc; -struct taskStruct taskList[numTasks]; +struct taskStruct *taskList = (struct taskStruct *)0xDAC00000; struct taskStruct *_current,*_usedMath = 0x0; extern union descriptorTableunion GDT[7]; diff --git a/src/sys/kernel/vsprintf.c b/src/sys/kernel/vsprintf.c index 768bc2d..0c9ba99 100755 --- a/src/sys/kernel/vsprintf.c +++ b/src/sys/kernel/vsprintf.c @@ -2,46 +2,239 @@ 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. + Redistribution and use in source and binary forms, with or without modification, + are prohibited. $Id$ **************************************************************************************/ +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + #include -int vsprintf(char *buffer, const char *format, vaList args) { - int length, x,intVal; - char *outputString, *string; - for (outputString=buffer;*format;format++) { - if (*format != '%') { - *outputString++ = *format; - } - else { - format++; - switch (*format) { - case 's': - string = vaArg(args, char *); - length = strlen(string); - for (x=0; x= '0' && (c) <= '9') + +static int skip_atoi(const char **s) +{ + int i=0; + + while (is_digit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define SMALL 64 /* use 'abcdef' instead of 'ABCDEF' */ + +#define do_div(n,base) ({ \ +int __res; \ +__asm__("divl %4":"=a" (n),"=d" (__res):"0" (n),"1" (0),"r" (base)); \ +__res; }) + +static char * number(char * str, int num, int base, int size, int precision + ,int type) +{ + char c,sign,tmp[36]; + const char *digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + + if (type&SMALL) digits="0123456789abcdefghijklmnopqrstuvwxyz"; + if (type&LEFT) type &= ~ZEROPAD; + if (base<2 || base>36) + return 0; + c = (type & ZEROPAD) ? '0' : ' ' ; + if (type&SIGN && num<0) { + sign='-'; + num = -num; + } else + sign=(type&PLUS) ? '+' : ((type&SPACE) ? ' ' : 0); + if (sign) size--; + if (type&SPECIAL) { + if (base==16) { size -= 2; } + else if (base==8) { size--; } + } + i=0; + if (num==0) + tmp[i++]='0'; + else while (num!=0) + tmp[i++]=digits[do_div(num,base)]; + if (i>precision) precision=i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type&SPECIAL) { + if (base==8) { + *str++ = '0'; + } + else if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type&LEFT)) + while(size-->0) + *str++ = c; + while(i0) + *str++ = tmp[i]; + while(size-->0) + *str++ = ' '; + return str; +} + +int vsprintf(char *buf, const char *fmt, vaList args) +{ + int len; + int i; + char * str; + char *s; + int *ip; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + + for (str=buf ; *fmt ; ++fmt) { + if (*fmt != '%') { + *str++ = *fmt; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (is_digit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + field_width = vaArg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (is_digit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + precision = vaArg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + ++fmt; + } + + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + *str++ = ' '; + *str++ = (unsigned char) vaArg(args, int); + while (--field_width > 0) + *str++ = ' '; + break; + + case 's': + s = vaArg(args, char *); + len = strlen(s); + if (precision < 0) + precision = len; + else if (len > precision) + len = precision; + + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + break; + + case 'o': + str = number(str, vaArg(args, unsigned long), 8, + field_width, precision, flags); + break; + + case 'p': + if (field_width == -1) { + field_width = 8; + flags |= ZEROPAD; + } + str = number(str, + (unsigned long) vaArg(args, void *), 16, + field_width, precision, flags); + break; + + case 'x': + flags |= SMALL; + case 'X': + str = number(str, vaArg(args, unsigned long), 16, + field_width, precision, flags); + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + str = number(str, vaArg(args, unsigned long), 10, + field_width, precision, flags); + break; + + case 'n': + ip = vaArg(args, int *); + *ip = (str - buf); + break; + + default: + if (*fmt != '%') + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + break; + } + } + *str = '\0'; + return str-buf; +} diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 32be090..e49cd49 100755 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -77,6 +77,29 @@ return(page); } +void remapPage(uInt source,uInt dest) { + uInt spi=0,spage=0,dpi=0,dpage=0; + uInt *srcPagetable,*dstPagetable; + + spi = source/(1024*4096); + spage = (source-(spi*(1024*4096)))/4096; + dpi = dest/(1024*4096); + dpage = (dest-(dpi*(1024*4096)))/4096; + srcPagetable = (unsigned int *)(pageDirectory[spi]-39); + if (pageDirectory[dpi] == 0) { + pageDirectory[dpi] = (unsigned int *)(allocPage()+39); + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + dstPagetable = (unsigned int *)(pageDirectory[dpi]-39); + dstPagetable[dpage] = srcPagetable[spage]; + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } void pageFault() { uInt cr2 = 0,i = 0, page = 0,pi = 0; diff --git a/ubixos.kdevprj b/ubixos.kdevprj index 7e4f5d5..0f43927 100755 --- a/ubixos.kdevprj +++ b/ubixos.kdevprj @@ -44,7 +44,7 @@ kdevprj_version=1.3 lfv_open_groups=Others make_options=\s-j1 clean all install -makefiles=./Makefile.am,src/Makefile.am,src/sys/Makefile.am,src/sys/include/Makefile.am,src/lib/Makefile.am,src/lib/libc/Makefile.am,src/lib/libc/include/Makefile.am,src/bin/Makefile.am,src/bin/shell/Makefile.am,Makefile.am,src/sys/boot/Makefile.am,src/sys/init/Makefile.am,src/sys/include/ubixos/Makefile.am,src/sys/drivers/Makefile.am,src/sys/kernel/Makefile.am,src/sys/compile/Makefile.am,src/sys/include/version/Makefile.am,src/sys/include/drivers/Makefile.am,src/sys/vmm/Makefile.am,src/sys/include/vmm/Makefile.am,src/sys/include/ubixfs/Makefile.am,src/sys/ubixfs/Makefile.am,src/tools/Makefile.am,src/bin/init/Makefile.am,src/lib/libc/stdio/Makefile.am,src/lib/libc/include/sys/Makefile.am,src/lib/libc/sys/Makefile.am,src/lib/libc/stdlib/Makefile.am,src/sys/misc/Makefile.am,src/sys/deviceman/Makefile.am,src/grayspace-misc/Makefile.am,src/sys/include/deviceman/Makefile.am,src/sys/include/misc/Makefile.am +makefiles=./Makefile.am,src/Makefile.am,src/sys/Makefile.am,src/sys/include/Makefile.am,src/lib/Makefile.am,src/lib/libc/Makefile.am,src/lib/libc/include/Makefile.am,src/bin/Makefile.am,src/bin/shell/Makefile.am,Makefile.am,src/sys/boot/Makefile.am,src/sys/init/Makefile.am,src/sys/include/ubixos/Makefile.am,src/sys/drivers/Makefile.am,src/sys/kernel/Makefile.am,src/sys/compile/Makefile.am,src/sys/include/version/Makefile.am,src/sys/include/drivers/Makefile.am,src/sys/vmm/Makefile.am,src/sys/include/vmm/Makefile.am,src/sys/include/ubixfs/Makefile.am,src/sys/ubixfs/Makefile.am,src/tools/Makefile.am,src/bin/init/Makefile.am,src/lib/libc/stdio/Makefile.am,src/lib/libc/include/sys/Makefile.am,src/lib/libc/sys/Makefile.am,src/lib/libc/stdlib/Makefile.am,src/sys/misc/Makefile.am modifyMakefiles=true project_name=UbixOS project_type=normal_empty @@ -94,7 +94,7 @@ [src/Makefile.am] files= -sub_dirs=sys,lib,bin,tools,grayspace-misc +sub_dirs=sys,lib,bin,tools type=normal [src/bin/Makefile] @@ -142,17 +142,6 @@ install_location= type=SOURCE -[src/grayspace-misc/Makefile.am] -files=src/grayspace-misc/gsdefines.h -sub_dirs= -type=normal - -[src/grayspace-misc/gsdefines.h] -dist=true -install=false -install_location= -type=HEADER - [src/lib/Makefile.am] sub_dirs=libc, type=normal @@ -321,7 +310,7 @@ [src/sys/Makefile.am] files=src/sys/Makefile -sub_dirs=include,boot,init,drivers,kernel,compile,vmm,ubixfs,misc,deviceman +sub_dirs=include,boot,init,drivers,kernel,compile,vmm,ubixfs,misc type=normal [src/sys/boot/Makefile] @@ -352,23 +341,6 @@ sub_dirs= type=normal -[src/sys/deviceman/Makefile] -dist=true -install=false -install_location= -type=DATA - -[src/sys/deviceman/Makefile.am] -files=src/sys/deviceman/Makefile,src/sys/deviceman/bus_resources_portio.c -sub_dirs= -type=static_library - -[src/sys/deviceman/bus_resources_portio.c] -dist=true -install=false -install_location= -type=SOURCE - [src/sys/drivers/8259.c] dist=true install=false @@ -406,44 +378,9 @@ [src/sys/include/Makefile.am] files=src/sys/include/stdarg.h -sub_dirs=ubixos,version,drivers,vmm,ubixfs,deviceman,misc +sub_dirs=ubixos,version,drivers,vmm,ubixfs type=normal -[src/sys/include/deviceman/Makefile.am] -files=src/sys/include/deviceman/bus.h,src/sys/include/deviceman/bus_resources.h,src/sys/include/deviceman/bus_resources_portio.h,src/sys/include/deviceman/device.h,src/sys/include/deviceman/isapnp.h -sub_dirs= -type=normal - -[src/sys/include/deviceman/bus.h] -dist=true -install=false -install_location= -type=HEADER - -[src/sys/include/deviceman/bus_resources.h] -dist=true -install=false -install_location= -type=HEADER - -[src/sys/include/deviceman/bus_resources_portio.h] -dist=true -install=false -install_location= -type=HEADER - -[src/sys/include/deviceman/device.h] -dist=true -install=false -install_location= -type=HEADER - -[src/sys/include/deviceman/isapnp.h] -dist=true -install=false -install_location= -type=HEADER - [src/sys/include/drivers/8259.h] dist=true install=false @@ -473,23 +410,6 @@ install_location= type=HEADER -[src/sys/include/misc/Makefile.am] -files=src/sys/include/misc/kernel_string_pool.h,src/sys/include/misc/misc_bit_array.h -sub_dirs= -type=normal - -[src/sys/include/misc/kernel_string_pool.h] -dist=true -install=false -install_location= -type=HEADER - -[src/sys/include/misc/misc_bit_array.h] -dist=true -install=false -install_location= -type=HEADER - [src/sys/include/stdarg.h] dist=true install=false @@ -709,7 +629,7 @@ type=SOURCE [src/sys/misc/Makefile.am] -files=src/sys/misc/kernel_string_pool.c,src/sys/misc/misc_bit_array.c +files=src/sys/misc/kernel_string_pool.c,src/sys/misc/kernel_string_pool.h,src/sys/misc/misc_bit_array.c sharedlib_LDFLAGS=-version-info 0:0:1 sharedlib_rootname=misc sub_dirs= @@ -721,6 +641,12 @@ install_location= type=SOURCE +[src/sys/misc/kernel_string_pool.h] +dist=true +install=false +install_location= +type=HEADER + [src/sys/misc/misc_bit_array.c] dist=true install=false