From fd775493ceb1614b48e7ce58f16bfb36c156518f Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Wed, 19 Oct 2022 08:40:11 +0200 Subject: [PATCH] FIRST BIT: M2 kaem.run: Remove --bootstrap-mode. * include/linux/arm/syscall.h, include/linux/x86/syscall.h, include/mes/constants.h: Remove CONSTANTs. * lib/m2/open.c: Move to... * lib/linux/open.c: ...here. Update to make gcc-compatible. * scaffold/argv.kaem: Update accordingly. * lib/linux/lseek.c (lseek): Suport M2-Planet. * lib/linux/waitpid.c (waitpid): Suport M2-Planet. * lib/m2/getcwd.c (PATH_MAX): Remove CONSTANT. * lib/m2/isatty.c (TCGETS): Remove CONSTANT. * lib/mes/ntoab.c: Support M2-Planet. * lib/posix/getcwd.c (__getcwd_buf): Remove. * lib/posix/getenv.c (M2_PTR_SIZE)[__M2__]: Update to #define. * lib/posix/setenv.c: Likewise. * lib/stub/__raise.c (SIGABRT): Remove CONSTANT. * src/core.c (error): Use __M2__ instead of __M2_PLANET__. * src/gc.c (M2_CELL_SIZE)[__M2__]: Update to #define. Support non-bootstrap-mode. * src/posix.c: Likewise. * src/symbol.c: Likewise. * src/vector.c: Likewise. * kaem.run: Remove --botstrap-mode. Update source list accordingly. * simple.make (M2_PLANET_FLAGS): Remove --bootstrap-mode. * simple.make (M2_SOURCES, M2_PLANET_INCLUDES): Update source list accordingly. --- build-aux/pointer.sh | 1 - include/m2/lib.h | 70 ---------------------------------------- kaem.run | 34 ++++++++++++------- lib/{m2 => linux}/open.c | 17 +++++++++- 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/m2/read.c | 31 ------------------ lib/m2/waitpid.c | 39 ---------------------- scaffold/read.kaem | 2 +- simple.make | 45 +++++++++++++++----------- 15 files changed, 69 insertions(+), 331 deletions(-) delete mode 100644 include/m2/lib.h rename lib/{m2 => linux}/open.c (72%) delete mode 100644 lib/m2/chmod.c delete mode 100644 lib/m2/clock_gettime.c delete mode 100644 lib/m2/exit.c delete mode 100644 lib/m2/malloc.c delete mode 100644 lib/m2/mes_open.c delete mode 100644 lib/m2/read.c delete mode 100644 lib/m2/waitpid.c diff --git a/build-aux/pointer.sh b/build-aux/pointer.sh index 384b0689..51cea49f 100755 --- a/build-aux/pointer.sh +++ b/build-aux/pointer.sh @@ -48,7 +48,6 @@ 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/m2/lib.h b/include/m2/lib.h deleted file mode 100644 index 93762931..00000000 --- a/include/m2/lib.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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/kaem.run b/kaem.run index 7fe29ec3..07713d1a 100644 --- a/kaem.run +++ b/kaem.run @@ -25,34 +25,41 @@ stage0_cpu=${stage0_cpu:-x86} mkdir -p m2 M2-Planet \ - --bootstrap-mode \ --debug \ --architecture ${stage0_cpu} \ - -f include/m2/lib.h \ + -D __linux__=1 \ + -f include/mes/config.h \ + -f include/mes/lib-mini.h \ + -f include/mes/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/m2/exit.c \ + -f lib/stdlib/exit.c \ -f lib/mes/write.c \ - -f lib/linux/${mes_cpu}-mes-m2/syscall.c \ -f include/linux/${mes_cpu}/syscall.h \ + -f lib/linux/${mes_cpu}-mes-m2/syscall.c \ -f lib/stub/__raise.c \ -f lib/linux/brk.c \ - -f lib/m2/malloc.c \ + -f lib/linux/malloc.c \ -f lib/string/memset.c \ - -f lib/m2/read.c \ + -f lib/linux/read.c \ -f lib/mes/fdgetc.c \ -f lib/stdio/getchar.c \ -f lib/stdio/putchar.c \ - -f lib/m2/open.c \ - -f lib/m2/mes_open.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/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 \ @@ -81,17 +88,20 @@ M2-Planet \ -f lib/mes/fdungetc.c \ -f lib/posix/setenv.c \ -f lib/linux/access.c \ - -f lib/m2/chmod.c \ + -f include/sys/stat.h \ + -f lib/linux/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/m2/waitpid.c \ + -f lib/linux/waitpid.c \ -f lib/linux/gettimeofday.c \ - -f lib/m2/clock_gettime.c \ + -f lib/linux/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 \ @@ -102,6 +112,7 @@ 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 \ @@ -109,6 +120,7 @@ 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/m2/open.c b/lib/linux/open.c similarity index 72% rename from lib/m2/open.c rename to lib/linux/open.c index 3d3fe4dc..5a9ac979 100644 --- a/lib/m2/open.c +++ b/lib/linux/open.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,6 +22,7 @@ #include #include +#if __M2__ int open (char *file_name, int flags, int mask) { @@ -30,3 +31,17 @@ 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/chmod.c b/lib/m2/chmod.c deleted file mode 100644 index f5a9a662..00000000 --- a/lib/m2/chmod.c +++ /dev/null @@ -1,31 +0,0 @@ -/* -*-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 deleted file mode 100644 index 3bcfdc37..00000000 --- a/lib/m2/clock_gettime.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -*-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 deleted file mode 100644 index 2fa78612..00000000 --- a/lib/m2/exit.c +++ /dev/null @@ -1,29 +0,0 @@ -/* -*-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 849c0a0f..7c748302 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 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,8 +24,6 @@ #include #include -// CONSTANT PATH_MAX 1024 - char *__getcwd_buf; char * diff --git a/lib/m2/isatty.c b/lib/m2/isatty.c index fbe50ead..31b06ae3 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 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,7 +24,6 @@ #include #include -// CONSTANT TCGETS 0x5401 #define TCGETS 0x5401 struct ktermios diff --git a/lib/m2/malloc.c b/lib/m2/malloc.c deleted file mode 100644 index 4c3488d0..00000000 --- a/lib/m2/malloc.c +++ /dev/null @@ -1,36 +0,0 @@ -/* -*-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 deleted file mode 100644 index d2b1c1ca..00000000 --- a/lib/m2/mes_open.c +++ /dev/null @@ -1,28 +0,0 @@ -/* -*-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/m2/read.c b/lib/m2/read.c deleted file mode 100644 index b1d911a1..00000000 --- a/lib/m2/read.c +++ /dev/null @@ -1,31 +0,0 @@ -/* -*-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 deleted file mode 100644 index a3d98d1d..00000000 --- a/lib/m2/waitpid.c +++ /dev/null @@ -1,39 +0,0 @@ -/* -*-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/scaffold/read.kaem b/scaffold/read.kaem index f23e2dfb..26e7b0be 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/m2/open.c \ + -f lib/linux/open.c \ -f include/sys/types.h \ -f include/stdio.h \ -f scaffold/read.c \ diff --git a/simple.make b/simple.make index 4bb59752..347b57ea 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 = --bootstrap-mode --debug --architecture $(M2_PLANET_ARCH) +M2_PLANET_FLAGS = --debug --architecture $(M2_PLANET_ARCH) CFLAGS:= \ $(CFLAGS) \ @@ -76,21 +76,26 @@ 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/m2/exit.c \ - lib/mes/write.c \ + lib/stdlib/exit.c \ + lib/stub/__buffered_read.c \ lib/linux/x86-mes-m2/syscall.c \ lib/stub/__raise.c \ lib/linux/brk.c \ - lib/m2/malloc.c \ + lib/linux/malloc.c \ lib/string/memset.c \ - \ - lib/m2/read.c \ + lib/linux/read.c \ lib/mes/fdgetc.c \ + lib/linux/lseek.c \ + lib/posix/write.c \ + \ lib/stdio/getchar.c \ lib/stdio/putchar.c \ - lib/m2/open.c \ - lib/m2/mes_open.c \ + lib/stub/__buffered_read.c \ + lib/linux/_open3.c \ + lib/linux/open.c \ + lib/mes/mes_open.c \ lib/string/strlen.c \ lib/mes/eputs.c \ lib/mes/fdputc.c \ @@ -119,15 +124,15 @@ M2_SOURCES = \ lib/mes/fdungetc.c \ lib/posix/setenv.c \ lib/linux/access.c \ - lib/m2/chmod.c \ + lib/linux/chmod.c \ lib/linux/ioctl3.c \ lib/m2/isatty.c \ lib/linux/fork.c \ lib/m2/execve.c \ lib/m2/execv.c \ - lib/m2/waitpid.c \ + lib/linux/waitpid.c \ lib/linux/gettimeofday.c \ - lib/m2/clock_gettime.c \ + lib/linux/clock_gettime.c \ lib/m2/time.c \ lib/linux/_getcwd.c \ lib/m2/getcwd.c \ @@ -138,12 +143,6 @@ 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 \ @@ -187,8 +186,18 @@ 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/m2/lib.h \ + include/mes/config.h \ + include/mes/lib-mini.h \ + include/mes/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 \