gdbmach.c File Reference

GDB architecture-specific bits for i386. More...

#include <stddef.h>
#include <stdio.h>
#include <assert.h>
#include <gpxe/uaccess.h>
#include <gpxe/gdbstub.h>
#include <gdbmach.h>

Go to the source code of this file.

Data Structures

struct  hwbp
 Hardware breakpoint, fields stored in x86 bit pattern form. More...

Enumerations

enum  { DR7_CLEAR = 0x00000400, DR6_CLEAR = 0xffff0ff0 }

Functions

static struct hwbpgdbmach_find_hwbp (int type, unsigned long addr, size_t len)
static void gdbmach_commit_hwbp (struct hwbp *bp)
int gdbmach_set_breakpoint (int type, unsigned long addr, size_t len, int enable)
static void gdbmach_disable_hwbps (void)
static void gdbmach_enable_hwbps (void)
__asmcall void gdbmach_handler (int signo, gdbreg_t *regs)

Variables

static struct hwbp hwbps [4]
static gdbreg_t dr7 = DR7_CLEAR


Detailed Description

GDB architecture-specific bits for i386.

Definition in file gdbmach.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
DR7_CLEAR 
DR6_CLEAR 

Definition at line 32 of file gdbmach.c.

00032      {
00033         DR7_CLEAR = 0x00000400,    /* disable hardware breakpoints */
00034         DR6_CLEAR = 0xffff0ff0,    /* clear breakpoint status */
00035 };


Function Documentation

static struct hwbp* gdbmach_find_hwbp ( int  type,
unsigned long  addr,
size_t  len 
) [static, read]

Definition at line 48 of file gdbmach.c.

References hwbp::enabled, hwbps, and NULL.

Referenced by gdbmach_set_breakpoint().

00048                                                                                    {
00049         struct hwbp *available = NULL;
00050         unsigned int i;
00051         for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) {
00052                 if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) {
00053                         return &hwbps [ i ];
00054                 }
00055                 if ( !hwbps [ i ].enabled ) {
00056                         available = &hwbps [ i ];
00057                 }
00058         }
00059         return available;
00060 }

static void gdbmach_commit_hwbp ( struct hwbp bp  )  [static]

Definition at line 62 of file gdbmach.c.

References __asm__(), hwbp::addr, assert, dr7, hwbp::enabled, hwbps, hwbp::len, and hwbp::type.

Referenced by gdbmach_set_breakpoint().

00062                                                     {
00063         unsigned int regnum = bp - hwbps;
00064 
00065         /* Set breakpoint address */
00066         assert ( regnum < ( sizeof hwbps / sizeof hwbps [ 0 ] ) );
00067         switch ( regnum ) {
00068                 case 0:
00069                         __asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) );
00070                         break;
00071                 case 1:
00072                         __asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) );
00073                         break;
00074                 case 2:
00075                         __asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) );
00076                         break;
00077                 case 3:
00078                         __asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) );
00079                         break;
00080         }
00081 
00082         /* Set type */
00083         dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) );
00084         dr7 |= bp->type << ( 16 + 4 * regnum );
00085 
00086         /* Set length */
00087         dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) );
00088         dr7 |= bp->len << ( 18 + 4 * regnum );
00089 
00090         /* Set/clear local enable bit */
00091         dr7 &= ~( 0x3 << 2 * regnum );
00092         dr7 |= bp->enabled << 2 * regnum;
00093 }

int gdbmach_set_breakpoint ( int  type,
unsigned long  addr,
size_t  len,
int  enable 
)

Definition at line 95 of file gdbmach.c.

References hwbp::addr, hwbp::enabled, GDBMACH_AWATCH, gdbmach_commit_hwbp(), gdbmach_find_hwbp(), GDBMACH_WATCH, hwbp::len, hwbp::type, and virt_offset.

Referenced by gdbstub_breakpoint().

00095                                                                                     {
00096         struct hwbp *bp;
00097         
00098         /* Check and convert breakpoint type to x86 type */
00099         switch ( type ) {
00100                 case GDBMACH_WATCH:
00101                         type = 0x1;
00102                         break;
00103                 case GDBMACH_AWATCH:
00104                         type = 0x3;
00105                         break;
00106                 default:
00107                         return 0; /* unsupported breakpoint type */
00108         }
00109 
00110         /* Only lengths 1, 2, and 4 are supported */
00111         if ( len != 2 && len != 4 ) {
00112                 len = 1;
00113         }
00114         len--; /* convert to x86 breakpoint length bit pattern */
00115 
00116         /* Calculate linear address by adding segment base */
00117         addr += virt_offset;
00118 
00119         /* Set up the breakpoint */
00120         bp = gdbmach_find_hwbp ( type, addr, len );
00121         if ( !bp ) {
00122                 return 0; /* ran out of hardware breakpoints */
00123         }
00124         bp->type = type;
00125         bp->addr = addr;
00126         bp->len = len;
00127         bp->enabled = enable;
00128         gdbmach_commit_hwbp ( bp );
00129         return 1;
00130 }

static void gdbmach_disable_hwbps ( void   )  [static]

Definition at line 132 of file gdbmach.c.

References __asm__(), and DR7_CLEAR.

Referenced by gdbmach_handler().

00132                                            {
00133         /* Store and clear hardware breakpoints */
00134         __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) );
00135 }

static void gdbmach_enable_hwbps ( void   )  [static]

Definition at line 137 of file gdbmach.c.

References __asm__(), DR6_CLEAR, and dr7.

Referenced by gdbmach_handler().

00137                                           {
00138         /* Clear breakpoint status register */
00139         __asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) );
00140 
00141         /* Restore hardware breakpoints */
00142         __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) );
00143 }

__asmcall void gdbmach_handler ( int  signo,
gdbreg_t regs 
)

Definition at line 145 of file gdbmach.c.

References gdbmach_disable_hwbps(), gdbmach_enable_hwbps(), and gdbstub_handler().

00145                                                              {
00146         gdbmach_disable_hwbps();
00147         gdbstub_handler ( signo, regs );
00148         gdbmach_enable_hwbps();
00149 }


Variable Documentation

struct hwbp hwbps[4] [static]

Definition at line 45 of file gdbmach.c.

Referenced by gdbmach_commit_hwbp(), and gdbmach_find_hwbp().

gdbreg_t dr7 = DR7_CLEAR [static]

Definition at line 46 of file gdbmach.c.

Referenced by gdbmach_commit_hwbp(), and gdbmach_enable_hwbps().


Generated on Tue Apr 6 20:01:11 2010 for gPXE by  doxygen 1.5.7.1