2 * Interrupt handlers for GDB stub
5 #define SIZEOF_I386_REGS 32
6 #define SIZEOF_I386_FLAGS 4
8 /****************************************************************************
10 ****************************************************************************
12 .section ".text", "ax", @progbits
15 /* POSIX signal numbers for reporting traps to GDB */
23 .globl gdbmach_nocode_sigfpe
24 gdbmach_nocode_sigfpe:
28 .globl gdbmach_nocode_sigtrap
29 gdbmach_nocode_sigtrap:
33 .globl gdbmach_nocode_sigstkflt
34 gdbmach_nocode_sigstkflt:
38 .globl gdbmach_nocode_sigill
39 gdbmach_nocode_sigill:
43 .globl gdbmach_withcode_sigbus
44 gdbmach_withcode_sigbus:
48 .globl gdbmach_withcode_sigsegv
49 gdbmach_withcode_sigsegv:
53 /* When invoked, the stack contains: eflags, cs, eip, signo. */
54 #define IH_OFFSET_GDB_REGS ( 0 )
55 #define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
56 #define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
57 #define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
58 #define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
59 #define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
60 #define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
61 #define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
62 #define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
63 #define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
65 /* We also access the stack whilst still storing or restoring
66 * the register snapshot. Since ESP is in flux, we need
69 #define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
70 #define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
71 #define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
72 #define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
74 /* Store CPU state in GDB register snapshot */
86 pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
87 pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
88 pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
92 leal IH_OFFSET_FLUX_END(%esp), %edi
93 pushl %edi /* old ESP */
99 /* Switch to virtual addressing */
102 /* Call GDB stub exception handler */
104 pushl (IH_OFFSET_SIGNO + 4)(%esp)
108 /* Copy register snapshot to new stack and switch to new stack */
110 movl (IH_OFFSET_GDB_SEG_REGS + 4)(%esp), %eax
112 movl (IH_OFFSET_GDB_REGS + 16)(%esp), %edi
113 subl $IH_OFFSET_END, %edi
114 movl $(IH_OFFSET_END / 4), %ecx
121 /* Restore CPU state from GDB register snapshot */
126 popl %ebp /* Skip %esp: already loaded */
130 popl IH_OFFSET_FLUX_OLD_EIP(%esp)
131 popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
132 popl IH_OFFSET_FLUX_OLD_CS(%esp)
133 popl %ds /* Skip %ss: already loaded */
139 addl $4, %esp /* drop signo */