From aa536a690f82b8db8a94d7fd341e6dd737cd2d86 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Wed, 19 Oct 2022 08:21:55 +0200 Subject: [PATCH] Revert "kaem.run: Remove --bootstrap-mode." This reverts commit b4405b54ea67d892e3af0521bf66ef328ffef398. --- build-aux/pointer.sh | 1 + include/fcntl.h | 3 -- include/linux/arm/syscall.h | 18 ++++++++++ include/linux/x86/syscall.h | 22 +++++++++++- include/m2/lib.h | 70 +++++++++++++++++++++++++++++++++++++ include/mes/constants.h | 46 +++++++++++++++++++++++- include/mes/symbols.h | 8 ++++- include/signal.h | 9 ++--- include/sys/ioctl.h | 5 --- include/sys/stat.h | 24 +------------ include/sys/types.h | 4 --- include/time.h | 6 ++-- kaem.run | 34 ++++++------------ lib/linux/lseek.c | 18 +++++++--- lib/linux/waitpid.c | 9 ++--- lib/m2/chmod.c | 31 ++++++++++++++++ lib/m2/clock_gettime.c | 30 ++++++++++++++++ lib/m2/exit.c | 29 +++++++++++++++ lib/m2/getcwd.c | 4 ++- lib/m2/isatty.c | 3 +- lib/m2/malloc.c | 36 +++++++++++++++++++ lib/m2/mes_open.c | 28 +++++++++++++++ lib/{linux => m2}/open.c | 17 +-------- lib/m2/read.c | 31 ++++++++++++++++ lib/m2/waitpid.c | 39 +++++++++++++++++++++ lib/mes/ntoab.c | 14 +------- lib/posix/getcwd.c | 4 ++- lib/posix/getenv.c | 7 ++-- lib/posix/setenv.c | 7 ++-- lib/stub/__raise.c | 4 ++- scaffold/read.kaem | 2 +- simple.make | 45 ++++++++++-------------- src/core.c | 2 +- src/gc.c | 17 +++------ src/posix.c | 15 +++----- src/symbol.c | 6 +++- src/test/gc.c | 7 ++-- src/vector.c | 6 ++-- 38 files changed, 478 insertions(+), 183 deletions(-) create mode 100644 include/m2/lib.h create mode 100644 lib/m2/chmod.c create mode 100644 lib/m2/clock_gettime.c create mode 100644 lib/m2/exit.c create mode 100644 lib/m2/malloc.c create mode 100644 lib/m2/mes_open.c rename lib/{linux => m2}/open.c (72%) create mode 100644 lib/m2/read.c create mode 100644 lib/m2/waitpid.c diff --git a/build-aux/pointer.sh b/build-aux/pointer.sh index 51cea49f..384b0689 100755 --- a/build-aux/pointer.sh +++ b/build-aux/pointer.sh @@ -48,6 +48,7 @@ sed -ri \ include/mes/mes.h \ include/mes/symbols.h \ include/mes/builtins.h \ + include/m2/lib.h \ src/builtins.c \ src/cc.c \ src/core.c \ diff --git a/include/fcntl.h b/include/fcntl.h index c5bc6951..2a8ece80 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -69,11 +69,8 @@ #define creat(file_name, mode) open (file_name, O_WRONLY | O_CREAT | O_TRUNC, mode) int dup (int old); int dup2 (int old, int new); - -#if !__M2__ int fcntl (int filedes, int command, ...); int open (char const *s, int flags, ...); -#endif #endif // ! SYSTEM_LIBC diff --git a/include/linux/arm/syscall.h b/include/linux/arm/syscall.h index 62029463..b04ff039 100644 --- a/include/linux/arm/syscall.h +++ b/include/linux/arm/syscall.h @@ -25,29 +25,47 @@ /* libc-mini */ #ifndef SYS_exit +// CONSTANT SYS_exit 0x01 #define SYS_exit 0x01 #endif #ifndef SYS_write +// CONSTANT SYS_write 0x04 #define SYS_write 0x04 #endif /* libc */ +// CONSTANT SYS_fork 0x02 #define SYS_fork 0x02 +// CONSTANT SYS_read 0x03 #define SYS_read 0x03 +// CONSTANT SYS_open 0x05 #define SYS_open 0x05 //#define SYS_waitpid +// CONSTANT SYS_wait4 0x72 #define SYS_wait4 0x72 +// CONSTANT SYS_execve 0x0b #define SYS_execve 0x0b +// CONSTANT SYS_chmod 0x0f #define SYS_chmod 0x0f +// CONSTANT SYS_access 0x21 #define SYS_access 0x21 +// CONSTANT SYS_brk 0x2d #define SYS_brk 0x2d +// CONSTANT SYS_ioctl 0x36 #define SYS_ioctl 0x36 +// CONSTANT SYS_fsync 0x76 #define SYS_fsync 0x76 +// CONSTANT SYS_getcwd 0xb7 #define SYS_getcwd 0xb7 +// CONSTANT SYS_dup 0x29 #define SYS_dup 0x29 +// CONSTANT SYS_dup2 0x3f #define SYS_dup2 0x3f +// CONSTANT SYS_unlink 0x0a #define SYS_unlink 0x0a +// CONSTANT SYS_gettimeofday 0x4e #define SYS_gettimeofday 0x4e +// CONSTANT SYS_clock_gettime 0x107 #define SYS_clock_gettime 0x107 /* libc+tcc */ diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index c1271f06..01c46a35 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2017 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,30 +22,50 @@ /* libc-mini */ #ifndef SYS_exit +// CONSTANT SYS_exit 0x01 #define SYS_exit 0x01 #endif #ifndef SYS_write +// CONSTANT SYS_write 0x04 #define SYS_write 0x04 #endif /* libc */ +// CONSTANT SYS_fork 0x02 #define SYS_fork 0x02 +// CONSTANT SYS_read 0x03 #define SYS_read 0x03 +// CONSTANT SYS_open 0x05 #define SYS_open 0x05 +// CONSTANT SYS_waitpid 0x07 #define SYS_waitpid 0x07 +// CONSTANT SYS_wait4 0x72 #define SYS_wait4 0x72 +// CONSTANT SYS_execve 0x0b #define SYS_execve 0x0b +// CONSTANT SYS_chmod 0x0f #define SYS_chmod 0x0f +// CONSTANT SYS_access 0x21 #define SYS_access 0x21 +// CONSTANT SYS_brk 0x2d #define SYS_brk 0x2d +// CONSTANT SYS_ioctl 0x36 #define SYS_ioctl 0x36 +// CONSTANT SYS_fsync 0x76 #define SYS_fsync 0x76 +// CONSTANT SYS_getcwd 0xb7 #define SYS_getcwd 0xb7 +// CONSTANT SYS_dup 0x29 #define SYS_dup 0x29 +// CONSTANT SYS_dup2 0x3f #define SYS_dup2 0x3f +// CONSTANT SYS_unlink 0x0a #define SYS_unlink 0x0a +// CONSTANT SYS_gettimeofday 0x4e #define SYS_gettimeofday 0x4e +// CONSTANT SYS_clock_gettime 0x109 #define SYS_clock_gettime 0x109 +// CONSTANT SYS_time 0x0d #define SYS_time 0x0d /* libc+tcc */ diff --git a/include/m2/lib.h b/include/m2/lib.h new file mode 100644 index 00000000..93762931 --- /dev/null +++ b/include/m2/lib.h @@ -0,0 +1,70 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#ifndef __M2_LIB_H +#define __M2_LIB_H + +char **environ; +int __stdin; +int __stdout; +int __stderr; +int errno; + +// CONSTANT EOF 0xffffffff +// CONSTANT __FILEDES_MAX 512 + +char* cast_intp_to_charp (int *i); +char* cast_long_to_charp (long i); +long cast_charp_to_long (char const *); +long cast_int_to_long (int i); +long cast_voidp_to_long (void const *); + +char *itoa (int number); +char *ltoa (long number); +int __ungetc_p (int filedes); +int eputs (char *s); +int oputs (char *s); +int puts (char *s); +size_t strlen (char *s); +ssize_t _write (); +ssize_t write (int filedes, void *buffer, size_t size); +void __ungetc_clear (int filedes); +void __ungetc_init (); +void __ungetc_set (int filedes, int c); + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; + +struct timespec +{ + long tv_sec; + long tv_nsec; +}; + +struct timeval +{ + long tv_sec; + long tv_usec; +}; + +#endif /* __M2_LIB_H */ diff --git a/include/mes/constants.h b/include/mes/constants.h index ebf7787a..42424390 100644 --- a/include/mes/constants.h +++ b/include/mes/constants.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -23,32 +23,76 @@ /* Cell types */ +// CONSTANT TCHAR 0 #define TCHAR 0 +// CONSTANT TBYTES 1 #define TBYTES 1 +// CONSTANT TCLOSURE 2 #define TCLOSURE 2 +// CONSTANT TCONTINUATION 3 #define TCONTINUATION 3 +// CONSTANT TKEYWORD 4 #define TKEYWORD 4 +// CONSTANT TMACRO 5 #define TMACRO 5 +// CONSTANT TNUMBER 6 #define TNUMBER 6 +// CONSTANT TPAIR 7 #define TPAIR 7 +// CONSTANT TPORT 8 #define TPORT 8 +// CONSTANT TREF 9 #define TREF 9 +// CONSTANT TSPECIAL 10 #define TSPECIAL 10 +// CONSTANT TSTRING 11 #define TSTRING 11 +// CONSTANT TSTRUCT 12 #define TSTRUCT 12 +// CONSTANT TSYMBOL 13 #define TSYMBOL 13 +// CONSTANT TVALUES 14 #define TVALUES 14 +// CONSTANT TVARIABLE 15 #define TVARIABLE 15 +// CONSTANT TVECTOR 16 #define TVECTOR 16 +// CONSTANT TBROKEN_HEART 17 #define TBROKEN_HEART 17 /* Struct types */ +// CONSTANT STRUCT_TYPE 0 #define STRUCT_TYPE 0 +// CONSTANT STRUCT_PRINTER 1 #define STRUCT_PRINTER 1 +// CONSTANT GC_FRAME_SIZE 5 #define GC_FRAME_SIZE 5 +// CONSTANT GC_FRAME_PROCEDURE 4 #define GC_FRAME_PROCEDURE 4 +// CONSTANT STDIN 0 +// CONSTANT STDOUT 1 +// CONSTANT STDERR 2 + +/* Unknown type 1 +// CONSTANT EOF -1 +*/ + +// CONSTANT O_RDONLY 0 +// CONSTANT O_WRONLY 1 +// CONSTANT O_CREAT 0x40 +// CONSTANT O_TRUNC 0x200 + +// CONSTANT PATH_MAX 1024 +// CONSTANT __FILEDES_MAX 512 + +// CONSTANT S_IRUSR 00400 +// CONSTANT S_IWUSR 00200 + +// CONSTANT CLOCK_PROCESS_CPUTIME_ID 2 + + #endif /* __MES_CONSTANTS_H */ diff --git a/include/mes/symbols.h b/include/mes/symbols.h index 6e435720..490fa1e2 100644 --- a/include/mes/symbols.h +++ b/include/mes/symbols.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2021,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2021 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -137,8 +137,14 @@ extern struct scm *cell_type_broken_heart; extern struct scm *cell_symbol_program; extern struct scm *cell_symbol_test; +// CONSTANT SYMBOL_MAX 114 #define SYMBOL_MAX 114 + +// CONSTANT CELL_UNSPECIFIED 7 #define CELL_UNSPECIFIED 7 + +// CONSTANT CELL_SYMBOL_RECORD_TYPE 82 #define CELL_SYMBOL_RECORD_TYPE 82 + #endif /* __MES_SYMBOLS_H */ diff --git a/include/signal.h b/include/signal.h index aef1da50..07730b02 100644 --- a/include/signal.h +++ b/include/signal.h @@ -29,12 +29,9 @@ #define _SIGSET_NITEMS (_NSIG / (8 * sizeof(unsigned long))) -#if !__M2__ -typedef struct -{ +typedef struct { unsigned long items[_SIGSET_NITEMS]; } sigset_t; -#endif typedef long stack_t; #include @@ -94,7 +91,6 @@ typedef long stack_t; #define SA_NOMASK SA_NODEFER #define SA_ONESHOT SA_RESETHAND -#if !__M2__ // lacks short, casts typedef struct siginfo_t { int si_signo; @@ -124,7 +120,7 @@ typedef struct siginfo_t } siginfo_t; // *INDENT-ON* -#if __M2__ || __MESC__ +#if __MESC__ typedef long sighandler_t; #else typedef void (*sighandler_t) (int); @@ -259,7 +255,6 @@ int sigemptyset (sigset_t * set); #endif int sigprocmask (int how, sigset_t const *set, sigset_t * oldset); -#endif // !__M2__ #endif //! SYSTEM_LIBC #endif // __MES_SIGNAL_H diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h index c4bf13e5..2650929e 100644 --- a/include/sys/ioctl.h +++ b/include/sys/ioctl.h @@ -28,13 +28,8 @@ #define TCGETS 0x5401 #define TCGETA 0x5405 -#if __M2__ -int ioctl (int fd, unsigned request, long data); -int ioctl3 (int fd, unsigned request, long data); -#else int ioctl (int fd, unsigned long request, ...); int ioctl3 (int fd, unsigned long request, long data); -#endif #endif // ! SYSTEM_LIBC diff --git a/include/sys/stat.h b/include/sys/stat.h index 0644b361..0aefa286 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -36,29 +36,7 @@ typedef int mode_t; #endif // *INDENT-OFF* -#if __M2__ -struct stat -{ - unsigned st_dev; - unsigned st_ino; - char st_mode[2]; - char st_nlink[2]; - char st_uid[2]; - char st_gid[2]; - unsigned st_rdev; - long st_size; /* Linux: unsigned long; glibc: off_t (i.e. signed) */ - unsigned st_blksize; - unsigned st_blocks; - time_t st_atime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_atime_usec; - time_t st_mtime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_mtime_usec; - time_t st_ctime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_ctime_usec; - unsigned __foo0; - unsigned __foo1; -}; -#elif __i386__ || __arm__ +#if __i386__ || __arm__ struct stat { unsigned long st_dev; diff --git a/include/sys/types.h b/include/sys/types.h index 034f30a8..24ea71c7 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -142,13 +142,9 @@ typedef long sigval_t; #ifndef __MES_SIZE_T #define __MES_SIZE_T #undef size_t -#if __M2__ -typedef unsigned size_t; -#else typedef unsigned long size_t; #endif #endif -#endif #ifndef __MES_SSIZE_T #define __MES_SSIZE_T diff --git a/include/time.h b/include/time.h index 189200a1..161d006f 100644 --- a/include/time.h +++ b/include/time.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2017 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -27,8 +27,8 @@ #ifndef __MES_TIME_T #define __MES_TIME_T 1 -typedef long clockid_t; -typedef long time_t; +typedef long int clockid_t; +typedef long int time_t; #endif struct tm diff --git a/kaem.run b/kaem.run index 07713d1a..7fe29ec3 100644 --- a/kaem.run +++ b/kaem.run @@ -25,41 +25,34 @@ stage0_cpu=${stage0_cpu:-x86} mkdir -p m2 M2-Planet \ + --bootstrap-mode \ --debug \ --architecture ${stage0_cpu} \ - -D __linux__=1 \ - -f include/mes/config.h \ - -f include/mes/lib-mini.h \ - -f include/mes/lib.h \ + -f include/m2/lib.h \ -f lib/linux/${mes_cpu}-mes-m2/crt1.c \ -f lib/linux/${mes_cpu}-mes-m2/_exit.c \ -f lib/linux/${mes_cpu}-mes-m2/_write.c \ -f lib/mes/globals.c \ -f lib/m2/cast.c \ - -f lib/stdlib/exit.c \ + -f lib/m2/exit.c \ -f lib/mes/write.c \ - -f include/linux/${mes_cpu}/syscall.h \ -f lib/linux/${mes_cpu}-mes-m2/syscall.c \ + -f include/linux/${mes_cpu}/syscall.h \ -f lib/stub/__raise.c \ -f lib/linux/brk.c \ - -f lib/linux/malloc.c \ + -f lib/m2/malloc.c \ -f lib/string/memset.c \ - -f lib/linux/read.c \ + -f lib/m2/read.c \ -f lib/mes/fdgetc.c \ -f lib/stdio/getchar.c \ -f lib/stdio/putchar.c \ - -f lib/stub/__buffered_read.c \ - -f lib/linux/_open3.c \ - -f lib/linux/open.c \ - -f lib/mes/mes_open.c \ + -f lib/m2/open.c \ + -f lib/m2/mes_open.c \ -f lib/string/strlen.c \ -f lib/mes/eputs.c \ -f lib/mes/fdputc.c \ -f lib/mes/eputc.c \ \ - -f include/time.h \ - -f include/sys/time.h \ - -f include/sys/types.h \ -f include/mes/mes.h \ -f include/mes/builtins.h \ -f include/mes/constants.h \ @@ -88,20 +81,17 @@ M2-Planet \ -f lib/mes/fdungetc.c \ -f lib/posix/setenv.c \ -f lib/linux/access.c \ - -f include/sys/stat.h \ - -f lib/linux/chmod.c \ + -f lib/m2/chmod.c \ -f lib/linux/ioctl3.c \ - -f include/sys/ioctl.h \ -f lib/m2/isatty.c \ -f lib/linux/fork.c \ -f lib/m2/execve.c \ -f lib/m2/execv.c \ - -f lib/linux/waitpid.c \ + -f lib/m2/waitpid.c \ -f lib/linux/gettimeofday.c \ - -f lib/linux/clock_gettime.c \ + -f lib/m2/clock_gettime.c \ -f lib/m2/time.c \ -f lib/linux/_getcwd.c \ - -f include/limits.h \ -f lib/m2/getcwd.c \ -f lib/linux/dup.c \ -f lib/linux/dup2.c \ @@ -112,7 +102,6 @@ M2-Planet \ -f src/core.c \ -f src/display.c \ -f src/eval-apply.c \ - -f include/fcntl.h \ -f src/gc.c \ -f src/hash.c \ -f src/lib.c \ @@ -120,7 +109,6 @@ M2-Planet \ -f src/math.c \ -f src/mes.c \ -f src/module.c \ - -f include/signal.h \ -f src/posix.c \ -f src/reader.c \ -f src/stack.c \ diff --git a/lib/linux/lseek.c b/lib/linux/lseek.c index 34af9364..f71af59f 100644 --- a/lib/linux/lseek.c +++ b/lib/linux/lseek.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,13 +24,23 @@ #include #include +#if !__MESC__ /* FIXME: We want bin/mes-mescc's x86-linux sha256sum to stay the same. */ +off_t +_lseek (int filedes, off_t offset, int whence) +{ + return _sys_call3 (SYS_lseek, (int) filedes, (long) offset, (int) whence); +} +#endif + off_t lseek (int filedes, off_t offset, int whence) { - long long_filedes = filedes; - long long_offset = offset; +#if !__MESC__ /* FIXME: We want bin/mes-mescc's x86-linux sha256sum to stay the same. */ + if (_lseek (filedes, 0, SEEK_CUR) == -1) + return -1; +#endif size_t skip = __buffered_read_clear (filedes); if (whence == SEEK_CUR) offset -= skip; - return _sys_call3 (SYS_lseek, long_filedes, long_offset, whence); + return _sys_call3 (SYS_lseek, (int) filedes, (long) offset, (int) whence); } diff --git a/lib/linux/waitpid.c b/lib/linux/waitpid.c index da5d5a65..693e3dfa 100644 --- a/lib/linux/waitpid.c +++ b/lib/linux/waitpid.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -25,13 +25,10 @@ pid_t waitpid (pid_t pid, int *status_ptr, int options) { - long long_pid = pid; - long long_status_ptr = cast_voidp_to_long (status_ptr); - long long_options = options; #if __i386__ - return _sys_call3 (SYS_waitpid, long_pid, long_status_ptr, long_options); + return _sys_call3 (SYS_waitpid, (long) pid, (long) status_ptr, (int) options); #elif __x86_64__ || __arm__ - return _sys_call4 (SYS_wait4, long_pid, long_status_ptr, long_options, 0); + return _sys_call4 (SYS_wait4, (long) pid, (long) status_ptr, (int) options, 0); #else #error arch not supported #endif diff --git a/lib/m2/chmod.c b/lib/m2/chmod.c new file mode 100644 index 00000000..f5a9a662 --- /dev/null +++ b/lib/m2/chmod.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include + +int +chmod (char const *file_name, int mask) +{ + long long_file_name = file_name; + long long_mask = mask; + return _sys_call2 (SYS_chmod, long_file_name, long_mask); +} diff --git a/lib/m2/clock_gettime.c b/lib/m2/clock_gettime.c new file mode 100644 index 00000000..3bcfdc37 --- /dev/null +++ b/lib/m2/clock_gettime.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include + +int +clock_gettime (long clk_id, struct timespec *tp) +{ + long long_tp = tp; + return _sys_call2 (SYS_clock_gettime, clk_id, tp); +} diff --git a/lib/m2/exit.c b/lib/m2/exit.c new file mode 100644 index 00000000..2fa78612 --- /dev/null +++ b/lib/m2/exit.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +void _exit (int code); + +void +exit (int code) +{ + _exit (code); +} diff --git a/lib/m2/getcwd.c b/lib/m2/getcwd.c index 7c748302..849c0a0f 100644 --- a/lib/m2/getcwd.c +++ b/lib/m2/getcwd.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,6 +24,8 @@ #include #include +// CONSTANT PATH_MAX 1024 + char *__getcwd_buf; char * diff --git a/lib/m2/isatty.c b/lib/m2/isatty.c index 31b06ae3..fbe50ead 100644 --- a/lib/m2/isatty.c +++ b/lib/m2/isatty.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,6 +24,7 @@ #include #include +// CONSTANT TCGETS 0x5401 #define TCGETS 0x5401 struct ktermios diff --git a/lib/m2/malloc.c b/lib/m2/malloc.c new file mode 100644 index 00000000..4c3488d0 --- /dev/null +++ b/lib/m2/malloc.c @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2021 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +char *__brk = 0; + +void * +malloc (size_t size) +{ + if (!__brk) + __brk = cast_long_to_charp (brk (0)); + if (brk (__brk + size) == -1) + return 0; + char *p = __brk; + __brk = __brk + size; + return p; +} diff --git a/lib/m2/mes_open.c b/lib/m2/mes_open.c new file mode 100644 index 00000000..d2b1c1ca --- /dev/null +++ b/lib/m2/mes_open.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +int +mes_open (char *file_name, int flags, int mask) +{ + int filedes = open (file_name, flags, mask); + if (filedes > 2) + __ungetc_clear (filedes); + return filedes; +} diff --git a/lib/linux/open.c b/lib/m2/open.c similarity index 72% rename from lib/linux/open.c rename to lib/m2/open.c index 5a9ac979..3d3fe4dc 100644 --- a/lib/linux/open.c +++ b/lib/m2/open.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,7 +22,6 @@ #include #include -#if __M2__ int open (char *file_name, int flags, int mask) { @@ -31,17 +30,3 @@ open (char *file_name, int flags, int mask) __ungetc_clear (r); return r; } -#else // !__M2__ -int -open (char const *file_name, int flags, ...) -{ - va_list ap; - va_start (ap, flags); - int mask = va_arg (ap, int); - int r = _sys_call3 (SYS_open, (long) file_name, flags, mask); - va_end (ap); - if (r > 2) - __ungetc_clear (r); - return r; -} -#endif // __M2__ diff --git a/lib/m2/read.c b/lib/m2/read.c new file mode 100644 index 00000000..b1d911a1 --- /dev/null +++ b/lib/m2/read.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include +#include + +long +read (int filedes, void *buffer, long size) +{ + long bytes = _sys_call3 (SYS_read, filedes, buffer, size); + return bytes; +} diff --git a/lib/m2/waitpid.c b/lib/m2/waitpid.c new file mode 100644 index 00000000..a3d98d1d --- /dev/null +++ b/lib/m2/waitpid.c @@ -0,0 +1,39 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include +#include + +int +waitpid (int pid, int *status_ptr, int options) +{ + long long_pid = pid; + long long_status_ptr = cast_voidp_to_long (status_ptr); + long long_options = options; +//##if __i386__ +//# return _sys_call3 (SYS_waitpid, long_pid, long_status_ptr, long_options); +//##elif __x86_64__ || __arm__ + return _sys_call4 (SYS_wait4, long_pid, long_status_ptr, long_options, 0); +//##else +//##error arch not supported +//##endif +} diff --git a/lib/mes/ntoab.c b/lib/mes/ntoab.c index c8827503..98e81072 100644 --- a/lib/mes/ntoab.c +++ b/lib/mes/ntoab.c @@ -23,19 +23,7 @@ #include #include -#if __MESC__ && __arm__ -#define __MESC__and__arm__ -#endif - -#if __TINYC__ && __arm__ && BOOTSTRAP -#define __TINYC__and__arm__and__BOOTSTRAP -#endif - -#define __not__MESC__arm__and__not__TINYC__arm__BOOTSTRAP !defined (__MESC__and__arm__) && !defined (__TINYC__and__arm__and__BOOTSTRAP) - -// FIXME: M2-Planet 1.10.0 crashes on this... -// #if __M2__ || (!defined (__MESC__and__arm__) && !defined (__TINYC__and__arm__and__BOOTSTRAP)) -#if __M2__ || __not__MESC__arm__and__not__TINYC__arm__BOOTSTRAP +#if __M2_PLANET__ || (!(__MESC__ && __arm__) && !(__TINYC__ && __arm__ && BOOTSTRAP)) size_t __mesabi_uldiv (size_t a, size_t b, size_t *remainder) { diff --git a/lib/posix/getcwd.c b/lib/posix/getcwd.c index 97e81c75..e3e6d67c 100644 --- a/lib/posix/getcwd.c +++ b/lib/posix/getcwd.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -23,6 +23,8 @@ #include #include +char *__getcwd_buf; + char * getcwd (char *buffer, size_t size) { diff --git a/lib/posix/getenv.c b/lib/posix/getenv.c index 9386044b..9130f76d 100644 --- a/lib/posix/getenv.c +++ b/lib/posix/getenv.c @@ -1,6 +1,6 @@ /* * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,11 +22,8 @@ #include #include -#if __M2__ -#define M2_PTR_SIZE 4 -#else +// CONSTANT M2_PTR_SIZE 4 #define M2_PTR_SIZE 1 -#endif char * getenv (char const *s) diff --git a/lib/posix/setenv.c b/lib/posix/setenv.c index 1754e6e9..321a5ab1 100644 --- a/lib/posix/setenv.c +++ b/lib/posix/setenv.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,11 +22,8 @@ #include #include -#if __M2__ -#define M2_PTR_SIZE 4 -#else +// CONSTANT M2_PTR_SIZE 4 #define M2_PTR_SIZE 1 -#endif int setenv (char const *s, char const *v, int overwrite_p) diff --git a/lib/stub/__raise.c b/lib/stub/__raise.c index bfa9853c..9467513c 100644 --- a/lib/stub/__raise.c +++ b/lib/stub/__raise.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +// CONSTANT SIGABRT 0 + int __raise (int signum) { diff --git a/scaffold/read.kaem b/scaffold/read.kaem index 26e7b0be..f23e2dfb 100644 --- a/scaffold/read.kaem +++ b/scaffold/read.kaem @@ -44,7 +44,7 @@ M2-Planet \ -f lib/mes/fdgetc.c \ -f lib/stdio/getchar.c \ -f lib/stdio/putchar.c \ - -f lib/linux/open.c \ + -f lib/m2/open.c \ -f include/sys/types.h \ -f include/stdio.h \ -f scaffold/read.c \ diff --git a/simple.make b/simple.make index 347b57ea..4bb59752 100644 --- a/simple.make +++ b/simple.make @@ -33,7 +33,7 @@ M2_PLANET_FUBAR = i386 #M2_PLANET_ARCH = amd64 #M2_PLANET_FUBAR = amd64 -M2_PLANET_FLAGS = --debug --architecture $(M2_PLANET_ARCH) +M2_PLANET_FLAGS = --bootstrap-mode --debug --architecture $(M2_PLANET_ARCH) CFLAGS:= \ $(CFLAGS) \ @@ -76,26 +76,21 @@ M2_SOURCES = \ lib/linux/x86-mes-m2/crt1.c \ lib/linux/x86-mes-m2/_exit.c \ lib/linux/x86-mes-m2/_write.c \ - lib/mes/globals.c \ lib/m2/cast.c \ - lib/stdlib/exit.c \ - lib/stub/__buffered_read.c \ + lib/m2/exit.c \ + lib/mes/write.c \ lib/linux/x86-mes-m2/syscall.c \ lib/stub/__raise.c \ lib/linux/brk.c \ - lib/linux/malloc.c \ + lib/m2/malloc.c \ lib/string/memset.c \ - lib/linux/read.c \ - lib/mes/fdgetc.c \ - lib/linux/lseek.c \ - lib/posix/write.c \ \ + lib/m2/read.c \ + lib/mes/fdgetc.c \ lib/stdio/getchar.c \ lib/stdio/putchar.c \ - lib/stub/__buffered_read.c \ - lib/linux/_open3.c \ - lib/linux/open.c \ - lib/mes/mes_open.c \ + lib/m2/open.c \ + lib/m2/mes_open.c \ lib/string/strlen.c \ lib/mes/eputs.c \ lib/mes/fdputc.c \ @@ -124,15 +119,15 @@ M2_SOURCES = \ lib/mes/fdungetc.c \ lib/posix/setenv.c \ lib/linux/access.c \ - lib/linux/chmod.c \ + lib/m2/chmod.c \ lib/linux/ioctl3.c \ lib/m2/isatty.c \ lib/linux/fork.c \ lib/m2/execve.c \ lib/m2/execv.c \ - lib/linux/waitpid.c \ + lib/m2/waitpid.c \ lib/linux/gettimeofday.c \ - lib/linux/clock_gettime.c \ + lib/m2/clock_gettime.c \ lib/m2/time.c \ lib/linux/_getcwd.c \ lib/m2/getcwd.c \ @@ -143,6 +138,12 @@ M2_SOURCES = \ lib/linux/unlink.c \ src/m2.c +M2_TODO = \ + lib/m2/file_print.c \ + lib/mes/ntoab.c \ + lib/mes/fdgetc.c \ + lib/mes/fdungetc.c + INCLUDES = \ include/mes/builtins.h \ include/mes/constants.h \ @@ -186,18 +187,8 @@ bin/gc-gcc: simple.make $(GCC_SOURCES) $(TEST_GC_SOURCES) $(INCLUDES) | bin $(CC) $(CFLAGS) -D GC_TEST=1 $(GCC_SOURCES) $(TEST_GC_SOURCES) -o $@ M2_PLANET_INCLUDES = \ - include/mes/config.h \ - include/mes/lib-mini.h \ - include/mes/lib.h \ + include/m2/lib.h \ include/linux/x86/syscall.h \ - include/time.h \ - include/sys/time.h \ - include/sys/types.h \ - include/stdio.h \ - include/limits.h \ - include/sys/stat.h \ - include/fcntl.h \ - include/signal.h \ include/mes/mes.h \ include/mes/builtins.h \ include/mes/constants.h \ diff --git a/src/core.c b/src/core.c index a986dcf7..15585e45 100644 --- a/src/core.c +++ b/src/core.c @@ -148,7 +148,7 @@ length (struct scm *x) struct scm * error (struct scm *key, struct scm *x) { -#if !__MESC_MES__ && !__M2__ +#if !__MESC_MES__ && !__M2_PLANET__ struct scm *throw = module_ref (R0, cell_symbol_throw); if (throw != cell_undefined) return apply (throw, cons (key, cons (x, cell_nil)), R0); diff --git a/src/gc.c b/src/gc.c index a55f24dc..4b45069e 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen * Copyright © 2022 Gabriel Wicki * * This file is part of GNU Mes. @@ -31,11 +31,8 @@ int g_dump_filedes; -#if __M2__ -#define M2_CELL_SIZE 12 -#else #define M2_CELL_SIZE 1U -#endif +// CONSTANT M2_CELL_SIZE 12 char * cell_bytes (struct scm *x) @@ -44,20 +41,16 @@ cell_bytes (struct scm *x) return p + (2 * sizeof (long)); } -#if __M2__ -#define U10 10 -#define U100 100 -#else #define U10 10U +// CONSTANT U10 10 #define U100 100U -#endif - +// CONSTANT U100 100 void gc_init () { #if SYSTEM_LIBC ARENA_SIZE = 100000000; /* 2.3GiB */ -#elif ! __M2__ +#elif ! __M2_PLANET__ ARENA_SIZE = 300000; /* 32b: 3MiB, 64b: 6 MiB */ #else ARENA_SIZE = 20000000; diff --git a/src/posix.c b/src/posix.c index 74e04675..bfb1bcd3 100644 --- a/src/posix.c +++ b/src/posix.c @@ -35,7 +35,7 @@ #include #if SYSTEM_LIBC -//#define __raise(x) -1 +#define __raise(x) -1 #endif struct scm * @@ -377,14 +377,13 @@ waitpid_ (struct scm *pid, struct scm *options) return cons (make_number (child), make_number (status)); } -#if __M2__ -/* Milliseconds for everyone else. */ -#define TIME_UNITS_PER_SECOND 1000 -#elif __x86_64__ +#if __x86_64__ /* Nanoseconds on 64-bit systems with POSIX timers. */ +// CONSTANT TIME_UNITS_PER_SECOND 1000000000 #define TIME_UNITS_PER_SECOND 1000000000U #else /* Milliseconds for everyone else. */ +// CONSTANT TIME_UNITS_PER_SECOND 1000 #define TIME_UNITS_PER_SECOND 1000U #endif @@ -409,12 +408,8 @@ gettimeofday_ () /*:((name . "gettimeofday")) */ return cons (make_number (time->tv_sec), make_number (time->tv_usec)); } -#if __M2__ -#define UL1000000000 1000000000 -#else #define UL1000000000 1000000000UL -#endif - +// CONSTANT UL1000000000 1000000000 long seconds_and_nanoseconds_to_long (long s, long ns) { diff --git a/src/symbol.c b/src/symbol.c index 5d0aaaa2..4ae8baca 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -23,10 +23,14 @@ #include -#if __M2__ +// char const *MES_VERSION = "0.24"; + +#if __M2_PLANET__ #define M2_CELL_SIZE 12 +// CONSTANT M2_CELL_SIZE 12 #else #define M2_CELL_SIZE 1 +// CONSTANT M2_CELL_SIZE 12 #endif struct scm * diff --git a/src/test/gc.c b/src/test/gc.c index edafad8c..8d3c70cf 100644 --- a/src/test/gc.c +++ b/src/test/gc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,11 +24,8 @@ #include #include -#if __M2__ -#define M2_CELL_SIZE 12 -#else #define M2_CELL_SIZE 1 -#endif +// CONSTANT M2_CELL_SIZE 12 int g_debug; diff --git a/src/vector.c b/src/vector.c index e4a35ead..0fc84040 100644 --- a/src/vector.c +++ b/src/vector.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -21,10 +21,12 @@ #include "mes/lib.h" #include "mes/mes.h" -#if __M2__ +#if __M2_PLANET__ #define M2_CELL_SIZE 12 +// CONSTANT M2_CELL_SIZE 12 #else #define M2_CELL_SIZE 1 +// CONSTANT M2_CELL_SIZE 12 #endif struct scm *