porting: Add x86 scaffold: exit and write in assembly.
* lib/x86-mes-gcc/exit-42.S: New file. * lib/x86-mes-gcc/hello-mes.S: New file. * lib/x86-mes/elf32-0exit-42.hex2: New file. * lib/x86-mes/elf32-0hello-mes.hex2: New file. * lib/x86-mes/elf32-body-hello-mes.hex2: New file. * lib/x86-mes/elf32-body-exit-42.hex2: Rewrite. * lib/x86-mes/elf32-header.hex2: Fix copyright header. * lib/x86-mes/elf32-0header.hex2: Likewise. * lib/x86-mes/elf-0footer.hex2: Remove. * build-aux/build-scaffold.sh: Build them. * .dir-locals.el (asm-mode): Allow TABs. * .gitignore: Reserve .S assembly sources, i.e. manual written assembly. Update build system. * module/mescc/mescc.scm: Update. * build-aux/build-lib.sh: Update. * scripts/ar.in: Update.
This commit is contained in:
parent
502a203742
commit
fbe0b2eef8
|
@ -26,6 +26,7 @@
|
|||
(indent-tabs-mode . nil)))
|
||||
|
||||
(makefile-mode . ((indent-tabs-mode . t)))
|
||||
(asm-mode . ((indent-tabs-mode . t)))
|
||||
|
||||
(nil . ((indent-tabs-mode . nil)
|
||||
(fill-column . 72)))
|
||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -2,7 +2,7 @@
|
|||
*~
|
||||
.#*
|
||||
*.E
|
||||
*.S
|
||||
*.s
|
||||
*.blood-elf
|
||||
*.blood-elf-M1
|
||||
*.blood-elf-hex2
|
||||
|
@ -162,3 +162,9 @@
|
|||
/gcc-lib
|
||||
/mescc-lib
|
||||
/bin
|
||||
/0exit-42
|
||||
/0hello-mes
|
||||
/body-exit-42
|
||||
/body-hello-mes
|
||||
/exit-42
|
||||
/hello-mes
|
||||
|
|
|
@ -357,26 +357,26 @@ fi
|
|||
|
||||
archive libc-mini.a $libc_mini_SOURCES
|
||||
cp libc-mini.a $mes_cpu-mes
|
||||
if test -e libc-mini.S; then
|
||||
cp libc-mini.S $mes_cpu-mes
|
||||
if test -e libc-mini.s; then
|
||||
cp libc-mini.s $mes_cpu-mes
|
||||
fi
|
||||
|
||||
archive libmes.a $libmes_SOURCES
|
||||
cp libmes.a $mes_cpu-mes
|
||||
if test -e libmes.S; then
|
||||
cp libmes.S $mes_cpu-mes
|
||||
if test -e libmes.s; then
|
||||
cp libmes.s $mes_cpu-mes
|
||||
fi
|
||||
|
||||
archive libc.a $libc_SOURCES
|
||||
cp libc.a $mes_cpu-mes
|
||||
if test -e libc.S; then
|
||||
if test -e libc.s; then
|
||||
cp libc.S $mes_cpu-mes
|
||||
fi
|
||||
|
||||
archive libc+tcc.a $libc_tcc_SOURCES
|
||||
cp libc+tcc.a $mes_cpu-mes
|
||||
if test -e libc+tcc.S; then
|
||||
cp libc+tcc.S $mes_cpu-mes
|
||||
if test -e libc+tcc.s; then
|
||||
cp libc+tcc.s $mes_cpu-mes
|
||||
fi
|
||||
|
||||
if $courageous; then
|
||||
|
@ -385,18 +385,18 @@ fi
|
|||
|
||||
archive libc+gnu.a $libc_gnu_SOURCES
|
||||
cp libc+gnu.a $mes_cpu-mes
|
||||
if test -e libc+gnu.S; then
|
||||
cp libc+gnu.S $mes_cpu-mes
|
||||
if test -e libc+gnu.s; then
|
||||
cp libc+gnu.s $mes_cpu-mes
|
||||
fi
|
||||
|
||||
archive libtcc1.a $libtcc1_SOURCES
|
||||
cp libtcc1.a $mes_cpu-mes
|
||||
if test -e libtcc1.S; then
|
||||
cp libtcc1.S $mes_cpu-mes
|
||||
if test -e libtcc1.s; then
|
||||
cp libtcc1.s $mes_cpu-mes
|
||||
fi
|
||||
|
||||
archive libgetopt.a lib/posix/getopt.c
|
||||
cp libgetopt.a $mes_cpu-mes
|
||||
if test -e libgetopt.S; then
|
||||
cp libgetopt.S $mes_cpu-mes
|
||||
if test -e libgetopt.s; then
|
||||
cp libgetopt.s $mes_cpu-mes
|
||||
fi
|
||||
|
|
|
@ -46,13 +46,23 @@ case "$mes_cpu" in
|
|||
stage0_cpu=$mes_cpu;;
|
||||
esac
|
||||
|
||||
trace "HEX2 0exit-42.hex2" $HEX2\
|
||||
trace "CCLD ${srcdest}lib/$mes_cpu-mes-$compiler/exit-42.S" $CC\
|
||||
-nostdlib\
|
||||
-g\
|
||||
${srcdest}lib/$mes_cpu-mes-$compiler/exit-42.S\
|
||||
-o exit-42
|
||||
|
||||
trace "TEST exit-42"
|
||||
{ set +e; ./exit-42; r=$?; set -e; }
|
||||
[ $r != 42 ] && echo " => $r"
|
||||
[ $r == 42 ]
|
||||
|
||||
trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2" $HEX2\
|
||||
--LittleEndian\
|
||||
--architecture $stage0_cpu\
|
||||
--BaseAddress 0x1000000\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0header.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf-0footer.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2\
|
||||
--exec_enable\
|
||||
-o 0exit-42
|
||||
|
||||
|
@ -61,7 +71,7 @@ trace "TEST 0exit-42"
|
|||
[ $r != 42 ] && echo " => $r"
|
||||
[ $r == 42 ]
|
||||
|
||||
trace "HEX2 exit-42.hex2" $HEX2\
|
||||
trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2" $HEX2\
|
||||
--LittleEndian\
|
||||
--architecture $stage0_cpu\
|
||||
--BaseAddress 0x1000000\
|
||||
|
@ -69,9 +79,50 @@ trace "HEX2 exit-42.hex2" $HEX2\
|
|||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\
|
||||
--exec_enable\
|
||||
-o exit-42
|
||||
-o body-exit-42
|
||||
|
||||
trace "TEST exit-42"
|
||||
{ set +e; ./exit-42; r=$?; set -e; }
|
||||
trace "TEST body-exit-42"
|
||||
{ set +e; ./body-exit-42; r=$?; set -e; }
|
||||
[ $r != 42 ] && echo " => $r"
|
||||
[ $r == 42 ]
|
||||
|
||||
### FIXME: c&p from exit-42
|
||||
trace "CCLD ${srcdest}lib/$mes_cpu-mes-$compiler/hello-mes.S" $CC\
|
||||
-nostdlib\
|
||||
-g\
|
||||
${srcdest}lib/$mes_cpu-mes-$compiler/hello-mes.S\
|
||||
-o hello-mes
|
||||
|
||||
trace "TEST hello-mes"
|
||||
{ set +e; ./hello-mes; r=$?; set -e; }
|
||||
[ $r != 0 ] && echo " => $r"
|
||||
[ $r == 0 ]
|
||||
|
||||
trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2" $HEX2\
|
||||
--LittleEndian\
|
||||
--architecture $stage0_cpu\
|
||||
--BaseAddress 0x1000000\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0header.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2\
|
||||
--exec_enable\
|
||||
-o 0hello-mes
|
||||
|
||||
trace "TEST 0hello-mes"
|
||||
{ set +e; ./0hello-mes; r=$?; set -e; }
|
||||
[ $r != 0 ] && echo " => $r"
|
||||
[ $r == 0 ]
|
||||
|
||||
trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2" $HEX2\
|
||||
--LittleEndian\
|
||||
--architecture $stage0_cpu\
|
||||
--BaseAddress 0x1000000\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-header.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2\
|
||||
-f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\
|
||||
--exec_enable\
|
||||
-o body-hello-mes
|
||||
|
||||
trace "TEST body-hello-mes"
|
||||
{ set +e; ./body-hello-mes; r=$?; set -e; }
|
||||
[ $r != 0 ] && echo " => $r"
|
||||
[ $r == 0 ]
|
||||
|
|
46
lib/x86-mes-gcc/exit-42.S
Normal file
46
lib/x86-mes-gcc/exit-42.S
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 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/>.
|
||||
*/
|
||||
|
||||
/** Commentary: */
|
||||
|
||||
/* Using gdb, esp. GUD in GNU Emacs is recommended
|
||||
M-x gdb-display-disassembly-buffer
|
||||
M-x gdb-display-io-buffer
|
||||
set disassemble-next-line on
|
||||
break _start
|
||||
run
|
||||
info registers
|
||||
si
|
||||
p/x $eax
|
||||
RET
|
||||
...
|
||||
*/
|
||||
|
||||
/** Code: */
|
||||
|
||||
SYS_exit = 1 /* Linux syscall: exit. */
|
||||
.globl _start /* Magic linker symbol: --entry-address. */
|
||||
|
||||
.text /* Program text. */
|
||||
_start:
|
||||
mov $SYS_exit,%eax /* System call function: exit, in %eax. */
|
||||
mov $42,%ebx /* First parameter: exit status, in %ebx. */
|
||||
int $0x80 /* Call system. */
|
||||
hlt /* Should not be reached. */
|
58
lib/x86-mes-gcc/hello-mes.S
Normal file
58
lib/x86-mes-gcc/hello-mes.S
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 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/>.
|
||||
*/
|
||||
|
||||
/** Commentary: */
|
||||
|
||||
/* Using gdb, esp. GUD in GNU Emacs is recommended
|
||||
M-x gdb-display-disassembly-buffer
|
||||
M-x gdb-display-io-buffer
|
||||
set disassemble-next-line on
|
||||
break _start
|
||||
run
|
||||
info registers
|
||||
si
|
||||
p/x $eax
|
||||
RET
|
||||
...
|
||||
*/
|
||||
|
||||
/** Code: */
|
||||
|
||||
SYS_exit = 1 /* Linux syscalls. */
|
||||
SYS_write = 4
|
||||
stdout = 1 /* File discriptor */
|
||||
.globl _start /* Magic linker symbol: --entry-address. */
|
||||
|
||||
.text /* Program text. */
|
||||
_start:
|
||||
mov $SYS_write,%eax /* System call function: write, in %eax. */
|
||||
mov $stdout,%ebx /* 1st parameter: file descriptor, in %ebx. */
|
||||
mov $hello,%ecx /* 2nd parameter: address, in %ecx. */
|
||||
mov $(bye-hello),%edx /* 3rd parameter: byte count %edx. */
|
||||
int $0x80 /* Call system. */
|
||||
|
||||
mov $SYS_exit,%eax /* System call function: exit, in %eax. */
|
||||
mov $0,%ebx /* 1st parameter: exit status, in %ebx. */
|
||||
int $0x80 /* Call system. */
|
||||
hlt /* Should not be reached. */
|
||||
|
||||
.data
|
||||
hello: .ascii "Hello, GNU Mes!\n"
|
||||
bye: .byte 0
|
|
@ -1,26 +0,0 @@
|
|||
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### This file is part of stage0.
|
||||
###
|
||||
### stage0 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.
|
||||
###
|
||||
### 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
|
||||
### !<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
|
34
lib/x86-mes/elf32-0exit-42.hex2
Normal file
34
lib/x86-mes/elf32-0exit-42.hex2
Normal file
|
@ -0,0 +1,34 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2019 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/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-exit-42.hex2: `exit 42' for i686-linux written in hex2 assembly,
|
||||
# for usage with elf32-0header.hex2. This produces a 112-byte binary
|
||||
# (70 hex). Inspiration was taken from GNU Gcc output of exit-42.S.
|
||||
|
||||
### Code:
|
||||
|
||||
# @60
|
||||
:ELF_text
|
||||
b8 01 00 00 00 # mov $1, %eax
|
||||
bb 2a 00 00 00 # mov $42, %ebx
|
||||
cd 80 # int $0x80
|
||||
f4 # hlt
|
||||
00 00 00 # align to @70
|
||||
:ELF_end
|
|
@ -1,30 +1,36 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### This file is part of stage0.
|
||||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
###
|
||||
### stage0 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.
|
||||
### This file is part of GNU Mes.
|
||||
###
|
||||
### stage0 is distributed in the hope that it will be useful,
|
||||
### but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
### stage0's hex2 format for x86
|
||||
### !<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>
|
||||
### Commentary:
|
||||
|
||||
### elf32-header-exit-42.hex2: 32 bit elf header in hex2 for `exit 42'
|
||||
# elf32-0header.hex2: Simplest 32 bit elf header in hex2. Only a text
|
||||
# segment, no data segment, no symbol tables.
|
||||
|
||||
# stage0's hex2 format for x86
|
||||
# !<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>
|
||||
|
||||
### Code:
|
||||
|
||||
:ELF_base
|
||||
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||
|
@ -75,4 +81,5 @@
|
|||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
01 00 00 00 # ph_align
|
||||
|
||||
# @60
|
||||
:ELF_text
|
||||
|
|
53
lib/x86-mes/elf32-0hello-mes.hex2
Normal file
53
lib/x86-mes/elf32-0hello-mes.hex2
Normal file
|
@ -0,0 +1,53 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2019 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/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-0hello-mes.hex2: `Hello, GNU Mes!' for i686-linux written in
|
||||
# hex2 assembly, for usage with elf32-0header.hex2. This produces a
|
||||
# 160-byte binary (a0 hex). Inspiration was taken from GNU Gcc output
|
||||
# of hello-mes.S.
|
||||
|
||||
### Code:
|
||||
|
||||
# @60
|
||||
:ELF_text
|
||||
|
||||
# print <hello>
|
||||
b8 04 00 00 00 # mov $4,%eax
|
||||
bb 00 00 00 00 # mov $1,%ebx
|
||||
b9 &hello # mov $hello,%ecx
|
||||
ba %bye>hello # mov $(bye-hello),%edx
|
||||
cd 80 # int $0x80
|
||||
|
||||
# exit 0
|
||||
b8 01 00 00 00 # mov $1,%eax
|
||||
bb 00 00 00 00 # mov $0,%ebx
|
||||
cd 80 # int $0x80
|
||||
f4 # hlt
|
||||
|
||||
00 00 00 00 00 00 00 00 00 00 # align to @90
|
||||
00 00 00
|
||||
|
||||
# @90
|
||||
:ELF_data
|
||||
:hello
|
||||
48 65 6c 6c 6f 2c 20 47 # Hello, G
|
||||
4e 55 20 4d 65 73 21 0a # NU Mes!\n
|
||||
:bye
|
||||
:ELF_end
|
|
@ -1,34 +1,35 @@
|
|||
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### This file is part of stage0.
|
||||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
###
|
||||
### stage0 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.
|
||||
### This file is part of GNU Mes.
|
||||
###
|
||||
### stage0 is distributed in the hope that it will be useful,
|
||||
### but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
### stage0's hex2 format for x86
|
||||
### !<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>
|
||||
### Commentary:
|
||||
|
||||
### elf32-body-exit-42.hex2: 32 bit elf body in hex2 for `exit 42'
|
||||
# elf32-body-exit-42.hex2: `exit 42' for i686-linux written in hex2
|
||||
# assembly, for usage with generic elf32-header.hex2 and
|
||||
# elf32-footer-single-main.hex.
|
||||
|
||||
# This ELF binary contains a symbol table, which means that objdump and
|
||||
# gdb can be used to inspect and debug.
|
||||
|
||||
### Code:
|
||||
|
||||
# @200
|
||||
:ELF_text
|
||||
:_start
|
||||
# exit(42)
|
||||
e8 %main # call +11 <main>
|
||||
00 00 00
|
||||
00 00 00 00
|
||||
|
@ -39,9 +40,11 @@ e8 %main # call +11 <main>
|
|||
bb 2a 00 00 00 # mov $42,%ebx
|
||||
b8 01 00 00 00 # mov $0x1,%eax
|
||||
cd 80 # int $0x80
|
||||
f4 # hlt
|
||||
|
||||
00 00 00 00
|
||||
00 00 00 # align
|
||||
|
||||
# @220
|
||||
:ELF_data
|
||||
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"
|
||||
00
|
||||
|
|
63
lib/x86-mes/elf32-body-hello-mes.hex2
Normal file
63
lib/x86-mes/elf32-body-hello-mes.hex2
Normal file
|
@ -0,0 +1,63 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2019 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/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-body-hello-mes.hex2: `Hello, GNU Mes!' for i686-linux written in
|
||||
# hex2 assembly, for usage with generic elf32-header.hex2 and
|
||||
# elf32-footer-single-main.hex.
|
||||
|
||||
# This ELF binary contains a symbol table which means that objdump and
|
||||
# gdb can be used to inspect and debug.
|
||||
|
||||
### Code:
|
||||
|
||||
# @200
|
||||
:ELF_text
|
||||
:_start
|
||||
e8 %main # call +11 <main>
|
||||
00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @210
|
||||
:main
|
||||
# print <hello>
|
||||
b8 04 00 00 00 # mov $4, %eax
|
||||
bb 00 00 00 00 # mov $1, %ebx
|
||||
b9 &hello # mov $hello,%ecx
|
||||
ba %bye>hello # mov $(bye-hello),%edx
|
||||
cd 80 # int $0x80
|
||||
|
||||
# exit 0
|
||||
b8 01 00 00 00 # mov $0x1,%eax
|
||||
bb 00 00 00 00 # mov $0,%ebx
|
||||
cd 80 # int $0x80
|
||||
f4 # hlt
|
||||
|
||||
00 00 00 00 00 00 00 00 00 00 # align to @240
|
||||
00 00 00
|
||||
|
||||
# @240
|
||||
:ELF_data
|
||||
:hello
|
||||
48 65 6c 6c 6f 2c 20 47 # Hello, G
|
||||
4e 55 20 4d 65 73 21 0a # NU Mes!\n
|
||||
|
||||
:bye
|
||||
00
|
|
@ -1,30 +1,36 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### This file is part of stage0.
|
||||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
###
|
||||
### stage0 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.
|
||||
### This file is part of GNU Mes.
|
||||
###
|
||||
### stage0 is distributed in the hope that it will be useful,
|
||||
### but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
### stage0's hex2 format for x86
|
||||
### !<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>
|
||||
### Commentary:
|
||||
|
||||
### elf32-header-exit-42.hex2: 32 bit elf header in hex2 for `exit 42'
|
||||
# elf32-header.hex2: 32 bit elf header in hex2, with text segment, data
|
||||
# segment and symbol tables.
|
||||
|
||||
# stage0's hex2 format for x86
|
||||
# !<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>
|
||||
|
||||
### Code:
|
||||
|
||||
:ELF_base
|
||||
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
(input-file-name (car files))
|
||||
(M1-file-name (cond ((and (option-ref options 'compile #f)
|
||||
(option-ref options 'output #f)))
|
||||
(else (replace-suffix input-file-name ".S"))))
|
||||
(else (replace-suffix input-file-name ".s"))))
|
||||
(infos (map (cut file->info options <>) files))
|
||||
(verbose? (option-ref options 'verbose #f))
|
||||
(align? (option-ref options 'align #f)))
|
||||
|
@ -101,14 +101,14 @@
|
|||
(hex2-file-name (cond ((and (option-ref options 'assemble #f)
|
||||
(option-ref options 'output #f)))
|
||||
(else (replace-suffix input-file-name ".o"))))
|
||||
(S-files (filter .S? files))
|
||||
(s-files (filter .s? files))
|
||||
(hex2-files M1->hex2 ) ;; FIXME
|
||||
(source-files (filter (disjoin .c? .E?) files))
|
||||
(infos (map (cut file->info options <>) source-files)))
|
||||
(if (and (pair? S-files) (pair? infos))
|
||||
(error "mixing source and object not supported:" source-files S-files))
|
||||
(when (pair? S-files)
|
||||
(M1->hex2 options S-files))
|
||||
(if (and (pair? s-files) (pair? infos))
|
||||
(error "mixing source and object not supported:" source-files s-files))
|
||||
(when (pair? s-files)
|
||||
(M1->hex2 options s-files))
|
||||
(when (pair? infos)
|
||||
(infos->hex2 options hex2-file-name infos))
|
||||
hex2-file-name))
|
||||
|
@ -116,17 +116,17 @@
|
|||
(define (mescc:link options)
|
||||
(let* ((files (option-ref options '() '("a.c")))
|
||||
(source-files (filter (disjoin .c? .E?) files))
|
||||
(S-files (filter .S? files))
|
||||
(s-files (filter .s? files))
|
||||
(o-files (filter .o? files))
|
||||
(input-file-name (car files))
|
||||
(hex2-file-name (if (or (string-suffix? ".hex2" input-file-name)
|
||||
(string-suffix? ".o" input-file-name)) input-file-name
|
||||
(replace-suffix input-file-name ".o")))
|
||||
(infos (map (cut file->info options <>) source-files))
|
||||
(S-files (filter .S? files))
|
||||
(s-files (filter .s? files))
|
||||
(hex2-files (filter .o? files))
|
||||
(hex2-files (if (null? S-files) hex2-files
|
||||
(append hex2-files (list (M1->hex2 options S-files)))))
|
||||
(hex2-files (if (null? s-files) hex2-files
|
||||
(append hex2-files (list (M1->hex2 options s-files)))))
|
||||
(hex2-files (if (null? infos) hex2-files
|
||||
(append hex2-files
|
||||
(list (infos->hex2 options hex2-file-name infos)))))
|
||||
|
@ -137,18 +137,18 @@
|
|||
(libraries (delete-duplicates (append libraries default-libraries)))
|
||||
(hex2-libraries (map (cut find-library options ".a" <>) libraries))
|
||||
(hex2-files (append hex2-files hex2-libraries))
|
||||
(S-files (append S-files (map (cut find-library options ".S" <>) libraries)))
|
||||
(s-files (append s-files (map (cut find-library options ".s" <>) libraries)))
|
||||
(debug-info? (option-ref options 'debug-info #f))
|
||||
(S-files (cons (replace-suffix input-file-name ".S") S-files))
|
||||
(s-files (cons (replace-suffix input-file-name ".s") s-files))
|
||||
(elf-footer (and debug-info?
|
||||
(or (M1->blood-elf options S-files)
|
||||
(or (M1->blood-elf options s-files)
|
||||
(exit 1)))))
|
||||
(or (hex2->elf options hex2-files #:elf-footer elf-footer)
|
||||
(exit 1))))
|
||||
|
||||
(define (infos->hex2 options hex2-file-name infos)
|
||||
(let* ((input-file-name (car (option-ref options '() '("a.c"))))
|
||||
(M1-file-name (replace-suffix hex2-file-name ".S"))
|
||||
(M1-file-name (replace-suffix hex2-file-name ".s"))
|
||||
(options (acons 'compile #t options)) ; ugh
|
||||
(options (acons 'output hex2-file-name options))
|
||||
(verbose? (option-ref options 'verbose #f))
|
||||
|
@ -328,12 +328,12 @@
|
|||
(string-suffix? ".arm-mes-E" o)
|
||||
(string-suffix? ".x86-mes-E" o)
|
||||
(string-suffix? ".x86_64-mes-E" o)))
|
||||
(define (.S? o) (or (string-suffix? ".S" o)
|
||||
(define (.s? o) (or (string-suffix? ".s" o)
|
||||
(string-suffix? ".S" o)
|
||||
(string-suffix? ".mes-S" o)
|
||||
(string-suffix? ".arm-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)
|
||||
|
|
|
@ -26,11 +26,11 @@ command=$1
|
|||
archive=$2
|
||||
shift
|
||||
shift
|
||||
M1_archive=$(dirname "$archive")/$(basename "$archive" .a).S
|
||||
M1_archive=$(dirname "$archive")/$(basename "$archive" .a).s
|
||||
declare -a M1_objects
|
||||
for o in "$@"; do
|
||||
((i++))
|
||||
M1_objects[$i]=$(dirname "$o")/$(basename "$o" .o).S
|
||||
M1_objects[$i]=$(dirname "$o")/$(basename "$o" .o).s
|
||||
done
|
||||
cat "${M1_objects[@]}" > "$M1_archive"
|
||||
cat "$@" > "$archive"
|
||||
|
|
Loading…
Reference in a new issue