diff --git a/.gitignore b/.gitignore index d20997ac..cdf7b840 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,11 @@ *.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 @@ -29,6 +34,8 @@ *.stderr *.stdout +/lib/x86-mes-gcc +/lib/x86-mes-tcc /src/*.h /src/*.i /src/mes diff --git a/GNUmakefile b/GNUmakefile index 1bc2c095..eb2d1afc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,7 +18,10 @@ cc: 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 @@ -41,8 +44,7 @@ install: .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 @@ -65,6 +67,7 @@ Targets: 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 @@ -112,6 +115,10 @@ ifdef GUILE_TOOLS export GUILE_TOOLS endif +ifdef TCC +export TCC +endif + ifdef GUILE_LOAD_PATH export GUILE_LOAD_PATH endif diff --git a/build-aux/build-mes-gcc.sh b/build-aux/build-cc32.sh similarity index 62% rename from build-aux/build-mes-gcc.sh rename to build-aux/build-cc32.sh index 6f47e542..11084f30 100755 --- a/build-aux/build-mes-gcc.sh +++ b/build-aux/build-cc32.sh @@ -25,7 +25,7 @@ if [ -n "$BUILD_DEBUG" ]; then fi MODULEDIR=${MODULEDIR-${DATADIR}${DATADIR:+/}module} -export CC32 CPPFLAGS C32FLAGS +export CC32 TCC CPPFLAGS C32FLAGS CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)} build-aux/mes-snarf.scm --mes src/gc.c @@ -54,7 +54,7 @@ CPPFLAGS=${CPPFLAGS-" "} C32FLAGS=${C32FLAGS-" ---std=gnu99 +-std=gnu99 -O0 -fno-stack-protector -g @@ -63,24 +63,24 @@ C32FLAGS=${C32FLAGS-" -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 +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/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/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/cc-mes-gcc.sh src/mes +sh build-aux/cc32-mes.sh src/mes diff --git a/build-aux/cc-mes-gcc.sh b/build-aux/cc32-mes.sh similarity index 84% rename from build-aux/cc-mes-gcc.sh rename to build-aux/cc32-mes.sh index f33dab04..d994f452 100755 --- a/build-aux/cc-mes-gcc.sh +++ b/build-aux/cc32-mes.sh @@ -34,7 +34,7 @@ CPPFLAGS=${CPPFLAGS-" "} C32FLAGS=${C32FLAGS-" ---std=gnu99 +-std=gnu99 -O0 -fno-builtin -fno-stack-protector @@ -44,20 +44,28 @@ C32FLAGS=${C32FLAGS-" -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/x86-mes-gcc/lib$LIBC.o" + CC32LIBS="lib/$arch/lib$LIBC.o" fi c=$1 if [ -z "$ARCHDIR" ]; then o="$c" - p="mes-gcc-" + p="$a-" else b=${c##*/} d=${c%/*} - o="$d/x86-mes-gcc/$b" - mkdir -p $d/x86-mes-gcc + o="$d/$arch/$b" + mkdir -p $d/$arch fi $CC32\ @@ -71,7 +79,7 @@ if [ -z "$NOLINK" ]; then $CC32\ $C32FLAGS\ -o "$o".${p}out\ - lib/x86-mes-gcc/crt1.o\ + lib/$arch/crt1.o\ "$o".${p}o\ $CC32LIBS fi diff --git a/build-aux/test.sh b/build-aux/test.sh index 25e83ff8..5030f05e 100755 --- a/build-aux/test.sh +++ b/build-aux/test.sh @@ -54,7 +54,7 @@ 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) diff --git a/build.sh b/build.sh index 0c78e7f3..4a334074 100755 --- a/build.sh +++ b/build.sh @@ -23,7 +23,7 @@ if [ -n "$BUILD_DEBUG" ]; then 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 @@ -86,8 +86,13 @@ if [ -n "$CC" ]; then 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 diff --git a/configure b/configure index 5a9750bb..d47de7cd 100755 --- a/configure +++ b/configure @@ -224,6 +224,7 @@ Some influential environment variables: 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"))) @@ -245,6 +246,7 @@ Some influential environment variables: (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")) @@ -281,6 +283,8 @@ Some influential environment variables: (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)) @@ -298,6 +302,7 @@ Some influential environment variables: (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 "")) diff --git a/lib/crt1.c b/lib/crt1.c index 6c133b98..a3999583 100644 --- a/lib/crt1.c +++ b/lib/crt1.c @@ -21,43 +21,7 @@ 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 () @@ -89,4 +53,39 @@ _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__ diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 5c1fe9cd..8b0e5e34 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -112,7 +112,15 @@ __fixunsxfdi (double a1) 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; @@ -132,7 +140,7 @@ __fixxfdi (double a1) return 0; } -unsigned long long +long long __fixsfdi (double a1) { static int stub = 0; diff --git a/lib/linux-gcc.c b/lib/linux-gcc.c index f21704b5..fd617783 100644 --- a/lib/linux-gcc.c +++ b/lib/linux-gcc.c @@ -23,14 +23,13 @@ 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) @@ -41,13 +40,11 @@ _sys_call (int sys_call) else errno = 0; return r; -#endif } int _sys_call1 (int sys_call, int one) { -#if !__TINYC__ int r; asm ( "mov %1,%%eax\n\t" @@ -55,7 +52,7 @@ _sys_call1 (int sys_call, int one) "int $0x80\n\t" "mov %%eax,%0\n\t" : "=r" (r) - : "" (sys_call), "" (one) + : "rm" (sys_call), "rm" (one) : "eax", "ebx" ); if (r < 0) @@ -66,13 +63,11 @@ _sys_call1 (int sys_call, int one) 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" @@ -81,7 +76,7 @@ _sys_call2 (int sys_call, int one, int two) "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) @@ -92,13 +87,11 @@ _sys_call2 (int sys_call, int one, int two) 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" @@ -108,7 +101,7 @@ _sys_call3 (int sys_call, int one, int two, int three) "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) @@ -119,5 +112,4 @@ _sys_call3 (int sys_call, int one, int two, int three) else errno = 0; return r; -#endif } diff --git a/lib/linux-mini-gcc.c b/lib/linux-mini-gcc.c index 737a1ba6..40a79610 100644 --- a/lib/linux-mini-gcc.c +++ b/lib/linux-mini-gcc.c @@ -24,23 +24,13 @@ 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); } @@ -49,7 +39,6 @@ ssize_t _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" @@ -58,21 +47,8 @@ _write (int filedes, void const *buffer, size_t size) "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; }