From 521f97dfb3e82bf358938189b7d4d9909f7427d5 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 10 Aug 2018 11:15:43 +0200 Subject: [PATCH] mescc: Initial x86_64-mes scaffold. * build-aux/GNUmakefile.in (x86_64-mes): New target. * .gitignore: Ignore x86 and x86_64 out files. * build-aux/build-mes.sh: Resurrect three initial exit42 scaffold tests. * build-aux/build-x86_64-mes.sh: New file. Add initial exit42 scaffold test. * lib/x86-mes/elf32-0header.hex2: Fix comment. * lib/x86-mes/elf32-header.hex2: Likewise. * lib/x86_64-mes/elf-0footer.hex2: New file. * lib/x86_64-mes/elf64-0header.hex2: New file. * lib/x86_64-mes/elf64-body-exit-42.hex2: New file. * lib/x86_64-mes/exit-42.c: New file. --- .gitignore | 9 +- build-aux/GNUmakefile.in | 3 + build-aux/build-mes.sh | 39 +++++- build-aux/build-x86_64-mes.sh | 159 +++++++++++++++++++++++++ build-aux/cc-mes.sh | 2 +- lib/x86-mes/elf32-0header.hex2 | 2 +- lib/x86-mes/elf32-body-exit-42.hex2 | 1 - lib/x86-mes/elf32-header.hex2 | 2 +- lib/x86_64-mes/elf-0footer.hex2 | 26 ++++ lib/x86_64-mes/elf64-0header.hex2 | 78 ++++++++++++ lib/x86_64-mes/elf64-body-exit-42.hex2 | 47 ++++++++ lib/x86_64-mes/exit-42.c | 30 +++++ 12 files changed, 390 insertions(+), 8 deletions(-) create mode 100755 build-aux/build-x86_64-mes.sh create mode 100644 lib/x86_64-mes/elf-0footer.hex2 create mode 100644 lib/x86_64-mes/elf64-0header.hex2 create mode 100644 lib/x86_64-mes/elf64-body-exit-42.hex2 create mode 100644 lib/x86_64-mes/exit-42.c diff --git a/.gitignore b/.gitignore index 7c208c5d..beb36099 100644 --- a/.gitignore +++ b/.gitignore @@ -19,14 +19,14 @@ *.mes-gcc-out *.mes-gcc-out *.mes-gcc-stdout +*.mes-o +*.mes-out +*.mes-stdout *.mes-tcc *.mes-tcc-o *.mes-tcc-out *.mes-tcc-out *.mes-tcc-stdout -*.mes-o -*.mes-out -*.mes-stdout *.mini-M1 *.mini-guile *.mini-hex2 @@ -34,6 +34,9 @@ *.seed-out *.stderr *.stdout +*.x86-out +*.x86_64-mes-out +*.x86_64-out /lib/x86-mes-gcc /lib/x86-mes-tcc diff --git a/build-aux/GNUmakefile.in b/build-aux/GNUmakefile.in index 607a5a07..8965b925 100644 --- a/build-aux/GNUmakefile.in +++ b/build-aux/GNUmakefile.in @@ -101,6 +101,9 @@ endif mes: ${srcdest}build-aux/build-mes.sh +x86_64-mes: + ${srcdest}build-aux/build-x86_64-mes.sh + clean: git clean -dfx\ -e GNUmakefile\ diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 99fc0f3c..8517d2c8 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -32,6 +32,34 @@ MES=${MES-$(command -v mes)} set -e +trace "HEX2 0exit-42" $HEX2\ + --LittleEndian\ + --Architecture 1\ + --BaseAddress 0x1000000\ + -f ${srcdest}lib/x86-mes/elf32-0header.hex2\ + -f ${srcdest}lib/x86-mes/elf32-body-exit-42.hex2\ + -f ${srcdest}lib/x86-mes/elf-0footer.hex2\ + --exec_enable\ + -o lib/x86-mes/0exit-42.x86-out + +trace "TEST 0exit-42" +{ set +e; lib/x86-mes/0exit-42.x86-out; r=$?; set -e; } +[ $r != 42 ] && echo " => $r" && exit 1 + +trace "HEX2 0exit-42" $HEX2\ + --LittleEndian\ + --Architecture 1\ + --BaseAddress 0x1000000\ + -f ${srcdest}lib/x86-mes/elf32-header.hex2\ + -f ${srcdest}lib/x86-mes/elf32-body-exit-42.hex2\ + -f ${srcdest}lib/x86-mes/elf32-footer-single-main.hex2\ + --exec_enable\ + -o lib/x86-mes/exit-42.x86-out + +trace "TEST exit-42" +{ set +e; lib/x86-mes/exit-42.x86-out; r=$?; set -e; } +[ $r != 42 ] && echo " => $r" && exit 1 + if [ -d "$MES_SEED" ]; then mkdir -p lib/x86-mes trace "M1 crt1.S" $M1\ @@ -87,15 +115,24 @@ fi MES_ARENA=100000000 ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crt0 +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc-mini + +PREPROCESS= bash ${srcdest}build-aux/cc-mes.sh lib/x86-mes/exit-42 + +trace "TEST exit-42.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/crt1 ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crti ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crtn -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc-mini + 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/libgetopt 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 + [ -n "$SEED" ] && exit 0 MES_ARENA=${MES_ARENA-100000000} diff --git a/build-aux/build-x86_64-mes.sh b/build-aux/build-x86_64-mes.sh new file mode 100755 index 00000000..2144f812 --- /dev/null +++ b/build-aux/build-x86_64-mes.sh @@ -0,0 +1,159 @@ +#! /bin/sh + +# 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 . + +. ${srcdest}build-aux/config.sh +. ${srcdest}build-aux/trace.sh + +GUILE=${GUILE-guile} +if [ -z "$GUILE" -o "$GUILE" = "true" ] || ! command -v $GUILE > /dev/null; then + GUILE=src/mes +fi + +[ -z "$MESCC" ] && MESCC=scripts/mescc +MES=${MES-$(command -v mes)} +[ -z "$MES" ] && MES=src/mes + +set -e + +trace "HEX2 0exit-42" $HEX2\ + --LittleEndian\ + --Architecture 2\ + --BaseAddress 0x1000000\ + -f ${srcdest}lib/x86_64-mes/elf64-0header.hex2\ + -f ${srcdest}lib/x86_64-mes/elf64-body-exit-42.hex2\ + -f ${srcdest}lib/x86_64-mes/elf-0footer.hex2\ + --exec_enable\ + -o lib/x86_64-mes/0exit-42.x86_64-out + +trace "TEST 0exit-42" +{ set +e; lib/x86_64-mes/0exit-42.x86_64-out; r=$?; set -e; } +[ $r != 42 ] && echo " => $r" && exit 1 + +# trace "HEX2 0exit-42" $HEX2\ +# --LittleEndian\ +# --Architecture 2\ +# --BaseAddress 0x1000000\ +# -f ${srcdest}lib/x86_64-mes/elf64-header.hex2\ +# -f ${srcdest}lib/x86_64-mes/elf64-body-exit-42.hex2\ +# -f ${srcdest}lib/x86_64-mes/elf64-footer-single-main.hex2\ +# --exec_enable\ +# -o lib/x86_64-mes/exit-42.x86_64-out + +# trace "TEST 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 + +# PREPROCESS=1 +# if [ ! -d "$MES_SEED" ] \ +# && [ "$ARCH" = "i386" \ +# -o "$ARCH" = "i586" \ +# -o "$ARCH" = "i686" ]; then +# MES_ARENA=100000000 +# fi + +# MES_ARENA=100000000 +# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crt0 +# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc-mini + +# PREPROCESS= bash ${srcdest}build-aux/cc-mes.sh lib/x86_64-mes/exit-42 + +# trace "TEST 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-mes.sh lib/linux/crt1 +# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crti +# ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/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/libgetopt +# 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 + + +# [ -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 + +# echo MES_ARENA=$MES_ARENA +# bash ${srcdest}build-aux/cc-mes.sh scaffold/main + +# bash ${srcdest}build-aux/cc-mes.sh scaffold/main +# bash ${srcdest}build-aux/cc-mes.sh scaffold/hello +# bash ${srcdest}build-aux/cc-mes.sh scaffold/argv +# bash ${srcdest}build-aux/cc-mes.sh scaffold/malloc +# ##sh ${srcdest}build-aux/cc-mes.sh scaffold/micro-mes +# ##sh ${srcdest}build-aux/cc-mes.sh scaffold/tiny-mes +# # bash ${srcdest}build-aux/cc-mes.sh scaffold/mini-mes +# bash ${srcdest}build-aux/cc-mes.sh src/mes +# cp src/mes.mes-out src/mes +true diff --git a/build-aux/cc-mes.sh b/build-aux/cc-mes.sh index aa300902..c6f53a2b 100755 --- a/build-aux/cc-mes.sh +++ b/build-aux/cc-mes.sh @@ -61,7 +61,7 @@ elif [ -n "$COMPILE" ]; then trace "MESLD $c.o" ./pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS fi elif [ -z "$NOLINK" ]; then - trace "MESLD $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "${srcdest}$c".c $MES_LIBS + trace "MESCC $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "${srcdest}$c".c $MES_LIBS else trace "MESCC $c.c" ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -c -o "$o".${p}o "${srcdest}$c".c fi diff --git a/lib/x86-mes/elf32-0header.hex2 b/lib/x86-mes/elf32-0header.hex2 index 36e584a1..ec279620 100644 --- a/lib/x86-mes/elf32-0header.hex2 +++ b/lib/x86-mes/elf32-0header.hex2 @@ -39,7 +39,7 @@ 00 00 00 00 00 00 00 # e_ident[EI_PAD] 02 00 # e_type Indicating Executable -03 00 # e_machine Indicating AMD64 +03 00 # e_machine Indicating 32bit x86 01 00 00 00 # e_version Indicating original elf &ELF_text # e_entry Address of the entry point diff --git a/lib/x86-mes/elf32-body-exit-42.hex2 b/lib/x86-mes/elf32-body-exit-42.hex2 index 130f69b0..b884ec3d 100644 --- a/lib/x86-mes/elf32-body-exit-42.hex2 +++ b/lib/x86-mes/elf32-body-exit-42.hex2 @@ -45,4 +45,3 @@ cd 80 # int $0x80 # @220 :ELF_data 65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here" - diff --git a/lib/x86-mes/elf32-header.hex2 b/lib/x86-mes/elf32-header.hex2 index 406457e3..28f5a4c4 100644 --- a/lib/x86-mes/elf32-header.hex2 +++ b/lib/x86-mes/elf32-header.hex2 @@ -39,7 +39,7 @@ 00 00 00 00 00 00 00 # e_ident[EI_PAD] 02 00 # e_type Indicating Executable -03 00 # e_machine Indicating AMD64 +03 00 # e_machine Indicating 32bit x86 01 00 00 00 # e_version Indicating original elf &ELF_text # e_entry Address of the entry point diff --git a/lib/x86_64-mes/elf-0footer.hex2 b/lib/x86_64-mes/elf-0footer.hex2 new file mode 100644 index 00000000..28a2fa07 --- /dev/null +++ b/lib/x86_64-mes/elf-0footer.hex2 @@ -0,0 +1,26 @@ +### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen +### This file is part of stage0. +### +### stage0 is free software: you an 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. +### +### stage0 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 stage0. If not, see . + +### stage0's hex2 format for x86_64 +### !