You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

com32_wrapper.S 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2008 Daniel Verkamp <daniel@drv.nu>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER )
  19. .text
  20. .arch i386
  21. .code32
  22. /*
  23. * This code is entered after running the following sequence out of
  24. * the interrupt jump buffer:
  25. *
  26. * pushal
  27. * movb $vector, %al
  28. * jmp com32_irq_wrapper
  29. */
  30. .globl com32_irq_wrapper
  31. com32_irq_wrapper:
  32. movzbl %al,%eax
  33. pushl %eax
  34. movl $com32_irq, %eax
  35. call com32_wrapper
  36. popl %eax
  37. popal
  38. iret
  39. .globl com32_farcall_wrapper
  40. com32_farcall_wrapper:
  41. movl $com32_farcall, %eax
  42. jmp com32_wrapper
  43. .globl com32_cfarcall_wrapper
  44. com32_cfarcall_wrapper:
  45. movl $com32_cfarcall, %eax
  46. jmp com32_wrapper
  47. .globl com32_intcall_wrapper
  48. com32_intcall_wrapper:
  49. movl $com32_intcall, %eax
  50. /*jmp com32_wrapper*/ /* fall through */
  51. com32_wrapper:
  52. cli
  53. /* Switch to internal virtual address space */
  54. call _phys_to_virt
  55. /* Switch to internal IDT (if we have one for debugging) */
  56. lidt com32_internal_idtr
  57. mov %eax, (com32_helper_function)
  58. /* Save external COM32 stack pointer */
  59. movl %esp, (com32_external_esp)
  60. /* Copy arguments to caller-save registers */
  61. movl 12(%esp), %eax
  62. movl 8(%esp), %ecx
  63. movl 4(%esp), %edx
  64. /* Switch to internal stack */
  65. movl (com32_internal_esp), %esp
  66. /* Copy arguments to internal stack */
  67. pushl %eax
  68. pushl %ecx
  69. pushl %edx
  70. call *(com32_helper_function)
  71. /* Clean up stack */
  72. addl $12, %esp
  73. /* Save internal stack pointer and restore external stack pointer */
  74. movl %esp, (com32_internal_esp)
  75. movl (com32_external_esp), %esp
  76. /* Switch to com32 IDT */
  77. lidt com32_external_idtr
  78. /* Switch to external flat physical address space */
  79. call _virt_to_phys
  80. sti
  81. ret
  82. .data
  83. /* Internal iPXE virtual address space %esp */
  84. .globl com32_internal_esp
  85. .lcomm com32_internal_esp, 4
  86. /* External flat physical address space %esp */
  87. .globl com32_external_esp
  88. .lcomm com32_external_esp, 4
  89. /* Function pointer of helper to call */
  90. .lcomm com32_helper_function, 4