iPXE
gdbmach.h
Go to the documentation of this file.
00001 #ifndef GDBMACH_H
00002 #define GDBMACH_H
00003 
00004 /** @file
00005  *
00006  * GDB architecture specifics
00007  *
00008  * This file declares functions for manipulating the machine state and
00009  * debugging context.
00010  *
00011  */
00012 
00013 #include <stdint.h>
00014 
00015 typedef unsigned long gdbreg_t;
00016 
00017 /* The register snapshot, this must be in sync with interrupt handler and the
00018  * GDB protocol. */
00019 enum {
00020         GDBMACH_EAX,
00021         GDBMACH_ECX,
00022         GDBMACH_EDX,
00023         GDBMACH_EBX,
00024         GDBMACH_ESP,
00025         GDBMACH_EBP,
00026         GDBMACH_ESI,
00027         GDBMACH_EDI,
00028         GDBMACH_EIP,
00029         GDBMACH_EFLAGS,
00030         GDBMACH_CS,
00031         GDBMACH_SS,
00032         GDBMACH_DS,
00033         GDBMACH_ES,
00034         GDBMACH_FS,
00035         GDBMACH_GS,
00036         GDBMACH_NREGS,
00037         GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
00038 };
00039 
00040 /* Breakpoint types */
00041 enum {
00042         GDBMACH_BPMEM,
00043         GDBMACH_BPHW,
00044         GDBMACH_WATCH,
00045         GDBMACH_RWATCH,
00046         GDBMACH_AWATCH,
00047 };
00048 
00049 /* Interrupt vectors */
00050 extern void gdbmach_sigfpe ( void );
00051 extern void gdbmach_sigtrap ( void );
00052 extern void gdbmach_sigstkflt ( void );
00053 extern void gdbmach_sigill ( void );
00054 
00055 static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
00056         regs [ GDBMACH_EIP ] = pc;
00057 }
00058 
00059 static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
00060         regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
00061         regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
00062 }
00063 
00064 static inline void gdbmach_breakpoint ( void ) {
00065         __asm__ __volatile__ ( "int $3\n" );
00066 }
00067 
00068 extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable );
00069 
00070 extern void gdbmach_init ( void );
00071 
00072 #endif /* GDBMACH_H */