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.

gdbidt.S 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Interrupt handlers for GDB stub
  3. */
  4. #define SIZEOF_I386_REGS 32
  5. #define SIZEOF_I386_FLAGS 4
  6. /****************************************************************************
  7. * Interrupt handlers
  8. ****************************************************************************
  9. */
  10. .section ".text", "ax", @progbits
  11. .code32
  12. /* POSIX signal numbers for reporting traps to GDB */
  13. #define SIGILL 4
  14. #define SIGTRAP 5
  15. #define SIGFPE 8
  16. #define SIGSTKFLT 16
  17. .globl gdbmach_sigfpe
  18. gdbmach_sigfpe:
  19. pushl $SIGFPE
  20. jmp gdbmach_interrupt
  21. .globl gdbmach_sigtrap
  22. gdbmach_sigtrap:
  23. pushl $SIGTRAP
  24. jmp gdbmach_interrupt
  25. .globl gdbmach_sigstkflt
  26. gdbmach_sigstkflt:
  27. pushl $SIGSTKFLT
  28. jmp gdbmach_interrupt
  29. .globl gdbmach_sigill
  30. gdbmach_sigill:
  31. pushl $SIGILL
  32. jmp gdbmach_interrupt
  33. /* When invoked, the stack contains: eflags, cs, eip, signo. */
  34. #define IH_OFFSET_GDB_REGS ( 0 )
  35. #define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
  36. #define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
  37. #define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
  38. #define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
  39. #define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
  40. #define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
  41. #define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
  42. #define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
  43. #define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
  44. /* We also access the stack whilst still storing or restoring
  45. * the register snapshot. Since ESP is in flux, we need
  46. * special offsets.
  47. */
  48. #define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
  49. #define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
  50. #define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
  51. #define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
  52. gdbmach_interrupt:
  53. /* Store CPU state in GDB register snapshot */
  54. pushw $0
  55. pushw %gs
  56. pushw $0
  57. pushw %fs
  58. pushw $0
  59. pushw %es
  60. pushw $0
  61. pushw %ds
  62. pushw $0
  63. pushw %ss
  64. pushw $0
  65. pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
  66. pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
  67. pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
  68. pushl %edi
  69. pushl %esi
  70. pushl %ebp
  71. leal IH_OFFSET_FLUX_END(%esp), %edi
  72. pushl %edi /* old ESP */
  73. pushl %ebx
  74. pushl %edx
  75. pushl %ecx
  76. pushl %eax
  77. /* Switch to virtual addressing */
  78. call _intr_to_virt
  79. /* Call GDB stub exception handler */
  80. pushl %esp
  81. pushl (IH_OFFSET_SIGNO + 4)(%esp)
  82. call gdbmach_handler
  83. addl $8, %esp
  84. /* Copy register snapshot to new stack and switch to new stack */
  85. movl %esp, %esi
  86. movl (IH_OFFSET_GDB_SEG_REGS + 4)(%esp), %eax
  87. movl %eax, %es
  88. movl (IH_OFFSET_GDB_REGS + 16)(%esp), %edi
  89. subl $IH_OFFSET_END, %edi
  90. movl $(IH_OFFSET_END / 4), %ecx
  91. pushl %edi
  92. ss rep movsl
  93. popl %edi
  94. movl %eax, %ss
  95. movl %edi, %esp
  96. /* Restore CPU state from GDB register snapshot */
  97. popl %eax
  98. popl %ecx
  99. popl %edx
  100. popl %ebx
  101. popl %ebp /* Skip %esp: already loaded */
  102. popl %ebp
  103. popl %esi
  104. popl %edi
  105. popl IH_OFFSET_FLUX_OLD_EIP(%esp)
  106. popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
  107. popl IH_OFFSET_FLUX_OLD_CS(%esp)
  108. popl %ds /* Skip %ss: already loaded */
  109. popl %ds
  110. popl %es
  111. popl %fs
  112. popl %gs
  113. addl $4, %esp /* drop signo */
  114. iret