diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index 5ef2c003..6af57bc5 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -55,12 +55,17 @@ #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 /* libc+tcc */ #define SYS_close 0x06 #define SYS_time 0x0d #define SYS_lseek 0x13 -#define SYS_unlink 0x0a #define SYS_rmdir 0x28 #define SYS_gettimeofday 0x4e #define SYS_stat 0x6a @@ -74,7 +79,6 @@ #define SYS_kill 0x25 #define SYS_rename 0x26 #define SYS_mkdir 0x27 -#define SYS_dup 0x29 #define SYS_pipe 0x2a #define SYS_getgid 0x2f #define SYS_signal 0x30 @@ -82,7 +86,6 @@ #define SYS_rt_sigaction 0xae #define SYS_signal 0x30 #define SYS_fcntl 0x37 -#define SYS_dup2 0x3f #define SYS_getrusage 0x4d #define SYS_lstat 0x6b #define SYS_setitimer 0x68 diff --git a/kaem.run b/kaem.run new file mode 100644 index 00000000..748b2fe3 --- /dev/null +++ b/kaem.run @@ -0,0 +1,131 @@ +#!/bin/bash +# Copyright (C) 2019 Jeremiah Orians +# 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 . + +# Usage: +# kaem --verbose --strict +# bin/mes-m2 --boot scaffold/boot/14-exit.scm +# bin/mes-m2 --boot scaffold/boot/15-display.scm + +M2-Planet \ + --debug \ + --architecture x86 \ + -f include/m2/lib.h \ + -f lib/linux/x86-mes-m2/crt1.c \ + -f lib/linux/x86-mes-m2/mini.c \ + -f lib/m2/exit.c \ + -f lib/mes/write.c \ + -f lib/linux/x86-mes-m2/syscall.c \ + -f include/linux/x86/syscall.h \ + -f lib/linux/brk.c \ + -f lib/stdlib/malloc.c \ + -f lib/string/memset.c \ + -f lib/m2/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/string/strlen.c \ + -f lib/mes/eputs.c \ + -f lib/mes/fdputc.c \ + -f lib/mes/eputc.c \ + \ + -f include/mes/mes.h.m2 \ + -f include/mes/m2.h.m2 \ + -f include/mes/builtins.h.m2 \ + -f include/mes/constants.h.m2 \ + -f include/mes/symbols.h.m2 \ + \ + -f lib/mes/__assert_fail.c \ + -f lib/mes/assert_msg.c \ + \ + -f lib/mes/fdputc.c \ + -f lib/string/strncmp.c \ + -f lib/posix/getenv.c \ + -f lib/mes/fdputs.c \ + -f lib/m2/ntoab.c \ + -f lib/ctype/isdigit.c \ + -f lib/ctype/isxdigit.c \ + -f lib/ctype/isspace.c \ + -f lib/ctype/isnumber.c \ + -f lib/mes/abtol.c \ + -f lib/stdlib/atoi.c \ + -f lib/string/memcpy.c \ + -f lib/stdlib/free.c \ + -f lib/stdlib/realloc.c \ + -f lib/string/strcpy.c \ + -f lib/mes/itoa.c \ + -f lib/mes/fdungetc.c \ + -f lib/posix/setenv.c \ + -f lib/m2/access.c \ + -f lib/m2/chmod.c \ + -f lib/m2/isatty.c \ + -f lib/m2/fork.c \ + -f lib/m2/execve.c \ + -f lib/m2/execv.c \ + -f lib/m2/waitpid.c \ + -f lib/m2/clock_gettime.c \ + -f lib/m2/time.c \ + -f lib/linux/_getcwd.c \ + -f lib/m2/getcwd.c \ + -f lib/linux/dup.c \ + -f lib/linux/dup2.c \ + -f lib/linux/unlink.c \ + -f lib/string/strcmp.c \ + -f lib/string/memcmp.c \ + -f src/builtins.c.m2 \ + -f src/display.c.m2 \ + -f src/eval-apply.c.m2 \ + -f src/gc.c.m2 \ + -f src/hash.c.m2 \ + -f src/lib.c.m2 \ + -f src/math.c.m2 \ + -f src/mes.c.m2 \ + -f src/module.c.m2 \ + -f src/posix.c.m2 \ + -f src/reader.c.m2 \ + -f src/string.c.m2 \ + -f src/struct.c.m2 \ + -f src/symbol.c.m2 \ + -f src/vector.c.m2 \ + -o bin/mes.M1 + +blood-elf -f bin/mes.M1 -o bin/mes.blood-elf-M1 + +M1 \ + --LittleEndian \ + --architecture x86 \ + -f lib/m2/x86/x86_defs.M1 \ + -f lib/x86-mes/x86.M1 \ + -f lib/linux/x86-mes-m2/crt1.M1 \ + -f bin/mes.M1 \ + -f bin/mes.blood-elf-M1 \ + -o bin/mes.hex2 + +hex2 \ + --LittleEndian \ + --architecture x86 \ + --BaseAddress 0x1000000 \ + --exec_enable \ + -f lib/x86-mes/elf32-header.hex2 \ + -f bin/mes.hex2 \ + -f lib/m2/missing.hex2 \ + -o bin/mes-m2 + +echo Running mes-m2 +./bin/mes-m2 --boot scaffold/boot/14-exit.scm +#./bin/mes-m2 --boot scaffold/boot/15-display.scm diff --git a/lib/linux/_getcwd.c b/lib/linux/_getcwd.c index 55db9a02..699edb3b 100644 --- a/lib/linux/_getcwd.c +++ b/lib/linux/_getcwd.c @@ -25,7 +25,7 @@ char * _getcwd (char *buffer, size_t size) { - int r = _sys_call2 (SYS_getcwd, (long) buffer, (long) size); + int r = _sys_call2 (SYS_getcwd, buffer, size); if (r >= 0) return buffer; return 0; diff --git a/lib/linux/dup.c b/lib/linux/dup.c index 02d01283..9237ef97 100644 --- a/lib/linux/dup.c +++ b/lib/linux/dup.c @@ -24,5 +24,6 @@ int dup (int old) { - return _sys_call1 (SYS_dup, (int) old); + long long_old = old; + return _sys_call1 (SYS_dup, long_old); } diff --git a/lib/linux/dup2.c b/lib/linux/dup2.c index f61344f5..ef996273 100644 --- a/lib/linux/dup2.c +++ b/lib/linux/dup2.c @@ -24,5 +24,7 @@ int dup2 (int old, int new) { - return _sys_call2 (SYS_dup2, (int) old, (int) new); + long long_old = old; + long long_new = new; + return _sys_call2 (SYS_dup2, long_old, long_new); } diff --git a/lib/linux/read.c b/lib/linux/read.c index 34e65949..efd25744 100644 --- a/lib/linux/read.c +++ b/lib/linux/read.c @@ -26,7 +26,8 @@ ssize_t read (int filedes, void *buffer, size_t size) { - ssize_t bytes = _sys_call3 (SYS_read, filedes, buffer, size); + long long_filedes = filedes; + ssize_t bytes = _sys_call3 (SYS_read, long_filedes, buffer, size); if (__mes_debug () > 4) { if (bytes == 1) diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c index 3889a067..4a6881fc 100644 --- a/lib/linux/unlink.c +++ b/lib/linux/unlink.c @@ -24,5 +24,5 @@ int unlink (char const *file_name) { - return _sys_call1 (SYS_unlink, (long) file_name); + return _sys_call1 (SYS_unlink, file_name); } diff --git a/lib/m2/_getcwd.c b/lib/m2/_getcwd.c deleted file mode 100644 index 3f69ec30..00000000 --- a/lib/m2/_getcwd.c +++ /dev/null @@ -1,32 +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 - -char * -_getcwd (char *buffer, int size) -{ - int r = _sys_call2 (SYS_getcwd, buffer, size); - if (r >= 0) - return buffer; - return 0; -} diff --git a/lib/m2/abtol.c b/lib/m2/abtol.c index 22378a65..48be4fc9 100644 --- a/lib/m2/abtol.c +++ b/lib/m2/abtol.c @@ -21,7 +21,7 @@ #include #include -int +long abtol (char **p, int base) { char *s = p[0]; diff --git a/lib/m2/atoi.c b/lib/m2/atoi.c deleted file mode 100644 index 2baf3e39..00000000 --- a/lib/m2/atoi.c +++ /dev/null @@ -1,26 +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 -atoi (char *string) -{ - char *p = string; - return abtol (&p, 0); -} diff --git a/lib/m2/dup.c b/lib/m2/dup.c deleted file mode 100644 index fffded27..00000000 --- a/lib/m2/dup.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * 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 . - */ - -int dup (int old); diff --git a/lib/m2/dup2.c b/lib/m2/dup2.c deleted file mode 100644 index 817f580a..00000000 --- a/lib/m2/dup2.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * 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 . - */ - -int dup2 (int old, int new); diff --git a/lib/m2/fdputc.c b/lib/m2/fdputc.c deleted file mode 100644 index 6a00cd20..00000000 --- a/lib/m2/fdputc.c +++ /dev/null @@ -1,28 +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 - -int -fdputc (int c, int fd) -{ - write (fd, &c, 1); - return 0; -} diff --git a/lib/m2/getenv.c b/lib/m2/getenv.c deleted file mode 100644 index f703f35d..00000000 --- a/lib/m2/getenv.c +++ /dev/null @@ -1,47 +0,0 @@ -/* -*-comment-start: " - * 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 - -char * -getenv (char *s) -{ - /* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */ - char **p = environ; - int length = strlen (s); - while (p[0] != 0) - { - /* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */ - if (strncmp (s, p[0], length) == 0) - { - /* eputs ("found!\n"); */ - char *q = p[0] + length; - if (q[0] == '=') - return q + 1; - } - /* else */ - /* eputs ("not found!\n"); */ - p = p + sizeof (char *); /* FIXME! */ - } - - return 0; -} diff --git a/lib/m2/malloc.c b/lib/m2/malloc.c deleted file mode 100644 index 804bed7d..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 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 (int size) -{ - if (__brk == 0) - __brk = brk (0); - if (brk (__brk + size) == -1) - return 0; - char *p = __brk; - __brk = __brk + size; - return p; -} diff --git a/lib/m2/memchr.c b/lib/m2/memchr.c deleted file mode 100644 index 5effe7eb..00000000 --- a/lib/m2/memchr.c +++ /dev/null @@ -1,37 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 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 * -memchr (void *block, int c, size_t size) -{ - char *p = block; - - while (size != 0) - { - size = size - 1; - if (c == p[0]) - return p; - p = p + 1; - } - - return 0; -} diff --git a/lib/m2/memcmp.c b/lib/m2/memcmp.c deleted file mode 100644 index 3e4839b1..00000000 --- a/lib/m2/memcmp.c +++ /dev/null @@ -1,39 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 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 - -int -memcmp (void *s1, void *s2, int size) -{ - if (size == 0) - return 0; - - char *a = s1; - char *b = s2; - - while (a[0] == b[0] && size > 0) - { - size = size - 1; - a = a + 1; - b = b + 1; - } - return a[0] - b[0]; -} diff --git a/lib/m2/memcpy.c b/lib/m2/memcpy.c deleted file mode 100644 index 5f72cebc..00000000 --- a/lib/m2/memcpy.c +++ /dev/null @@ -1,38 +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 - -void * -memcpy (void *dest, void *src, int n) -{ - char *p = dest; - - while (n != 0) - { - n = n - 1; - dest[0] = src[0]; - dest = dest + 1; - src = src + 1; - } - - return p; -} diff --git a/lib/m2/memset.c b/lib/m2/memset.c deleted file mode 100644 index b5ad533e..00000000 --- a/lib/m2/memset.c +++ /dev/null @@ -1,34 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 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 - -void * -memset (void *s, int c, int n) -{ - char *p = s; - while (n != 0) - { - n = n - 1; - s[0] = c; - s = s + 1; - } - return p; -} diff --git a/lib/m2/ntoab.c b/lib/m2/ntoab.c index b3115678..f2d2e3ad 100644 --- a/lib/m2/ntoab.c +++ b/lib/m2/ntoab.c @@ -25,7 +25,7 @@ char *__itoa_buf; char * -ntoab (int x, int base, int signed_p) +ntoab (long x, int base, int signed_p) { if (__itoa_buf == 0) __itoa_buf = malloc (20); diff --git a/lib/m2/setenv.c b/lib/m2/setenv.c deleted file mode 100644 index 9d92f602..00000000 --- a/lib/m2/setenv.c +++ /dev/null @@ -1,52 +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 -setenv (char *s, char *v, int overwrite_p) -{ - char **p = environ; - int length = strlen (s); - - while (p[0] != 0) - { - if (strncmp (s, p[0], length) == 0) - { - char *q = p[0] + length; - if (q[0] == '=') - break; - } - p = p + 1; - } - char *entry = malloc (length + strlen (v) + 2); - int end_p = p[0] == 0; - p[0] = entry; - strcpy (entry, s); - strcpy (entry + length, "="); - strcpy (entry + length + 1, v); - entry[length + strlen (v) + 2] = 0; - if (end_p != 0) - p[1] = 0; - - return 0; -} diff --git a/lib/m2/strcmp.c b/lib/m2/strcmp.c deleted file mode 100644 index af617384..00000000 --- a/lib/m2/strcmp.c +++ /dev/null @@ -1,33 +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 - -int -strcmp (char *a, char *b) -{ - while (a[0] != 0 && b[0] != 0 && a[0] == b[0]) - { - a = a + 1; - b = b + 1; - } - - return a[0] - b[0]; -} diff --git a/lib/m2/strcpy.c b/lib/m2/strcpy.c deleted file mode 100644 index 33d5dcc2..00000000 --- a/lib/m2/strcpy.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -*-comment-start: " - * 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 - -char * -strcpy (char *dest, char *src) -{ - /* eputs ("\nstrcpy: src="); */ - /* eputs (src); */ - /* eputs ("\n"); */ - char *p = dest; - char *orig = dest; - - /* eputs ("dest="); */ - /* eputs (dest); */ - /* eputs ("\n"); */ - - /* eputs ("c:" ); */ - while (0 != src[0]) - { - /* eputc (src[0]); */ - /* eputs (" "); */ - dest[0] = src[0]; - dest = dest + 1; - src = src + 1; - } - dest[0] = 0; - /* eputs ("\n => orig="); */ - /* eputs (orig); */ - /* eputs ("\n"); */ - - return p; -} diff --git a/lib/m2/strlen.c b/lib/m2/strlen.c deleted file mode 100644 index afd061f8..00000000 --- a/lib/m2/strlen.c +++ /dev/null @@ -1,30 +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 -strlen (char *s) -{ - int i = 0; - - while (s[i] != 0) - i = i + 1; - - return i; -} diff --git a/lib/m2/strncmp.c b/lib/m2/strncmp.c index 44fe15bf..b4270074 100644 --- a/lib/m2/strncmp.c +++ b/lib/m2/strncmp.c @@ -19,7 +19,7 @@ */ int -strncmp (char *a, char *b, int size) +strncmp (char const *a, char const *b, size_t size) { if (size == 0) return 0; diff --git a/lib/m2/unlink.c b/lib/m2/unlink.c deleted file mode 100644 index a71101d3..00000000 --- a/lib/m2/unlink.c +++ /dev/null @@ -1,21 +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 unlink (char *file_name); diff --git a/lib/mes/fdputc.c b/lib/mes/fdputc.c index 0e68195b..a06b6546 100644 --- a/lib/mes/fdputc.c +++ b/lib/mes/fdputc.c @@ -23,6 +23,7 @@ int fdputc (int c, int fd) { - write (fd, (char *) &c, 1); + char *p = &c; + write (fd, p, 1); return 0; } diff --git a/lib/posix/getenv.c b/lib/posix/getenv.c index 6848399c..cf630e25 100644 --- a/lib/posix/getenv.c +++ b/lib/posix/getenv.c @@ -1,4 +1,4 @@ -/* -*-comment-start: "//";comment-end:""-*- +/* * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * @@ -22,21 +22,29 @@ #include #include +// CONSTANT M2_PTR_SIZE 4 +#define M2_PTR_SIZE 1 + char * getenv (char const *s) { + /* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */ char **p = environ; int length = strlen (s); while (p[0] != 0) { + /* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */ if (strncmp (s, p[0], length) == 0) { + /* eputs ("found!\n"); */ char *q = p[0] + length; if (q[0] == '=') return q + 1; } - p = p + 1; + /* else */ + /* eputs ("not found!\n"); */ + p = p + M2_PTR_SIZE; } return 0; diff --git a/lib/posix/setenv.c b/lib/posix/setenv.c index 5e695278..3d20e42f 100644 --- a/lib/posix/setenv.c +++ b/lib/posix/setenv.c @@ -27,7 +27,8 @@ setenv (char const *s, char const *v, int overwrite_p) { char **p = environ; int length = strlen (s); - while (p[0]) + + while (p[0] != 0) { if (strncmp (s, p[0], length) == 0) { @@ -44,7 +45,7 @@ setenv (char const *s, char const *v, int overwrite_p) strcpy (entry + length, "="); strcpy (entry + length + 1, v); entry[length + strlen (v) + 2] = 0; - if (end_p) + if (end_p != 0) p[1] = 0; return 0; diff --git a/lib/string/memcpy.c b/lib/string/memcpy.c index cba7ec96..874b660e 100644 --- a/lib/string/memcpy.c +++ b/lib/string/memcpy.c @@ -26,8 +26,13 @@ memcpy (void *dest, void const *src, size_t n) { char *p = dest; - while (n--) - *p++ = *q++; + while (n != 0) + { + n = n - 1; + dest[0] = src[0]; + dest = dest + 1; + src = src + 1; + } - return dest; + return p; } diff --git a/simple.make b/simple.make index c577c67e..fdec1441 100644 --- a/simple.make +++ b/simple.make @@ -70,43 +70,44 @@ M2_SOURCES = \ lib/linux/x86-mes-m2/crt1.c \ lib/linux/x86-mes-m2/mini.c \ lib/m2/exit.c \ - lib/m2/write.c \ + lib/mes/write.c \ lib/linux/x86-mes-m2/syscall.c \ - lib/m2/brk.c \ - lib/m2/malloc.c \ - lib/m2/memset.c \ + lib/linux/brk.c \ + lib/stdlib/malloc.c \ + lib/string/memset.c \ + \ lib/m2/read.c \ - lib/m2/fdgetc.c \ + lib/mes/fdgetc.c \ lib/stdio/getchar.c \ - lib/m2/putchar.c \ + lib/stdio/putchar.c \ lib/m2/open.c \ lib/m2/mes_open.c \ - lib/m2/strlen.c \ - lib/m2/eputs.c \ - lib/m2/fdputc.c \ + lib/string/strlen.c \ + lib/mes/eputs.c \ + lib/mes/fdputc.c \ lib/mes/eputc.c \ \ lib/mes/__assert_fail.c \ lib/mes/assert_msg.c \ \ - lib/m2/fdputc.c \ - lib/m2/strncmp.c \ - lib/m2/getenv.c \ + lib/mes/fdputc.c \ + lib/string/strncmp.c \ + lib/posix/getenv.c \ lib/mes/fdputs.c \ lib/m2/ntoab.c \ lib/ctype/isdigit.c \ lib/ctype/isxdigit.c \ lib/ctype/isspace.c \ lib/ctype/isnumber.c \ - lib/m2/abtol.c \ - lib/m2/atoi.c \ - lib/m2/memcpy.c \ + lib/mes/abtol.c \ + lib/stdlib/atoi.c \ + lib/string/memcpy.c \ lib/stdlib/free.c \ lib/stdlib/realloc.c \ - lib/m2/strcpy.c \ + lib/string/strcpy.c \ lib/mes/itoa.c \ lib/mes/fdungetc.c \ - lib/m2/setenv.c \ + lib/posix/setenv.c \ lib/m2/access.c \ lib/m2/chmod.c \ lib/m2/isatty.c \ @@ -116,14 +117,13 @@ M2_SOURCES = \ lib/m2/waitpid.c \ lib/m2/clock_gettime.c \ lib/m2/time.c \ - lib/m2/_getcwd.c \ + lib/linux/_getcwd.c \ lib/m2/getcwd.c \ - lib/m2/dup.c \ - lib/m2/dup2.c \ - lib/m2/unlink.c \ - lib/m2/strcmp.c \ - lib/m2/memcmp.c - + lib/linux/dup.c \ + lib/linux/dup2.c \ + lib/string/strcmp.c \ + lib/string/memcmp.c \ + lib/linux/unlink.c M2_TODO = \ lib/m2/file_print.c \ @@ -165,6 +165,8 @@ bin/mes-gcc: simple.make $(GCC_SOURCES) $(INCLUDES) | bin $(CC) $(CFLAGS) $(GCC_SOURCES) -o $@ M2_PLANET_INCLUDES = \ + include/m2/lib.h \ + include/linux/x86/syscall.h \ include/mes/mes.h \ include/mes/m2.h \ include/mes/builtins.h \