1
0

debug.asm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. dump_nibble:
  15. cmp al, 10
  16. jb dump_nibble_dec
  17. sub al, 10
  18. add al, 0x61
  19. push eax
  20. call serial_write_char
  21. add esp, 4
  22. ret
  23. dump_nibble_dec:
  24. add al, 0x30
  25. push eax
  26. call serial_write_char
  27. add esp, 4
  28. ret
  29. dump_byte:
  30. mov ebx, eax
  31. mov edx, 0
  32. mov ecx, 16
  33. div ecx
  34. and eax, 0xf
  35. call dump_nibble
  36. mov eax, ebx
  37. and eax, 0xf
  38. call dump_nibble
  39. mov eax, 0x20
  40. push eax
  41. call serial_write_char
  42. add esp, 4
  43. ret
  44. dump_code_and_die:
  45. call serial_setup
  46. mov esi, ecx
  47. mov edi, 0x100
  48. dump_code_and_die_loop:
  49. cmp edi, 0
  50. je dump_code_and_die_end
  51. mov eax, 0
  52. mov al, [esi]
  53. call dump_byte
  54. add esi, 1
  55. sub edi, 1
  56. jmp dump_code_and_die_loop
  57. dump_code_and_die_end:
  58. push 0xa
  59. call serial_write_char
  60. add esp, 4
  61. mov eax, 0
  62. jmp shutdown
  63. SERIAL_PORT equ 0x3f8
  64. ;; void serial_setup()
  65. serial_setup:
  66. ;; Send command as indicated in https://wiki.osdev.org/Serial_Port
  67. mov edx, SERIAL_PORT
  68. add edx, 1
  69. mov eax, 0x00
  70. out dx, al
  71. mov edx, SERIAL_PORT
  72. add edx, 3
  73. mov eax, 0x80
  74. out dx, al
  75. mov edx, SERIAL_PORT
  76. add edx, 0
  77. mov eax, 0x03
  78. out dx, al
  79. mov edx, SERIAL_PORT
  80. add edx, 1
  81. mov eax, 0x00
  82. out dx, al
  83. mov edx, SERIAL_PORT
  84. add edx, 3
  85. mov eax, 0x03
  86. out dx, al
  87. mov edx, SERIAL_PORT
  88. add edx, 2
  89. mov eax, 0xc7
  90. out dx, al
  91. mov edx, SERIAL_PORT
  92. add edx, 4
  93. mov eax, 0x0b
  94. out dx, al
  95. ret
  96. ;; void serial_write_char(char c)
  97. serial_write_char:
  98. ;; Test until the serial is available for transmit
  99. mov edx, SERIAL_PORT
  100. add edx, 5
  101. in al, dx
  102. and eax, 0x20
  103. cmp eax, 0
  104. je serial_write_char
  105. ;; Actually write the char
  106. mov edx, SERIAL_PORT
  107. mov eax, [esp+4]
  108. out dx, al
  109. ret