2008-06-04 21:09:59 +01:00
|
|
|
/*
|
2014-04-28 20:17:15 +01:00
|
|
|
* Interrupt handlers for GDB stub
|
2008-06-04 21:09:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define SIZEOF_I386_REGS 32
|
|
|
|
|
#define SIZEOF_I386_FLAGS 4
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Interrupt handlers
|
|
|
|
|
****************************************************************************
|
|
|
|
|
*/
|
[i386] Add explicit flags and type on all .section declarations
Try to avoid future problems caused by implicit section flags and/or
type information by instituting a policy that all .section
declarations must explicitly state the flags and type.
Most of this change was achieved using
perl -pi \
-e 's/".text"$/".text", "ax", \@progbits/ ; ' \
-e 's/".text16"$/".text16", "ax", \@progbits/ ; ' \
-e 's/".text16.null"$/".text16.null", "ax", \@progbits/ ; ' \
-e 's/".text16.data"$/".text16.data", "aw", \@progbits/ ; ' \
-e 's/".data"$/".data", "aw", \@progbits/ ; ' \
-e 's/".data16"$/".data16", "aw", \@progbits/ ; ' \
-e 's/".bss"$/".bss", "aw", \@nobits/ ; ' \
-e 's/".bss16"$/".bss16", "aw", \@nobits/ ; ' \
-e 's/".prefix"$/".prefix", "ax", \@progbits/ ; ' \
-e 's/".prefix.lib"$/".prefix.lib", "awx", \@progbits/ ; ' \
-e 's/".prefix.data"$/".prefix.data", "aw", \@progbits/ ; ' \
-e 's/".weak"$/".weak", "a", \@nobits/ ; ' \
`git grep -l '\.section'`
2009-02-15 10:54:52 +00:00
|
|
|
.section ".text", "ax", @progbits
|
2008-06-04 21:09:59 +01:00
|
|
|
.code32
|
|
|
|
|
|
|
|
|
|
/* POSIX signal numbers for reporting traps to GDB */
|
|
|
|
|
#define SIGILL 4
|
|
|
|
|
#define SIGTRAP 5
|
|
|
|
|
#define SIGBUS 7
|
|
|
|
|
#define SIGFPE 8
|
|
|
|
|
#define SIGSEGV 11
|
|
|
|
|
#define SIGSTKFLT 16
|
|
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_nocode_sigfpe
|
|
|
|
|
gdbmach_nocode_sigfpe:
|
2008-06-04 21:09:59 +01:00
|
|
|
pushl $SIGFPE
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_nocode_sigtrap
|
|
|
|
|
gdbmach_nocode_sigtrap:
|
2008-06-04 21:09:59 +01:00
|
|
|
pushl $SIGTRAP
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_nocode_sigstkflt
|
|
|
|
|
gdbmach_nocode_sigstkflt:
|
2008-06-04 21:09:59 +01:00
|
|
|
pushl $SIGSTKFLT
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_nocode_sigill
|
|
|
|
|
gdbmach_nocode_sigill:
|
2008-06-04 21:09:59 +01:00
|
|
|
pushl $SIGILL
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_withcode_sigbus
|
|
|
|
|
gdbmach_withcode_sigbus:
|
2008-06-04 21:09:59 +01:00
|
|
|
movl $SIGBUS, (%esp)
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
.globl gdbmach_withcode_sigsegv
|
|
|
|
|
gdbmach_withcode_sigsegv:
|
2008-06-04 21:09:59 +01:00
|
|
|
movl $SIGSEGV, (%esp)
|
2014-04-28 20:17:15 +01:00
|
|
|
jmp gdbmach_interrupt
|
2008-06-04 21:09:59 +01:00
|
|
|
|
|
|
|
|
/* When invoked, the stack contains: eflags, cs, eip, signo. */
|
|
|
|
|
#define IH_OFFSET_GDB_REGS ( 0 )
|
|
|
|
|
#define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
|
|
|
|
|
#define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
|
|
|
|
|
#define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
|
|
|
|
|
#define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
|
|
|
|
|
#define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
|
|
|
|
|
#define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
|
|
|
|
|
#define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
|
|
|
|
|
#define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
|
|
|
|
|
#define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
|
|
|
|
|
|
|
|
|
|
/* We also access the stack whilst still storing or restoring
|
|
|
|
|
* the register snapshot. Since ESP is in flux, we need
|
|
|
|
|
* special offsets.
|
|
|
|
|
*/
|
|
|
|
|
#define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
|
|
|
|
|
#define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
|
|
|
|
|
#define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
|
|
|
|
|
#define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
|
2014-04-28 20:17:15 +01:00
|
|
|
gdbmach_interrupt:
|
2008-06-04 21:09:59 +01:00
|
|
|
/* Store CPU state in GDB register snapshot */
|
2008-06-13 10:26:49 +01:00
|
|
|
pushw $0
|
|
|
|
|
pushw %gs
|
|
|
|
|
pushw $0
|
|
|
|
|
pushw %fs
|
|
|
|
|
pushw $0
|
|
|
|
|
pushw %es
|
|
|
|
|
pushw $0
|
|
|
|
|
pushw %ds
|
|
|
|
|
pushw $0
|
|
|
|
|
pushw %ss
|
|
|
|
|
pushw $0
|
|
|
|
|
pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
|
2008-06-04 21:09:59 +01:00
|
|
|
pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
|
|
|
|
|
pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
|
|
|
|
|
pushl %edi
|
|
|
|
|
pushl %esi
|
|
|
|
|
pushl %ebp
|
|
|
|
|
leal IH_OFFSET_FLUX_END(%esp), %edi
|
|
|
|
|
pushl %edi /* old ESP */
|
|
|
|
|
pushl %ebx
|
|
|
|
|
pushl %edx
|
|
|
|
|
pushl %ecx
|
|
|
|
|
pushl %eax
|
|
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
/* Switch to virtual addressing */
|
|
|
|
|
call _intr_to_virt
|
|
|
|
|
|
2008-06-04 21:09:59 +01:00
|
|
|
/* Call GDB stub exception handler */
|
|
|
|
|
pushl %esp
|
|
|
|
|
pushl (IH_OFFSET_SIGNO + 4)(%esp)
|
2008-06-12 16:56:20 +01:00
|
|
|
call gdbmach_handler
|
2008-06-04 21:09:59 +01:00
|
|
|
addl $8, %esp
|
|
|
|
|
|
2014-04-28 20:17:15 +01:00
|
|
|
/* Copy register snapshot to new stack and switch to new stack */
|
|
|
|
|
movl %esp, %esi
|
|
|
|
|
movl (IH_OFFSET_GDB_SEG_REGS + 4)(%esp), %eax
|
|
|
|
|
movl %eax, %es
|
|
|
|
|
movl (IH_OFFSET_GDB_REGS + 16)(%esp), %edi
|
|
|
|
|
subl $IH_OFFSET_END, %edi
|
|
|
|
|
movl $(IH_OFFSET_END / 4), %ecx
|
|
|
|
|
pushl %edi
|
|
|
|
|
ss rep movsl
|
|
|
|
|
popl %edi
|
|
|
|
|
movl %eax, %ss
|
|
|
|
|
movl %edi, %esp
|
|
|
|
|
|
2008-06-04 21:09:59 +01:00
|
|
|
/* Restore CPU state from GDB register snapshot */
|
|
|
|
|
popl %eax
|
|
|
|
|
popl %ecx
|
|
|
|
|
popl %edx
|
|
|
|
|
popl %ebx
|
2014-04-28 20:17:15 +01:00
|
|
|
popl %ebp /* Skip %esp: already loaded */
|
2008-06-04 21:09:59 +01:00
|
|
|
popl %ebp
|
|
|
|
|
popl %esi
|
|
|
|
|
popl %edi
|
|
|
|
|
popl IH_OFFSET_FLUX_OLD_EIP(%esp)
|
|
|
|
|
popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
|
|
|
|
|
popl IH_OFFSET_FLUX_OLD_CS(%esp)
|
2014-04-28 20:17:15 +01:00
|
|
|
popl %ds /* Skip %ss: already loaded */
|
2008-06-04 21:09:59 +01:00
|
|
|
popl %ds
|
|
|
|
|
popl %es
|
|
|
|
|
popl %fs
|
|
|
|
|
popl %gs
|
|
|
|
|
|
|
|
|
|
addl $4, %esp /* drop signo */
|
|
|
|
|
iret
|