bioscall.S 1.5 KB

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