From 9726af20bbd1a40c21451e01a6b5594dc43bc19c Mon Sep 17 00:00:00 2001 From: Mathias Gottschlag Date: Tue, 23 Dec 2008 23:20:05 +0100 Subject: [PATCH] Stubbed out some more libc functions. --- programs/external/CMakeLists.txt | 11 ++++ programs/include/{sys/time.h => locale.h} | 48 +++++++++++++----- programs/include/signal.h | 2 + programs/include/sys/{time.h => select.h} | 24 ++++++--- programs/include/sys/time.h | 2 + programs/include/{sys/time.h => termio.h} | 29 +++++++---- programs/include/termios.h | 59 ++++++++++++++++++++++ programs/include/unistd.h | 5 ++ programs/libc/CMakeLists.txt | 1 + programs/libc/files.c | 31 ++++++++++++ programs/libc/signal.c | 5 ++ programs/libc/stdio.c | 23 +++++++++ programs/libc/stdlib.c | 84 +++++++++++++++++++++++++++++++ programs/libc/time.c | 10 ++++ programs/libc/unistd.c | 32 ++++++++++++ shared/include/planlos/syscalls.h | 1 + shared/include/stdio.h | 6 +++ system/include/sys/serial.h | 4 +- system/kernel/sys/syscall.c | 3 ++ 19 files changed, 349 insertions(+), 31 deletions(-) create mode 100644 programs/external/CMakeLists.txt copy programs/include/{sys/time.h => locale.h} (57%) copy programs/include/sys/{time.h => select.h} (68%) copy programs/include/{sys/time.h => termio.h} (77%) diff --git a/programs/external/CMakeLists.txt b/programs/external/CMakeLists.txt new file mode 100644 index 0000000..2641b7d --- /dev/null +++ b/programs/external/CMakeLists.txt @@ -0,0 +1,11 @@ + +file(GLOB SUBDIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt") + +foreach(SUBDIR ${SUBDIRS}) + get_filename_component(PATH "${SUBDIR}" PATH) + add_subdirectory(${PATH}) +endforeach() + +set(OBJECTS ${OBJECTS} PARENT_SCOPE) + diff --git a/programs/include/sys/time.h b/programs/include/locale.h similarity index 57% copy from programs/include/sys/time.h copy to programs/include/locale.h index 3e16e31..d8ed71d 100644 --- a/programs/include/sys/time.h +++ b/programs/include/locale.h @@ -19,22 +19,46 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SYS_TIME_H_INCLUDED -#define SYS_TIME_H_INCLUDED +#ifndef LOCALE_H_INCLUDED +#define LOCALE_H_INCLUDED -#include - -struct timeval +struct lconv { - time_t tv_sec; - suseconds_t tv_usec; + char *currency_symbol; + char *decimal_point; + char frac_digits; + char *grouping; + char *int_curr_symbol; + char int_frac_digits; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_p_sign_posn; + char *mon_decimal_point; + char *mon_grouping; + char *mon_thousands_sep; + char *negative_sign; + char n_cs_precedes; + char n_sep_by_space; + char n_sign_posn; + char *positive_sign; + char p_cs_precedes; + char p_sep_by_space; + char p_sign_posn; + char *thousands_sep; }; -struct itimerval -{ - struct timeval it_interval; - struct timeval it_value; -}; +#define LC_ALL 1 +#define LC_COLLATE 2 +#define LC_CTYPE 3 +#define LC_MESSAGES 4 +#define LC_MONETARY 5 +#define LC_NUMERIC 6 +#define LC_TIME 7 + +char *setlocale(int category, const char *locale); #endif diff --git a/programs/include/signal.h b/programs/include/signal.h index 7a474cd..7f5e004 100644 --- a/programs/include/signal.h +++ b/programs/include/signal.h @@ -135,5 +135,7 @@ int sigaddset(sigset_t *set, int signo); int sigaction(int sig, const struct sigaction *act, struct sigaction *oact); +int sigismember(const sigset_t *set, int signo); + #endif diff --git a/programs/include/sys/time.h b/programs/include/sys/select.h similarity index 68% copy from programs/include/sys/time.h copy to programs/include/sys/select.h index 3e16e31..a46d7c5 100644 --- a/programs/include/sys/time.h +++ b/programs/include/sys/select.h @@ -19,10 +19,12 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SYS_TIME_H_INCLUDED -#define SYS_TIME_H_INCLUDED +#ifndef SYS_SELECT_H_INCLUDED +#define SYS_SELECT_H_INCLUDED #include +#include +#include struct timeval { @@ -30,11 +32,21 @@ struct timeval suseconds_t tv_usec; }; -struct itimerval +#define FD_SETSIZE 128 + +typedef struct fd_set { - struct timeval it_interval; - struct timeval it_value; -}; +} fd_set; + +void FD_CLR(int fd, fd_set *fdset); +int FD_ISSET(int fd, fd_set *fdset); +void FD_SET(int fd, fd_set *fdset); +void FD_ZERO(fd_set *fdset); + +int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, + const struct timespec *timeout, const sigset_t *sigmask); +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, + struct timeval *timeout); #endif diff --git a/programs/include/sys/time.h b/programs/include/sys/time.h index 3e16e31..d58d5a5 100644 --- a/programs/include/sys/time.h +++ b/programs/include/sys/time.h @@ -36,5 +36,7 @@ struct itimerval struct timeval it_value; }; +int gettimeofday(struct timeval *t, void *tz); + #endif diff --git a/programs/include/sys/time.h b/programs/include/termio.h similarity index 77% copy from programs/include/sys/time.h copy to programs/include/termio.h index 3e16e31..5f06c89 100644 --- a/programs/include/sys/time.h +++ b/programs/include/termio.h @@ -19,21 +19,28 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SYS_TIME_H_INCLUDED -#define SYS_TIME_H_INCLUDED +#ifndef TERMIO_H_INCLUDED +#define TERMIO_H_INCLUDED -#include +#include -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; +#define TCSBRK 1 +#define TCSBREAK 2 +#define TCXONC 3 +#define TCFLSH 4 + +#define TCGETA 1 +#define TCSETA 2 +#define TCSETAF 3 +#define TCSETAW 4 -struct itimerval +struct termio { - struct timeval it_interval; - struct timeval it_value; + tcflag_t c_iflag; + tcflag_t c_oflag; + tcflag_t c_cflag; + tcflag_t c_lflag; + tcflag_t c_cc[1]; }; #endif diff --git a/programs/include/termios.h b/programs/include/termios.h index fe336f6..d5d096a 100644 --- a/programs/include/termios.h +++ b/programs/include/termios.h @@ -22,12 +22,71 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef TERMIOS_H_INCLUDED #define TERMIOS_H_INCLUDED +#include + typedef int cc_t; typedef int speed_t; typedef int tcflag_t; +#define B0 1 +#define B50 2 +#define B75 3 +#define B110 4 +#define B134 5 +#define B150 6 +#define B200 7 +#define B300 8 +#define B600 9 +#define B1200 10 +#define B1800 11 +#define B2400 12 +#define B4800 13 +#define B9600 14 +#define B19200 15 +#define B38400 16 + +#define VEOF -1 +#define VEOL '\n' +#define VERASE ' ' +#define VINTR 0 +#define VKILL 0 +#define VMIN 0 +#define VQUIT 0 +#define VSTART 0 +#define VSTOP 0 +#define VSUSP 0 +#define VTIME 0 + #define NCCS 16 +#define TCIFLUSH 1 +#define TCIOFLUSH 2 +#define TCOFLUSH 3 + +#define ECHO 1 +#define ECHOE 2 +#define ECHOK 3 +#define ECHONL 4 +#define ICANON 5 +#define IEXTEN 6 +#define ISIG 7 +#define NOFLSH 8 +#define TOSTOP 9 +#define XCASE 10 + +#define CSIZE 1 +#define CS5 5 +#define CS6 6 +#define CS7 7 +#define CS8 8 +#define CSTOPB 2 +#define CREAD 3 +#define PARENB 4 +#define PARODD 5 +#define HUPCL 6 +#define CLOCAL 7 +#define CBAUD 8 + struct termios { tcflag_t c_iflag; diff --git a/programs/include/unistd.h b/programs/include/unistd.h index 41078d1..eab900f 100644 --- a/programs/include/unistd.h +++ b/programs/include/unistd.h @@ -66,6 +66,11 @@ extern int optreset; int getopt(int argc, char *const *argv, const char *optstring); +pid_t getpid(void); + +int access(const char *path, int amode); + +pid_t tcgetpgrp(int fd); #endif diff --git a/programs/libc/CMakeLists.txt b/programs/libc/CMakeLists.txt index 145a77b..e875ace 100644 --- a/programs/libc/CMakeLists.txt +++ b/programs/libc/CMakeLists.txt @@ -11,6 +11,7 @@ stdlib.c time.c unistd.c wait.c +terminal.c ../../shared/string.c ../../shared/ctype.c ../../shared/sprintf.c diff --git a/programs/libc/files.c b/programs/libc/files.c index 8036445..a1390d8 100644 --- a/programs/libc/files.c +++ b/programs/libc/files.c @@ -25,6 +25,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include #include int open(const char *path, int oflag, ...) @@ -156,3 +157,33 @@ int fcntl(int fd, int cmd, ...) return status; } +int stat(const char *path, struct stat *buf) +{ + return -1; +} + +void FD_CLR(int fd, fd_set *fdset) +{ +} +int FD_ISSET(int fd, fd_set *fdset) +{ + return 0; +} +void FD_SET(int fd, fd_set *fdset) +{ +} +void FD_ZERO(fd_set *fdset) +{ +} + +/*int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, + const struct timespec *timeout, const sigset_t *sigmask) +{ +}*/ +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, + struct timeval *timeout) +{ + return -1; +} + + diff --git a/programs/libc/signal.c b/programs/libc/signal.c index 5bf67b1..4d0b788 100644 --- a/programs/libc/signal.c +++ b/programs/libc/signal.c @@ -71,3 +71,8 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) return -1; } +int sigismember(const sigset_t *set, int signo) +{ + return -1; +} + diff --git a/programs/libc/stdio.c b/programs/libc/stdio.c index 25a2bc0..8227217 100644 --- a/programs/libc/stdio.c +++ b/programs/libc/stdio.c @@ -297,9 +297,32 @@ int puts(const char *s) printf("%s\n", s); return 0; } +int putc(int c) +{ + return fputc(c, stdout); +} void perror(const char *str) { printf("%s\n", str); } +int fflush(FILE *file) +{ + return 0; +} + +int setvbuf(FILE *file, char *buf, int type, size_t size) +{ + return 0; +} + +int scanf(const char *format, ... ) +{ + return -1; +} +int sscanf(const char *s, const char *format, ... ) +{ + return -1; +} + diff --git a/programs/libc/stdlib.c b/programs/libc/stdlib.c index 075beff..695bfd8 100644 --- a/programs/libc/stdlib.c +++ b/programs/libc/stdlib.c @@ -64,3 +64,87 @@ int atoi(const char *str) return number; } +int abs(int n) +{ + if (n < 0) return -n; + return n; +} + +char *getenv(const char *name) +{ + if (!strcmp(name, "TERM")) + { + return "/dev/tty0"; + } + else if (!strcmp(name, "TERMINFO")) + { + return "/usr/lib/terminfo"; + } + // TODO + return ""; +} + +static int strtol_is_digit(const char c, int base) +{ + if ((c >= '0') && (c <= '9')) + { + if (c - '0' < base) + { + return 1; + } + return 0; + } + else if ((c >= 'a') && (c <= 'z')) + { + if (c - 'a' < base - 10) + { + return 1; + } + } + else if ((c >= 'A') && (c <= 'Z')) + { + if (c - 'A' < base - 10) + { + return 1; + } + } + return 0; +} +static int strtol_get_digit(const char c, int base) +{ + if ((c >= '0') && (c <= '9')) + { + return c - '0'; + } + else if ((c >= 'a') && (c <= 'z')) + { + return c - 'a'; + } + else if ((c >= 'A') && (c <= 'Z')) + { + return c - 'A'; + } + else return 0; +} + +long int strtol(const char *nptr, char **endptr, int base) +{ + int negative = 0; + if (*nptr == '-') + { + negative = 1; + nptr++; + } + + long int number = 0; + + while (strtol_is_digit(*nptr, base)) + { + number = number * base + strtol_get_digit(*nptr, base); + nptr++; + } + if (endptr) *endptr = (char*)nptr; + if (negative) number = -number; + return number; +} + diff --git a/programs/libc/time.c b/programs/libc/time.c index 472a89d..a42f822 100644 --- a/programs/libc/time.c +++ b/programs/libc/time.c @@ -34,3 +34,13 @@ unsigned sleep(unsigned seconds) return 0; } +int gettimeofday(struct timeval *t, void *tz) +{ + return -1; +} + +clock_t times(struct tms *buffer) +{ + return -1; +} + diff --git a/programs/libc/unistd.c b/programs/libc/unistd.c index 4b76dce..c5d47be 100644 --- a/programs/libc/unistd.c +++ b/programs/libc/unistd.c @@ -79,3 +79,35 @@ int dup2(int fd, int fd2) return fcntl(fd, F_DUPFD, fd2); } +pid_t getpid(void) +{ + int pid; + asm volatile("int $0x80" : "=b"(pid): "a"(SYS_GETPID)); + return pid; + +} + +int isatty(int fildes) +{ + return 1; +} + +int access(const char *path, int amode) +{ + return R_OK; +} + +char *setlocale(int category, const char *locale) +{ + return 0; +} + +pid_t tcgetpgrp(int fd) +{ + return -1; +} +pid_t getpgrp(void) +{ + return 0; +} + diff --git a/shared/include/planlos/syscalls.h b/shared/include/planlos/syscalls.h index 2e12a5f..93fd9d7 100644 --- a/shared/include/planlos/syscalls.h +++ b/shared/include/planlos/syscalls.h @@ -44,6 +44,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SYS_FCNTL 20 #define SYS_SIGNAL 21 #define SYS_RAISE 22 +#define SYS_GETPID 23 #endif diff --git a/shared/include/stdio.h b/shared/include/stdio.h index f81b039..cad0f4a 100644 --- a/shared/include/stdio.h +++ b/shared/include/stdio.h @@ -35,6 +35,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define BUFSIZ 256 +#define _IOFBF 1 +#define _IOLBF 2 +#define _IONBF 3 + #define NULL ((void*)0) typedef unsigned int fpos_t; @@ -92,5 +96,7 @@ int vasprintf(char **buf, const char *fmt, va_list arg); void perror(const char *str); +int setvbuf(FILE *file, char *buf, int type, size_t size); + #endif diff --git a/system/include/sys/serial.h b/system/include/sys/serial.h index d120adb..53036a6 100644 --- a/system/include/sys/serial.h +++ b/system/include/sys/serial.h @@ -20,14 +20,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * \file serial.h - * Serial device functions (/dev/debug) + * Serial device functions (/dev/serial) */ #ifndef SYS_SERIAL_H_INCLUDED #define SYS_SERIAL_H_INCLUDED /** - * Initializes the serial device and creates /dev/debug. + * Initializes the serial device and creates /dev/serial. */ void sysInitSerial(void); diff --git a/system/kernel/sys/syscall.c b/system/kernel/sys/syscall.c index 36508e4..03534ea 100644 --- a/system/kernel/sys/syscall.c +++ b/system/kernel/sys/syscall.c @@ -769,6 +769,9 @@ void sysSyscall(KeThread *thread, uintptr_t index, uintptr_t *param1, case SYS_RAISE: sysRaise(thread, param1, param2, param3, param4, param5); break; + case SYS_GETPID: + *param1 = thread->process->pid; + break; default: *param1 = -1; break; -- 2.11.4.GIT