diff --git a/.dir-locals.el b/.dir-locals.el index 5f81649c..3196ef88 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -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))) diff --git a/.gitignore b/.gitignore index e8f4d87c..69991eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/build-aux/build-lib.sh b/build-aux/build-lib.sh index fc0eb42e..073842ed 100755 --- a/build-aux/build-lib.sh +++ b/build-aux/build-lib.sh @@ -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 diff --git a/build-aux/build-scaffold.sh b/build-aux/build-scaffold.sh index d4251381..79f0e9f7 100755 --- a/build-aux/build-scaffold.sh +++ b/build-aux/build-scaffold.sh @@ -46,32 +46,83 @@ case "$mes_cpu" in stage0_cpu=$mes_cpu;; esac -trace "HEX2 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\ - --exec_enable\ - -o 0exit-42 +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-0exit-42.hex2\ + --exec_enable\ + -o 0exit-42 trace "TEST 0exit-42" { set +e; ./0exit-42; r=$?; set -e; } [ $r != 42 ] && echo " => $r" [ $r == 42 ] -trace "HEX2 exit-42.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-exit-42.hex2\ - -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\ - --exec_enable\ - -o exit-42 +trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.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-exit-42.hex2\ + -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\ + --exec_enable\ + -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 ] diff --git a/lib/x86-mes-gcc/exit-42.S b/lib/x86-mes-gcc/exit-42.S new file mode 100644 index 00000000..2ab7b170 --- /dev/null +++ b/lib/x86-mes-gcc/exit-42.S @@ -0,0 +1,46 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 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 . + */ + +/** 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. */ diff --git a/lib/x86-mes-gcc/hello-mes.S b/lib/x86-mes-gcc/hello-mes.S new file mode 100644 index 00000000..88b55fe8 --- /dev/null +++ b/lib/x86-mes-gcc/hello-mes.S @@ -0,0 +1,58 @@ +/* + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 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 . + */ + +/** 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 diff --git a/lib/x86-mes/elf-0footer.hex2 b/lib/x86-mes/elf-0footer.hex2 deleted file mode 100644 index 5f85a71a..00000000 --- a/lib/x86-mes/elf-0footer.hex2 +++ /dev/null @@ -1,26 +0,0 @@ -### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen -### 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 . - -### stage0's hex2 format for x86 -### !