Home | History | Annotate | Download | only in gdbstub
      1     .section ".text","ax"
      2 
      3 #define SIGTRAP 5
      4 
      5 #define SIZEOF_I386_REGS    32
      6 #define SIZEOF_I386_FLAGS   4
      7 
      8 /* When invoked, the stack contains: eflags, cs, eip, signo. */
      9 #define IH_OFFSET_GDB_REGS ( 0 )
     10 #define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
     11 #define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
     12 #define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
     13 #define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
     14 #define IH_OFFSET_OLD_EIP ( IH_OFFSET_GDB_END )
     15 #define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
     16 #define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
     17 #define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
     18 
     19 /* We also access the stack whilst still storing or restoring
     20  * the register snapshot.  Since ESP is in flux, we need
     21  * special offsets.
     22  */
     23 #define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
     24 #define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
     25 #define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
     26 #define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
     27 
     28     .global int_handler
     29 int_handler:
     30 	/* Store CPU state in GDB register snapshot */
     31 	pushw	$0
     32 	pushw	%gs
     33 	pushw	$0
     34 	pushw	%fs
     35 	pushw	$0
     36 	pushw	%es
     37 	pushw	$0
     38 	pushw	%ds
     39 	pushw	$0
     40 	pushw	%ss
     41 	pushw	$0
     42 	pushw	IH_OFFSET_FLUX_OLD_CS + 2(%esp)
     43 	pushl	IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
     44 	pushl	IH_OFFSET_FLUX_OLD_EIP(%esp)
     45 	pushl	%edi
     46 	pushl	%esi
     47 	pushl	%ebp
     48 	leal	IH_OFFSET_FLUX_END(%esp), %edi
     49 	pushl	%edi /* old ESP */
     50 	pushl	%ebx
     51 	pushl	%edx
     52 	pushl	%ecx
     53 	pushl	%eax
     54 
     55 	/* Call GDB stub exception handler */
     56     movl    $SIGTRAP, %eax
     57 	movl	%esp, %edx
     58 	call	gdbstub_handler
     59 
     60 	/* Restore CPU state from GDB register snapshot */
     61 	popl	%eax
     62 	popl	%ecx
     63 	popl	%edx
     64 	popl	%ebx
     65 	addl	$4, %esp /* Changing ESP currently not supported */
     66 	popl	%ebp
     67 	popl	%esi
     68 	popl	%edi
     69 	popl	IH_OFFSET_FLUX_OLD_EIP(%esp)
     70 	popl	IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
     71 	popl	IH_OFFSET_FLUX_OLD_CS(%esp)
     72 	popl	%ss
     73 	popl	%ds
     74 	popl	%es
     75 	popl	%fs
     76 	popl	%gs
     77 	iret
     78