mescc: Mes C Library: Add x86_64 libc-mini support.

* lib/linux/x86-mes-gcc/mini.c: Rename from lib/linux/mini-gcc.c.
* lib/linux/x86-mes/mini.c: Rename from lib/linux/mini-mes.c.
* lib/linux/x86_64-mes-gcc/crt1.c: Rename from lib/linux/x86_64/crt1.c.
* lib/linux/x86_64-mes-gcc/mini.c: New file.
* build-aux/build-cc.sh: Build libc-mini, scaffold/main, scaffold/hello.
* build-aux/cc64.sh: New file.
This commit is contained in:
Jan Nieuwenhuizen 2018-08-10 17:05:01 +02:00
parent 75c54406ce
commit 46e0641e9c
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
15 changed files with 283 additions and 15 deletions

3
.gitignore vendored
View File

@ -35,9 +35,12 @@
*.stderr
*.stdout
*.x86-out
*.x86_64-mes-gcc-o
*.x86_64-mes-gcc-out
*.x86_64-mes-out
*.x86_64-out
/lib/x86-mes-gcc
/lib/x86-mes-tcc
/src/*.h

View File

@ -191,6 +191,9 @@ b *0x804a79d
** Create memory dump with 32 bit Gcc compiled Mes
make out/i686-unknown-linux-gnu-mes
out/i686-unknown-linux-gnu-mes --dump < module/mes/read-0.mes > module/mes/read-0-32.mo
x/s *((char **)($rsp+8))
** C parser/compiler
*** [[https://savannah.gnu.org/projects/nyacc][nyacc]]
*** PEG: [[http://piumarta.com/software/peg/][parse C using PEG]]

View File

@ -23,6 +23,10 @@ set -e
. ${srcdest}build-aux/config.sh
. ${srcdest}build-aux/trace.sh
# cc64
LIBC=${LIBC-c-mini}
# native
trace "SNARF gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c
trace "SNARF lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c
trace "SNARF math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c
@ -31,5 +35,37 @@ trace "SNARF posix.c" ${srcdest}build-aux/mes-snarf.scm src/posix.c
trace "SNARF reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c
trace "SNARF vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c
# cc64-mes
trace "MSNARF gc.c" ${srcdest}build-aux/mes-snarf.scm --mes src/gc.c
trace "MSNARF lib.c" ${srcdest}build-aux/mes-snarf.scm --mes src/lib.c
trace "MSNARF math.c" ${srcdest}build-aux/mes-snarf.scm --mes src/math.c
trace "MSNARF mes.c" ${srcdest}build-aux/mes-snarf.scm --mes src/mes.c
trace "MSNARF posix.c" ${srcdest}build-aux/mes-snarf.scm --mes src/posix.c
trace "MSNARF reader.c" ${srcdest}build-aux/mes-snarf.scm --mes src/reader.c
trace "MSNARF vector.c" ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc.sh lib/libmes
sh ${srcdest}build-aux/cc.sh src/mes
#ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crt0
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crt1
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crti
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crtn
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc-mini
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libgetopt
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+tcc
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libtcc1
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+gnu
# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libg
sh ${srcdest}build-aux/cc64-mes.sh scaffold/main
sh ${srcdest}build-aux/cc64-mes.sh scaffold/hello
sh ${srcdest}build-aux/cc64-mes.sh scaffold/argv
sh ${srcdest}build-aux/cc64-mes.sh scaffold/malloc
sh ${srcdest}build-aux/cc64-mes.sh scaffold/micro-mes
sh ${srcdest}build-aux/cc64-mes.sh scaffold/tiny-mes
# sh ${srcdest}build-aux/cc64-mes.sh scaffold/cons-mes
sh ${srcdest}build-aux/cc64-mes.sh scaffold/mini-mes
sh ${srcdest}build-aux/cc64-mes.sh src/mes

View File

@ -27,6 +27,7 @@ LIBC=${LIBC-c}
##moduledir=${moduledir-${datadir}${datadir:+/}module}
# native
# trace "SNARF gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c
# trace "SNARF lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c
# trace "SNARF math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c
@ -35,6 +36,7 @@ LIBC=${LIBC-c}
# trace "SNARF reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c
# trace "SNARF vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c
# cc32-mes
trace "MSNARF gc.c" ${srcdest}build-aux/mes-snarf.scm --mes src/gc.c
trace "MSNARF lib.c" ${srcdest}build-aux/mes-snarf.scm --mes src/lib.c
trace "MSNARF math.c" ${srcdest}build-aux/mes-snarf.scm --mes src/math.c
@ -55,12 +57,12 @@ ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libtcc1
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc+gnu
ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libg
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/main
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/hello
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/argv
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/malloc
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/micro-mes
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/tiny-mes
# sh ${srcdest}build-aux/cc32-mes.sh scaffold/mini-mes
sh ${srcdest}build-aux/cc32-mes.sh scaffold/main
sh ${srcdest}build-aux/cc32-mes.sh scaffold/hello
sh ${srcdest}build-aux/cc32-mes.sh scaffold/argv
sh ${srcdest}build-aux/cc32-mes.sh scaffold/malloc
sh ${srcdest}build-aux/cc32-mes.sh scaffold/micro-mes
sh ${srcdest}build-aux/cc32-mes.sh scaffold/tiny-mes
sh ${srcdest}build-aux/cc32-mes.sh scaffold/mini-mes
sh ${srcdest}build-aux/cc32-mes.sh src/mes

64
build-aux/cc64-mes.sh Executable file
View File

@ -0,0 +1,64 @@
#! /bin/sh
# GNU Mes --- Maxwell Equations of Software
# Copyright © 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/>.
set -e
. ${srcdest}build-aux/config.sh
. ${srcdest}build-aux/trace.sh
arch=x86_64-mes-gcc
if [ "$CC64" = "$TCC" ]; then
arch=x86_64-mes-tcc
LIBC=c+tcc # tcc bug with undefined symbols
fi
if [ -n "$LIBC" ]; then
CC64LIBS="lib/$arch/lib$LIBC.o"
fi
c=$1
if [ -z "$ARCHDIR" ]; then
o="$c"
d=${c%%/*}
p="$arch-"
else
b=${c##*/}
d=${c%%/*}/$arch
o="$d/$b"
fi
mkdir -p $d
trace "CC64 $c.c" $CC64\
-c\
$CC64_CPPFLAGS\
$CC64_CFLAGS\
-o "$o".${p}o\
"${srcdest}$c".c
if [ -z "$NOLINK" ]; then
trace "CCLD64 $c.c" $CC64\
$CC64_CPPFLAGS\
$CC64_CFLAGS\
-o "$o".${p}out\
lib/$arch/crt1.o\
"$o".${p}o\
$CC64LIBS
fi

View File

@ -26,6 +26,7 @@ fi
export CC
export CC CFLAGS
export CC32
export CC64
export CC_CFLAGS
export CC_CFLAGS
export CC_CPPFLAGS
@ -82,6 +83,33 @@ CC_CFLAGS=${CC_CFLAGS-"
-g
"}
CC64_CPPFLAGS=${CC64_CPPFLAGS-"
-D 'VERSION=\"$VERSION\"'
-D 'MODULEDIR=\"$moduledir\"'
-D 'PREFIX=\"$prefix\"'
-I src
-I ${srcdest}src
-I ${srcdest}lib
-I ${srcdest}include
"}
CC64_CFLAGS=${CC64_CFLAGS-"
-std=gnu99
-O0
-fno-builtin
-fno-stack-protector
-g
-m64
-nostdinc
-nostdlib
-Wno-discarded-qualifiers
-Wno-int-to-pointer-cast
-Wno-pointer-to-int-cast
-Wno-pointer-sign
-Wno-int-conversion
-Wno-incompatible-pointer-types
"}
CC32_CPPFLAGS=${CC32_CPPFLAGS-"
-D 'VERSION=\"$VERSION\"'
-D 'MODULEDIR=\"$moduledir\"'

View File

@ -60,6 +60,10 @@ ifdef CC32
export CC32
endif
ifdef CC64
export CC64
endif
ifdef BLOOD_ELF
export BLOOD_ELF
endif
@ -124,6 +128,10 @@ ifdef CC32_CFLAGS
export CC32_CFLAGS
endif
ifdef CC64_CFLAGS
export CC64_CFLAGS
endif
ifdef HEX2FLAGS
export HEX2FLAGS
endif

7
configure vendored
View File

@ -281,6 +281,8 @@ Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
CC32 x86 C compiler command
CC64_CFLAGS x86_64 C compiler flags
CC64 x86_64 C compiler command
CC32_CFLAGS x86 C compiler flags
GUILE guile command
GUILE_TOOLS guile-tools command
@ -364,6 +366,9 @@ Some influential environment variables:
(make-dep "cc32" '(2 95)
#:optional? #t
#:commands '("i686-unknown-linux-gnu-gcc"))
(make-dep "cc64" '(2 95)
#:optional? #t
#:commands '("gcc"))
(make-dep "M1" '(0 3))
(make-dep "blood-elf" '(0 1))
(make-dep "hex2" '(0 3))
@ -458,9 +463,9 @@ Some influential environment variables:
'(
"CFLAGS"
"CC32_CFLAGS"
"CC64_CFLAGS"
"HEX2FLAGS"
"M1FLAGS"
"CC32_CFLAGS"
"MES_CFLAGS"
))))

View File

@ -20,13 +20,21 @@
#if __MESC__
#include <linux/mini-mes.c>
#include <linux/x86-mes/mini.c>
#else // !__MESC__
#elif __i386__
#include <linux/mini-gcc.c>
#include <linux/x86-mes-gcc/mini.c>
#endif // !__MESC__
#elif __x86_64__
#include <linux/x86_64-mes-gcc/mini.c>
#else
#error arch not supported
#endif
ssize_t
write (int filedes, void const *buffer, size_t size)

View File

@ -38,7 +38,7 @@ _exit (int code)
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
int r;
long r;
asm (
"mov $"SYS_write",%%eax\n\t"
"mov %1,%%ebx\n\t"

View File

@ -0,0 +1,57 @@
/* -*-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/>.
*/
char **environ = 0;
int main (int argc, char *argv[]);
// gcc x86_64 calling convention:
// edi, esi, edx, ecx, r8d, r9d, <stack0>, <stack1>
void
_start ()
{
asm (
"movq %%rbp,%%rax\n\t"
"add $8,%%rax\n\t"
"movq (%%rax),%%rax\n\t"
"add $3,%%rax\n\t"
"shl $3,%%rax\n\t"
"add %%rbp,%%rax\n\t"
"mov %%rax,%0\n\t"
: "=r" (environ)
: //no inputs ""
);
asm (
"mov %rbp,%rax\n\t"
"add $16,%rax\n\t"
"mov %rax,%rsi\n\t"
"mov %rbp,%rax\n\t"
"add $8,%rax\n\t"
"mov (%rax),%rax\n\t"
"mov %rax,%rdi\n\t"
"call main\n\t"
"mov %rax,%rdi\n\t"
"mov $0x3c,%rax\n\t"
"syscall \n\t"
"hlt \n\t"
);
}

View File

@ -0,0 +1,54 @@
/* -*-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/>.
*/
#define SYS_exit "0x3c"
#define SYS_write "0x01"
void
_exit (int code)
{
asm (
"mov $"SYS_exit",%%rax\n\t"
"mov %0,%%rdi\n\t"
"syscall \n\t"
: // no outputs "=" (r)
: "rm" (code)
);
// not reached
_exit (0);
}
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
long r;
asm (
"mov $"SYS_write",%%rax\n\t"
"mov %1,%%rdi\n\t"
"mov %2,%%rsi\n\t"
"mov %3,%%rdx\n\t"
"syscall \n\t"
"mov %%rax,%0\n\t"
: "=r" (r)
: "rm" (filedes), "rm" (buffer), "rm" (size)
: "rax", "rdi", "rsi", "rdx"
);
return r;
}

View File

@ -38,7 +38,7 @@ int JAM_SIZE = 20000;
int GC_SAFETY = 2000;
char *g_arena = 0;
typedef int SCM;
typedef long SCM;
int g_debug = 0;
int g_free = 0;

View File

@ -36,7 +36,7 @@ int JAM_SIZE = 20000;
int GC_SAFETY = 2000;
char *g_arena = 0;
typedef int SCM;
typedef long SCM;
int g_debug = 0;
int g_free = 0;