diff --git a/sys/kernel/Makefile b/sys/kernel/Makefile index 7f9a7be..0ced24d 100644 --- a/sys/kernel/Makefile +++ b/sys/kernel/Makefile @@ -6,7 +6,7 @@ include ../Makefile.incl # Objects -OBJS = vfs_calls.o tty.o kern_sig.o pipe.o kern_descrip.o kern_sysctl.o gen_calls.o endtask.o ld.o time.o elf.o ubthread.o vitals.o access.o syscall.o syscall_posix.o syscalls_posix.o execve.o +OBJS = vfs_calls.o tty.o kern_sig.o pipe.o descrip.o kern_sysctl.o gen_calls.o endtask.o ld.o time.o elf.o ubthread.o vitals.o access.o syscall.o syscall_posix.o syscalls_posix.o execve.o #OBJS += ../${_ARCH}/schedyield.o ../${_ARCH}/kpanic.o ../${_ARCH}/timer.o ../${_ARCH}/spinlock.o ../${_ARCH}/exec.o ../${_ARCH}/sys_call_new.o ../${_ARCH}/sys_call.o ../${_ARCH}/bioscall.o ../${_ARCH}/fork.o ../${_ARCH}/syscall.o ../${_ARCH}/systemtask.o ../${_ARCH}/sched.o ../${_ARCH}/cpu.o # ap-boot.o smp.o vitals.o(obsolete) diff --git a/sys/kernel/descrip.c b/sys/kernel/descrip.c new file mode 100644 index 0000000..0580317 --- /dev/null +++ b/sys/kernel/descrip.c @@ -0,0 +1,224 @@ +/*- + * Copyright (c) 2002-2018 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) 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. + * 3) 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 AUTHOR 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct file *kern_files = 0x0; + +int fcntl(struct thread *td, struct fcntl_args *uap) { + struct file *fp = 0x0; + +#ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); +#endif + + if (td->o_files[uap->fd] == 0x0) { + kprintf("ERROR!!!\n"); + return (-1); + } + + fp = (struct file *) td->o_files[uap->fd]; + switch (uap->cmd) { + case 3: + td->td_retval[0] = fp->f_flag; + break; + case 4: + fp->f_flag &= ~FCNTLFLAGS; + fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS; + break; + default: + kprintf("ERROR DEFAULT"); + } + + return (0x0); +} + +int falloc(struct thread *td, struct file **resultfp, int *resultfd) { + + struct file *fp = 0x0; + int i = 0; + + fp = (struct file *) kmalloc(sizeof(struct file)); + + /* First 5 Descriptors Are Reserved */ + for (i = 5; i < MAX_FILES; i++) { + if (td->o_files[i] == 0x0) { + td->o_files[i] = (void *) fp; + if (resultfd) + *resultfd = i; + if (resultfp) + *resultfp = fp; + goto allocated; + } + } + + kfree(fp); + + *resultfp = 0x0; + *resultfd = 0x0; + + allocated: + + return (0x0); +} + +int fdestroy(struct thread *td, struct file *fp, int fd) { + int error = 0; + + if (td->o_files[fd] != fp) { + error = -1; + } + else { + kfree(td->o_files[fd]); + td->o_files[fd] = 0x0; + } + + return (error); +} + +int close(struct thread *td, struct close_args *uap) { +#ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); +#endif + kfree((void *) td->o_files[uap->fd]); + td->o_files[uap->fd] = 0x0; + td->td_retval[0] = 0x0; + return (0x0); +} + +/*! + * \brief return data table size + */ +int getdtablesize(struct thread *td, struct getdtablesize_args *uap) { +#ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); +#endif + td->td_retval[0] = O_FILES; + return (0); +} + +/* HACK */ +int fstat(struct thread *td, struct sys_fstat_args *uap) { + struct file *fp = 0x0; + +#ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); +#endif + + fp = (struct file *) _current->td.o_files[uap->fd]; + uap->sb->st_mode = 0x2180; + uap->sb->st_blksize = 0x1000; + kprintf("fstat: %i", uap->fd); + return (0x0); +} + +/*! + * \brief ioctl functionality not implimented yet + * + * \returns NULL for now + */ +int ioctl(struct thread *td, struct ioctl_args *uap) { + td->td_retval[0] = 0x0; + return (0x0); +} + +/*! + * \brief get pointer to file fd in specified thread + * + * \return returns fp + */ +int getfd(struct thread *td, struct file **fp, int fd) { + int error = 0x0; + +#ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); +#endif + + *fp = (struct file *) td->o_files[fd]; + + if (fp == 0x0) + error = -1; + + return (error); +} + +int sys_ioctl(struct thread *td, struct sys_ioctl_args *args) { + switch(args->com) { + case TIOCGETA: + if (args->fd == 0 || args->fd == 1) { + struct termios *t = (struct termios *)args->data; + + t->c_iflag = 0x2B02; + t->c_oflag = 0x3; + t->c_cflag = 0x4B00; + t->c_lflag = 0x5CB; + + t->c_cc[0] = 4; + t->c_cc[1] = 255; + t->c_cc[2] = 255; + t->c_cc[3] = 127; + t->c_cc[4] = 23; + t->c_cc[5] = 21; + t->c_cc[6] = 18; + t->c_cc[7] = 8; + t->c_cc[8] = 3; + t->c_cc[9] = 28; + t->c_cc[10] = 26; + t->c_cc[11] = 25; + t->c_cc[12] = 17; + t->c_cc[13] = 19; + t->c_cc[14] = 22; + t->c_cc[15] = 15; + t->c_cc[16] = 1; + t->c_cc[17] = 0; + t->c_cc[18] = 20; + t->c_cc[19] = 255; + + t->c_ispeed = 0x9600; + t->c_ospeed = 0x9600; + + td->td_retval[0] = 0; + } + else { + td->td_retval[0] = -1; + } + break; + default: + kprintf("ioFD:%i:%i!", args->fd, args->com); + break; + } + td->td_retval[0] = 0x0; + return (0x0); +} diff --git a/sys/kernel/kern_descrip.c b/sys/kernel/kern_descrip.c deleted file mode 100644 index 0580317..0000000 --- a/sys/kernel/kern_descrip.c +++ /dev/null @@ -1,224 +0,0 @@ -/*- - * Copyright (c) 2002-2018 The UbixOS Project. - * All rights reserved. - * - * This was developed by Christopher W. Olsen for the UbixOS Project. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1) Redistributions of source code must retain the above copyright notice, this list of - * conditions, the following disclaimer and the list of authors. - * 2) 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. - * 3) 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 AUTHOR 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static struct file *kern_files = 0x0; - -int fcntl(struct thread *td, struct fcntl_args *uap) { - struct file *fp = 0x0; - -#ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); -#endif - - if (td->o_files[uap->fd] == 0x0) { - kprintf("ERROR!!!\n"); - return (-1); - } - - fp = (struct file *) td->o_files[uap->fd]; - switch (uap->cmd) { - case 3: - td->td_retval[0] = fp->f_flag; - break; - case 4: - fp->f_flag &= ~FCNTLFLAGS; - fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS; - break; - default: - kprintf("ERROR DEFAULT"); - } - - return (0x0); -} - -int falloc(struct thread *td, struct file **resultfp, int *resultfd) { - - struct file *fp = 0x0; - int i = 0; - - fp = (struct file *) kmalloc(sizeof(struct file)); - - /* First 5 Descriptors Are Reserved */ - for (i = 5; i < MAX_FILES; i++) { - if (td->o_files[i] == 0x0) { - td->o_files[i] = (void *) fp; - if (resultfd) - *resultfd = i; - if (resultfp) - *resultfp = fp; - goto allocated; - } - } - - kfree(fp); - - *resultfp = 0x0; - *resultfd = 0x0; - - allocated: - - return (0x0); -} - -int fdestroy(struct thread *td, struct file *fp, int fd) { - int error = 0; - - if (td->o_files[fd] != fp) { - error = -1; - } - else { - kfree(td->o_files[fd]); - td->o_files[fd] = 0x0; - } - - return (error); -} - -int close(struct thread *td, struct close_args *uap) { -#ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); -#endif - kfree((void *) td->o_files[uap->fd]); - td->o_files[uap->fd] = 0x0; - td->td_retval[0] = 0x0; - return (0x0); -} - -/*! - * \brief return data table size - */ -int getdtablesize(struct thread *td, struct getdtablesize_args *uap) { -#ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); -#endif - td->td_retval[0] = O_FILES; - return (0); -} - -/* HACK */ -int fstat(struct thread *td, struct sys_fstat_args *uap) { - struct file *fp = 0x0; - -#ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); -#endif - - fp = (struct file *) _current->td.o_files[uap->fd]; - uap->sb->st_mode = 0x2180; - uap->sb->st_blksize = 0x1000; - kprintf("fstat: %i", uap->fd); - return (0x0); -} - -/*! - * \brief ioctl functionality not implimented yet - * - * \returns NULL for now - */ -int ioctl(struct thread *td, struct ioctl_args *uap) { - td->td_retval[0] = 0x0; - return (0x0); -} - -/*! - * \brief get pointer to file fd in specified thread - * - * \return returns fp - */ -int getfd(struct thread *td, struct file **fp, int fd) { - int error = 0x0; - -#ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); -#endif - - *fp = (struct file *) td->o_files[fd]; - - if (fp == 0x0) - error = -1; - - return (error); -} - -int sys_ioctl(struct thread *td, struct sys_ioctl_args *args) { - switch(args->com) { - case TIOCGETA: - if (args->fd == 0 || args->fd == 1) { - struct termios *t = (struct termios *)args->data; - - t->c_iflag = 0x2B02; - t->c_oflag = 0x3; - t->c_cflag = 0x4B00; - t->c_lflag = 0x5CB; - - t->c_cc[0] = 4; - t->c_cc[1] = 255; - t->c_cc[2] = 255; - t->c_cc[3] = 127; - t->c_cc[4] = 23; - t->c_cc[5] = 21; - t->c_cc[6] = 18; - t->c_cc[7] = 8; - t->c_cc[8] = 3; - t->c_cc[9] = 28; - t->c_cc[10] = 26; - t->c_cc[11] = 25; - t->c_cc[12] = 17; - t->c_cc[13] = 19; - t->c_cc[14] = 22; - t->c_cc[15] = 15; - t->c_cc[16] = 1; - t->c_cc[17] = 0; - t->c_cc[18] = 20; - t->c_cc[19] = 255; - - t->c_ispeed = 0x9600; - t->c_ospeed = 0x9600; - - td->td_retval[0] = 0; - } - else { - td->td_retval[0] = -1; - } - break; - default: - kprintf("ioFD:%i:%i!", args->fd, args->com); - break; - } - td->td_retval[0] = 0x0; - return (0x0); -} diff --git a/sys/net/net/sys_arch.c b/sys/net/net/sys_arch.c index 869caaa..2426f1b 100644 --- a/sys/net/net/sys_arch.c +++ b/sys/net/net/sys_arch.c @@ -560,3 +560,5 @@ return(error); } + +/* END */