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.
This commit is contained in:
Jan Nieuwenhuizen 2018-08-10 11:15:43 +02:00
parent 959525330c
commit 521f97dfb3
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
12 changed files with 390 additions and 8 deletions

9
.gitignore vendored
View File

@ -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

View File

@ -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\

View File

@ -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}

159
build-aux/build-x86_64-mes.sh Executable file
View File

@ -0,0 +1,159 @@
#! /bin/sh
# 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/>.
. ${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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -0,0 +1,26 @@
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### 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 <http://www.gnu.org/licenses/>.
### stage0's hex2 format for x86_64
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
:ELF_end

View File

@ -0,0 +1,78 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### 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 <http://www.gnu.org/licenses/>.
### stage0's hex2 format for x86_64
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
00 # e_ident[EI_OSABI] Set at 0 because none cares
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
3E 00 # e_machine Indicating AMD64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base # e_phoff Address of program header table
00 00 00 00
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
# @34
00 00 00 00
00 00 00 00
00 00 00 00
# @40
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # p_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text

View File

@ -0,0 +1,47 @@
### Copyright (C) 2017, 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### 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 <http://www.gnu.org/licenses/>.
### stage0's hex2 format for x86_64
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
### elf64-body-exit-42.hex2: 64 bit elf body in hex2 for `exit 42'
# @200
:ELF_text
:_start
# exit(42)
e8 %main # callq +11 <main>
00 00 00
00 00 00 00
00 00 00 00
# @210
:main
48 c7 c7 2a 00 00 00 # mov $42,%rdi
48 c7 c0 3c 00 00 00 # mov $0x3c,%rax
0f 05 # syscall
00 00 00 00
# @220
:ELF_data
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"

30
lib/x86_64-mes/exit-42.c Normal file
View File

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 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/>.
*/
int
main (int argc, char *argv[])
{
#if 1
asm ("mov $00,%rdi");
asm ("mov $0x3c,%rax");
asm ("syscall");
#endif
return 42;
}