main.g 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. const RUN_ASM 0
  15. const RUN_FASM 0
  16. const RUN_C 0
  17. const RUN_MESCC 0
  18. const RUN_MCPP 0
  19. const RUN_TINYCC 0
  20. const TEST_C 1
  21. const USE_TRIVIAL_MALLOC 0
  22. const USE_SIMPLE_MALLOC 0
  23. const USE_CHECKED_MALLOC 0
  24. const USE_KMALLOC 1
  25. const USE_SIMPLE_MAP 0
  26. const USE_AVL_MAP 1
  27. fun main 0 {
  28. "Hello, G!\n" 1 platform_log ;
  29. "Memory break after entering main: " 1 platform_log ;
  30. 0 platform_allocate itoa 1 platform_log ;
  31. "\n" 1 platform_log ;
  32. "Compiling utils.g... " 1 platform_log ;
  33. "utils.g" platform_g_compile ;
  34. "done!\n" 1 platform_log ;
  35. if USE_TRIVIAL_MALLOC {
  36. "Compiling triv_malloc.g... " 1 platform_log ;
  37. "triv_malloc.g" platform_g_compile ;
  38. "done!\n" 1 platform_log ;
  39. }
  40. if USE_SIMPLE_MALLOC {
  41. "Compiling simple_malloc.g... " 1 platform_log ;
  42. "simple_malloc.g" platform_g_compile ;
  43. "done!\n" 1 platform_log ;
  44. }
  45. if USE_CHECKED_MALLOC {
  46. "Compiling check_malloc.g... " 1 platform_log ;
  47. "check_malloc.g" platform_g_compile ;
  48. "done!\n" 1 platform_log ;
  49. }
  50. if USE_KMALLOC {
  51. "Compiling kmalloc.g... " 1 platform_log ;
  52. "kmalloc.g" platform_g_compile ;
  53. "done!\n" 1 platform_log ;
  54. }
  55. "Compiling malloc_utils.g... " 1 platform_log ;
  56. "malloc_utils.g" platform_g_compile ;
  57. "done!\n" 1 platform_log ;
  58. "Compiling vector.g... " 1 platform_log ;
  59. "vector.g" platform_g_compile ;
  60. "done!\n" 1 platform_log ;
  61. if USE_SIMPLE_MAP {
  62. "Compiling map.g... " 1 platform_log ;
  63. "map.g" platform_g_compile ;
  64. "done!\n" 1 platform_log ;
  65. }
  66. if USE_AVL_MAP {
  67. "Compiling avl_map.g... " 1 platform_log ;
  68. "avl_map.g" platform_g_compile ;
  69. "done!\n" 1 platform_log ;
  70. }
  71. # "Compiling map_test.g... " 1 platform_log ;
  72. # "map_test.g" platform_g_compile ;
  73. # "done!\n" 1 platform_log ;
  74. # 0 "map_test" platform_get_symbol \0 ;
  75. "Compiling utils2.g... " 1 platform_log ;
  76. "utils2.g" platform_g_compile ;
  77. "done!\n" 1 platform_log ;
  78. "Compiling atapio.g... " 1 platform_log ;
  79. "atapio.g" platform_g_compile ;
  80. "done!\n" 1 platform_log ;
  81. "Compiling diskfs.g... " 1 platform_log ;
  82. "diskfs.g" platform_g_compile ;
  83. "done!\n" 1 platform_log ;
  84. "Compiling debugfs.g... " 1 platform_log ;
  85. "debugfs.g" platform_g_compile ;
  86. "done!\n" 1 platform_log ;
  87. "Compiling ramfs.g... " 1 platform_log ;
  88. "ramfs.g" platform_g_compile ;
  89. "done!\n" 1 platform_log ;
  90. "Compiling mbr.g... " 1 platform_log ;
  91. "mbr.g" platform_g_compile ;
  92. "done!\n" 1 platform_log ;
  93. "Compiling vfs.g... " 1 platform_log ;
  94. "vfs.g" platform_g_compile ;
  95. "done!\n" 1 platform_log ;
  96. "Compiling vfs_utils.g... " 1 platform_log ;
  97. "vfs_utils.g" platform_g_compile ;
  98. "done!\n" 1 platform_log ;
  99. if RUN_ASM RUN_FASM || {
  100. #"Memory break before ASM assembler compilation: " 1 platform_log ;
  101. #0 platform_allocate itoa 1 platform_log ;
  102. #"\n" 1 platform_log ;
  103. "Compiling asm_regs.g... " 1 platform_log ;
  104. "asm_regs.g" platform_g_compile ;
  105. "done!\n" 1 platform_log ;
  106. "Compiling asm_preproc.g... " 1 platform_log ;
  107. "asm_preproc.g" platform_g_compile ;
  108. "done!\n" 1 platform_log ;
  109. "Compiling asm_opcodes.g... " 1 platform_log ;
  110. "asm_opcodes.g" platform_g_compile ;
  111. "done!\n" 1 platform_log ;
  112. "Compiling asm_compile.g... " 1 platform_log ;
  113. "asm_compile.g" platform_g_compile ;
  114. "done!\n" 1 platform_log ;
  115. #"Memory break after ASM assembler compilation: " 1 platform_log ;
  116. #0 platform_allocate itoa 1 platform_log ;
  117. #"\n" 1 platform_log ;
  118. }
  119. if RUN_C RUN_MCPP || RUN_TINYCC || TEST_C || {
  120. "Compiling c_ast.g... " 1 platform_log ;
  121. "c_ast.g" platform_g_compile ;
  122. "done!\n" 1 platform_log ;
  123. "Compiling c_preproc.g... " 1 platform_log ;
  124. "c_preproc.g" platform_g_compile ;
  125. "done!\n" 1 platform_log ;
  126. "Compiling c_compile.g... " 1 platform_log ;
  127. "c_compile.g" platform_g_compile ;
  128. "done!\n" 1 platform_log ;
  129. "Compiling c_test.g... " 1 platform_log ;
  130. "c_test.g" platform_g_compile ;
  131. "done!\n" 1 platform_log ;
  132. }
  133. if RUN_MESCC {
  134. "Compiling mescc_hex2.g... " 1 platform_log ;
  135. "mescc_hex2.g" platform_g_compile ;
  136. "done!\n" 1 platform_log ;
  137. "Compiling mescc_m1.g... " 1 platform_log ;
  138. "mescc_m1.g" platform_g_compile ;
  139. "done!\n" 1 platform_log ;
  140. "Compiling mescc_m2.g... " 1 platform_log ;
  141. "mescc_m2.g" platform_g_compile ;
  142. "done!\n" 1 platform_log ;
  143. }
  144. "Memory break after compilers compilation: " 1 platform_log ;
  145. 0 platform_allocate itoa 1 platform_log ;
  146. "\n" 1 platform_log ;
  147. "Initializing Virtual File System...\n" 1 platform_log ;
  148. 0 "vfs_init" platform_get_symbol \0 ;
  149. "Virtual File System initialized!\n" 1 platform_log ;
  150. # Determine if there is an actual script
  151. $script_file
  152. @script_file "/init/script.g" 0 "vfs_open" platform_get_symbol \1 = ;
  153. $have_script
  154. @have_script script_file 0 "vfs_read" platform_get_symbol \1 0xffffffff != = ;
  155. script_file 0 "vfs_close" platform_get_symbol \1 ;
  156. if have_script {
  157. "Compiling script.g... " 1 platform_log ;
  158. "script.g" platform_g_compile ;
  159. "done!\n" 1 platform_log ;
  160. "Running the script...\n" 1 platform_log ;
  161. 0 "run_script" platform_get_symbol \0 ;
  162. } else {
  163. "No script, running the usual payload...\n" 1 platform_log ;
  164. if RUN_ASM {
  165. "/init/test.asm" 0 "parse_asm" platform_get_symbol \1 ;
  166. }
  167. if RUN_FASM {
  168. "Compiling fasm.g... " 1 platform_log ;
  169. "fasm.g" platform_g_compile ;
  170. "done!\n" 1 platform_log ;
  171. 0 "compile_fasm" platform_get_symbol \0 ;
  172. }
  173. if RUN_C {
  174. "/disk1/tests/test.c" 0 "parse_c" platform_get_symbol \1 ;
  175. }
  176. if TEST_C {
  177. 0 "c_run_testcases" platform_get_symbol \0 ;
  178. }
  179. if RUN_MESCC {
  180. 0 "hex2_test" platform_get_symbol \0 ;
  181. 0 "m1_test" platform_get_symbol \0 ;
  182. 0 "m2_test" platform_get_symbol \0 ;
  183. 0 "m2_test_full_compilation" platform_get_symbol \0 ;
  184. }
  185. if RUN_MCPP {
  186. "Compiling mcpp.g... " 1 platform_log ;
  187. "mcpp.g" platform_g_compile ;
  188. "done!\n" 1 platform_log ;
  189. 0 "compile_mcpp" platform_get_symbol \0 ;
  190. }
  191. if RUN_TINYCC {
  192. "Compiling tinycc.g... " 1 platform_log ;
  193. "tinycc.g" platform_g_compile ;
  194. "done!\n" 1 platform_log ;
  195. 0 "compile_tinycc" platform_get_symbol \0 ;
  196. }
  197. }
  198. "Destroying Virtual File System... " 1 platform_log ;
  199. 0 "vfs_destroy" platform_get_symbol \0 ;
  200. "done!\n" 1 platform_log ;
  201. "Destroying debugfs... " 1 platform_log ;
  202. 0 "debugfs_deinit" platform_get_symbol \0 ;
  203. "done!\n" 1 platform_log ;
  204. "Memory break before exiting main: " 1 platform_log ;
  205. 0 platform_allocate itoa 1 platform_log ;
  206. "\n" 1 platform_log ;
  207. 0 "malloc_stats" platform_get_symbol \0 ;
  208. }