1
0

debugfs.g 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 DEBUGFS_ATAPIO 0
  15. const DEBUGFS_START 4
  16. const DEBUGFS_END 8
  17. const DEBUGFS_POS 12
  18. const DEBUGFS_BUF 16
  19. const DEBUGFS_BUF_POS 20
  20. const SIZEOF_DEBUGFS 24
  21. fun debugfsinst_init 3 {
  22. $atapio
  23. $start
  24. $size
  25. @atapio 2 param = ;
  26. @start 1 param = ;
  27. @size 0 param = ;
  28. $debugfs
  29. @debugfs SIZEOF_DEBUGFS malloc = ;
  30. debugfs DEBUGFS_ATAPIO take_addr atapio = ;
  31. debugfs DEBUGFS_START take_addr start = ;
  32. debugfs DEBUGFS_END take_addr start size + = ;
  33. debugfs DEBUGFS_POS take_addr start 1 + = ;
  34. debugfs DEBUGFS_BUF take_addr 0 = ;
  35. debugfs ret ;
  36. }
  37. fun debugfsinst_destroy 1 {
  38. $debugfs
  39. @debugfs 0 param = ;
  40. debugfs DEBUGFS_ATAPIO take atapio_destroy ;
  41. debugfs DEBUGFS_BUF take free ;
  42. debugfs free ;
  43. }
  44. fun debugfsinst_begin_file 2 {
  45. $debugfs
  46. $filename
  47. @debugfs 1 param = ;
  48. @filename 0 param = ;
  49. debugfs DEBUGFS_BUF take 0 == "debugfsinst_begin_file: already in file" assert_msg ;
  50. debugfs DEBUGFS_BUF take_addr 512 1 calloc = ;
  51. debugfs DEBUGFS_BUF_POS take_addr 0 = ;
  52. filename strlen 511 < "debugfsinst_begin_file: filename too long" assert_msg ;
  53. $sector
  54. @sector 512 1 calloc = ;
  55. filename sector strcpy ;
  56. debugfs DEBUGFS_POS take debugfs DEBUGFS_END take != "debugfsinst_begin_file: partition limit exceeded" assert_msg ;
  57. debugfs DEBUGFS_ATAPIO take debugfs DEBUGFS_POS take sector atapio_write_sect ;
  58. sector free ;
  59. debugfs DEBUGFS_POS take_addr debugfs DEBUGFS_POS take 1 + = ;
  60. }
  61. fun _debugfsinst_flush_buffer 1 {
  62. $debugfs
  63. @debugfs 0 param = ;
  64. debugfs DEBUGFS_BUF take 0 != "_debugfsinst_flush_buffer: not in file" assert_msg ;
  65. debugfs DEBUGFS_POS take debugfs DEBUGFS_END take != "_debugfsinst_flush_buffer: partition limit exceeded" assert_msg ;
  66. debugfs DEBUGFS_ATAPIO take debugfs DEBUGFS_POS take debugfs DEBUGFS_BUF take atapio_write_sect ;
  67. debugfs DEBUGFS_BUF take free ;
  68. debugfs DEBUGFS_BUF take_addr 512 1 calloc = ;
  69. debugfs DEBUGFS_BUF_POS take_addr 0 = ;
  70. debugfs DEBUGFS_POS take_addr debugfs DEBUGFS_POS take 1 + = ;
  71. }
  72. fun debugfsinst_write_char 2 {
  73. $debugfs
  74. $c
  75. @debugfs 1 param = ;
  76. @c 0 param = ;
  77. debugfs DEBUGFS_BUF take debugfs DEBUGFS_BUF_POS take + c =c ;
  78. debugfs DEBUGFS_BUF_POS take_addr debugfs DEBUGFS_BUF_POS take 1 + = ;
  79. if debugfs DEBUGFS_BUF_POS take 512 == {
  80. debugfs _debugfsinst_flush_buffer ;
  81. }
  82. }
  83. fun debugfsinst_finish_file 1 {
  84. $debugfs
  85. @debugfs 0 param = ;
  86. debugfs DEBUGFS_BUF take 0 != "debugfsinst_finish_file: not in file" assert_msg ;
  87. if debugfs DEBUGFS_BUF_POS take 0 != {
  88. debugfs _debugfsinst_flush_buffer ;
  89. }
  90. # Write an empty sector
  91. debugfs '\0' debugfsinst_write_char ;
  92. debugfs _debugfsinst_flush_buffer ;
  93. debugfs DEBUGFS_BUF take free ;
  94. debugfs DEBUGFS_BUF take_addr 0 = ;
  95. }
  96. $global_debugfs
  97. fun debugfs_set 1 {
  98. $debugfs
  99. @debugfs 0 param = ;
  100. if global_debugfs {
  101. global_debugfs debugfsinst_destroy ;
  102. }
  103. @global_debugfs debugfs = ;
  104. }
  105. fun debugfs_deinit 0 {
  106. 0 debugfs_set ;
  107. }
  108. fun debugfs_begin_file 1 {
  109. $filename
  110. @filename 0 param = ;
  111. if global_debugfs {
  112. global_debugfs filename debugfsinst_begin_file ;
  113. }
  114. }
  115. fun debugfs_write_char 1 {
  116. $c
  117. @c 0 param = ;
  118. if global_debugfs {
  119. global_debugfs c debugfsinst_write_char ;
  120. }
  121. }
  122. fun debugfs_finish_file 0 {
  123. if global_debugfs {
  124. global_debugfs debugfsinst_finish_file ;
  125. }
  126. }
  127. fun debugfs_copy_file 2 {
  128. $from_filename
  129. $to_filename
  130. @from_filename 1 param = ;
  131. @to_filename 0 param = ;
  132. $fd
  133. @fd from_filename 0 "vfs_open" platform_get_symbol \1 = ;
  134. $cont
  135. @cont 1 = ;
  136. to_filename debugfs_begin_file ;
  137. while cont {
  138. $c
  139. @c fd 0 "vfs_read" platform_get_symbol \1 = ;
  140. if c 0xffffffff == {
  141. @cont 0 = ;
  142. } else {
  143. c debugfs_write_char ;
  144. }
  145. }
  146. debugfs_finish_file ;
  147. fd 0 "vfs_close" platform_get_symbol \1 ;
  148. }