kaem.run: New file.

* kaem.run: New file.
This commit is contained in:
Jan Nieuwenhuizen 2019-10-23 18:08:50 +02:00
parent 78c4757ec3
commit 421687c624
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
31 changed files with 198 additions and 589 deletions

View File

@ -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

131
kaem.run Normal file
View File

@ -0,0 +1,131 @@
#!/bin/bash
# Copyright (C) 2019 Jeremiah Orians <jeremiah@pdp10.guru>
# 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 <http://www.gnu.org/licenses/>.
# 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

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)

View File

@ -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);
}

View File

@ -1,32 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib-mini.h>
#include <linux/syscall.h>
#include <syscall.h>
char *
_getcwd (char *buffer, int size)
{
int r = _sys_call2 (SYS_getcwd, buffer, size);
if (r >= 0)
return buffer;
return 0;
}

View File

@ -21,7 +21,7 @@
#include <mes/lib.h>
#include <ctype.h>
int
long
abtol (char **p, int base)
{
char *s = p[0];

View File

@ -1,26 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
int
atoi (char *string)
{
char *p = string;
return abtol (&p, 0);
}

View File

@ -1,21 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
int dup (int old);

View File

@ -1,21 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
int dup2 (int old, int new);

View File

@ -1,28 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
int
fdputc (int c, int fd)
{
write (fd, &c, 1);
return 0;
}

View File

@ -1,47 +0,0 @@
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
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;
}

View File

@ -1,36 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
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;
}

View File

@ -1,37 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
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;
}

View File

@ -1,39 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
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];
}

View File

@ -1,38 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
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;
}

View File

@ -1,34 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
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;
}

View File

@ -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);

View File

@ -1,52 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
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;
}

View File

@ -1,33 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
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];
}

View File

@ -1,51 +0,0 @@
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
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;
}

View File

@ -1,30 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
int
strlen (char *s)
{
int i = 0;
while (s[i] != 0)
i = i + 1;
return i;
}

View File

@ -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;

View File

@ -1,21 +0,0 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
int unlink (char *file_name);

View File

@ -23,6 +23,7 @@
int
fdputc (int c, int fd)
{
write (fd, (char *) &c, 1);
char *p = &c;
write (fd, p, 1);
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*-comment-start: "//";comment-end:""-*-
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
@ -22,21 +22,29 @@
#include <string.h>
#include <stdlib.h>
// 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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 \