* configure: check for tcc.
* build-aux/cc32-mes.sh: Rename from cc-mes-gcc.sh. Support
tcc. Update users.
* build-aux/build-cc32-mes.sh: Rename from build-mes-gcc.sh. Update users.
* GNUmakefile (mes-tcc): New target.
* .gitignore: Ignore mes-tcc arch output.
* lib/crt1.c (_start): Add "rm" constraint so satisfy tcc.
* lib/linux-gcc.c (_sys_call, _sys_call1 _sys_call2 _sys_call3): Likewise.
*.mes-gcc-out
*.mes-gcc-out
*.mes-gcc-stdout
+*.mes-tcc
+*.mes-tcc-o
+*.mes-tcc-out
+*.mes-tcc-out
+*.mes-tcc-stdout
*.mes-o
*.mes-out
*.mes-stdout
*.stderr
*.stdout
+/lib/x86-mes-gcc
+/lib/x86-mes-tcc
/src/*.h
/src/*.i
/src/mes
build-aux/build-cc.sh
mes-gcc:
- build-aux/build-mes-gcc.sh
+ build-aux/build-cc32.sh
+
+mes-tcc:
+ CC32=$(TCC) build-aux/build-cc32.sh
mes:
build-aux/build-mes.sh
.config.make: ./configure
-seed: all-go
- build-aux/build-mes-gcc.sh
+seed: all-go mes-gcc mes-tcc
cd $(TINYCC_SEED) && MES_PREFIX=$(PWD) ./refresh.sh
cd $(MES_SEED) && git reset --hard HEAD
MES=$(GUILE) GUILE=$(GUILE) SEED=1 build-aux/build-mes.sh
all-go update .go files
cc update src/mes.gcc-out
mes-gcc update src/mes.mes-gcc-out
+ mes-tcc update src/mes.mes-tcc-out
mes update src/mes
check run unit tests
clean run git clean -dfx
export GUILE_TOOLS
endif
+ifdef TCC
+export TCC
+endif
+
ifdef GUILE_LOAD_PATH
export GUILE_LOAD_PATH
endif
--- /dev/null
+#! /bin/sh
+
+# Mes --- Maxwell Equations of Software
+# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+#
+# This file is part of Mes.
+#
+# 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.
+#
+# 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 Mes. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+if [ -n "$BUILD_DEBUG" ]; then
+ set -x
+fi
+
+MODULEDIR=${MODULEDIR-${DATADIR}${DATADIR:+/}module}
+export CC32 TCC CPPFLAGS C32FLAGS
+
+CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)}
+build-aux/mes-snarf.scm --mes src/gc.c
+build-aux/mes-snarf.scm --mes src/lib.c
+build-aux/mes-snarf.scm --mes src/math.c
+build-aux/mes-snarf.scm --mes src/mes.c
+build-aux/mes-snarf.scm --mes src/posix.c
+build-aux/mes-snarf.scm --mes src/reader.c
+build-aux/mes-snarf.scm --mes src/vector.c
+
+build-aux/mes-snarf.scm src/gc.c
+build-aux/mes-snarf.scm src/lib.c
+build-aux/mes-snarf.scm src/math.c
+build-aux/mes-snarf.scm src/mes.c
+build-aux/mes-snarf.scm src/posix.c
+build-aux/mes-snarf.scm src/reader.c
+build-aux/mes-snarf.scm src/vector.c
+
+CPPFLAGS=${CPPFLAGS-"
+-D VERSION=\"$VERSION\"
+-D MODULEDIR=\"$MODULEDIR\"
+-D PREFIX=\"$PREFIX\"
+-I src
+-I lib
+-I include
+"}
+
+C32FLAGS=${C32FLAGS-"
+-std=gnu99
+-O0
+-fno-stack-protector
+-g
+-m32
+-nostdinc
+-nostdlib
+"}
+
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crt0
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crt1
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crti
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crtn
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc-mini
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libgetopt
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc+tcc
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libtcc1
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc+gnu
+ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libg
+
+sh build-aux/cc32-mes.sh scaffold/main
+sh build-aux/cc32-mes.sh scaffold/hello
+sh build-aux/cc32-mes.sh scaffold/argv
+sh build-aux/cc32-mes.sh scaffold/malloc
+sh build-aux/cc32-mes.sh scaffold/micro-mes
+sh build-aux/cc32-mes.sh scaffold/tiny-mes
+sh build-aux/cc32-mes.sh scaffold/mini-mes
+
+sh build-aux/cc32-mes.sh src/mes
+++ /dev/null
-#! /bin/sh
-
-# Mes --- Maxwell Equations of Software
-# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
-#
-# This file is part of Mes.
-#
-# 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.
-#
-# 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 Mes. If not, see <http://www.gnu.org/licenses/>.
-
-set -e
-
-if [ -n "$BUILD_DEBUG" ]; then
- set -x
-fi
-
-MODULEDIR=${MODULEDIR-${DATADIR}${DATADIR:+/}module}
-export CC32 CPPFLAGS C32FLAGS
-
-CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)}
-build-aux/mes-snarf.scm --mes src/gc.c
-build-aux/mes-snarf.scm --mes src/lib.c
-build-aux/mes-snarf.scm --mes src/math.c
-build-aux/mes-snarf.scm --mes src/mes.c
-build-aux/mes-snarf.scm --mes src/posix.c
-build-aux/mes-snarf.scm --mes src/reader.c
-build-aux/mes-snarf.scm --mes src/vector.c
-
-build-aux/mes-snarf.scm src/gc.c
-build-aux/mes-snarf.scm src/lib.c
-build-aux/mes-snarf.scm src/math.c
-build-aux/mes-snarf.scm src/mes.c
-build-aux/mes-snarf.scm src/posix.c
-build-aux/mes-snarf.scm src/reader.c
-build-aux/mes-snarf.scm src/vector.c
-
-CPPFLAGS=${CPPFLAGS-"
--D VERSION=\"$VERSION\"
--D MODULEDIR=\"$MODULEDIR\"
--D PREFIX=\"$PREFIX\"
--I src
--I lib
--I include
-"}
-
-C32FLAGS=${C32FLAGS-"
---std=gnu99
--O0
--fno-stack-protector
--g
--m32
--nostdinc
--nostdlib
-"}
-
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt0
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt1
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crti
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crtn
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc-mini
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libgetopt
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+tcc
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libtcc1
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc+gnu
-ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libg
-
-sh build-aux/cc-mes-gcc.sh scaffold/main
-sh build-aux/cc-mes-gcc.sh scaffold/hello
-sh build-aux/cc-mes-gcc.sh scaffold/argv
-sh build-aux/cc-mes-gcc.sh scaffold/malloc
-sh build-aux/cc-mes-gcc.sh scaffold/micro-mes
-sh build-aux/cc-mes-gcc.sh scaffold/tiny-mes
-sh build-aux/cc-mes-gcc.sh scaffold/mini-mes
-
-sh build-aux/cc-mes-gcc.sh src/mes
+++ /dev/null
-#! /bin/sh
-
-# Mes --- Maxwell Equations of Software
-# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
-#
-# This file is part of Mes.
-#
-# 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.
-#
-# 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 Mes. If not, see <http://www.gnu.org/licenses/>.
-
-set -e
-
-if [ -n "$BUILD_DEBUG" ]; then
- set -x
-fi
-
-CPPFLAGS=${CPPFLAGS-"
--D VERSION=\"$VERSION\"
--D MODULEDIR=\"$MODULEDIR\"
--D PREFIX=\"$PREFIX\"
--I src
--I lib
--I include
-"}
-
-C32FLAGS=${C32FLAGS-"
---std=gnu99
--O0
--fno-builtin
--fno-stack-protector
--g
--m32
--nostdinc
--nostdlib
-"}
-LIBC=${LIBC-c}
-if [ -n "$LIBC" ]; then
- CC32LIBS="lib/x86-mes-gcc/lib$LIBC.o"
-fi
-
-c=$1
-
-if [ -z "$ARCHDIR" ]; then
- o="$c"
- p="mes-gcc-"
-else
- b=${c##*/}
- d=${c%/*}
- o="$d/x86-mes-gcc/$b"
- mkdir -p $d/x86-mes-gcc
-fi
-
-$CC32\
- -c\
- $CPPFLAGS\
- $C32FLAGS\
- -o "$o".${p}o\
- "$c".c
-
-if [ -z "$NOLINK" ]; then
- $CC32\
- $C32FLAGS\
- -o "$o".${p}out\
- lib/x86-mes-gcc/crt1.o\
- "$o".${p}o\
- $CC32LIBS
-fi
--- /dev/null
+#! /bin/sh
+
+# Mes --- Maxwell Equations of Software
+# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+#
+# This file is part of Mes.
+#
+# 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.
+#
+# 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 Mes. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+if [ -n "$BUILD_DEBUG" ]; then
+ set -x
+fi
+
+CPPFLAGS=${CPPFLAGS-"
+-D VERSION=\"$VERSION\"
+-D MODULEDIR=\"$MODULEDIR\"
+-D PREFIX=\"$PREFIX\"
+-I src
+-I lib
+-I include
+"}
+
+C32FLAGS=${C32FLAGS-"
+-std=gnu99
+-O0
+-fno-builtin
+-fno-stack-protector
+-g
+-m32
+-nostdinc
+-nostdlib
+"}
+LIBC=${LIBC-c}
+
+a=mes-gcc
+if [ "$CC32" = "$TCC" ]; then
+ a=mes-tcc
+ LIBC=c+tcc # tcc bug with undefined symbols
+fi
+arch=x86-$a
+
+if [ -n "$LIBC" ]; then
+ CC32LIBS="lib/$arch/lib$LIBC.o"
+fi
+
+c=$1
+
+if [ -z "$ARCHDIR" ]; then
+ o="$c"
+ p="$a-"
+else
+ b=${c##*/}
+ d=${c%/*}
+ o="$d/$arch/$b"
+ mkdir -p $d/$arch
+fi
+
+$CC32\
+ -c\
+ $CPPFLAGS\
+ $C32FLAGS\
+ -o "$o".${p}o\
+ "$c".c
+
+if [ -z "$NOLINK" ]; then
+ $CC32\
+ $C32FLAGS\
+ -o "$o".${p}out\
+ lib/$arch/crt1.o\
+ "$o".${p}o\
+ $CC32LIBS
+fi
rm -f "$t".mes-gcc-out
if [ -n "$CC32" ]; then
- sh build-aux/cc-mes-gcc.sh "$t"
+ sh build-aux/cc32-mes.sh "$t"
r=0
[ -f "$t".exit ] && r=$(cat "$t".exit)
fi
# dash does not export foo=${foo-bar} for some values
-export CC CC32 GUILE MESCC MES_SEED
+export CC CC32 TCC GUILE MESCC MES_SEED
export MES_ARENA MES_DEBUG
export PREFIX DATADIR MODULEDIR
export CPPFLAGS CFLAGS C32FLAGS MESCCFLAGS
fi
if [ -n "$CC32" ]; then
- sh build-aux/build-mes-gcc.sh
+ sh build-aux/build-cc32.sh
cp src/mes.mes-gcc-out src/mes
fi
+if [ -n "$TCC" ]; then
+ CC32=$TCC sh build-aux/build-cc32.sh
+ cp src/mes.mes-tcc-out src/mes
+fi
+
sh build-aux/build-mes.sh
GUILE_TOOLS guile-tools command
MES_SEED location of mes-seed
MESCC_TOOLS_SEED location of mescc-tools-seed
+ TCC tcc C compiler command
TINYCC_SEED location of tinycc-seed
" PACKAGE VERSION (getenv "PREFIX")))
(let ((CC32 (or (getenv "CC32")
(if (member ARCH '("i686" "arm")) (string-append BUILD_TRIPLET "-" CC)
"i686-unknown-linux-gnu-gcc")))
+ (TCC (or (getenv "TCC") "tcc"))
(GUILE_TOOLS (or (getenv "GUILE_TOOLS") "guile-tools"))
(BLOOD_ELF (or (getenv "BLOOD_ELF") "blood-elf"))
(HEX2 (or (getenv "HEX2") "hex2"))
(check-header-c "limits.h" "linux-headers"))
(if (not (check-version CC32 '(4 8) #:optional? #t))
(set! CC32 #f))
+ (if (not (check-version TCC '(0 9 26) #:optional? #t #:version-option "-v"))
+ (set! TCC #f))
(set! make? (check-version "make" '(4 0) #:optional? #t))
(check-version "perl" '(5))
(stdout "ARCH:=~a\n" ARCH)
(stdout "CC:=~a\n" (or CC ""))
(stdout "CC32:=~a\n" (or CC32 ""))
+ (stdout "TCC:=~a\n" (or TCC ""))
(stdout "BLOOD_ELF:=~a\n" (or BLOOD_ELF ""))
(stdout "MES_SEED:=~a\n" (or MES_SEED ""))
(stdout "MESCC_TOOLS_SEED:=~a\n" (or MESCC_TOOLS_SEED ""))
char **environ = 0;
int main (int argc, char *argv[]);
-#if __GNUC__
-
-void
-_start ()
-{
- asm (
- "mov %%ebp,%%eax\n\t"
- "addl $4,%%eax\n\t"
- "movzbl (%%eax),%%eax\n\t"
- "addl $3,%%eax\n\t"
- "shl $2,%%eax\n\t"
- "add %%ebp,%%eax\n\t"
- "movl %%eax,%0\n\t"
- : "=environ" (environ)
- : //no inputs ""
- );
- asm (
- "mov %%ebp,%%eax\n\t"
- "addl $8,%%eax\n\t"
- "push %%eax\n\t"
-
- "mov %%ebp,%%eax\n\t"
- "addl $4,%%eax\n\t"
- "movzbl (%%eax),%%eax\n\t"
- "push %%eax\n\t"
-
- "call main\n\t"
-
- "mov %%eax,%%ebx\n\t"
- "mov $1,%%eax\n\t"
- "int $0x80\n\t"
- "hlt \n\t"
- :
- );
-}
-
-#elif __MESC__
+#if __MESC__
int
_start ()
asm ("hlt");
}
-#endif
+#else // !__MESC__
+
+void
+_start ()
+{
+ asm (
+ "mov %%ebp,%%eax\n\t"
+ "add $4,%%eax\n\t"
+ "movzbl (%%eax),%%eax\n\t"
+ "add $3,%%eax\n\t"
+ "shl $2,%%eax\n\t"
+ "add %%ebp,%%eax\n\t"
+ "mov %%eax,%0\n\t"
+ : "=r" (environ)
+ : //no inputs ""
+ );
+ asm (
+ "mov %ebp,%eax\n\t"
+ "add $8,%eax\n\t"
+ "push %eax\n\t"
+
+ "mov %ebp,%eax\n\t"
+ "add $4,%eax\n\t"
+ "movzbl (%eax),%eax\n\t"
+ "push %eax\n\t"
+
+ "call main\n\t"
+
+ "mov %eax,%ebx\n\t"
+ "mov $1,%eax\n\t"
+ "int $0x80\n\t"
+ "hlt \n\t"
+ );
+}
+
+#endif // !__MESC__
return 0;
}
-unsigned long long
+#if __TINYC__ == 9227
+int
+#if __TINYC__ == 9226
+long
+#else
+long long
+int
+#endif // __TINYC__ == 9226
+#endif // __TINYC__ == 9227
__fixdfdi (double a1)
{
static int stub = 0;
return 0;
}
-unsigned long long
+long long
__fixsfdi (double a1)
{
static int stub = 0;
int
_sys_call (int sys_call)
{
-#if !__TINYC__
int r;
asm (
"mov %1,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
- : "" (sys_call)
+ : "rm" (sys_call)
: "eax"
);
if (r < 0)
else
errno = 0;
return r;
-#endif
}
int
_sys_call1 (int sys_call, int one)
{
-#if !__TINYC__
int r;
asm (
"mov %1,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
- : "" (sys_call), "" (one)
+ : "rm" (sys_call), "rm" (one)
: "eax", "ebx"
);
if (r < 0)
else
errno = 0;
return r;
-#endif
}
int
_sys_call2 (int sys_call, int one, int two)
{
-#if !__TINYC__
int r;
asm (
"mov %1,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
- : "" (sys_call), "" (one), "" (two)
+ : "rm" (sys_call), "rm" (one), "rm" (two)
: "eax", "ebx", "ecx"
);
if (r < 0)
else
errno = 0;
return r;
-#endif
}
int
_sys_call3 (int sys_call, int one, int two, int three)
{
-#if !__TINYC__
int r;
asm (
"mov %2,%%ebx\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
- : "" (sys_call), "" (one), "" (two), "" (three)
+ : "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three)
: "eax", "ebx", "ecx", "edx"
);
if (r < 0)
else
errno = 0;
return r;
-#endif
}
void
_exit (int code)
{
-#if !__TINYC__
asm (
"mov $"SYS_exit",%%eax\n\t"
"mov %0,%%ebx\n\t"
"int $0x80\n\t"
: // no outputs "=" (r)
- : "" (code)
+ : "rm" (code)
);
-#else // __TINYC__
- asm (
- "mov $"SYS_exit",%%eax\n\t"
- "mov %0,%%ebx\n\t"
- "int $128\n\t"
- : // no outputs "=" (r)
- : "Ir" (code)
- );
-#endif // __TINYC__
// not reached
_exit (0);
}
_write (int filedes, void const *buffer, size_t size)
{
int r;
-#if __GNUC__
asm (
"mov $"SYS_write",%%eax\n\t"
"mov %1,%%ebx\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=r" (r)
- : "" (filedes), "" (buffer), "" (size)
+ : "rm" (filedes), "rm" (buffer), "rm" (size)
: "eax", "ebx", "ecx", "edx"
);
-#elif __TINYC__
- asm (
- "mov $"SYS_write",%%eax\n\t"
- "mov %1,%%ebx\n\t"
- "mov %2,%%ecx\n\t"
- "mov %3,%%edx\n\t"
- "int $128\n\t"
- "mov %%eax,%0\n\t"
- : "=r" (r)
- : "Ir" (filedes), "Ir" (buffer), "Ir" (size)
- : "eax", "ebx", "ecx"//, "edx"
- );
-#endif
return r;
}