hello-x86.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #! /bin/sh
  2. ## Copyright (C) 2017 Jeremiah Orians
  3. ## Copyright (C) 2021 deesix <deesix@tuta.io>
  4. ## This file is part of M2-Planet.
  5. ##
  6. ## M2-Planet is free software: you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation, either version 3 of the License, or
  9. ## (at your option) any later version.
  10. ##
  11. ## M2-Planet is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  18. set -x
  19. TMPDIR="test/test0008/tmp-x86"
  20. mkdir -p ${TMPDIR}
  21. # Build the test
  22. bin/M2-Planet \
  23. --architecture x86 \
  24. -f M2libc/x86/Linux/unistd.h \
  25. -f M2libc/stdlib.c \
  26. -f M2libc/x86/Linux/fcntl.h \
  27. -f M2libc/stdio.c \
  28. -f test/test0008/struct.c \
  29. --debug \
  30. -o ${TMPDIR}/struct.M1 \
  31. || exit 1
  32. # Build debug footer
  33. blood-elf \
  34. -f ${TMPDIR}/struct.M1 \
  35. --entry _start \
  36. -o ${TMPDIR}/struct-footer.M1 \
  37. || exit 2
  38. # Macro assemble with libc written in M1-Macro
  39. M1 \
  40. -f M2libc/x86/x86_defs.M1 \
  41. -f M2libc/x86/libc-full.M1 \
  42. -f ${TMPDIR}/struct.M1 \
  43. -f ${TMPDIR}/struct-footer.M1 \
  44. --LittleEndian \
  45. --architecture x86 \
  46. -o ${TMPDIR}/struct.hex2 \
  47. || exit 2
  48. # Resolve all linkages
  49. hex2 \
  50. -f test/common_x86/ELF-i386-debug.hex2 \
  51. -f ${TMPDIR}/struct.hex2 \
  52. --LittleEndian \
  53. --architecture x86 \
  54. --BaseAddress 0x8048000 \
  55. -o test/results/test0008-x86-binary \
  56. --exec_enable \
  57. || exit 3
  58. # Ensure binary works if host machine supports test
  59. if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ]
  60. then
  61. # Verify that the compiled program returns the correct result
  62. out=$(./test/results/test0008-x86-binary 2>&1 )
  63. [ 16 = $? ] || exit 4
  64. [ "$out" = "35419896642975313541989657891634" ] || exit 5
  65. fi
  66. exit 0