Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .org 0x7C00
  2. .code16
  3.  
  4. start:
  5. movw %cs, %ax
  6. movw %ax, %ds
  7. movw %ax, %ss
  8. movw start, %sp
  9. call clean_screen
  10.  
  11. load_kernel:
  12. movw $0x1100, %ax
  13. movw %ax, %es
  14. movw $0x00, %bx
  15. movb $0x02, %ah
  16. movb $1, %dl
  17. movb $0, %dh
  18. movb $0, %ch
  19. movb $2, %cl #Pointer to raw data
  20. movb $15,%al #Size of raw data
  21. int $0x13
  22.  
  23. movw $0x1300, %ax
  24. movw %ax, %es
  25. movw $0x0, %bx
  26. movb $0x02, %ah
  27. movb $1, %dl
  28. movb $0, %dh
  29. movb $0, %ch
  30. movb $17, %cl #Pointer to raw data
  31. movb $2,%al #Size of raw data
  32. int $0x13
  33.  
  34. movw $0x1360, %ax
  35. movw %ax, %es
  36. movw $0x00, %bx
  37. movb $0x02, %ah
  38. movb $1, %dl
  39. movb $0, %dh
  40. movb $1, %ch
  41. movb $1, %cl #Pointer to raw data
  42. movb $18,%al #Size of raw data
  43. int $0x13
  44.  
  45. movw $0x1660, %ax
  46. movw %ax, %es
  47. movw $0x00, %bx
  48. movb $0x02, %ah
  49. movb $1, %dl
  50. movb $1, %dh
  51. movb $0, %ch
  52. movb $1, %cl #Pointer to raw data
  53. movb $18,%al #Size of raw data
  54. int $0x13
  55.  
  56. movw $0x1960, %ax
  57. movw %ax, %es
  58. movw $0x00, %bx
  59. movb $0x02, %ah
  60. movb $1, %dl
  61. movb $0, %dh
  62. movb $1, %ch
  63. movb $1, %cl #Pointer to raw data
  64. movb $17,%al #Size of raw data
  65. int $0x13
  66.  
  67.  
  68. movw $hello_string, %bx
  69. call puts
  70. hello_world:
  71. movb $0, %ah
  72. int $0x16
  73. cmpb $32, %al
  74. je clean_screen_hello
  75. jne hello_world
  76.  
  77. print_string:
  78. movw $alphabet_copy, %bx
  79. movw $alphabet_string, %cx
  80. call puts
  81. jmp input_letters
  82.  
  83. output_string:
  84. movw $alphabet_string, %ax
  85. movw %ax, %es
  86. movw $0, %bx
  87. movb $3, %ah
  88. movb $1, %dl
  89. movb $0x00, %dh
  90. movb $0, %ch
  91. movb $0x01, %cl  #Pointer to raw data
  92. movb $1, %al  #size of raw data
  93. int $0x13
  94.  
  95. before_ProtectedMode:
  96. cli
  97. lgdt gdt_info
  98. inb $0x92, %al
  99. orb $2, %al
  100. outb %al, $0x92
  101. movl %cr0, %eax
  102. orb $1, %al
  103. movl %eax, %cr0
  104. ljmp $0x8, $protected_mode
  105.  
  106. input_letters:
  107. movb $0, %ah
  108. int $0x16
  109. cmpb $0x0D, %al
  110. je output_string #If a symbol was "Enter"
  111.  
  112. inf_loop:
  113. cmpb 0(%bx), %al
  114. je delete_letter
  115. addw $1, %bx
  116. addw $1, %cx
  117. jmp inf_loop
  118.              
  119. delete_letter:
  120. movw %cx, %bx
  121. movb 0(%bx), %ah
  122. cmpb $0x5F, %ah
  123. je swap
  124. movb $0x5F, %ah
  125. movb %ah, 0(%bx)
  126. call clean_screen
  127. movw $alphabet_string, %bx
  128. movw $alphabet_string, %cx
  129. call puts
  130. jmp input_letters
  131.  
  132. swap:
  133. movb %al, 0(%bx)
  134. call clean_screen
  135. movw $alphabet_string, %bx
  136. movw $alphabet_string, %cx
  137. call puts
  138. jmp input_letters
  139.  
  140. alphabet_string:
  141.     .asciz "abcdefghijklmnopqrstuvwxyz"
  142. alphabet_copy:
  143.     .asciz "abcdefghijklmnopqrstuvwxyz"
  144. hello_string:
  145.     .asciz "Hello, it's Dict_OS' bootloader, if u want to enter letter, press space!"
  146. puts:
  147. movb 0(%bx), %al
  148. test %al, %al
  149. jz end_puts
  150. movb $0x0e, %ah
  151. int $0x10
  152. addw $1, %bx
  153. jmp puts
  154.  
  155. end_puts:
  156. movw $alphabet_copy, %bx
  157. ret
  158.  
  159. clean_screen:
  160. movb $0, %ah
  161. movb $2, %al
  162. int $0x10
  163. ret
  164. clean_screen_hello:
  165. xorw %bx,%bx
  166. movb $0, %ah
  167. movb $2, %al
  168. int $0x10
  169. jmp print_string
  170. gdt:
  171. .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  172. .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
  173. .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
  174. gdt_info:
  175. .word gdt_info - gdt
  176. .word gdt, 0
  177.  
  178. .code32
  179. protected_mode:
  180. # Здесь идут первые инструкции в защищенном режиме
  181. movw $0x10, %ax
  182. movw %ax, %es
  183. movw %ax, %ds
  184. movw %ax, %ss
  185. call 0x11000
  186.  
  187. .zero (512 - (. - start) - 2)
  188. .byte 0x55, 0xAA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement