diff --git a/src/bin/clock/main.c b/src/bin/clock/main.c index 3ee83be..75fb3af 100644 --- a/src/bin/clock/main.c +++ b/src/bin/clock/main.c @@ -38,6 +38,7 @@ #define HOUR (60*MINUTE) #define DAY (24*HOUR) #define YEAR (365*DAY) +extern const char *__progname; static int monthSecs[12] = { @@ -91,6 +92,7 @@ sec = sysTime; printf("[%s][%02d/%02d/%i, %02d:%02d.%02d]\n",argv[0],month,day,year,hour,min,sec); + printf("[0x%X][%s][%i]\n",argv[1],__progname,argc); return(0); } diff --git a/src/bin/ld/addlibrary.c b/src/bin/ld/addlibrary.c index 402e40f..894a174 100644 --- a/src/bin/ld/addlibrary.c +++ b/src/bin/ld/addlibrary.c @@ -24,7 +24,9 @@ printf("Could not open library: %s\n",lib); exit(-1); } - if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) { + //if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) { + //if ((tmpLib->output = (char *)malloc(0x111000)) == 0x0) { + if ((tmpLib->output = (char *)getPage((0x111000/0x1000),2)) == 0x0) { printf("malloc failed: tmpLib->output\n"); exit(0x1); } diff --git a/src/bin/login/main.c b/src/bin/login/main.c index a668fa0..65af73f 100644 --- a/src/bin/login/main.c +++ b/src/bin/login/main.c @@ -63,7 +63,6 @@ char passWord[32]; char *data2 = 0x0; struct passwd *data = 0x0; - int foo; if ((getuid() != 0x0) && (getgid() != 0x0)) { diff --git a/src/bin/shell/exec.c b/src/bin/shell/exec.c index d3eec3f..8fff6f4 100644 --- a/src/bin/shell/exec.c +++ b/src/bin/shell/exec.c @@ -33,9 +33,9 @@ int cPid = 0x0; cPid = fork(); if (!cPid) { - sprintf(file,"%s%s",cwd,data->argv[0]); - exec(file,data->argc,data->argv); - printf("%s: Command Not Found.\n",data->argv[0]); + sprintf(file,"%s%s",cwd,data->argv[1]); + exec(file,data->argc,data->argv+1); + printf("%s: Command Not Found.\n",data->argv[1]); exit(-1); } else { diff --git a/src/bin/shell/input.c b/src/bin/shell/input.c index 672781d..66651b2 100644 --- a/src/bin/shell/input.c +++ b/src/bin/shell/input.c @@ -57,12 +57,15 @@ } buffer->argv = (char **)malloc(4*(buffer->argc * 1)); + buffer->envp = (char **)malloc(sizeof(char)); + buffer->envp[0] = 0x1; tmpArgs = buffer->args; - for (i=0;iargc;i++) { + for (i=1;i<=buffer->argc;i++) { buffer->argv[i] = tmpArgs->arg; tmpArgs = tmpArgs->next; } - buffer->argv[i] = 0x0; + buffer->argv[0] = buffer->argc; + buffer->argv[buffer->argc+1] = buffer->envp; } void freeArgs(inputBuffer *ptr) { diff --git a/src/bin/shell/shell.h b/src/bin/shell/shell.h index 4d0f59f..e140799 100644 --- a/src/bin/shell/shell.h +++ b/src/bin/shell/shell.h @@ -10,6 +10,7 @@ typedef struct { int argc; char **argv; + char **envp; uInt8 bg; struct argsStruct *args; } inputBuffer; diff --git a/src/lib/csu/crt1.c b/src/lib/csu/crt1.c index de72fb2..5b1e959 100644 --- a/src/lib/csu/crt1.c +++ b/src/lib/csu/crt1.c @@ -43,7 +43,7 @@ extern void _fini(void); extern void _init(void); extern int main(int, char **, char **); -extern void _start(char *, ...); +extern void _start(char **, ...); #ifdef GCRT extern void _mcleanup(void); @@ -69,12 +69,10 @@ } /* The entry function. */ -void -_start(char *ap, ...) -{ +void _start(char **argv, ...) { fptr cleanup; int argc; - char **argv; + //char **argv; char **env; const char *s; @@ -82,7 +80,8 @@ __asm__("and $0xfffffff0,%esp"); #endif cleanup = get_rtld_cleanup(); - argv = ≈ + //≈ HACK + //argv = ≈ argc = *(long *)(void *)(argv - 1); env = argv + argc + 1; environ = env; diff --git a/src/lib/libc/Makefile.inc b/src/lib/libc/Makefile.inc index 409ae4f..7ef6339 100644 --- a/src/lib/libc/Makefile.inc +++ b/src/lib/libc/Makefile.inc @@ -1,2 +1,2 @@ INCLUDES = -I../include -I../../../include.new -CFLAGS += -DPIC -DPORTMAP -D__DBINTERFACE_PRIVATE -nostdinc +CFLAGS += -DPORTMAP -D__DBINTERFACE_PRIVATE -nostdinc -DPIC diff --git a/src/lib/libc/gen/tls.c b/src/lib/libc/gen/tls.c index d4a0fd0..e769255 100644 --- a/src/lib/libc/gen/tls.c +++ b/src/lib/libc/gen/tls.c @@ -266,6 +266,8 @@ int i; void *tls; + __sys_write(1,"TLS"); + sp = (Elf_Addr *) environ; while (*sp++ != 0) ; diff --git a/src/lib/libc/i386/Makefile.inc b/src/lib/libc/i386/Makefile.inc index ec4bcba..55053b0 100755 --- a/src/lib/libc/i386/Makefile.inc +++ b/src/lib/libc/i386/Makefile.inc @@ -1,2 +1,2 @@ INCLUDES = -I../../include -I../../../../include.new -CFLAGS += -DPIC -DPORTMAP -D__DBINTERFACE_PRIVATE -nostdinc +CFLAGS += -DPORTMAP -D__DBINTERFACE_PRIVATE -nostdinc -DPIC diff --git a/src/lib/libc/stdio/makebuf.c b/src/lib/libc/stdio/makebuf.c index a3de9fa..9667705 100644 --- a/src/lib/libc/stdio/makebuf.c +++ b/src/lib/libc/stdio/makebuf.c @@ -70,7 +70,9 @@ fp->_bf._size = 1; return; } + __sys_write(1,"__swhatbuf"); flags = __swhatbuf(fp, &size, &couldbetty); + __sys_write(1,"__swhatbuf!"); if ((p = malloc(size)) == NULL) { fp->_flags |= __SNBF; fp->_bf._base = fp->_p = fp->_nbuf; @@ -96,11 +98,13 @@ int *couldbetty; { struct stat st; + __sys_write(1,"_fstat"); if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) { *couldbetty = 0; *bufsize = BUFSIZ; return (__SNPT); } + __sys_write(1,"_fstat!"); /* could be a tty iff it is a character device */ *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; diff --git a/src/lib/libc/stdio/vfprintf.c b/src/lib/libc/stdio/vfprintf.c index b2b1286..67932d0 100644 --- a/src/lib/libc/stdio/vfprintf.c +++ b/src/lib/libc/stdio/vfprintf.c @@ -649,16 +649,16 @@ decimal_point = localeconv()->decimal_point; #endif /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ -__sys_write(1,"A"); +__sys_write(1,"AAAAA"); if (prepwrite(fp) != 0) return (EOF); -__sys_write(1,"B"); +__sys_write(1,"BBBBBBBBBBBBBBBBBBB"); /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0) return (__sbprintf(fp, fmt0, ap)); - +__sys_write(1,"ABABABC"); fmt = (char *)fmt0; argtable = NULL; nextarg = 1; @@ -1137,7 +1137,7 @@ sign = '\0'; break; } - +__sys_write(1,"HERE?"); /* * All reasonable formats wind up here. At this point, `cp' * points to a string which (if not flags&LADJUST) should be diff --git a/src/lib/libc/stdio/wsetup.c b/src/lib/libc/stdio/wsetup.c index 8d10c35..f165d63 100644 --- a/src/lib/libc/stdio/wsetup.c +++ b/src/lib/libc/stdio/wsetup.c @@ -55,8 +55,10 @@ FILE *fp; { /* make sure stdio is set up */ + __sys_write(1,"__swsetup"); if (!__sdidinit) __sinit(); + __sys_write(1,"__swsetup!"); /* * If we are not writing, we had better be reading and writing. */ @@ -79,8 +81,10 @@ /* * Make a buffer if necessary, then set _w. */ + __sys_write(1,"smakebuf"); if (fp->_bf._base == NULL) __smakebuf(fp); + __sys_write(1,"smakebuf!"); if (fp->_flags & __SLBF) { /* * It is line buffered, so make _lbfsize be -_bufsize diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c index ba2694d..b266a53 100644 --- a/src/lib/libc/stdlib/getenv.c +++ b/src/lib/libc/stdlib/getenv.c @@ -61,9 +61,9 @@ int len, i; const char *np; char **p, *cp; - /* TEMP */ + + //HACK return(NULL); - if (name == NULL || environ == NULL) return (NULL); diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 343da15..fe7420e 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c @@ -310,32 +310,29 @@ /* * Allocate a number of pages from the OS */ -static void * -map_pages(size_t pages) -{ - caddr_t result, tail; +static void *map_pages(size_t pages) { + caddr_t result, tail; - result = (caddr_t)pageround((u_long)sbrk(0)); - tail = result + (pages << malloc_pageshift); - if (tail < result) - return (NULL); + result = (caddr_t)pageround((u_long)sbrk(0)); + tail = result + (pages << malloc_pageshift); - // __sys_write(1,""); + if (tail < result) + return (NULL); - if (brk(tail)) { - wrterror("(ES): map_pages fails\n"); - return (NULL); + if (brk(tail)) { + wrterror("(ES): map_pages fails\n"); + return (NULL); } - __sys_write(1,""); - last_index = ptr2index(tail) - 1; - malloc_brk = tail; + + last_index = ptr2index(tail) - 1; + malloc_brk = tail; - if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index)) - return (NULL); + if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index)) + return (NULL); - return (result); -} + return (result); + } /* * Extend page directory @@ -460,10 +457,9 @@ */ if (malloc_zero) malloc_junk=1; - __sys_write(1,""); + /* Allocate one page for the page directory */ page_dir = (struct pginfo **) MMAP(malloc_pagesize); - __sys_write(1,""); if (page_dir == MAP_FAILED) wrterror("mmap(2) failed, check limits\n"); @@ -474,7 +470,6 @@ */ malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift; malloc_origo -= malloc_pageshift; - __sys_write(1,""); malloc_ninfo = malloc_pagesize / sizeof *page_dir; /* Recalculate the cache size in bytes, and make sure it's nonzero */ @@ -495,69 +490,41 @@ /* * Allocate a number of complete pages */ -static void * -malloc_pages(size_t size) -{ - void *p, *delay_free = NULL; - size_t i; - struct pgfree *pf; - u_long index; +static void *malloc_pages(size_t size) { + void *p, *delay_free = NULL; + size_t i; + struct pgfree *pf; + u_long index; - size = pageround(size); + size = pageround(size); - p = NULL; - __sys_write(1,""); - /* Look for free pages before asking for more */ - for(pf = free_list.next; pf; pf = pf->next) { - __sys_write(1,""); -#ifdef MALLOC_EXTRA_SANITY -__sys_write(1,"<*>"); - if (pf->size & malloc_pagemask) - wrterror("(ES): junk length entry on free_list\n"); - if (!pf->size) - wrterror("(ES): zero length entry on free_list\n"); - if (pf->page == pf->end) - wrterror("(ES): zero entry on free_list\n"); - if (pf->page > pf->end) - wrterror("(ES): sick entry on free_list\n"); - if ((void*)pf->page >= (void*)sbrk(0)) - wrterror("(ES): entry on free_list past brk\n"); - if (page_dir[ptr2index(pf->page)] != MALLOC_FREE) - wrterror("(ES): non-free first page on free-list\n"); - if (page_dir[ptr2index(pf->end)-1] != MALLOC_FREE) - wrterror("(ES): non-free last page on free-list\n"); -#endif /* MALLOC_EXTRA_SANITY */ + p = NULL; + /* Look for free pages before asking for more */ + for(pf = free_list.next; pf; pf = pf->next) { - if (pf->size < size) - continue; + if (pf->size < size) + continue; - if (pf->size == size) { - p = pf->page; - if (pf->next != NULL) - pf->next->prev = pf->prev; - pf->prev->next = pf->next; - delay_free = pf; - break; - } - __sys_write(1,""); + if (pf->size == size) { + p = pf->page; + if (pf->next != NULL) + pf->next->prev = pf->prev; + pf->prev->next = pf->next; + delay_free = pf; + break; + } - p = pf->page; - pf->page = (char *)pf->page + size; - pf->size -= size; - break; + p = pf->page; + pf->page = (char *)pf->page + size; + pf->size -= size; + break; } -#ifdef MALLOC_EXTRA_SANITY - if (p != NULL && page_dir[ptr2index(p)] != MALLOC_FREE) - wrterror("(ES): allocated non-free page on free-list\n"); -#endif /* MALLOC_EXTRA_SANITY */ + size >>= malloc_pageshift; + /* Map new pages */ + if (p == NULL) + p = map_pages(size); - size >>= malloc_pageshift; - __sys_write(1,""); - /* Map new pages */ - if (p == NULL) - p = map_pages(size); - __sys_write(1,""); if (p != NULL) { @@ -592,11 +559,9 @@ int i, k, l; /* Allocate a new bucket */ - __sys_write(1,""); pp = malloc_pages(malloc_pagesize); if (pp == NULL) return (0); - __sys_write(1,""); /* Find length of admin structure */ l = offsetof(struct pginfo, bits[0]); l += sizeof bp->bits[0] * @@ -672,11 +637,9 @@ i = size-1; while (i >>= 1) j++; - __sys_write(1,""); /* If it's empty, make a page more of that size chunks */ if (page_dir[j] == NULL && !malloc_make_chunks(j)) return (NULL); - __sys_write(1,""); bp = page_dir[j]; /* Find first word of bitmap which isn't empty */ @@ -726,14 +689,11 @@ result = NULL; } else if (size <= malloc_maxsize) { - __sys_write(1,""); result = malloc_bytes(size); } else { - __sys_write(1,""); result = malloc_pages(size); } - if (malloc_zero && result != NULL) memset(result, 0, size); @@ -1131,7 +1091,7 @@ r = irealloc(ptr, size); err = (r == NULL); } - + __sys_write(1,""); UTRACE(ptr, size, r); malloc_active = 0; _MALLOC_UNLOCK(); diff --git a/src/lib/libc/uthread/uthread_fd.c b/src/lib/libc/uthread/uthread_fd.c index bc41528..534939e 100644 --- a/src/lib/libc/uthread/uthread_fd.c +++ b/src/lib/libc/uthread/uthread_fd.c @@ -329,10 +329,11 @@ * Check that the file descriptor table is initialised for this * entry: */ + __sys_write(1,"_thread_fd_table_init"); if ((ret = _thread_fd_table_init(fd)) == 0) { /* Clear the interrupted flag: */ curthread->interrupted = 0; - +__sys_write(1,"UBU"); /* * Lock the file descriptor table entry to prevent * other threads for clashing with the current @@ -509,6 +510,7 @@ } } + __sys_write(1,"_thread_fd_table_init"); /* Return the completion status: */ return (ret); } diff --git a/src/lib/libc/uthread/uthread_fstat.c b/src/lib/libc/uthread/uthread_fstat.c index 2801ab0..b8371ff 100644 --- a/src/lib/libc/uthread/uthread_fstat.c +++ b/src/lib/libc/uthread/uthread_fstat.c @@ -48,12 +48,16 @@ int ret; /* Lock the file descriptor for read: */ + __sys_write(1,"_FD_LOCK"); if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { /* Get the file status: */ + __sys_write(1,"__sys_fstat"); ret = __sys_fstat(fd, buf); + __sys_write(1,"__sys_fstat!"); /* Unlock the file descriptor: */ _FD_UNLOCK(fd, FD_READ); } + __sys_write(1,"_FD_LOCK!"); return (ret); } diff --git a/src/lib/libc/uthread/uthread_init.c b/src/lib/libc/uthread/uthread_init.c index 32b0182..1324715 100644 --- a/src/lib/libc/uthread/uthread_init.c +++ b/src/lib/libc/uthread/uthread_init.c @@ -216,13 +216,14 @@ struct clockinfo clockinfo; struct sigaction act; - +__sys_write(1,"UBOO",strlen("UBOO")); /* Check if this function has already been called: */ if (_thread_initial) /* Only initialise the threaded application once. */ return; - _pthread_page_size = getpagesize();; + _pthread_page_size = getpagesize(); + __sys_write(1,"getpagesize",strlen("getpagesize")); _pthread_guard_default = _pthread_page_size; sched_stack_size = 4 * _pthread_page_size; if (sizeof(void *) == 8) { @@ -276,7 +277,7 @@ __sys_dup2(fd, 2) == -1) PANIC("Can't dup2"); } - + __sys_write(1,"getpid!",strlen("getpid!")); /* Get the standard I/O flags before messing with them : */ for (i = 0; i < 3; i++) { if (((_pthread_stdio_flags[i] = @@ -343,6 +344,7 @@ else if ((_thread_kern_sched_stack = malloc(sched_stack_size)) == NULL) PANIC("Failed to allocate stack for scheduler"); else { + __sys_write(1,"else!!!",strlen("else!!!")); /* Zero the global kernel thread structure: */ memset(&_thread_kern_thread, 0, sizeof(struct pthread)); _thread_kern_thread.flags = PTHREAD_FLAGS_PRIVATE; @@ -376,7 +378,7 @@ _pthread_guard_default, _pthread_guard_default, 0, MAP_ANON, -1, 0) == MAP_FAILED) PANIC("Cannot allocate red zone for initial thread"); - + __sys_write(1,"mmap!",strlen("mmap!")); /* Set the main thread stack pointer. */ _thread_initial->stack = _usrstack - _pthread_stack_initial; diff --git a/src/lib/ubix/Makefile b/src/lib/ubix/Makefile index 1f49f18..bb633b7 100644 --- a/src/lib/ubix/Makefile +++ b/src/lib/ubix/Makefile @@ -9,7 +9,10 @@ BINARY = none #Objects -OBJS = startup.o +OBJS = sstart.o #startup.o + +CFLAGS = -fno-builtin -Wno-uninitialized -O2 -fno-strict-aliasing -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls + # Make the Binary $(BINARY) : $(OBJS) diff --git a/src/lib/ubix/sstart.c b/src/lib/ubix/sstart.c new file mode 100644 index 0000000..ae293db --- /dev/null +++ b/src/lib/ubix/sstart.c @@ -0,0 +1,25 @@ +char **environ; +const char *__progname = ""; + +void _start(char **argv,...) { + int argc; + // char **argv; + char **env; + const char *s; + + exit(main(argc, argv, env)); +// argv = ≈ +// printf("(ap: 0x%X)",&ap); + argc = *(long *)(void *)(argv - 1); + env = argv + argc + 1; + environ = env; + if (argc > 0 && argv[0] != 0x0) { + __progname = argv[0]; + for (s = __progname; *s != '\0'; s++) + if (*s == '/') + __progname = s + 1; + } + + exit(main(argc, argv, env)); + + } diff --git a/src/sys/include/sys/gen_calls.h b/src/sys/include/sys/gen_calls.h index 465af4e..42af101 100644 --- a/src/sys/include/sys/gen_calls.h +++ b/src/sys/include/sys/gen_calls.h @@ -39,6 +39,7 @@ int readlink(struct thread *,struct readlink_args *); int getuid(struct thread *, struct getuid_args *); int getgid(struct thread *, struct getgid_args *); +int gettimeofday_new(struct thread *, struct gettimeofday_args *); #endif diff --git a/src/sys/include/sys/kern_sig.h b/src/sys/include/sys/kern_sig.h index 5ab16b9..ffc208e 100644 --- a/src/sys/include/sys/kern_sig.h +++ b/src/sys/include/sys/kern_sig.h @@ -33,7 +33,23 @@ #include #include +#define _SIG_WORDS 4 +#define _SIG_MAXSIG 128 +#define _SIG_IDX(sig) ((sig) - 1) +#define _SIG_WORD(sig) (_SIG_IDX(sig) >> 5) +#define _SIG_BIT(sig) (1 << (_SIG_IDX(sig) & 31)) +#define _SIG_VALID(sig) ((sig) <= _SIG_MAXSIG && (sig) > 0) + +typedef struct __sigset { + __uint32_t __bits[_SIG_WORDS]; + } __sigset_t; + + +typedef __sigset_t sigset_t; + + int sigaction(struct thread *,register struct sigaction_args *); +int sigprocmask(register struct thread *, struct sigprocmask_args *); #endif diff --git a/src/sys/include/sys/sysproto.h b/src/sys/include/sys/sysproto.h index b125a18..2b1bf9a 100644 --- a/src/sys/include/sys/sysproto.h +++ b/src/sys/include/sys/sysproto.h @@ -30,6 +30,8 @@ #ifndef _SYSPROTO_H #define _SYSPROTO_H +#include + typedef int register_t; #define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ @@ -103,7 +105,7 @@ }; struct obreak_args { - char nsize_l_[PADL_(char *)]; char * nsize; char nsize_r_[PADR_(char *)]; + char nsize_l_[PADL_(char *)];char * nsize;char nsize_r_[PADR_(char *)]; }; struct sigaction_args { @@ -121,6 +123,18 @@ char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; }; +struct sigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char oset_l_[PADL_(sigset_t *)]; sigset_t * oset; char oset_r_[PADR_(sigset_t *)]; + }; +struct gettimeofday_args { + char tp_l_[PADL_(struct timeval *)]; struct timeval * tp; char tp_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; + }; + + + diff --git a/src/sys/include/sys/thread.h b/src/sys/include/sys/thread.h index 1bb8a10..fd51a39 100644 --- a/src/sys/include/sys/thread.h +++ b/src/sys/include/sys/thread.h @@ -30,11 +30,13 @@ #ifndef _THREAD_H #define _THREAD_H +#include + struct thread { - int td_retval[2]; - uInt32 o_files[1024]; - uInt32 vm_daddr; - uInt32 vm_dsize; + int td_retval[2]; + uInt32 o_files[64]; + char * vm_daddr; + int32_t vm_dsize; }; #endif diff --git a/src/sys/include/ubixos/syscalls_new.h b/src/sys/include/ubixos/syscalls_new.h index 50e00d8..d88dce3 100644 --- a/src/sys/include/ubixos/syscalls_new.h +++ b/src/sys/include/ubixos/syscalls_new.h @@ -46,6 +46,8 @@ int sigaction(); int getdtablesize(); int munmap(); +int sigprocmask(); +int gettimeofday_new(); #define invalid_call 0x0 #define PSL_C 0x00000001 /* carry bit */ @@ -171,7 +173,7 @@ invalid_call, /** 113 **/ invalid_call, /** 114 **/ invalid_call, /** 115 **/ - invalid_call, /** 116 **/ + gettimeofday_new, /** 116 **/ invalid_call, /** 117 **/ invalid_call, /** 118 **/ invalid_call, /** 119 **/ @@ -395,7 +397,7 @@ invalid_call, /** 337 **/ invalid_call, /** 338 **/ invalid_call, /** 339 **/ - invalid_call, /** 340 **/ + sigprocmask, /** 340 **/ invalid_call, /** 341 **/ invalid_call, /** 342 **/ invalid_call, /** 343 **/ diff --git a/src/sys/include/ubixos/types.h b/src/sys/include/ubixos/types.h index 2fe3f61..c53dc30 100644 --- a/src/sys/include/ubixos/types.h +++ b/src/sys/include/ubixos/types.h @@ -96,6 +96,7 @@ typedef __ssize_t ssize_t; typedef char * caddr_t; typedef __int64_t off_t; +typedef __uint32_t vm_offset_t; #endif diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index e561322..8281961 100644 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -34,6 +34,9 @@ #include #include +#define VM_THRD 0 +#define VM_TASK 1 + #define pageLength 0x00000400 #define pageSize 4096 #define pageEntries (pageSize/4) @@ -42,6 +45,7 @@ #define parentPageDirAddr 0x100000 #define PAGE_STACK 0x00000400 +#define PAGE_WIRED 0x00000600 #define PAGE_PRESENT 0x00000001 #define PAGE_WRITE 0x00000002 #define PAGE_USER 0x00000004 @@ -53,7 +57,10 @@ #define PAGE_MASK (PAGE_SIZE-1) #define trunc_page(x) ((x) & ~PAGE_MASK) -#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) +#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) +#define ctob(x) ((x)<>PAGE_SHIFT) + int vmmClearVirtualPage(uInt32 pageAddr); diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 3308ff2..70b1168 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -139,8 +139,9 @@ *****************************************************************************************/ void execFile(char *file,int argc,char **argv,int console) { - int i = 0x0; - int x = 0x0; + int i = 0x0; + int x = 0x0; + u_int32_t *tmp = 0x0; fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = 0x0; @@ -234,7 +235,7 @@ memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = 0x80000000;//((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); - _current->td.vm_daddr = (programHeader[i].phVaddr & 0xFFFFF000); + _current->td.vm_daddr = (char *)(programHeader[i].phVaddr & 0xFFFFF000); /* Now Load Section To Memory */ fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); @@ -326,6 +327,20 @@ kfree(programHeader); fclose(tmpFd); + tmp = (uInt32 *)_current->tss.esp0 - 5; + tmp[0] = binaryHeader->eEntry; + tmp[3] = 0xCBE8000-12;//0x5DD000-12; + // - 2 + tmp = (uInt32 *)0xCBE8000 - 2;//0x5DD000 - 2; + //tmp[0] = argc; + //1 + if (_current->id > 4) + kprintf("argv[0]: [%s]\n",argv[0]); + kprintf("argv: [0x%X]\n",argv); + tmp[0] = argv; + tmp[1] = argv; + + /* Switch Back To The Kernels VM Space */ asm volatile( "movl %0,%%eax \n" @@ -353,6 +368,7 @@ uInt32 ldAddr = 0x0; uInt32 seg_size = 0x0; uInt32 seg_addr = 0x0; + char *interp = 0x0; fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = 0x0; @@ -458,11 +474,12 @@ */ // kprintf("B[0x%X:0x%X:0x%X]",seg_size,seg_addr,seg_addr + seg_size); //_current->td.vm_daddr = (programHeader[i].phVaddr & 0xFFFFF000); - _current->td.vm_dsize = seg_size; + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; _current->td.vm_daddr = seg_addr; } - _current->oInfo.vmStart = 0x80000000;//((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + //_current->oInfo.vmStart = 0x80000000;//((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); break; case PT_DYNAMIC: //newLoc = (char *)programHeader[i].phVaddr; @@ -471,6 +488,10 @@ fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); break; case PT_INTERP: + interp = (char *)kmalloc(programHeader[i].phFilesz); + fseek(tmpFd,programHeader[i].phOffset,0); + fread((void *)interp,programHeader[i].phFilesz,1,tmpFd); + kprintf("Interp: [%s]\n",interp); ldAddr = ldEnable(); break; default: @@ -495,9 +516,15 @@ tmp = (uInt32 *)_current->tss.esp0 - 5; tmp[0] = binaryHeader->eEntry; tmp[3] = 0xCBE8000-12;//0x5DD000-12; + // - 2 tmp = (uInt32 *)0xCBE8000 - 2;//0x5DD000 - 2; - tmp[0] = argc; - tmp[1] = (uInt32)argv; + //tmp[0] = argc; + //1 + if (_current->id > 4) + kprintf("argv[0]: [%s]\n",argv[0]); + kprintf("argv: [0x%X]\n",argv); + tmp[0] = argv; + tmp[1] = argv; /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ kfree(binaryHeader); @@ -509,3 +536,4 @@ /*** END ***/ + diff --git a/src/sys/kernel/gen_calls.c b/src/sys/kernel/gen_calls.c index 8ae7fbb..5cd78c0 100644 --- a/src/sys/kernel/gen_calls.c +++ b/src/sys/kernel/gen_calls.c @@ -74,6 +74,11 @@ return(0x0); } +int gettimeofday_new(struct thread *td, struct gettimeofday_args *uap) { + return(0x0); + } + + /*** END diff --git a/src/sys/kernel/kern_descrip.c b/src/sys/kernel/kern_descrip.c index 03df200..b37baa2 100644 --- a/src/sys/kernel/kern_descrip.c +++ b/src/sys/kernel/kern_descrip.c @@ -100,7 +100,9 @@ int getdtablesize(struct thread *td, struct getdtablesize_args *uap) { /* HACK */ - td->td_retval[0] = 0x1000000; + /* WHY? */ + //td->td_retval[0] = 0x1000000; + td->td_retval[0] = 0x10; return (0); } diff --git a/src/sys/kernel/kern_sig.c b/src/sys/kernel/kern_sig.c index 78b382d..478f7fa 100644 --- a/src/sys/kernel/kern_sig.c +++ b/src/sys/kernel/kern_sig.c @@ -40,6 +40,11 @@ return(0x0); } +int sigprocmask(register struct thread *td, struct sigprocmask_args *uap) { + return (0x0); + } + + /*** END diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 7ed5484..7ec0819 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -192,12 +192,17 @@ Notes: ************************************************************************/ -void sysGetFreePage(long *ptr,int count) -{ - if (ptr) - *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,0); - return; -} +void sysGetFreePage(long *ptr,int count,int type) { + if (ptr) { + kprintf("{0x%X}",type); + if (type == 2) + *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_THRD); + else + *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_TASK); + } + //kprintf("addr: [0x%X]\n",*ptr); + return; + } void sysGetDrives(uInt32 *ptr) { diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c index efe4f5c..994e04d 100644 --- a/src/sys/vmm/getfreepage.c +++ b/src/sys/vmm/getfreepage.c @@ -77,42 +77,6 @@ } /*** - $Log$ - Revision 1.2 2005/10/12 00:13:38 reddawg - Removed - - Revision 1.1.1.1 2005/09/26 17:24:50 reddawg - no message - - Revision 1.6 2004/09/11 16:57:27 apwillia - Add locking get GetFreePage - - Revision 1.5 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.4 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.3 2004/07/24 23:04:44 reddawg - Changes... mark let me know if you fault at pid 185 when you type stress - - Revision 1.2 2004/07/20 22:29:55 reddawg - assert: remade assert - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.6 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - END ***/ + diff --git a/src/sys/vmm/getfreevirtualpage.c b/src/sys/vmm/getfreevirtualpage.c index bbc5bbe..6f28c5f 100644 --- a/src/sys/vmm/getfreevirtualpage.c +++ b/src/sys/vmm/getfreevirtualpage.c @@ -31,6 +31,7 @@ #include #include #include +#include static spinLock_t fvpSpinLock = SPIN_LOCK_INITIALIZER; @@ -54,21 +55,20 @@ pageDir = (uInt32 *) parentPageDirAddr; - /* - if (type == 0x0) - kprintf("getfreevirtualpage"); - */ - - /* Lets Search For A Free Page */ if (_current->oInfo.vmStart <= 0x100000) kpanic("Invalid vmStart\n"); - if (type == 0x0) { - start_page = (_current->td.vm_daddr + _current->td.vm_dsize); + + if (type == VM_THRD) { + start_page = (u_int32_t)(_current->td.vm_daddr + ctob(_current->td.vm_dsize)); } - else { + else if (type == VM_TASK) { + kprintf("vmStart"); start_page = _current->oInfo.vmStart; } + else + K_PANIC("Invalid Type"); + //for (x = ((_current->td.vm_daddr + _current->td.vm_dsize) / (1024 * 4096)); x < 1024; x++) { for (x = (start_page / (1024 * 4096)); x < 1024; x++) { /* Set Page Table Address */ @@ -93,10 +93,23 @@ } for (y = 0; y < 1024; y++) { /* Loop Through The Page Table Find An UnAllocated Page */ + if ((pageTableSrc[y] & pageCow) == pageCow) { + //kprintf("COW"); + //_current->td.vm_dsize += btoc(0x1000); + /* HACK MEMORY LEAK */ + pageTableSrc[y] = 0x0; + } if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { if (count > 0x1) { for (c = 0; c < count; c++) { if (y + c < 1024) { + if ((pageTableSrc[y + c] & pageCow) == pageCow) { + //kprintf("COW"); + //_current->td.vm_dsize += btoc(0x1000); + /* HACK MEMORY LEAK */ + pageTableSrc[y + c] = 0x0; + } + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { c = -1; break; @@ -109,8 +122,8 @@ kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } - if (type == 0x1) - _current->td.vm_dsize += (count * 0x1000); + if (type == VM_THRD) + _current->td.vm_dsize += btoc(count * 0x1000); spinUnlock(&fvpSpinLock); return ((void *)((x * (1024 * 4096)) + (y * 4096))); } @@ -123,11 +136,17 @@ */ if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); + /* Clear This Page So No Garbage Is There */ vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ - if (type == 0x1) - _current->td.vm_dsize += (count * 0x1000); + if (type == VM_THRD) { + _current->td.vm_dsize += btoc(count * 0x1000); + kprintf("vm_dsize: [0x%X]][0x%X]\n",ctob(_current->td.vm_dsize),_current->td.vm_dsize); + } + //kprintf("(0x%X:0x%X)",_current->td.vm_dsize,vmm_getPhysicalAddr(((x * (1024 * 4096)) + (y * 4096)))); +// kprintf("(0x%X:0x%X)",_current->td.vm_dsize + _current->td.vm_daddr,((x * (1024 * 4096)) + (y * 4096))); spinUnlock(&fvpSpinLock); return ((void *)((x * (1024 * 4096)) + (y * 4096))); } @@ -140,40 +159,6 @@ } /*** - $Log$ - Revision 1.1.1.1 2006/06/01 12:46:13 reddawg - ubix2 - - Revision 1.2 2005/10/12 00:13:38 reddawg - Removed - - Revision 1.1.1.1 2005/09/26 17:24:50 reddawg - no message - - Revision 1.4 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.3 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.2 2004/07/24 23:21:25 reddawg - ok last of my commits for the night I'm going to bed - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.10 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - END ***/ diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index 4253278..8860ce4 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -108,6 +108,9 @@ spinUnlock(&pageFaultSpinLock); endTask(_current->id); } + else if (memAddr < (_current->td.vm_dsize + _current->td.vm_daddr)) { + pageTable[pageTableIndex] = (uInt32)vmmFindFreePage(_current->id) | PAGE_DEFAULT; + } else { spinUnlock(&pageFaultSpinLock); /* Need To Create A Routine For Attempting To Access Non Mapped Memory */ @@ -129,6 +132,9 @@ /*** $Log$ + Revision 1.3 2006/11/06 19:10:12 reddawg + Lots Of Updates... Still having issues with brk(); + Revision 1.2 2006/10/31 20:44:19 reddawg Lots of changes diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 00445bb..18da2d8 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -213,10 +213,11 @@ /* If The Page Is Mapped In Free It Before We Remap */ if ((pageTable[destPageTableIndex] & PAGE_PRESENT) == PAGE_PRESENT) { if ((pageTable[destPageTableIndex] & PAGE_STACK) == PAGE_STACK) - kprintf("Stack Page\n"); + kprintf("Stack Page: [0x%X]\n",dest); + if ((pageTable[destPageTableIndex] & pageCow) != pageCow) { kprintf("Page NOT COW\n"); - kprintf("Page Present: [0x%X]",dest); + kprintf("Page Present: [0x%X][0x%X]",dest,pageTable[destPageTableIndex]); source = 0x0; goto rmDone; } @@ -450,44 +451,71 @@ } int mmap(struct thread *td,struct mmap_args *uap) { + vm_offset_t addr = 0x0; + + addr = (vm_offset_t) uap->addr; + if (uap->addr != 0x0) { kprintf("Address hints are not supported yet.\n"); } /* + kprintf("uap->flags: [0x%X]\n",uap->flags); kprintf("uap->addr: [0x%X]\n",uap->addr); kprintf("uap->len: [0x%X]\n",uap->len); kprintf("uap->prot: [0x%X]\n",uap->prot); - kprintf("uap->flags: [0x%X]\n",uap->flags); kprintf("uap->fd: [%i]\n",uap->fd); kprintf("uap->pad: [0x%X]\n",uap->pad); kprintf("uap->pos: [0x%X]\n",uap->pos); */ if (uap->fd == -1) - td->td_retval[0] = vmmGetFreeVirtualPage(_current->id,uap->len/0x1000,0x1); + td->td_retval[0] = vmmGetFreeVirtualPage(_current->id,uap->len/0x1000,VM_TASK); else td->td_retval[0] = 0x0; return(0x0); } int obreak(struct thread *td,struct obreak_args *uap) { - int i = 0x0; - uInt32 old = 0x0; + u_int32_t i = 0x0; + vm_offset_t old = 0x0; + vm_offset_t base = 0x0; + vm_offset_t new = 0x0; + + /* + kprintf("vm_offset_t: [%i]\n",sizeof(vm_offset_t)); kprintf("nsize: [0x%X]\n",uap->nsize); kprintf("vm_daddr: [0x%X]\n",td->vm_daddr); kprintf("vm_dsize: [0x%X]\n",td->vm_dsize); kprintf("total: [0x%X]\n",td->vm_daddr + td->vm_dsize); + */ - old = td->vm_daddr + td->vm_dsize; + new = round_page((vm_offset_t)uap->nsize); - for (i = (td->vm_daddr + td->vm_dsize);i <= uap->nsize ;i+= 0x1000) { - if (vmm_remapPage(vmmFindFreePage(_current->id),i,PAGE_DEFAULT) == 0x0) - K_PANIC("remap Failed"); + base = round_page((vm_offset_t)td->vm_daddr); + + old = base + ctob(td->vm_dsize); + //kprintf("ctob: [0x%X]\n",ctob(td->vm_dsize)); + //kprintf("Base: [0x%x], Old: [0x%x], New: [0x%x]\n",base,old,new); + + if (new < base) + K_PANIC("EINVAL"); + + kprintf("obreak: [0x%X]",new); + if (new > old) { + for (i = old + 0x1000;i <= new;i+= 0x1000) { + if (vmm_remapPage(vmmFindFreePage(_current->id),i,PAGE_DEFAULT) == 0x0) + K_PANIC("remap Failed"); + } + td->vm_dsize += btoc(new - old); } - td->vm_dsize += (uap->nsize - old); -// kprintf("vm_dsize: [0x%X]\n",td->vm_dsize); -// kprintf("total: [0x%X]\n",td->vm_daddr + td->vm_dsize); - - //td->td_retval[0] = td->vm_daddr + td->vm_dsize; + else if (new < old) { + /* + for (i = old; i > new;i -= 0x1000) { + kprintf("[0x%X]",i); + } + */ + K_PANIC("new < old"); + td->vm_dsize -= btoc(old - new); + } return(0x0); }