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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
  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. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * GDB exception handlers
  27. *
  28. */
  29. /* Size of a register */
  30. #define SIZEOF_REG 8
  31. /* POSIX signal numbers for reporting traps to GDB */
  32. #define SIGILL 4
  33. #define SIGTRAP 5
  34. #define SIGFPE 8
  35. #define SIGSTKFLT 16
  36. .section ".text.gdbmach_interrupt", "ax", @progbits
  37. .code64
  38. .struct 0
  39. /* Register dump created for GDB stub */
  40. regs:
  41. regs_rax: .space SIZEOF_REG
  42. regs_rbx: .space SIZEOF_REG
  43. regs_rcx: .space SIZEOF_REG
  44. regs_rdx: .space SIZEOF_REG
  45. regs_rsi: .space SIZEOF_REG
  46. regs_rdi: .space SIZEOF_REG
  47. regs_rbp: .space SIZEOF_REG
  48. regs_rsp: .space SIZEOF_REG
  49. regs_r8: .space SIZEOF_REG
  50. regs_r9: .space SIZEOF_REG
  51. regs_r10: .space SIZEOF_REG
  52. regs_r11: .space SIZEOF_REG
  53. regs_r12: .space SIZEOF_REG
  54. regs_r13: .space SIZEOF_REG
  55. regs_r14: .space SIZEOF_REG
  56. regs_r15: .space SIZEOF_REG
  57. regs_rip: .space SIZEOF_REG
  58. regs_rflags: .space SIZEOF_REG
  59. regs_cs: .space SIZEOF_REG
  60. regs_ss: .space SIZEOF_REG
  61. regs_ds: .space SIZEOF_REG
  62. regs_es: .space SIZEOF_REG
  63. regs_fs: .space SIZEOF_REG
  64. regs_gs: .space SIZEOF_REG
  65. regs_end:
  66. /* GDB signal code */
  67. gdb:
  68. gdb_code: .space SIZEOF_REG
  69. gdb_end:
  70. /* Long-mode exception frame */
  71. frame:
  72. frame_rip: .space SIZEOF_REG
  73. frame_cs: .space SIZEOF_REG
  74. frame_rflags: .space SIZEOF_REG
  75. frame_rsp: .space SIZEOF_REG
  76. frame_ss: .space SIZEOF_REG
  77. frame_end:
  78. .previous
  79. .globl gdbmach_sigfpe
  80. gdbmach_sigfpe:
  81. push $SIGFPE
  82. jmp gdbmach_interrupt
  83. .globl gdbmach_sigtrap
  84. gdbmach_sigtrap:
  85. push $SIGTRAP
  86. jmp gdbmach_interrupt
  87. .globl gdbmach_sigstkflt
  88. gdbmach_sigstkflt:
  89. push $SIGSTKFLT
  90. jmp gdbmach_interrupt
  91. .globl gdbmach_sigill
  92. gdbmach_sigill:
  93. push $SIGILL
  94. jmp gdbmach_interrupt
  95. gdbmach_interrupt:
  96. /* Create register dump */
  97. pushq %gs
  98. pushq %fs
  99. pushq $0 /* %es unused in long mode */
  100. pushq $0 /* %ds unused in long mode */
  101. pushq ( frame_ss - regs_ss - SIZEOF_REG )(%rsp)
  102. pushq ( frame_cs - regs_cs - SIZEOF_REG )(%rsp)
  103. pushq ( frame_rflags - regs_rflags - SIZEOF_REG )(%rsp)
  104. pushq ( frame_rip - regs_rip - SIZEOF_REG )(%rsp)
  105. pushq %r15
  106. pushq %r14
  107. pushq %r13
  108. pushq %r12
  109. pushq %r11
  110. pushq %r10
  111. pushq %r9
  112. pushq %r8
  113. pushq ( frame_rsp - regs_rsp - SIZEOF_REG )(%rsp)
  114. pushq %rbp
  115. pushq %rdi
  116. pushq %rsi
  117. pushq %rdx
  118. pushq %rcx
  119. pushq %rbx
  120. pushq %rax
  121. /* Call GDB stub exception handler */
  122. movq gdb_code(%rsp), %rdi
  123. movq %rsp, %rsi
  124. call gdbmach_handler
  125. /* Restore from register dump */
  126. popq %rax
  127. popq %rbx
  128. popq %rcx
  129. popq %rdx
  130. popq %rsi
  131. popq %rdi
  132. popq %rbp
  133. popq ( frame_rsp - regs_rsp - SIZEOF_REG )(%rsp)
  134. popq %r8
  135. popq %r9
  136. popq %r10
  137. popq %r11
  138. popq %r12
  139. popq %r13
  140. popq %r14
  141. popq %r15
  142. popq ( frame_rip - regs_rip - SIZEOF_REG )(%rsp)
  143. popq ( frame_rflags - regs_rflags - SIZEOF_REG )(%rsp)
  144. popq ( frame_cs - regs_cs - SIZEOF_REG )(%rsp)
  145. popq ( frame_ss - regs_ss - SIZEOF_REG )(%rsp)
  146. addq $( regs_fs - regs_ds ), %rsp /* skip %ds, %es */
  147. popq %fs
  148. popq %gs
  149. /* Skip code */
  150. addq $( gdb_end - gdb_code ), %rsp /* skip code */
  151. /* Return */
  152. iretq