int.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010,2011 Free Software Foundation, Inc.
  4. *
  5. * GRUB 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. * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. FUNCTION(grub_bios_interrupt)
  19. pushf
  20. cli
  21. popf
  22. pushl %ebp
  23. pushl %ecx
  24. pushl %eax
  25. pushl %ebx
  26. pushl %esi
  27. pushl %edi
  28. pushl %edx
  29. movb %al, intno
  30. movl (%edx), %eax
  31. movl %eax, LOCAL(bios_register_eax)
  32. movw 4(%edx), %ax
  33. movw %ax, LOCAL(bios_register_es)
  34. movw 6(%edx), %ax
  35. movw %ax, LOCAL(bios_register_ds)
  36. movw 8(%edx), %ax
  37. movw %ax, LOCAL(bios_register_flags)
  38. movl 12(%edx), %ebx
  39. movl 16(%edx), %ecx
  40. movl 20(%edx), %edi
  41. movl 24(%edx), %esi
  42. movl 28(%edx), %edx
  43. /*
  44. Via C3 CPUs have cache coherence problems, so we need to call
  45. wbinvd at these 2 points. As wbinvd slows down boot, don't do
  46. it on non-VIA. 9090 is nop nop. */
  47. VARIABLE(grub_bios_via_workaround1)
  48. .byte 0x90, 0x90
  49. PROT_TO_REAL
  50. .code16
  51. pushf
  52. cli
  53. mov %ds, %ax
  54. push %ax
  55. /* movw imm16, %ax*/
  56. .byte 0xb8
  57. LOCAL(bios_register_es):
  58. .short 0
  59. movw %ax, %es
  60. /* movw imm16, %ax*/
  61. .byte 0xb8
  62. LOCAL(bios_register_ds):
  63. .short 0
  64. movw %ax, %ds
  65. /* movw imm16, %ax*/
  66. .byte 0xb8
  67. LOCAL(bios_register_flags):
  68. .short 0
  69. push %ax
  70. popf
  71. /* movl imm32, %eax*/
  72. .byte 0x66, 0xb8
  73. LOCAL(bios_register_eax):
  74. .long 0
  75. /* int imm8. */
  76. .byte 0xcd
  77. intno:
  78. .byte 0
  79. movl %eax, %cs:LOCAL(bios_register_eax)
  80. movw %ds, %ax
  81. movw %ax, %cs:LOCAL(bios_register_ds)
  82. pop %ax
  83. mov %ax, %ds
  84. pushf
  85. pop %ax
  86. movw %ax, LOCAL(bios_register_flags)
  87. mov %es, %ax
  88. movw %ax, LOCAL(bios_register_es)
  89. popf
  90. VARIABLE(grub_bios_via_workaround2)
  91. .byte 0x90, 0x90
  92. REAL_TO_PROT
  93. .code32
  94. popl %eax
  95. movl %ebx, 12(%eax)
  96. movl %ecx, 16(%eax)
  97. movl %edi, 20(%eax)
  98. movl %esi, 24(%eax)
  99. movl %edx, 28(%eax)
  100. movl %eax, %edx
  101. movl LOCAL(bios_register_eax), %eax
  102. movl %eax, (%edx)
  103. movw LOCAL(bios_register_es), %ax
  104. movw %ax, 4(%edx)
  105. movw LOCAL(bios_register_ds), %ax
  106. movw %ax, 6(%edx)
  107. movw LOCAL(bios_register_flags), %ax
  108. movw %ax, 8(%edx)
  109. popl %edi
  110. popl %esi
  111. popl %ebx
  112. popl %eax
  113. popl %ecx
  114. popl %ebp
  115. ret