📄 plf_stub.c
字号:
asm(" movw registers+44, %ss");asm(" movl registers+16, %esp");asm(" movl registers+4, %ecx");asm(" movl registers+8, %edx");asm(" movl registers+12, %ebx");asm(" movl registers+20, %ebp");asm(" movl registers+24, %esi");asm(" movl registers+28, %edi");asm(" movw registers+48, %ds");asm(" movw registers+52, %es");asm(" movw registers+56, %fs");asm(" movw registers+60, %gs");asm(" movl registers+36, %eax");asm(" pushl %eax"); /* saved eflags */asm(" movl registers+40, %eax");asm(" pushl %eax"); /* saved cs */asm(" movl registers+32, %eax");asm(" pushl %eax"); /* saved eip */asm(" movl registers, %eax");/* use iret to restore pc and flags together so that trace flag works right. */asm(" iret");#if 0extern void return_to_prog ();/* Restore the program's registers (including the stack pointer, which means we get the right stack and don't have to worry about popping our return address and any stack frames and so on) and return. */asm(".text");asm(".globl return_to_prog");asm("return_to_prog:");asm(" movw registers+44, %ss");asm(" movl registers+16, %esp");asm(" movl registers+4, %ecx");asm(" movl registers+8, %edx");asm(" movl registers+12, %ebx");asm(" movl registers+20, %ebp");asm(" movl registers+24, %esi");asm(" movl registers+28, %edi");asm(" movw registers+48, %ds");asm(" movw registers+52, %es");asm(" movw registers+56, %fs");asm(" movw registers+60, %gs");asm(" movl registers+36, %eax");asm(" pushl %eax"); /* saved eflags */asm(" movl registers+40, %eax");asm(" pushl %eax"); /* saved cs */asm(" movl registers+32, %eax");asm(" pushl %eax"); /* saved eip */asm(" movl registers, %eax");/* use iret to restore pc and flags together so that trace flag works right. */asm(" iret");#define BREAKPOINT() asm(" int $3");/* Put the error code here just in case the user cares. */int gdb_i386errcode;/* Likewise, the vector number here (since GDB only gets the signal number through the usual means, and that's not very specific). */int gdb_i386vector = -1;/* 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 ("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 ("movw %ds, 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");#define SAVE_ERRCODE() \ asm ("popl %ebx"); \ asm ("movl %ebx, gdb_i386errcode");#define SAVE_REGISTERS2() \ asm ("popl %ebx"); /* old eip */ \ asm ("movl %ebx, registers+32"); \ asm ("popl %ebx"); /* old cs */ \ asm ("movl %ebx, registers+40"); \ asm ("movw %ax, registers+42"); \ asm ("popl %ebx"); /* old eflags */ \ asm ("movl %ebx, registers+36"); \ /* Now that we've done the pops, we can save the stack pointer."); */ \ asm ("movw %ss, registers+44"); \ asm ("movw %ax, registers+46"); \ asm ("movl %esp, registers+16");/* See if mem_fault_routine is set, if so just IRET to that address. */#define CHECK_FAULT() \ asm ("cmpl $0, mem_fault_routine"); \ asm ("jne mem_fault");asm (".text");asm ("mem_fault:");/* OK to clobber temp registers; we're just going to end up in set_mem_err. *//* Pop error code from the stack and save it. */asm (" popl %eax");asm (" movl %eax, gdb_i386errcode");asm (" popl %eax"); /* eip *//* We don't want to return there, we want to return to the function pointed to by mem_fault_routine instead. */asm (" movl mem_fault_routine, %eax");asm (" popl %ecx"); /* cs (low 16 bits; junk in hi 16 bits). */asm (" popl %edx"); /* eflags *//* Remove this stack frame; when we do the iret, we will be going to the start of a function, so we want the stack to look just like it would after a "call" instruction. */asm (" leave");/* Push the stuff that iret wants. */asm (" pushl %edx"); /* eflags */asm (" pushl %ecx"); /* cs */asm (" pushl %eax"); /* eip *//* Zero mem_fault_routine. */asm (" movl $0, %eax");asm (" movl %eax, mem_fault_routine");asm ("iret");/* * 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 */asm(" popl %eax"); /* get the exception number */asm(" movl stackPtr, %esp"); /* move to remcom stack area */asm(" pushl %eax"); /* push exception onto stack */asm(" call handle_exception"); /* this never returns */void _returnFromException(){ return_to_prog ();}#define CALL_HOOK() asm("call remcomHandler");#endif /* pjo */#define CHECK_FAULT()/* This function is called when a i386 exception occurs. It saves * all the cpu regs in the registers array, munges the stack a bit, * and invokes an exception handler (remcom_handler). * * stack on entry: stack on exit: * old eflags vector number * old cs (zero-filled to 32 bits) * old eip * */externC void hal_pc_exception_3(void);asm(".text");asm(".globl hal_pc_exception_3");asm("hal_pc_exception_3:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $3");CALL_HOOK();/* Same thing for exception 1. */externC void hal_pc_exception_1(void);asm(".text");asm(".globl hal_pc_exception_1");asm("hal_pc_exception_1:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $1");CALL_HOOK();/* Same thing for exception 0. */externC void hal_pc_exception_0(void);asm(".text");asm(".globl hal_pc_exception_0");asm("hal_pc_exception_0:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $0");CALL_HOOK();/* Same thing for exception 4. */externC void hal_pc_exception_4(void);asm(".text");asm(".globl hal_pc_exception_4");asm("hal_pc_exception_4:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $4");CALL_HOOK();/* Same thing for exception 5. */externC void hal_pc_exception_5(void);asm(".text");asm(".globl hal_pc_exception_5");asm("hal_pc_exception_5:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $5");CALL_HOOK();/* Same thing for exception 6. */externC void hal_pc_exception_6(void);asm(".text");asm(".globl hal_pc_exception_6");asm("hal_pc_exception_6:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $6");CALL_HOOK();/* Same thing for exception 7. */externC void hal_pc_exception_7(void);asm(".text");asm(".globl hal_pc_exception_7");asm("hal_pc_exception_7:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $7");CALL_HOOK();/* Same thing for exception 8. */externC void hal_pc_exception_8(void);asm(".text");asm(".globl hal_pc_exception_8");asm("hal_pc_exception_8:");SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $8");CALL_HOOK();/* Same thing for exception 9. */externC void hal_pc_exception_9(void);asm(".text");asm(".globl hal_pc_exception_9");asm("hal_pc_exception_9:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $9");CALL_HOOK();/* Same thing for exception 10. */externC void hal_pc_exception_10(void);asm(".text");asm(".globl hal_pc_exception_10");asm("hal_pc_exception_10:");SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $10");CALL_HOOK();/* Same thing for exception 12. */externC void hal_pc_exception_12(void);asm(".text");asm(".globl hal_pc_exception_12");asm("hal_pc_exception_12:");SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $12");CALL_HOOK();/* Same thing for exception 16. */externC void hal_pc_exception_16(void);asm(".text");asm(".globl hal_pc_exception_16");asm("hal_pc_exception_16:");SAVE_REGISTERS1();SAVE_REGISTERS2();asm ("pushl $16");CALL_HOOK();/* For 13, 11, and 14 we have to deal with the CHECK_FAULT stuff. *//* Same thing for exception 13. */externC void hal_pc_exception_13 (void);asm (".text");asm (".globl hal_pc_exception_13");asm ("hal_pc_exception_13:");CHECK_FAULT();SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $13");CALL_HOOK();/* Same thing for exception 11. */externC void hal_pc_exception_11 (void);asm (".text");asm (".globl hal_pc_exception_11");asm ("hal_pc_exception_11:");CHECK_FAULT();SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $11");CALL_HOOK();/* Same thing for exception 14. */externC void hal_pc_exception_14 (void);asm (".text");asm (".globl hal_pc_exception_14");asm ("hal_pc_exception_14:");CHECK_FAULT();SAVE_REGISTERS1();SAVE_ERRCODE();SAVE_REGISTERS2();asm ("pushl $14");CALL_HOOK();// Connect to the appropriate ISRs./* this function is used to set up exception handlers for tracing and breakpoints */void hal_pc_stubs_init(void){#if 0extern void remcomHandler();int exception; stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1];#endif#if 0 int i ; int * p = (int*) 0 ; for (i = 0; i < CYGNUM_HAL_ISR_COUNT; i++) { p[0] = 0 ; p++ ; p[0] = 0 ; p++ ; }#endif hal_pc_exception_handler(0, hal_pc_exception_0); hal_pc_exception_handler(1, hal_pc_exception_1); hal_pc_exception_handler(3, hal_pc_exception_3); hal_pc_exception_handler(4, hal_pc_exception_4); hal_pc_exception_handler(5, hal_pc_exception_5); hal_pc_exception_handler(6, hal_pc_exception_6); hal_pc_exception_handler(7, hal_pc_exception_7); hal_pc_exception_handler(8, hal_pc_exception_8); hal_pc_exception_handler(9, hal_pc_exception_9); hal_pc_exception_handler(10, hal_pc_exception_10); hal_pc_exception_handler(11, hal_pc_exception_11); hal_pc_exception_handler(12, hal_pc_exception_12); hal_pc_exception_handler(13, hal_pc_exception_13); hal_pc_exception_handler(14, hal_pc_exception_14); hal_pc_exception_handler(16, hal_pc_exception_16);}void hal_get_gdb_registers(target_register_t * d, HAL_SavedRegisters * s){ int i ; for (i = 0; i < NUMREGS; i++) d[i] = hal_pc_trap_registers[i] ;}void hal_set_gdb_registers(HAL_SavedRegisters * d, target_register_t * s){ int i ; for (i = 0; i < NUMREGS; i++) hal_pc_trap_registers[i] = s[i] ;}#endif // ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS//-----------------------------------------------------------------------------// End of plf_stub.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -