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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER )
  20. .text
  21. .arch i386
  22. .code32
  23. /*
  24. * This code is entered after running the following sequence out of
  25. * the interrupt jump buffer:
  26. *
  27. * pushal
  28. * movb $vector, %al
  29. * jmp com32_irq_wrapper
  30. */
  31. .globl com32_irq_wrapper
  32. com32_irq_wrapper:
  33. movzbl %al,%eax
  34. pushl %eax
  35. movl $com32_irq, %eax
  36. call com32_wrapper
  37. popl %eax
  38. popal
  39. iret
  40. .globl com32_farcall_wrapper
  41. com32_farcall_wrapper:
  42. movl $com32_farcall, %eax
  43. jmp com32_wrapper
  44. .globl com32_cfarcall_wrapper
  45. com32_cfarcall_wrapper:
  46. movl $com32_cfarcall, %eax
  47. jmp com32_wrapper
  48. .globl com32_intcall_wrapper
  49. com32_intcall_wrapper:
  50. movl $com32_intcall, %eax
  51. /*jmp com32_wrapper*/ /* fall through */
  52. com32_wrapper:
  53. cli
  54. /* Switch to internal virtual address space */
  55. call _phys_to_virt
  56. /* Switch to internal IDT (if we have one for debugging) */
  57. lidt com32_internal_idtr
  58. mov %eax, (com32_helper_function)
  59. /* Save external COM32 stack pointer */
  60. movl %esp, (com32_external_esp)
  61. /* Copy arguments to caller-save registers */
  62. movl 12(%esp), %eax
  63. movl 8(%esp), %ecx
  64. movl 4(%esp), %edx
  65. /* Switch to internal stack */
  66. movl (com32_internal_esp), %esp
  67. /* Copy arguments to internal stack */
  68. pushl %eax
  69. pushl %ecx
  70. pushl %edx
  71. call *(com32_helper_function)
  72. /* Clean up stack */
  73. addl $12, %esp
  74. /* Save internal stack pointer and restore external stack pointer */
  75. movl %esp, (com32_internal_esp)
  76. movl (com32_external_esp), %esp
  77. /* Switch to com32 IDT */
  78. lidt com32_external_idtr
  79. /* Switch to external flat physical address space */
  80. call _virt_to_phys
  81. sti
  82. ret
  83. .data
  84. /* Internal iPXE virtual address space %esp */
  85. .globl com32_internal_esp
  86. .lcomm com32_internal_esp, 4
  87. /* External flat physical address space %esp */
  88. .globl com32_external_esp
  89. .lcomm com32_external_esp, 4
  90. /* Function pointer of helper to call */
  91. .lcomm com32_helper_function, 4