boot64.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* arch/x86/boot/boot64.S
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. .code16
  19. /* load system to 0x8000, and boot */
  20. .globl _start
  21. _start: xorw %ax, %ax
  22. movw %ax, %ds
  23. movw %ax, %es
  24. movw %ax, %ss
  25. movw $0x7c00, %sp
  26. /* move self to 0x7e00 */
  27. movw $0x7e00, %di
  28. movw $0x7c00, %si
  29. movw $512, %cx
  30. cld
  31. rep
  32. movsb
  33. ljmp $0x0000, $real_start
  34. real_start:
  35. leaw loading_msg, %si
  36. call print
  37. call load_sys
  38. call setup_e820
  39. ljmp $0, $0x8000
  40. die: hlt
  41. jmp die
  42. load_sys:
  43. /* load the system to 0x8000, and jump */
  44. movw $0x0800, %ax
  45. movw %ax, %es
  46. xorw %bx, %bx
  47. xorl %eax, %eax
  48. lloop: incl %eax
  49. movw $16, %cx
  50. call read_lba
  51. movw %es, %cx
  52. addw $512, %cx
  53. movw %cx, %es
  54. cmpl $64, %eax
  55. jb cont
  56. ret
  57. cont: pushal
  58. /* put a '.' on screen */
  59. movb $'.', %al
  60. movb $0x0e, %ah
  61. movw $0x000f, %bx
  62. int $0x10
  63. popal
  64. jmp lloop
  65. read_lba:
  66. pushaw
  67. pushl $0
  68. pushl %eax
  69. pushw %es
  70. pushw %bx
  71. pushw %cx
  72. pushw $16
  73. movb $0x42, %ah
  74. /* dx didn't change */
  75. movw %sp, %si
  76. int $0x13
  77. jc read_failed
  78. addw $16, %sp
  79. popaw
  80. ret
  81. read_failed:
  82. leaw read_fail_msg, %si
  83. call print
  84. jmp die
  85. setup_e820:
  86. movl $0x9000, %ebx
  87. movl %ebx, %es
  88. movl $0, %edi
  89. xorl %ebx, %ebx
  90. sel: movl $0xe820, %eax
  91. movl $20, %ecx
  92. movl $0x534d4150, %edx
  93. int $0x15
  94. jc e820_failed
  95. addl $20, %edi
  96. cmpl $0, %ebx
  97. jne sel
  98. ret
  99. e820_failed:
  100. leaw e820_fail_msg, %si
  101. pushw $die
  102. print: cld
  103. lodsb
  104. testb %al, %al
  105. jz pret
  106. movb $0x0e, %ah
  107. movw $0x000f, %bx
  108. int $0x10
  109. jmp print
  110. pret: ret
  111. read_fail_msg:
  112. .ascii "read /dev/sda failed. "
  113. .byte 0x0d, 0x0a, 0x00
  114. loading_msg:
  115. .asciz "Loading System"
  116. e820_fail_msg:
  117. .asciz "get e820 meminfo failed. "
  118. .org 0x1be
  119. part0:
  120. .org 510
  121. .word 0xaa55