mb_mmap.asm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. ;; This file is part of asmc, a bootstrapping OS with minimal seed
  2. ;; Copyright (C) 2018-2019 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. dump_multiboot:
  15. push ebp
  16. mov ebp, esp
  17. push ebx
  18. push esi
  19. ;; Save multiboot location
  20. mov ebx, [ebp+8]
  21. ;; Log
  22. push str_dump_multiboot
  23. push 1
  24. call platform_log
  25. add esp, 8
  26. ;; Check mem_lower and mem_upper are supported
  27. mov eax, [ebx]
  28. test eax, 1
  29. je dump_multiboot_mmap
  30. ;; Print mem_lower
  31. push str_mem_lower
  32. push 1
  33. call platform_log
  34. add esp, 8
  35. mov eax, [ebx+4]
  36. push eax
  37. call itoa
  38. add esp, 4
  39. push eax
  40. push 1
  41. call platform_log
  42. add esp, 8
  43. push str_newline
  44. push 1
  45. call platform_log
  46. add esp, 8
  47. ;; Print mem_upper
  48. push str_mem_upper
  49. push 1
  50. call platform_log
  51. add esp, 8
  52. mov eax, [ebx+8]
  53. push eax
  54. call itoa
  55. add esp, 4
  56. push eax
  57. push 1
  58. call platform_log
  59. add esp, 8
  60. push str_newline
  61. push 1
  62. call platform_log
  63. add esp, 8
  64. dump_multiboot_mmap:
  65. ;; Check mmap_* are supported
  66. mov eax, [ebx]
  67. test eax, 64
  68. je dump_multiboot_end
  69. ;; Save mmap buffer in registers
  70. mov esi, [ebx+48]
  71. mov ebx, [ebx+44]
  72. add ebx, esi
  73. dump_multiboot_mmap_dump:
  74. ;; Call mmap_dump
  75. push esi
  76. call mmap_dump
  77. add esp, 4
  78. ;; Increment pointer
  79. add esi, [esi]
  80. add esi, 4
  81. cmp esi, ebx
  82. jb dump_multiboot_mmap_dump
  83. dump_multiboot_end:
  84. pop esi
  85. pop ebx
  86. pop ebp
  87. ret
  88. mmap_dump:
  89. push ebp
  90. mov ebp, esp
  91. push ebx
  92. mov ebx, [ebp+8]
  93. ;; Check that ignored fields are not used
  94. cmp DWORD [ebx+8], 0
  95. jne platform_panic
  96. cmp DWORD [ebx+16], 0
  97. jne platform_panic
  98. ;; Print size
  99. ;; push str_mmap_size
  100. ;; push 1
  101. ;; call platform_log
  102. ;; add esp, 8
  103. ;; mov eax, [ebx]
  104. ;; push eax
  105. ;; call itoa
  106. ;; add esp, 4
  107. ;; push eax
  108. ;; push 1
  109. ;; call platform_log
  110. ;; add esp, 8
  111. ;; push str_newline
  112. ;; push 1
  113. ;; call platform_log
  114. ;; add esp, 8
  115. ;; Print base_addr
  116. ;; push str_mmap_base_addr
  117. ;; push 1
  118. ;; call platform_log
  119. ;; add esp, 8
  120. push str_mmap
  121. push 1
  122. call platform_log
  123. add esp, 8
  124. mov eax, [ebx+4]
  125. push eax
  126. call itoa
  127. add esp, 4
  128. push eax
  129. push 1
  130. call platform_log
  131. add esp, 8
  132. ;; push str_newline
  133. ;; push 1
  134. ;; call platform_log
  135. ;; add esp, 8
  136. ;; Print length
  137. ;; push str_mmap_length
  138. ;; push 1
  139. ;; call platform_log
  140. ;; add esp, 8
  141. push str_slash
  142. push 1
  143. call platform_log
  144. add esp, 8
  145. mov eax, [ebx+12]
  146. push eax
  147. call itoa
  148. add esp, 4
  149. push eax
  150. push 1
  151. call platform_log
  152. add esp, 8
  153. ;; push str_newline
  154. ;; push 1
  155. ;; call platform_log
  156. ;; add esp, 8
  157. ;; Print type
  158. ;; push str_mmap_type
  159. ;; push 1
  160. ;; call platform_log
  161. ;; add esp, 8
  162. push str_slash
  163. push 1
  164. call platform_log
  165. add esp, 8
  166. mov eax, [ebx+20]
  167. push eax
  168. call itoa
  169. add esp, 4
  170. push eax
  171. push 1
  172. call platform_log
  173. add esp, 8
  174. push str_newline
  175. push 1
  176. call platform_log
  177. add esp, 8
  178. pop ebx
  179. pop ebp
  180. ret
  181. str_dump_multiboot:
  182. db 'Dumping multiboot boot information...'
  183. db NEWLINE
  184. db 0
  185. str_mem_lower:
  186. db 'mem_lower = '
  187. db 0
  188. str_mem_upper:
  189. db 'mem_lower = '
  190. db 0
  191. str_mmap:
  192. db 'Memory region: '
  193. db 0
  194. str_slash:
  195. db ' / '
  196. db 0