diff --git a/Makefile b/Makefile index 203903f..cd8b6d1 100755 --- a/Makefile +++ b/Makefile @@ -1,11 +1,14 @@ # $Id$ # The System Makefile (C) 2002 The UbixOS Project -all: libc kernel +all: libc bin kernel libc: src (cd src/lib/libc;make) +bin: src + (cd src/bin;make) + kernel: src (cd src/sys;make) @@ -14,4 +17,5 @@ clean: (cd src/sys;make clean) - (cd src/lib/libc;make clean) \ No newline at end of file + (cd src/lib/libc;make clean) + (cd src/bin;make clean) \ No newline at end of file diff --git a/src/bin/Makefile b/src/bin/Makefile new file mode 100755 index 0000000..457973d --- /dev/null +++ b/src/bin/Makefile @@ -0,0 +1,10 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +all: init-bin + +init-bin: init + (cd init;make) + +clean: + (cd init;make clean) diff --git a/src/bin/init/Makefile b/src/bin/init/Makefile new file mode 100755 index 0000000..3ac0dee --- /dev/null +++ b/src/bin/init/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 = init + +#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/sys/*.o $(OBJS) + +# 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/init/main.c b/src/bin/init/main.c new file mode 100755 index 0000000..695f0ba --- /dev/null +++ b/src/bin/init/main.c @@ -0,0 +1,39 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include +#include + +int main(); + +void _start() { + main(); + } + +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); + while(1); + exit(); + } \ No newline at end of file diff --git a/src/lib/libc/Makefile b/src/lib/libc/Makefile index a6bcd9d..f2e2a3c 100755 --- a/src/lib/libc/Makefile +++ b/src/lib/libc/Makefile @@ -3,7 +3,7 @@ #Compiler -GCC = gcc +GCC = gcc G++ = gcc #Linker @@ -14,13 +14,15 @@ REMOVE = rm -f #Objects -OBJS = vsprintf.o +OBJS = #Output OUTPUT = libc.so lib.so: $(OBJS) - $(LD) -o $(OUTPUT) $(OBJS) + (cd stdio;make) + (cd sys;make) + $(LD) -o $(OUTPUT) $(OBJS) ./stdio/*.o ./sys/*.o # Compile the source files .cc.o: @@ -41,3 +43,5 @@ # Clean up the junk clean: $(REMOVE) $(OBJS) $(OUTPUT) + (cd stdio;make clean) + (cd sys;make clean) diff --git a/src/lib/libc/include/stdarg.h b/src/lib/libc/include/stdarg.h index df1c4e9..0903960 100755 --- a/src/lib/libc/include/stdarg.h +++ b/src/lib/libc/include/stdarg.h @@ -11,8 +11,8 @@ typedef char *vaList; #define _vaSize(TYPE) (((sizeof(TYPE) + sizeof(int) -1) / sizeof(int)) * sizeof(int)) -#define va_start(AP, LASTARG) (AP=((vaList)&(LASTARG) + _vaSize(LASTARG))) -#define va_end(AP) -#define va_arg(AP, TYPE) (AP += _vaSize(TYPE), *((TYPE *)(AP - _vaSize(TYPE)))) +#define vaStart(AP, LASTARG) (AP=((vaList)&(LASTARG) + _vaSize(LASTARG))) +#define vaEnd(AP) +#define vaArg(AP, TYPE) (AP += _vaSize(TYPE), *((TYPE *)(AP - _vaSize(TYPE)))) -#endif \ No newline at end of file +#endif diff --git a/src/lib/libc/include/stdio.h b/src/lib/libc/include/stdio.h new file mode 100755 index 0000000..ade6696 --- /dev/null +++ b/src/lib/libc/include/stdio.h @@ -0,0 +1,40 @@ +/************************************************************************************** + 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 _STDIO_H +#define _STDIO_H + +#include + +/* Type Definitions */ + +typedef struct fileDescriptorTable { + unsigned short fd; + } FILE; + +/* Definitions */ + +extern FILE fdTable[]; + +#define stdin (&fdTable[0]) +#define stdout (&fdTable[1]) +#define stderr (&fdTable[2]) + +/* Functions Definitions */ + +int fprintf(FILE *, const char *,...); +int printf(const char *,...); +int vfprintf(FILE *,const char *,vaList args); +int vsprintf(char *buf,const char *fmt,vaList args); +FILE *fopen(const char *,const char *); +int fwrite(const void *ptr,int size,FILE *fd); + +#endif \ No newline at end of file diff --git a/src/lib/libc/include/sys/types.h b/src/lib/libc/include/sys/types.h new file mode 100755 index 0000000..12d1a30 --- /dev/null +++ b/src/lib/libc/include/sys/types.h @@ -0,0 +1,20 @@ +/************************************************************************************** + 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 _TYPES_H +#define _TYPES_H + +typedef unsigned short uShort; +typedef unsigned long uLong; +typedef unsigned char uChar; +typedef unsigned int uInt; + +#endif \ No newline at end of file diff --git a/src/lib/libc/include/unistd.h b/src/lib/libc/include/unistd.h new file mode 100755 index 0000000..8fbd476 --- /dev/null +++ b/src/lib/libc/include/unistd.h @@ -0,0 +1,19 @@ +/************************************************************************************** + 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 _UNISTD_H +#define _UNISTD_H + +#include + +uShort getpid(void); + +#endif \ No newline at end of file diff --git a/src/lib/libc/stdio/Makefile b/src/lib/libc/stdio/Makefile new file mode 100755 index 0000000..e3c36d5 --- /dev/null +++ b/src/lib/libc/stdio/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 = printf.o vsprintf.o fd.o vfprintf.o fopen.o fwrite.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/stdio/fd.c b/src/lib/libc/stdio/fd.c new file mode 100755 index 0000000..0c0e127 --- /dev/null +++ b/src/lib/libc/stdio/fd.c @@ -0,0 +1,18 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include + +FILE fdTable[3] = { + {0}, /* stdin */ + {1}, /* stdout */ + {2} /* stderr */ + }; \ No newline at end of file diff --git a/src/lib/libc/stdio/fopen.c b/src/lib/libc/stdio/fopen.c new file mode 100755 index 0000000..9cfa0d0 --- /dev/null +++ b/src/lib/libc/stdio/fopen.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$ + +**************************************************************************************/ + +#include + +FILE *fopen(const char *file,const char *mode) { + FILE *fp = 0x0; + return(fp); + } \ No newline at end of file diff --git a/src/lib/libc/stdio/fprintf.c b/src/lib/libc/stdio/fprintf.c new file mode 100755 index 0000000..4f85a33 --- /dev/null +++ b/src/lib/libc/stdio/fprintf.c @@ -0,0 +1,19 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +int fprintf(FILE *fp, const char *fmt, ...) { + int retVal; + vaList ap; + vaStart(ap, fmt); + retVal = vfprintf(fp, fmt, ap); + vaEnd(ap); + return(retVal); + } \ No newline at end of file diff --git a/src/lib/libc/stdio/fwrite.c b/src/lib/libc/stdio/fwrite.c new file mode 100755 index 0000000..ab491f3 --- /dev/null +++ b/src/lib/libc/stdio/fwrite.c @@ -0,0 +1,22 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include + +int fwrite(const void *ptr,int size,FILE *fd) { + int retVal = size; + asm( + "int %0" + : + : "i" (0x80),"a" (0),"b" (ptr),"c" (size),"d" (fd->fd) + ); + return(retVal); + } \ No newline at end of file diff --git a/src/lib/libc/stdio/printf.c b/src/lib/libc/stdio/printf.c new file mode 100755 index 0000000..23140a3 --- /dev/null +++ b/src/lib/libc/stdio/printf.c @@ -0,0 +1,22 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include +#include + +int printf(char const *fmt, ...) { + int retVal; + vaList ap; + vaStart(ap, fmt); + retVal = vfprintf(stdout, fmt, ap); + vaEnd(ap); + return(retVal); + } \ No newline at end of file diff --git a/src/lib/libc/stdio/vfprintf.c b/src/lib/libc/stdio/vfprintf.c new file mode 100755 index 0000000..9498a2e --- /dev/null +++ b/src/lib/libc/stdio/vfprintf.c @@ -0,0 +1,20 @@ +/************************************************************************************** + Copyright (c) 2002 + The UbixOS Project + + $Id$ +**************************************************************************************/ + +#include + +int vfprintf(FILE *fd,const char *fmt,vaList args) { + int retVal = 0; + char data[1024]; + retVal = vsprintf(data,fmt,args); + asm( + "int %0" + : + : "i" (0x80),"a" (0),"b" (data),"c" (sizeof(data)),"d" (fd->fd) + ); + return(retVal); + } \ No newline at end of file diff --git a/src/lib/libc/stdio/vsprintf.c b/src/lib/libc/stdio/vsprintf.c new file mode 100755 index 0000000..0c9ba99 --- /dev/null +++ b/src/lib/libc/stdio/vsprintf.c @@ -0,0 +1,240 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + 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 + +/* we use this so that we can do without the ctype library */ +#define is_digit(c) ((c) >= '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/lib/libc/sys/Makefile b/src/lib/libc/sys/Makefile new file mode 100755 index 0000000..992ade4 --- /dev/null +++ b/src/lib/libc/sys/Makefile @@ -0,0 +1,42 @@ +# $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 = exec.o getpid.o + +#Output +OUTPUT = sys.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/sys/exec.c b/src/lib/libc/sys/exec.c new file mode 100755 index 0000000..fee174d --- /dev/null +++ b/src/lib/libc/sys/exec.c @@ -0,0 +1,2 @@ +void exec() { + } diff --git a/src/lib/libc/sys/getpid.c b/src/lib/libc/sys/getpid.c new file mode 100755 index 0000000..0ef3f17 --- /dev/null +++ b/src/lib/libc/sys/getpid.c @@ -0,0 +1,25 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include + +uShort getpid(void) { + int pid = -1; + uShort *pidPtr; + pidPtr = pid; + asm( +// "movl %2,%%ebx \n" + "int %0 \n" + : + : "i" (0x80),"a" (1),"b" (pidPtr) + ); + return(pidPtr); + } \ No newline at end of file diff --git a/src/sys/Makefile b/src/sys/Makefile index d7567f5..75a53d9 100755 --- a/src/sys/Makefile +++ b/src/sys/Makefile @@ -29,6 +29,7 @@ install: (cd boot;make install) + (cd ../tools/;make format-dsk) clean: (cd boot;make clean) @@ -38,3 +39,4 @@ (cd compile;make clean) (cd vmm;make clean) (cd ubixfs;make clean) + (cd ../tools/;make clean) diff --git a/src/sys/boot/Makefile b/src/sys/boot/Makefile index 699e1ff..5ccef0c 100755 --- a/src/sys/boot/Makefile +++ b/src/sys/boot/Makefile @@ -17,6 +17,7 @@ (./format $(FDDEVICE) 101 2 help.txt readme.txt) ($(NASM) bootsec.asm -o bootsec) (cat ../compile/ubix.elf >>bootsec) + (cat buf >>bootsec) (./writeimg $(FDDEVICE)) (rm bootsec) diff --git a/src/sys/boot/buf b/src/sys/boot/buf new file mode 100755 index 0000000..ed17e0a --- /dev/null +++ b/src/sys/boot/buf Binary files differ diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile index 050509c..79261e9 100755 --- a/src/sys/compile/Makefile +++ b/src/sys/compile/Makefile @@ -40,4 +40,4 @@ # Clean up the junk clean: - $(REMOVE) $(OBJS) $(KERNEL) + $(REMOVE) $(OBJS) $(KERNEL) null.c diff --git a/src/sys/include/ubixfs/file.h b/src/sys/include/ubixfs/file.h new file mode 100755 index 0000000..082605c --- /dev/null +++ b/src/sys/include/ubixfs/file.h @@ -0,0 +1,42 @@ +/************************************************************************************** + 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 _FILE_H +#define _FILE_H + +#include + +#define maxFd 32 +#define fdAvail 1 +#define fdOpen 2 +#define fdRead 3 +#define fdEof 4 + +struct fileDescriptorTable { + uShort id; + uShort status; + uShort mode; + uShort offset; + uShort size; + uShort length; + uLong start; + uChar fileName[22]; + uChar buffer[512]; + }; + +extern struct fileDescriptorTable fdTable[maxFd]; + +int fopen(char *file,int mode); +int fclose(int fd); +int feof(int fd); +int fgetc(int fd); + +#endif \ No newline at end of file diff --git a/src/sys/include/ubixfs/ubixfs.h b/src/sys/include/ubixfs/ubixfs.h index 1e5ba7a..4c6b4b1 100755 --- a/src/sys/include/ubixfs/ubixfs.h +++ b/src/sys/include/ubixfs/ubixfs.h @@ -13,11 +13,13 @@ #define _UBIXFS_H #include +#include struct fileTableEntry { - uChar fileName[24]; + uChar fileName[22]; uShort start; - uShort end; + uShort length; + uShort size; uShort attributes; uShort reserved; }; @@ -38,5 +40,8 @@ }; void initUbixFS(); +int findFile(char *file,struct fileDescriptorTable *head); +int readFile(char *file); +int getFileByte(int fd,int offset); #endif \ No newline at end of file diff --git a/src/sys/include/ubixos/a.out.h b/src/sys/include/ubixos/a.out.h new file mode 100755 index 0000000..d8dae1b --- /dev/null +++ b/src/sys/include/ubixos/a.out.h @@ -0,0 +1,28 @@ +/************************************************************************************** + 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 _A_OUT_H +#define _A_OUT_H + +#include + +typedef struct { + uLong aMagic; /* Use macros N_MAGIC, etc for access */ + unsigned aText; /* length of text, in bytes */ + unsigned aData; /* length of data, in bytes */ + unsigned aBss; /* length of uninitialized data area for file, in bytes */ + unsigned aSyms; /* length of symbol table data in file, in bytes */ + unsigned aEntry; /* start address */ + unsigned aTrsize; /* length of relocation info for text, in bytes */ + unsigned aDrsize; /* length of relocation info for data, in bytes */ + } aoutHeader; + +#endif \ No newline at end of file diff --git a/src/sys/include/ubixos/elf.h b/src/sys/include/ubixos/elf.h new file mode 100755 index 0000000..2aef372 --- /dev/null +++ b/src/sys/include/ubixos/elf.h @@ -0,0 +1,58 @@ +/************************************************************************************** + 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 _ELF_H +#define _ELF_H + +#include + +typedef struct { + uChar eIdent[16]; /* File identification. */ + uShort eType; /* File type. */ + uShort eMachine; /* Machine architecture. */ + uLong eVersion; /* ELF format version. */ + uLong eEntry; /* Entry point. */ + uLong ePhoff; /* Program header file offset. */ + uLong eShoff; /* Section header file offset. */ + uLong eFlags; /* Architecture-specific flags. */ + uShort eEhsize; /* Size of ELF header in bytes. */ + uShort ePhentsize; /* Size of program header entry. */ + uShort ePhnum; /* Number of program header entries. */ + uShort eShentsize; /* Size of section header entry. */ + uShort eShnum; /* Number of section header entries. */ + uShort eShstrndx; /* Section name strings section. */ + } elfHeader; + +typedef struct { + uLong phType; /* Entry type. */ + uLong phOffset; /* File offset of contents. */ + uLong phVaddr; /* Virtual address in memory image. */ + uLong phPaddr; /* Physical address (not used). */ + uLong phFilesz; /* Size of contents in file. */ + uLong phMemsz; /* Size of contents in memory. */ + uLong phFlags; /* Access permission flags. */ + uLong phAlign; /* Alignment in memory and file. */ + } elfProgramheader; + +typedef struct { + uLong shName; /* Section name (index into the section header string table). */ + uLong shType; /* Section type. */ + uLong shFlags; /* Section flags. */ + uLong shAddr; /* Address in memory image. */ + uLong shOffset; /* Offset in file. */ + uLong shSize; /* Size in bytes. */ + uLong shLink; /* Index of a related section. */ + uLong shInfo; /* Depends on section type. */ + uLong shAddralign; /* Alignment in bytes. */ + uLong shEntsize; /* Size of each entry in section. */ + } elfSectionheader; + +#endif \ No newline at end of file diff --git a/src/sys/include/ubixos/exec.h b/src/sys/include/ubixos/exec.h index 3b955f7..1e63a03 100755 --- a/src/sys/include/ubixos/exec.h +++ b/src/sys/include/ubixos/exec.h @@ -9,5 +9,6 @@ #define _EXEC_H void execThread(void (* tproc)(void),int stack,char *descr); +int execFile(char *file); #endif \ No newline at end of file diff --git a/src/sys/include/ubixos/idt.h b/src/sys/include/ubixos/idt.h index dc0be05..d849450 100755 --- a/src/sys/include/ubixos/idt.h +++ b/src/sys/include/ubixos/idt.h @@ -12,4 +12,12 @@ void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); void intNull(); +void _int0(); +void _int1(); +void _int2(); +void _int3(); +void _int4(); +void _int5(); +void _int6(); + #endif \ No newline at end of file diff --git a/src/sys/include/ubixos/schedule.h b/src/sys/include/ubixos/schedule.h index 551d5f4..015a924 100755 --- a/src/sys/include/ubixos/schedule.h +++ b/src/sys/include/ubixos/schedule.h @@ -86,5 +86,6 @@ void initScheduler(); int findTask(); void timerInt(); +void schedule(); #endif \ No newline at end of file diff --git a/src/sys/include/ubixos/syscall.h b/src/sys/include/ubixos/syscall.h new file mode 100755 index 0000000..f612f54 --- /dev/null +++ b/src/sys/include/ubixos/syscall.h @@ -0,0 +1,18 @@ +/************************************************************************************** + 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 _SYSCALL_H +#define _SYSCALL_H + +void _sysCall(); +void invalidCall(); + +#endif \ No newline at end of file diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h new file mode 100755 index 0000000..31219f3 --- /dev/null +++ b/src/sys/include/ubixos/syscalls.h @@ -0,0 +1,26 @@ +/************************************************************************************** + 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 _SYSCALLS_H +#define _SYSCALLS_H + +void sysFwrite(); +void sysGetpid(); + +typedef void (*functionPTR)(); + +functionPTR systemCalls[] = { + sysFwrite,sysGetpid + }; + +int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); + +#endif \ No newline at end of file diff --git a/src/sys/include/vmm/memory.h b/src/sys/include/vmm/memory.h index 1cd6113..5ab60c5 100755 --- a/src/sys/include/vmm/memory.h +++ b/src/sys/include/vmm/memory.h @@ -8,6 +8,21 @@ #ifndef _MEMORY_H #define _MEMORY_H +#define memAvail 1 +#define memNotavail 2 + +typedef struct { + unsigned long pageAddr; + unsigned short status; + unsigned short pid; + } mMap; + +extern int numPages; +extern mMap *memoryMap; + int countMemory(); +unsigned long findFreepage(int pid); +void initMmap(); +void freePage(unsigned long pageAddr); #endif \ No newline at end of file diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index baead82..2da197c 100755 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -16,9 +16,11 @@ #define pageDefault (pagePresent|pageWrite|pageUser) extern unsigned int *pageDirectory; +extern int memoryStart; void initPaging(); unsigned int allocPage(); void pageFault(); +void _pageFault(); #endif \ No newline at end of file diff --git a/src/sys/init/main.c b/src/sys/init/main.c index abcae50..f30497f 100755 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -21,8 +21,7 @@ #include #include #include - -int main(); +#include int testVal=0; @@ -39,7 +38,10 @@ union descriptorTableunion *gdt __attribute__ ((packed)); } loadGdt = { (5 * sizeof(union descriptorTableunion) - 1), GDT }; +int main(); + void _start(void) { + countMemory(); asm( "lgdtl (loadGdt) \n" "movw $0x10,%ax \n" @@ -58,23 +60,30 @@ while(1); } -void test() { - int i=0; - for (i=0;i!=-1;i++) { - kprintf("Thread 2 [%i]\n",i); - } - } - int main() { - initPaging(); //Initialize Paging System clearScreen(); outputVersion(); //Display Version Info init8259(); //Initialize PIC initIdt(); //Initialize IDT + initPaging(); //Initialize Paging System + initMmap(); //Initialize Memory Map initKeyboard(); //Initialize Keyboard initScheduler(); //Initialize Scheduler initFloppy(); //Initialize Floppy Controller initUbixFS(); -// enableIrq(0); - return(0); - } \ No newline at end of file + execThread(idleThread,0xBFFF,"Idle Thread"); + execFile("init"); + /* + while(1) { + fd = fopen("COPYRIGHT",1); + while (ch != -1) { + ch = getFileByte(fd,i); + kprintf("%c",ch); + i++; + } + fclose(fd); + } + */ + enableIrq(0); + while (1); + } diff --git a/src/sys/kernel/Makefile b/src/sys/kernel/Makefile index 552186c..0db7a30 100755 --- a/src/sys/kernel/Makefile +++ b/src/sys/kernel/Makefile @@ -14,7 +14,7 @@ REMOVE = rm -fr # Objects -OBJS = io.o version.o kprintf.o vsprintf.o idt.o schedule.o exec.o dma.o idlethread.o +OBJS = io.o version.o kprintf.o vsprintf.o idt.o schedule.o exec.o dma.o idlethread.o syscall.o all: $(OBJS) diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 59ec830..7cc430d 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -7,7 +7,30 @@ #include #include +#include +#include #include +#include + +int execFile(char *file) { + int fd=0,i=0,x=0,eStart=0; + char *binarySpace = (char *)0x7C0000; + char *newLoc; + elfHeader *binaryHeader = (elfHeader *)0x7C0000; + elfProgramheader *programHeader; + fd = fopen(file,1); + for (i=0;feof(fd) == 0;i++) { + binarySpace[i] = fgetc(fd); + } + programHeader = (elfProgramheader *)0x7C0034;// + binaryHeader->ePhoff; + newLoc = (char *)programHeader->phVaddr; + for (x=0;xeEntry; + execThread((void *)eStart,0xAFFF,file); + return(0); + } void execThread(void (* tproc)(void),int stack,char *descr) { int pid = 0; diff --git a/src/sys/kernel/idlethread.c b/src/sys/kernel/idlethread.c index 901d512..0e56c56 100755 --- a/src/sys/kernel/idlethread.c +++ b/src/sys/kernel/idlethread.c @@ -6,6 +6,7 @@ **************************************************************************************/ #include +#include void idleThread() { /* This thread is for maintinance */ diff --git a/src/sys/kernel/idt.c b/src/sys/kernel/idt.c index 8041912..2fd4944 100755 --- a/src/sys/kernel/idt.c +++ b/src/sys/kernel/idt.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include descriptorTable(IDT, 256) { @@ -20,11 +22,9 @@ /* Sets Up Initial IDT Table */ void initIdt() { int i=0; - for (i=0;i<256;i++) { setVector(intNull, i, dPresent + dInt + dDpl3); } - asm ( "lidt (%0) \n" /* Load the IDT */ "pushfl \n" /* Clear the NT flag */ @@ -34,6 +34,14 @@ : : "r" ((char *) &loadidt) ); + setVector(_int0,0,dPresent + dInt + dDpl3); + setVector(_int1,1,dPresent + dInt + dDpl3); + setVector(_int2,2,dPresent + dInt + dDpl3); + setVector(_int3,3,dPresent + dInt + dDpl3); + setVector(_int4,4,dPresent + dInt + dDpl3); + setVector(_int5,5,dPresent + dInt + dDpl3); + setVector(_int6,6,dPresent + dInt + dDpl3); + setVector(_sysCall,128,dPresent + dInt + dDpl3); } /* Sets Up IDT Vector */ @@ -46,8 +54,39 @@ IDT[interrupt].gate.offsetHigh = (unsigned short) (((unsigned long)handler) >> 16); } + /* Null Intterupt Descriptor */ void intNull() { kprintf("Woot Invalid Interrupt\n"); while(1); + } +void _int0() { + kprint("int0: Divide-by-Zero\n"); + while(1); + } +void _int1() { + kprint("int1: Debug exception\n"); + while(1); + } +void _int2() { + kprint("int2: unknown error\n"); + while(1); + } +void _int3() { + kprint("int3: Breakpoint\n"); + while(1); + } +void _int4() { + kprint("int4: Overflow\n"); + while(1); + } +void _int5() { + kprint("int 5: Bounds check\n"); + while(1); + } +void _int6() { + kprintf("int6: Invalid opcode!\n"); + _current->status = AVAILABLE; + schedule(); + while(1); } \ No newline at end of file diff --git a/src/sys/kernel/kprintf.c b/src/sys/kernel/kprintf.c index 000c711..67fcd92 100755 --- a/src/sys/kernel/kprintf.c +++ b/src/sys/kernel/kprintf.c @@ -20,4 +20,13 @@ kprint(buf); printColor = defaultColor; return(i); + } + +int sprintf(char *buf,const char *fmt, ...) { + vaList args; + int i; + va_start(args, fmt); + i=vsprintf(buf,fmt,args); + va_end(args); + return(i); } \ No newline at end of file diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c new file mode 100755 index 0000000..3432f8e --- /dev/null +++ b/src/sys/kernel/syscall.c @@ -0,0 +1,73 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include +#include + +asm( + ".globl _sysCall \n" + "_sysCall: \n" + //" pusha \n" /* Save all registers */ + //" pushw %ds \n" /* Set up the data segment */ + //" pushw %es \n" + //" pushw %ss \n" /* Note that ss is always valid */ + //" pushw %ss \n" + //" popw %ds \n" + //" popw %es \n" + " cmpl totalCalls,%eax \n" + " jae invalidCall \n" + " call *systemCalls(,%eax,4) \n" + //" popw %es \n" + //" popw %ds \n" /* Restore registers */ + //" popa \n" + " iret \n" /* Exit interrupt */ + ); + +void invalidCall() { + kprintf("Invalid System Call!!\n"); + //_current->status = AVAILABLE; + //schedule(); + } + +void sysFwrite() { + char *ptr; + char data[1024]; + int i=0; + int size; + int fd; + asm ( + "" + : "=b" (ptr),"=c" (size),"=d" (fd) + ); + if (fd == 0) { + for (i=0;iid; + kprintf("Real: [%i]\n",pid); + } \ No newline at end of file diff --git a/src/sys/ubixfs/Makefile b/src/sys/ubixfs/Makefile index 4b84eca..662fa61 100755 --- a/src/sys/ubixfs/Makefile +++ b/src/sys/ubixfs/Makefile @@ -14,7 +14,7 @@ REMOVE = rm -fr # Objects -OBJS = ubixfs.o +OBJS = ubixfs.o file.o all: $(OBJS) diff --git a/src/sys/ubixfs/file.c b/src/sys/ubixfs/file.c new file mode 100755 index 0000000..52376f0 --- /dev/null +++ b/src/sys/ubixfs/file.c @@ -0,0 +1,55 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include + +struct fileDescriptorTable fdTable[maxFd]; + +int sprintf(char *buf,const char *fmt, ...); + +int fclose(int fd) { + fdTable[fd].status = fdAvail; + return(0); + } + +int feof(int fd) { + if (fdTable[fd].status == fdEof) { + return(-1); + } + else { + return(0); + } + } + +int fopen(char *file,int mode) { + int i=0; + for (i=0;i +#include #include #include int startSector; void initUbixFS() { + int i=0; struct bootSect *bs; char data[512]; readBlock(0,data,1); @@ -28,17 +30,64 @@ kprintf("Insert System Disk\n"); initUbixFS(); } + for (i=0;i *str2) return 1; + if(*str1 < *str2) return -1; + return -1; } int readFile(char *file) { - struct fileTable *ft; + struct fileTableEntry ft[1]; char data[2048]; - readBlock(startSector,data,4); - ft = (void *)data; +// findFile(file,ft); + if (ft->start > 1000) { } + else { + readBlock(ft->start,data,ft->length); + kprint(data); + } return(0); } -int findFile(char *file) { - struct fileTable *ft; - char data[2048]; +int getFileByte(int fd,int offset) { + int ch=0,mp=0; + mp = offset/512; + if ((offset%512 == 0) && (fdTable[fd].status == fdRead)) { + fdTable[fd].status = fdOpen; + } + if (offset < fdTable[fd].size) { + if (fdTable[fd].status != fdRead) { + readBlock(fdTable[fd].start+mp,fdTable[fd].buffer,1); + fdTable[fd].status = fdRead; + } + ch = fdTable[fd].buffer[offset-(mp*512)]; + } + else { + ch = -1; + fdTable[fd].status = fdEof; + } + return(ch); + } + +int findFile(char *file,struct fileDescriptorTable *head) { + int i=0; + struct fileTableEntry *ft; + char data[4096]; + readBlock(startSector,data,8); + ft = (void *)data; + for (i=0;i<128;i++) { + if (!kstrcmp(ft[i].fileName,file)) { + head->start = ft[i].start; + head->length = ft[i].length; + head->size = ft[i].size; + return(1); + } + } + return(0); } \ No newline at end of file diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index 30c9b4a..4acc898 100755 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -6,8 +6,12 @@ **************************************************************************************/ #include +#include #include +mMap *memoryMap = (mMap *) 0x100000; +int numPages; + int countMemory() { register unsigned long *mem; unsigned long memCount=-1, tempMemory; @@ -70,5 +74,37 @@ /* Return IRQ 1 & 2's States */ outportByte(0x21, irq1State); outportByte(0xA1, irq2State); + numPages = (memKb*1024*1024)/4096; return(memKb<<20); + } + +void initMmap() { + int i=0; + memoryMap = (mMap *) 0x100000; + for (i=0;i +#include +#include +#include +#include +#include unsigned int *pageDirectory = 0x0; int memoryStart = 0x100000; void initPaging() { - int i = 0; + int i=0,x=0; unsigned int *pageTable; int freePage = 0x0; - - pageDirectory = (unsigned int*)allocPage(); + memoryStart += (numPages * 8); + pageDirectory = (unsigned int*)memoryStart; + memoryStart += 4096; for (i=0;iid); + /* if (memoryStart%4096 != 0) { memoryStart += 4096 - memoryStart%4096; } page = memoryStart; memoryStart += 4096; + */ return(page); } void pageFault() { - while (1); - } \ No newline at end of file + uInt cr2 = 0,i = 0, page = 0,pi = 0; + uInt *pageTable; + asm( + "movl %%cr2,%%eax\n" + "movl %%eax,%0\n" + : "=g" (cr2) + ); + pi = cr2/(1024*4096); + page = (cr2-(pi*(1024*4096)))/4096; + if (pageDirectory[pi] == 0) { + pageTable = (unsigned int*)allocPage(); + pageDirectory[pi] = (unsigned int)pageTable | pageDefault; + for (i=0;i<1024;i++) { + pageTable[i] = 0; + } + pageTable[page] = allocPage() | pageDefault; + } + else { + pageTable = (unsigned int *)(pageDirectory[pi]-39); + pageTable[page] = allocPage() | pageDefault; + } + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + +asm( + ".global _pageFault \n" + "_pageFault: \n" + "xchgl %eax,(%esp) \n" + "pushl %ecx \n" + "pushl %edx \n" + "push %ds \n" + "push %es \n" + "push %fs \n" + "call pageFault \n" + "pop %fs \n" + "pop %es \n" + "pop %ds \n" + "popl %edx \n" + "popl %ecx \n" + "popl %eax \n" + "iret \n" + ); \ No newline at end of file diff --git a/src/tools/Makefile b/src/tools/Makefile new file mode 100755 index 0000000..8cac12a --- /dev/null +++ b/src/tools/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + + +#Compiler +GCC = gcc +G++ = gcc + +#Linker +LD = ld + +#Kernel File Name +BINARY = format + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = format.o + +# Link the kernel statically with fixed text+data address @1M +$(BINARY) : $(OBJS) + $(GCC) -o $@ $(OBJS) + +# Compile the source files +.cc.o: + $(G++) -Wall -fomit-frame-pointer -O -I../sys/include -c -o $@ $< + +.cc.s: + $(G++) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.c.o: + $(GCC) -Wall -O -I../sys/include -c -o $@ $< + +.c.s: + $(GCC) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.S.o: + $(GCC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) + +format-dsk: + (cp ../bin/init/init ./) + (./format 101 init) + (rm init) diff --git a/src/tools/format.c b/src/tools/format.c new file mode 100755 index 0000000..799dd63 --- /dev/null +++ b/src/tools/format.c @@ -0,0 +1,68 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are prohibited. + + $Id$ + +**************************************************************************************/ + +#include +#include "ubixfs/ubixfs.h" + +int main(int argc,char **argv) { + FILE *fd,*fd2; + int i=0,x=0,blocks=0,sb=9; + char temp[24]; + struct fileTableEntry ft[128]; + fd = fopen("/dev/fd1","wb"); + for (i=1;i<128;i++) { + ft[i].fileName[0] = '0'; + sprintf(ft[i].fileName,"File-%i",i); + } + fseek(fd,4096+(atoi(argv[1])*512),0); + sb = atoi(argv[1])+8; + for (i=2;i