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.3KB

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