From 5484e0ffdf0ff85911301525e16c6c3b01910afc Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 30 Sep 2018 12:15:11 +0200 Subject: [PATCH] build: Resurrect make seed. * build-aux/GNUmakefile.in (seed): Resurrect. * build-aux/build-x86_64-mes.sh: Build from seed. --- .gitignore | 2 + build-aux/GNUmakefile.in | 14 +++- build-aux/build-mes.sh | 4 - build-aux/build-x86_64-mes.sh | 145 ++++++++++++++++------------------ build-aux/cc-x86_64-mes.sh | 10 +-- lib/linux/x86-mes/crt0.c | 57 ------------- lib/linux/x86-mes/crti.c | 19 ----- lib/linux/x86-mes/crtn.c | 19 ----- lib/x86_64-mes/x86_64.M1 | 1 + module/mescc/mescc.scm | 10 ++- 10 files changed, 96 insertions(+), 185 deletions(-) delete mode 100644 lib/linux/x86-mes/crt0.c delete mode 100644 lib/linux/x86-mes/crti.c delete mode 100644 lib/linux/x86-mes/crtn.c diff --git a/.gitignore b/.gitignore index 1aa07166..d5291f40 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,8 @@ *.stderr *.stdout *.x86-out +*.x86_64-mes-E +*.x86_64-mes-S *.x86_64-mes-gcc-o *.x86_64-mes-gcc-out *.x86_64-mes-gcc-stdout diff --git a/build-aux/GNUmakefile.in b/build-aux/GNUmakefile.in index 71bf73a5..24d8e1f1 100644 --- a/build-aux/GNUmakefile.in +++ b/build-aux/GNUmakefile.in @@ -150,12 +150,18 @@ uninstall: seed: all-go gcc mes-gcc mes-tcc cd $(MES_SEED) && git reset --hard HEAD - MES=$(GUILE) GUILE=$(GUILE) SEED=1 ${srcdest}build-aux/build-mes.sh + $(MAKE) MES=guile MES_SEED= SEED=1 mes + cp -v lib/x86-mes/*.S $(MES_SEED)/x86-mes + cp -v src/mes.S $(MES_SEED)/x86-mes + $(MAKE) MES=guile MES_SEED= SEED=1 x86_64-mes + cp -v lib/x86_64-mes/*.S $(MES_SEED)/x86_64-mes + cp -v src/mes.x86_64-mes-S $(MES_SEED)/x86_64-mes/mes.S + MES=$(GUILE) GUILE=$(GUILE) SEED=1 MES_SEED= ${srcdest}build-aux/build-mes.sh cd $(MES_SEED) && MES_PREFIX=$(PWD) ./refresh.sh MES=$(GUILE) GUILE=$(GUILE) SEED=1 ${srcdest}build-aux/build-mes.sh - cp lib/x86-mes/elf32-header.hex2\ - lib/x86-mes/x86.M1\ - lib/x86-mes/libc+tcc.S\ + cd $(MES_SEED) && MES_PREFIX=$(PWD) arch=x86_64-mes ./refresh.sh + MES=$(GUILE) GUILE=$(GUILE) SEED=1 ${srcdest}build-aux/build-x86_64-mes.sh + cp lib/x86-mes/libc+tcc.S\ lib/x86-mes/libc.S\ lib/x86-mes/crt1.S\ lib/x86-mes/libgetopt.S\ diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 6d23c71b..1d4433a8 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -122,10 +122,6 @@ trace "TEST lib/x86-mes/exit-42.mes-out" echo lib/x86-mes/exit-42.mes-out { set +e; lib/x86-mes/exit-42.mes-out; r=$?; set -e; } [ $r != 42 ] && echo " => $r" && exit 1 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crt0 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crti -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crtn - ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+tcc ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc+gnu diff --git a/build-aux/build-x86_64-mes.sh b/build-aux/build-x86_64-mes.sh index 2d737b1d..4f35f0e1 100755 --- a/build-aux/build-x86_64-mes.sh +++ b/build-aux/build-x86_64-mes.sh @@ -60,50 +60,50 @@ trace "TEST lib/x86_64-mes/exit-42.x86_64-out" echo lib/x86_64-mes/exit-42 { set +e; lib/x86_64-mes/exit-42.x86_64-out; r=$?; set -e; } [ $r != 42 ] && echo " => $r" && exit 1 -# if [ -d "$MES_SEED" ]; then -# mkdir -p lib/x86_64-mes -# trace "M1 crt1.S" $M1\ -# $M1FLAGS\ -# -f ${srcdest}lib/x86_64-mes/x86_64.M1\ -# -f $MES_SEED/x86_64-mes/crt1.S\ -# -o lib/x86_64-mes/crt1.o -# trace "M1 libc.S" $M1\ -# $M1FLAGS\ -# -f ${srcdest}lib/x86_64-mes/x86_64.M1\ -# -f $MES_SEED/x86_64-mes/libc.S\ -# -o lib/x86_64-mes/libc.o -# trace "M1 mes.S" $M1\ -# --LittleEndian\ -# --Architecture 2\ -# -f ${srcdest}lib/x86_64-mes/x86_64.M1\ -# -f $MES_SEED/x86_64-mes/mes.S\ -# -o src/mes.o -# trace "BLOOD_ELF mes.S" $BLOOD_ELF\ -# -f ${srcdest}lib/x86_64-mes/x86_64.M1\ -# -f $MES_SEED/x86_64-mes/mes.S\ -# -f $MES_SEED/x86_64-mes/libc.S\ -# -o src/mes.S.blood-elf -# trace "M1 mes.blood-elf" $M1\ -# --LittleEndian\ -# --Architecture 2\ -# -f src/mes.S.blood-elf\ -# -o src/mes.o.blood-elf -# trace "HEX2 mes.o" $HEX2\ -# $HEX2FLAGS\ -# -f ${srcdest}lib/x86_64-mes/elf64-header.hex2\ -# -f lib/x86_64-mes/crt1.o\ -# -f lib/x86_64-mes/libc.o\ -# -f src/mes.o\ -# -f src/mes.o.blood-elf\ -# --exec_enable\ -# -o src/mes.seed-out -# cp src/mes.seed-out src/mes -# trace "M1 libc+tcc.S" $M1\ -# $M1FLAGS\ -# -f ${srcdest}lib/x86_64-mes/x86_64.M1\ -# -f $MES_SEED/x86_64-mes/libc+tcc.S\ -# -o lib/x86_64-mes/libc+tcc.o -# fi +if [ -d "$MES_SEED" ]; then + mkdir -p lib/x86_64-mes + trace "M1 crt1.S" $M1\ + $M1FLAGS\ + -f ${srcdest}lib/x86_64-mes/x86_64.M1\ + -f $MES_SEED/x86_64-mes/crt1.S\ + -o lib/x86_64-mes/crt1.o + trace "M1 libc.S" $M1\ + $M1FLAGS\ + -f ${srcdest}lib/x86_64-mes/x86_64.M1\ + -f $MES_SEED/x86_64-mes/libc.S\ + -o lib/x86_64-mes/libc.o + trace "M1 mes.S" $M1\ + --LittleEndian\ + --Architecture 2\ + -f ${srcdest}lib/x86_64-mes/x86_64.M1\ + -f $MES_SEED/x86_64-mes/mes.S\ + -o src/mes.o + trace "BLOOD_ELF mes.S" $BLOOD_ELF\ + -f ${srcdest}lib/x86_64-mes/x86_64.M1\ + -f $MES_SEED/x86_64-mes/mes.S\ + -f $MES_SEED/x86_64-mes/libc.S\ + -o src/mes.S.blood-elf + trace "M1 mes.blood-elf" $M1\ + --LittleEndian\ + --Architecture 2\ + -f src/mes.S.blood-elf\ + -o src/mes.o.blood-elf + trace "HEX2 mes.o" $HEX2\ + $HEX2FLAGS\ + -f ${srcdest}lib/x86_64-mes/elf64-header.hex2\ + -f lib/x86_64-mes/crt1.o\ + -f lib/x86_64-mes/libc.o\ + -f src/mes.o\ + -f src/mes.o.blood-elf\ + --exec_enable\ + -o src/mes.seed-out + cp src/mes.seed-out src/mes + trace "M1 libc+tcc.S" $M1\ + $M1FLAGS\ + -f ${srcdest}lib/x86_64-mes/x86_64.M1\ + -f $MES_SEED/x86_64-mes/libc+tcc.S\ + -o lib/x86_64-mes/libc+tcc.o +fi PREPROCESS=1 @@ -114,39 +114,35 @@ if [ ! -d "$MES_SEED" ] \ MES_ARENA=100000000 fi -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crt1 +MES_ARENA=100000000 -MES_LIBS='-l none' PREPROCESS= bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/x86_64-mes/exit-42 +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crt1 +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc-mini +MES64_LIBS='-l c-mini' PREPROCESS= bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/x86_64-mes/exit-42 trace "TEST lib/x86_64-mes/exit-42.x86_64-mes-out" echo lib/x86_64-mes/exit-42.x86_64-mes-out { set +e; lib/x86_64-mes/exit-42.x86_64-mes-out; r=$?; set -e; } [ $r != 42 ] && echo " => $r" && exit 1 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc - -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crt0 -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crti -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/linux/x86_64-mes/crtn - -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+tcc -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+gnu -# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libgetopt +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+tcc +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libc+gnu +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-x86_64-mes.sh lib/libgetopt -# [ -n "$SEED" ] && exit 0 +[ -n "$SEED" ] && exit 0 -# MES_ARENA=${MES_ARENA-100000000} -# trace "MSNARF gc.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/gc.c -# trace "MSNARF lib.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/lib.c -# trace "MSNARF math.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/math.c -# trace "MSNARF mes.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/mes.c -# trace "MSNARF posix.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/posix.c -# trace "MSNARF reader.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/reader.c -# trace "MSNARF vector.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c +MES_ARENA=${MES_ARENA-100000000} +trace "MSNARF gc.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/gc.c +trace "MSNARF lib.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/lib.c +trace "MSNARF math.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/math.c +trace "MSNARF mes.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/mes.c +trace "MSNARF posix.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/posix.c +trace "MSNARF reader.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/reader.c +trace "MSNARF vector.c" ./pre-inst-env bash ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c -# echo MES_ARENA=$MES_ARENA -# bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/main +echo MES_ARENA=$MES_ARENA +bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/main MES_LIBS='-l none' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/main @@ -154,12 +150,11 @@ trace "TEST scaffold/main.x86_64-mes-out" echo scaffold/main.x86_64-mes-ou { set +e; scaffold/main.x86_64-mes-out; r=$?; set -e; } [ $r != 42 ] && echo " => $r" && exit 1 -# MES_LIBS='-l mini' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/hello -# MES_LIBS='-l mini' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/argv -# bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/malloc -# ##sh ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/micro-mes -# ##sh ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/tiny-mes -# # bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/mini-mes -# bash ${srcdest}build-aux/cc-x86_64-mes.sh src/mes -# cp src/mes.mes-out src/mes -true +MES64_LIBS='-l c-mini' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/hello +MES64_LIBS='-l c-mini' bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/argv +bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/malloc +##sh ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/micro-mes +##sh ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/tiny-mes +# bash ${srcdest}build-aux/cc-x86_64-mes.sh scaffold/mini-mes +bash ${srcdest}build-aux/cc-x86_64-mes.sh src/mes +cp src/mes.x86_64-mes-out src/mes diff --git a/build-aux/cc-x86_64-mes.sh b/build-aux/cc-x86_64-mes.sh index e551b07d..4d0c90a4 100755 --- a/build-aux/cc-x86_64-mes.sh +++ b/build-aux/cc-x86_64-mes.sh @@ -48,15 +48,15 @@ fi mkdir -p $d if [ -n "$PREPROCESS" ]; then - trace "CPP.mes64 $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES64_CFLAGS -E -o "$o.E" "${srcdest}$c".c - trace "CC.mes64 $c.E" ./pre-inst-env bash $MESCC $MES64_CFLAGS -S "$o".E - trace "AS.mes64 $c.S" ./pre-inst-env bash $MESCC $MES64_CFLAGS -c -o "$o".${p}o "$o".S + trace "CPP.mes64 $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES64_CFLAGS -E -o "$o.${p}E" "${srcdest}$c".c + trace "CC.mes64 $c.E" ./pre-inst-env bash $MESCC $MES64_CFLAGS -S -o "$o".${p}S "$o".${p}E + trace "AS.mes64 $c.S" ./pre-inst-env bash $MESCC $MES64_CFLAGS -c -o "$o".${p}o "$o".${p}S if [ -z "$NOLINK" ]; then trace "LD.mes64 $c.o" ./pre-inst-env bash $MESCC $MES64_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS fi elif [ -n "$COMPILE" ]; then - trace "CC.mes64 $c.c" trace "MESCC $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES64_CFLAGS -S -o "$o.S" "${srcdest}$c".c - trace "AS.mes64 $c.S" ./pre-inst-env bash $MESCC $MES64_CFLAGS -c -o "$o".${p}o "$o".S + trace "CC.mes64 $c.c" trace "MESCC $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES64_CFLAGS -S -o "$o".${p}S "${srcdest}$c".c + trace "AS.mes64 $c.S" ./pre-inst-env bash $MESCC $MES64_CFLAGS -c -o "$o".${p}o "$o".${p}S if [ -z "$NOLINK" ]; then trace "LD.mes64 $c.o" ./pre-inst-env bash $MESCC $MES64_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS fi diff --git a/lib/linux/x86-mes/crt0.c b/lib/linux/x86-mes/crt0.c deleted file mode 100644 index 0072dcd4..00000000 --- a/lib/linux/x86-mes/crt0.c +++ /dev/null @@ -1,57 +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 . - */ - -// no clue what crt0.o is and why gcc-2.6.3 needs it - -// instead of calling main, it seems to call either _main or ___main, -// let's try _main first - -char **environ = 0; -int _main (int argc, char *argv[]); - -int -_start () -{ - asm ("mov____%ebp,%eax"); - asm ("add____$i8,%eax !4"); - - asm ("movzbl_(%eax),%eax"); - asm ("add____$i8,%eax !3"); - - asm ("shl____$i8,%eax !0x02"); - asm ("add____%ebp,%eax"); - asm ("mov____%eax,0x32 &environ"); - - asm ("mov____%ebp,%eax"); - asm ("add____$i8,%eax !8"); - asm ("push___%eax"); - - asm ("mov____%ebp,%eax"); - asm ("add____$i8,%eax !4"); - asm ("movzbl_(%eax),%eax"); - asm ("push___%eax"); - - _main (); - - asm ("mov____%eax,%ebx"); - asm ("mov____$i32,%eax %1"); - asm ("int____$0x80"); - asm ("hlt"); -} diff --git a/lib/linux/x86-mes/crti.c b/lib/linux/x86-mes/crti.c deleted file mode 100644 index e11c4684..00000000 --- a/lib/linux/x86-mes/crti.c +++ /dev/null @@ -1,19 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 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 . - */ diff --git a/lib/linux/x86-mes/crtn.c b/lib/linux/x86-mes/crtn.c deleted file mode 100644 index e11c4684..00000000 --- a/lib/linux/x86-mes/crtn.c +++ /dev/null @@ -1,19 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 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 . - */ diff --git a/lib/x86_64-mes/x86_64.M1 b/lib/x86_64-mes/x86_64.M1 index 70785ef9..99c46402 100644 --- a/lib/x86_64-mes/x86_64.M1 +++ b/lib/x86_64-mes/x86_64.M1 @@ -180,6 +180,7 @@ DEFINE setg___%dil 400f9fc7 DEFINE setge__%al 0f9dc0 DEFINE setge__%dil 400f9dc7 DEFINE setl___%al 0f9cc0 +DEFINE setl___%dil 400f9cc7 DEFINE setle__%al 0f9ec0 DEFINE setle__%dil 400f9ec7 DEFINE setne__%al 0f95c0 diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 48c5b1f6..39f6c465 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -286,12 +286,18 @@ (define (.c? o) (or (string-suffix? ".c" o) (string-suffix? ".M2" o))) -(define (.E? o) (string-suffix? ".E" o)) +(define (.E? o) (or (string-suffix? ".E" o) + (string-suffix? ".mes-E" o) + (string-suffix? ".x86-mes-E" o) + (string-suffix? ".x86_64-mes-E" o))) (define (.S? o) (or (string-suffix? ".S" o) (string-suffix? ".mes-S" o) + (string-suffix? ".x86-mes-S" o) + (string-suffix? ".x86_64-mes-S" o) (string-suffix? "S" o) (string-suffix? ".M1" o))) (define (.o? o) (or (string-suffix? ".o" o) (string-suffix? ".mes-o" o) - (string-suffix? "o" o) + (string-suffix? ".x86-mes-o" o) + (string-suffix? ".x86_64-mes-o" o) (string-suffix? ".hex2" o)))