bootstrap.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #! /usr/bin/env bash
  2. ## Copyright (C) 2017 Jeremiah Orians
  3. ## This file is part of M2-Planet.
  4. ##
  5. ## M2-Planet is free software: you can redistribute it and/or modify
  6. ## it under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation, either version 3 of the License, or
  8. ## (at your option) any later version.
  9. ##
  10. ## M2-Planet is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ## GNU General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  17. set -eux
  18. stage0_PREFIX=${stage0_PREFIX-../stage0}
  19. [ -e bin/M2-Planet ] && rm bin/M2-Planet
  20. # Refresh stage0's M2-Planet_x86.c
  21. # To execute this block ./bootstrap.sh refresh
  22. if [ "refresh" = "${1-NOPE}" ]
  23. then
  24. # Create header to prevent confusion
  25. {
  26. cat <<-EOF
  27. ## This file was generated by running:
  28. ## cat functions/file.c functions/malloc.c functions/calloc.c functions/exit.c functions/match.c -f functions/in_set.c functions/numerate_number.c functions/file_print.c functions/string.c cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c >| ../stage0/stage3/M2-Planet_x86.c
  29. ## inside M2-Planet's repo
  30. EOF
  31. } >| header
  32. # Update the C code in stage0's x86 bootstrap
  33. cat header \
  34. functions/file.c \
  35. functions/malloc.c \
  36. functions/calloc.c \
  37. functions/exit.c \
  38. functions/match.c \
  39. functions/in_set.c \
  40. functions/numerate_number.c \
  41. functions/file_print.c \
  42. functions/string.c \
  43. cc.h \
  44. cc_reader.c \
  45. cc_strings.c \
  46. cc_types.c \
  47. cc_core.c \
  48. cc.c >| $stage0_PREFIX/stage3/M2-Planet_x86.c
  49. # Clean up temp header
  50. rm header
  51. {
  52. # Create header to prevent confusion
  53. cat <<-EOF
  54. # This file was generated by running:
  55. # ./bin/vm --rom roms/cc_x86 --memory 4M --tape_01 stage3/M2-Planet_x86.c --tape_02 ../M2-Planet/seed.M1
  56. # In stage0
  57. EOF
  58. } >| preseed1
  59. # Create the seed
  60. $stage0_PREFIX/bin/vm --rom $stage0_PREFIX/roms/cc_x86 \
  61. --memory 4M \
  62. --tape_01 $stage0_PREFIX/stage3/M2-Planet_x86.c \
  63. --tape_02 preseed2
  64. # Combine to final seed
  65. cat preseed1 preseed2 >| seed.M1
  66. # Cleanup preseed values
  67. rm preseed1 preseed2
  68. fi
  69. # Make the required bin directry
  70. [ -d bin ] || mkdir bin
  71. # Build debug footer
  72. blood-elf -f seed.M1 \
  73. -o bin/seed-footer.M1 || exit 1
  74. # Macro assemble with libc written in M1-Macro
  75. M1 -f test/common_x86/x86_defs.M1 \
  76. -f test/common_x86/libc-core.M1 \
  77. -f seed.M1 \
  78. -f bin/seed-footer.M1 \
  79. --LittleEndian \
  80. --architecture x86 \
  81. -o bin/seed.hex2 || exit 2
  82. # Resolve all linkages
  83. hex2 -f test/common_x86/ELF-i386-debug.hex2 \
  84. -f bin/seed.hex2 \
  85. --LittleEndian \
  86. --architecture x86 \
  87. --BaseAddress 0x8048000 \
  88. -o bin/M2-Planet-seed \
  89. --exec_enable || exit 2
  90. # self-host
  91. ./test/test100/hello-x86.sh