From 66815ff987866d0da26bd6899ad431fbf4f596b1 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 12:13:33 +0200 Subject: [PATCH] Make linux386 work with the new libc layout. --- build.lua | 4 +- lang/cem/libcc.ansi/headers/time.h | 5 +- lang/cem/libcc.ansi/headers/unistd.h | 78 +++++++++++------- plat/cpm/include/sys/types.h | 2 + plat/linux/libsys/ioctl.c | 2 +- plat/linux386/include/ack/fcntl.h | 19 +++++ plat/linux386/include/ack/plat.h | 5 ++ .../include/{unistd.h => ack/signal.h} | 80 +------------------ plat/linux386/include/build.lua | 4 +- plat/linux386/include/sys/types.h | 9 +++ 10 files changed, 96 insertions(+), 112 deletions(-) create mode 100644 plat/linux386/include/ack/fcntl.h rename plat/linux386/include/{unistd.h => ack/signal.h} (64%) create mode 100644 plat/linux386/include/sys/types.h diff --git a/build.lua b/build.lua index f675b96ea..7b187c6d0 100644 --- a/build.lua +++ b/build.lua @@ -7,7 +7,7 @@ vars.ackcflags = { vars.ackldflags = {} vars.plats = { "cpm", --- "linux386", + "linux386", -- "linux68k", -- "linuxppc", -- "osx386", @@ -20,7 +20,7 @@ vars.plats = { } vars.plats_with_tests = { -- "linux68k", --- "linux386", + "linux386", -- "linuxppc", -- --"qemuppc", -- "pc86", diff --git a/lang/cem/libcc.ansi/headers/time.h b/lang/cem/libcc.ansi/headers/time.h index 27901bee9..088a0b0d1 100644 --- a/lang/cem/libcc.ansi/headers/time.h +++ b/lang/cem/libcc.ansi/headers/time.h @@ -7,10 +7,9 @@ #define _TIME_H #include +#include #define CLOCKS_PER_SEC 1000000 - -typedef unsigned long time_t; /* type returned by TOD clock */ typedef unsigned long clock_t; /* type returned by real time clock */ struct tm { @@ -25,7 +24,9 @@ struct tm { int tm_isdst; /* Daylight Saving Time flag */ }; +/* Not a system call; this calls gettimeofday() or times() to do the work */ extern clock_t clock(void); + extern double difftime(time_t _time1, time_t _time0); extern time_t mktime(struct tm *_timeptr); extern time_t time(time_t *_timeptr); diff --git a/lang/cem/libcc.ansi/headers/unistd.h b/lang/cem/libcc.ansi/headers/unistd.h index 65e0b9991..374a42070 100644 --- a/lang/cem/libcc.ansi/headers/unistd.h +++ b/lang/cem/libcc.ansi/headers/unistd.h @@ -13,44 +13,61 @@ #include #if ACKCONF_WANT_STANDARD_O -/* A standard set of flags for read/write/creat and friends for platforms - * where these aren't determined by the operating system. */ + /* A standard set of flags for read/write/creat and friends for platforms + * where these aren't determined by the operating system. */ -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0100, - O_TRUNC = 01000, - O_APPEND = 02000, - O_NONBLOCK = 04000 -}; + enum + { + O_ACCMODE = 0x3, + + O_RDONLY = 0, + O_WRONLY = 1, + O_RDWR = 2, + + O_CREAT = 0100, + O_TRUNC = 01000, + O_APPEND = 02000, + O_NONBLOCK = 04000 + }; +#else + #include #endif #if ACKCONF_WANT_STANDARD_SIGNALS -/* A standard set of definitions for signal handling for platforms where these - * aren't determined by the operating system. */ + /* A standard set of definitions for signal handling for platforms where these + * aren't determined by the operating system. */ -typedef int sig_atomic_t; + typedef int sig_atomic_t; -#define SIG_ERR ((sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ + #define SIG_ERR ((sighandler_t) -1) /* Error return. */ + #define SIG_DFL ((sighandler_t) 0) /* Default action. */ + #define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */ -#define SIGABRT 6 /* Abort (ANSI) */ -#define SIGILL 11 /* Illegal instruction */ - -#define _NSIG 16 /* Biggest signal number + 1 - (not including real-time signals). */ -typedef void (*sighandler_t)(int); -typedef uint16_t sigset_t; + #define SIGABRT 6 /* Abort (ANSI) */ + #define SIGILL 11 /* Illegal instruction */ + #define _NSIG 16 /* Biggest signal number + 1 + (not including real-time signals). */ + typedef void (*sighandler_t)(int); + typedef uint16_t sigset_t; +#else + #include #endif +/* Time handling. */ + +struct timeval +{ + time_t tv_sec; + suseconds_t tv_usec; +}; + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; /* obsolete, unused */ + /* Special variables */ extern char** environ; @@ -61,11 +78,14 @@ extern int brk(void* ptr); extern int close(int d); extern int creat(const char* path, mode_t mode); extern int execve(const char *path, char *const argv[], char *const envp[]); +extern int fcntl(int fd, int op, ...); +extern int gettimeofday(struct timeval* tv, struct timezone* tz); extern int isatty(int d); extern int isatty(int d); extern int kill(pid_t old, int sig); extern int open(const char* path, int access, ...); extern int raise(int signum); +extern int settimeofday(const struct timeval* tv, const struct timezone* tz); extern int sigprocmask(int, const sigset_t *, sigset_t *); extern int unlink(const char* path); extern off_t lseek(int fildes, off_t offset, int whence); @@ -75,6 +95,6 @@ extern ssize_t read(int fd, void* buffer, size_t count); extern ssize_t write(int fd, void* buffer, size_t count); extern void _exit(int); extern void* sbrk(int increment); -extern int fcntl(int fd, int op, ...); + #endif diff --git a/plat/cpm/include/sys/types.h b/plat/cpm/include/sys/types.h index 9b384113d..6a0c3d3db 100644 --- a/plat/cpm/include/sys/types.h +++ b/plat/cpm/include/sys/types.h @@ -3,5 +3,7 @@ typedef int pid_t; typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; #endif diff --git a/plat/linux/libsys/ioctl.c b/plat/linux/libsys/ioctl.c index a77d1f49f..13be2cd24 100644 --- a/plat/linux/libsys/ioctl.c +++ b/plat/linux/libsys/ioctl.c @@ -7,5 +7,5 @@ */ int ioctl(int fd, unsigned long request, void *argp) { - return _syscall(__NR_ioctl, fd, request, argp); + return _syscall(__NR_ioctl, fd, request, (quad)argp); } diff --git a/plat/linux386/include/ack/fcntl.h b/plat/linux386/include/ack/fcntl.h new file mode 100644 index 000000000..c3e2e643b --- /dev/null +++ b/plat/linux386/include/ack/fcntl.h @@ -0,0 +1,19 @@ +#ifndef _ACK_FCNTL_H +#define _ACK_FCNTL_H + +/* Linux O_ constants. */ + +enum +{ + O_ACCMODE = 0x3, + + O_RDONLY = 0, + O_WRONLY = 1, + O_RDWR = 2, + + O_CREAT = 0x40, + O_TRUNC = 0x200, + O_APPEND = 0x400 +}; + +#endif diff --git a/plat/linux386/include/ack/plat.h b/plat/linux386/include/ack/plat.h index f65adb8d7..65911f47e 100644 --- a/plat/linux386/include/ack/plat.h +++ b/plat/linux386/include/ack/plat.h @@ -11,4 +11,9 @@ /* #define ACKCONF_TIME_IS_A_SYSCALL */ +/* Linux has its own O_ definitions. */ + +#define ACKCONF_WANT_STANDARD_O 0 +#define ACKCONF_WANT_STANDARD_SIGNALS 0 + #endif diff --git a/plat/linux386/include/unistd.h b/plat/linux386/include/ack/signal.h similarity index 64% rename from plat/linux386/include/unistd.h rename to plat/linux386/include/ack/signal.h index 8c8637c09..1f41234b6 100644 --- a/plat/linux386/include/unistd.h +++ b/plat/linux386/include/ack/signal.h @@ -1,76 +1,7 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ +#ifndef _ACK_SIGNAL_H +#define _ACK_SIGNAL_H -#ifndef _UNISTD_H -#define _UNISTD_H - -#include -#include - -/* Types */ - -typedef int pid_t; -typedef int mode_t; - -typedef long suseconds_t; - -/* Time handling. */ - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -struct timezone -{ - int tz_minuteswest; - int tz_dsttime; -}; /* obsolete, unused */ - -extern int gettimeofday(struct timeval* tv, struct timezone* tz); -extern int settimeofday(const struct timeval* tv, const struct timezone* tz); - -/* File access. */ - -enum -{ - O_ACCMODE = 0x3, - - O_RDONLY = 0, - O_WRONLY = 1, - O_RDWR = 2, - - O_CREAT = 0x40, - O_TRUNC = 0x200, - O_APPEND = 0x400 -}; - -extern int open(const char* path, int access, ...); -extern int creat(const char* path, mode_t mode); -extern int close(int d); -extern int read(int fd, void* buffer, size_t count); -extern int write(int fd, void* buffer, size_t count); -extern off_t lseek(int fildes, off_t offset, int whence); -extern int fcntl(int fd, int op, ...); -extern int unlink(const char* path); - -/* Special variables */ - -extern char** environ; - -/* Implemented system calls */ - -extern void _exit(int); -extern pid_t getpid(void); -extern int brk(void* ptr); -extern void* sbrk(int increment); -extern int isatty(int d); -extern int execve(const char *path, char *const argv[], char *const envp[]); - -/* Signal handling */ +/* Signal constants. */ typedef int sig_atomic_t; @@ -124,10 +55,5 @@ typedef int sig_atomic_t; typedef unsigned long sigset_t; typedef void (*sighandler_t)(int); -extern sighandler_t signal(int signum, sighandler_t handler); -extern int sigprocmask(int, const sigset_t *, sigset_t *); -extern int raise(int signum); - - #endif diff --git a/plat/linux386/include/build.lua b/plat/linux386/include/build.lua index 129fd9035..37ef9c565 100644 --- a/plat/linux386/include/build.lua +++ b/plat/linux386/include/build.lua @@ -9,8 +9,10 @@ local function addheader(h) end addheader("ack/plat.h") +addheader("ack/fcntl.h") +addheader("ack/signal.h") addheader("sys/ioctl.h") -addheader("unistd.h") +addheader("sys/types.h") acklibrary { name = "headers", diff --git a/plat/linux386/include/sys/types.h b/plat/linux386/include/sys/types.h new file mode 100644 index 000000000..b706026ef --- /dev/null +++ b/plat/linux386/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef int pid_t; +typedef int mode_t; +typedef long suseconds_t; +typedef long time_t; + +#endif