69,382
社区成员
发帖
与我相关
我的任务
分享
#define CALL_HOOK() asm("call _remcomHandler");
/* GDB stores segment registers in 32-bit words (that's just the way
m-i386v.h is written). So zero the appropriate areas in registers. */
#define SAVE_REGISTERS1() \
asm ("pushw %ds"); \
asm ("pushw %cs"); \
asm ("popw %ds"); \
asm ("movl %eax, _registers"); \
asm ("movl %ecx, _registers+4"); \
asm ("movl %edx, _registers+8"); \
asm ("movl %ebx, _registers+12"); \
asm ("movl %ebp, _registers+20"); \
asm ("movl %esi, _registers+24"); \
asm ("movl %edi, _registers+28"); \
asm ("movw $0, %ax"); \
asm ("popw %bx") ; /*old ds*/ \
asm ("movw %bx, _registers+48"); \
asm ("movw %ax, _registers+50"); \
asm ("movw %es, _registers+52"); \
asm ("movw %ax, _registers+54"); \
asm ("movw %fs, _registers+56"); \
asm ("movw %ax, _registers+58"); \
asm ("movw %gs, _registers+60"); \
asm ("movw %ax, _registers+62"); \
asm ("popw %bx"); /* old ip */ \
asm ("movw %bx, _registers+32"); \
asm ("movw %ax, _registers+34"); \
asm ("popw %bx"); /* old cs */ \
asm ("movw %bx, _registers+40"); \
asm ("movw %ax, _registers+42"); \
asm ("popw %bx"); /* old eflags */ \
asm ("movw %bx, _registers+36"); \
asm ("movw %ax, _registers+38"); \
/* Now that we've done the pops, we can save the stack pointer."); */ \
asm ("movw %ss, _registers+44"); /* ss */ \
asm ("movw %ax, _registers+46"); \
asm ("movl %esp, _registers+16"); /* esp */
void
handle_exception (int exceptionVector)
{
int sigval;
int addr, length, reg;
char *ptr;
int i ;
unsigned char ch ;
asm ("movw _registers+40 , %gs "); //cs
asm ("movw _registers+48 , %fs "); //ds
if( mode == BIG_MODE )
registers[PC] = (registers[CS] << 4) + registers[PC];
.......................
.......................
}
/*
* remcomHandler is a front end for handle_exception. It moves the
* stack pointer into an area reserved for debugger use.
*/
asm ("_remcomHandler:");
asm (" popl %eax"); /* pop off return address .pop ip */
asm (" popl %eax"); /* get the exception number */
asm ("mov %cs , %bx");
asm ("mov %bx , %es");
asm ("mov %bx , %ss");
asm (" movl _stackPtr, %esp"); /* move to remcom stack area */
asm (" pushl %eax"); /* push exception onto stack */
asm (" call _handle_exception"); /* this never returns */
extern void catchException4 ();
asm (".text");
asm (".globl _catchException4");
asm ("_catchException4:");
SAVE_REGISTERS1 ();
asm ("pushl $4"); /*push 4*/
CALL_HOOK ();
#include<stdio.h>
int main()
{
int ia=90;
int ib=23;
_asm
{
push eax
mov eax,ia
add eax,ib
mov ia,eax
pop eax
}
printf("%d\n",ia);
return 0;
}