iPXE
Typedefs | Enumerations | Functions
gdbmach.h File Reference

GDB architecture specifics. More...

#include <stdint.h>

Go to the source code of this file.

Typedefs

typedef unsigned long gdbreg_t

Enumerations

enum  {
  GDBMACH_EAX, GDBMACH_ECX, GDBMACH_EDX, GDBMACH_EBX,
  GDBMACH_ESP, GDBMACH_EBP, GDBMACH_ESI, GDBMACH_EDI,
  GDBMACH_EIP, GDBMACH_EFLAGS, GDBMACH_CS, GDBMACH_SS,
  GDBMACH_DS, GDBMACH_ES, GDBMACH_FS, GDBMACH_GS,
  GDBMACH_NREGS, GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
}
enum  {
  GDBMACH_BPMEM, GDBMACH_BPHW, GDBMACH_WATCH, GDBMACH_RWATCH,
  GDBMACH_AWATCH
}

Functions

void gdbmach_sigfpe (void)
void gdbmach_sigtrap (void)
void gdbmach_sigstkflt (void)
void gdbmach_sigill (void)
static void gdbmach_set_pc (gdbreg_t *regs, gdbreg_t pc)
static void gdbmach_set_single_step (gdbreg_t *regs, int step)
static void gdbmach_breakpoint (void)
int gdbmach_set_breakpoint (int type, unsigned long addr, size_t len, int enable)
 Set hardware breakpoint.
void gdbmach_init (void)
 Initialise GDB.

Detailed Description

GDB architecture specifics.

This file declares functions for manipulating the machine state and debugging context.

Definition in file gdbmach.h.


Typedef Documentation

typedef unsigned long gdbreg_t

Definition at line 15 of file gdbmach.h.


Enumeration Type Documentation

anonymous enum
Enumerator:
GDBMACH_EAX 
GDBMACH_ECX 
GDBMACH_EDX 
GDBMACH_EBX 
GDBMACH_ESP 
GDBMACH_EBP 
GDBMACH_ESI 
GDBMACH_EDI 
GDBMACH_EIP 
GDBMACH_EFLAGS 
GDBMACH_CS 
GDBMACH_SS 
GDBMACH_DS 
GDBMACH_ES 
GDBMACH_FS 
GDBMACH_GS 
GDBMACH_NREGS 
GDBMACH_SIZEOF_REGS 

Definition at line 19 of file gdbmach.h.

anonymous enum
Enumerator:
GDBMACH_BPMEM 
GDBMACH_BPHW 
GDBMACH_WATCH 
GDBMACH_RWATCH 
GDBMACH_AWATCH 

Definition at line 41 of file gdbmach.h.


Function Documentation

void gdbmach_sigfpe ( void  )
void gdbmach_sigtrap ( void  )
void gdbmach_sigstkflt ( void  )
void gdbmach_sigill ( void  )
static void gdbmach_set_pc ( gdbreg_t regs,
gdbreg_t  pc 
) [inline, static]

Definition at line 55 of file gdbmach.h.

References GDBMACH_EIP.

Referenced by gdbstub_continue().

                                                                  {
        regs [ GDBMACH_EIP ] = pc;
}
static void gdbmach_set_single_step ( gdbreg_t regs,
int  step 
) [inline, static]

Definition at line 59 of file gdbmach.h.

References GDBMACH_EFLAGS.

Referenced by gdbstub_continue().

                                                                        {
        regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
        regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
}
static void gdbmach_breakpoint ( void  ) [inline, static]

Definition at line 64 of file gdbmach.h.

References __asm__().

Referenced by gdbstub_start().

                                               {
        __asm__ __volatile__ ( "int $3\n" );
}
int gdbmach_set_breakpoint ( int  type,
unsigned long  addr,
size_t  len,
int  enable 
)

Set hardware breakpoint.

Parameters:
typeGDB breakpoint type
addrVirtual address
lenLength
enableEnable (not disable) breakpoint
Return values:
rcReturn status code

Definition at line 134 of file gdbmach.c.

References addr, bp, DBGC, dr, dr7, DR7_G, DR7_RWLEN_1, DR7_RWLEN_2, DR7_RWLEN_4, DR7_RWLEN_8, DR7_RWLEN_ACCESS, DR7_RWLEN_MASK, DR7_RWLEN_WRITE, ENOBUFS, ENOTSUP, GDBMACH_AWATCH, gdbmach_find(), gdbmach_update(), GDBMACH_WATCH, and virt_to_phys().

Referenced by gdbstub_breakpoint().

                                          {
        unsigned int rwlen;
        unsigned long mask;
        int bp;

        /* Parse breakpoint type */
        switch ( type ) {
        case GDBMACH_WATCH:
                rwlen = DR7_RWLEN_WRITE;
                break;
        case GDBMACH_AWATCH:
                rwlen = DR7_RWLEN_ACCESS;
                break;
        default:
                return -ENOTSUP;
        }

        /* Parse breakpoint length */
        switch ( len ) {
        case 1:
                rwlen |= DR7_RWLEN_1;
                break;
        case 2:
                rwlen |= DR7_RWLEN_2;
                break;
        case 4:
                rwlen |= DR7_RWLEN_4;
                break;
        case 8:
                rwlen |= DR7_RWLEN_8;
                break;
        default:
                return -ENOTSUP;
        }

        /* Convert to linear address */
        if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
                addr = virt_to_phys ( ( void * ) addr );

        /* Find reusable or available hardware breakpoint */
        bp = gdbmach_find ( addr, rwlen );
        if ( bp < 0 )
                return ( enable ? -ENOBUFS : 0 );

        /* Configure this breakpoint */
        DBGC ( &dr[0], "GDB bp %d at %p+%zx type %d (%sabled)\n",
               bp, ( ( void * ) addr ), len, type, ( enable ? "en" : "dis" ) );
        dr[bp] = addr;
        mask = DR7_RWLEN_MASK ( bp );
        dr7 = ( ( dr7 & ~mask ) | ( rwlen & mask ) );
        mask = DR7_G ( bp );
        dr7 &= ~mask;
        if ( enable )
                dr7 |= mask;

        /* Update debug registers */
        gdbmach_update();

        return 0;
}
void gdbmach_init ( void  )

Initialise GDB.

Definition at line 242 of file gdbmach.c.

References gdbmach_vectors, and set_interrupt_vector().

Referenced by gdbstub_start().

                           {
        unsigned int i;

        /* Hook CPU exception vectors */
        for ( i = 0 ; i < ( sizeof ( gdbmach_vectors ) /
                            sizeof ( gdbmach_vectors[0] ) ) ; i++ ) {
                if ( gdbmach_vectors[i] )
                        set_interrupt_vector ( i, gdbmach_vectors[i] );
        }
}