bioscall.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* -----------------------------------------------------------------------
  3. *
  4. * Copyright 2009-2014 Intel Corporation; author H. Peter Anvin
  5. *
  6. * ----------------------------------------------------------------------- */
  7. /*
  8. * "Glove box" for BIOS calls. Avoids the constant problems with BIOSes
  9. * touching registers they shouldn't be.
  10. */
  11. .code16
  12. .section ".inittext","ax"
  13. .globl intcall
  14. .type intcall, @function
  15. intcall:
  16. /* Self-modify the INT instruction. Ugly, but works. */
  17. cmpb %al, 3f
  18. je 1f
  19. movb %al, 3f
  20. jmp 1f /* Synchronize pipeline */
  21. 1:
  22. /* Save state */
  23. pushfl
  24. pushw %fs
  25. pushw %gs
  26. pushal
  27. /* Copy input state to stack frame */
  28. subw $44, %sp
  29. movw %dx, %si
  30. movw %sp, %di
  31. movw $11, %cx
  32. rep; movsl
  33. /* Pop full state from the stack */
  34. popal
  35. popw %gs
  36. popw %fs
  37. popw %es
  38. popw %ds
  39. popfl
  40. /* Actual INT */
  41. .byte 0xcd /* INT opcode */
  42. 3: .byte 0
  43. /* Push full state to the stack */
  44. pushfl
  45. pushw %ds
  46. pushw %es
  47. pushw %fs
  48. pushw %gs
  49. pushal
  50. /* Re-establish C environment invariants */
  51. cld
  52. movzwl %sp, %esp
  53. movw %cs, %ax
  54. movw %ax, %ds
  55. movw %ax, %es
  56. /* Copy output state from stack frame */
  57. movw 68(%esp), %di /* Original %cx == 3rd argument */
  58. andw %di, %di
  59. jz 4f
  60. movw %sp, %si
  61. movw $11, %cx
  62. rep; movsl
  63. 4: addw $44, %sp
  64. /* Restore state and return */
  65. popal
  66. popw %gs
  67. popw %fs
  68. popfl
  69. retl
  70. .size intcall, .-intcall