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. More...
 
void gdbmach_init (void)
 Initialise GDB. More...
 

Detailed Description

GDB architecture specifics.

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

Definition in file gdbmach.h.

Typedef Documentation

◆ gdbreg_t

typedef unsigned long gdbreg_t

Definition at line 15 of file gdbmach.h.

Enumeration Type Documentation

◆ anonymous enum

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

anonymous enum
Enumerator
GDBMACH_BPMEM 
GDBMACH_BPHW 
GDBMACH_WATCH 
GDBMACH_RWATCH 
GDBMACH_AWATCH 

Definition at line 41 of file gdbmach.h.

Function Documentation

◆ gdbmach_sigfpe()

void gdbmach_sigfpe ( void  )

◆ gdbmach_sigtrap()

void gdbmach_sigtrap ( void  )

◆ gdbmach_sigstkflt()

void gdbmach_sigstkflt ( void  )

◆ gdbmach_sigill()

void gdbmach_sigill ( void  )

◆ gdbmach_set_pc()

static void gdbmach_set_pc ( gdbreg_t regs,
gdbreg_t  pc 
)
inlinestatic

Definition at line 55 of file gdbmach.h.

55  {
56  regs [ GDBMACH_EIP ] = pc;
57 }
struct i386_regs regs
Definition: registers.h:15

References GDBMACH_EIP, and regs.

Referenced by gdbstub_continue().

◆ gdbmach_set_single_step()

static void gdbmach_set_single_step ( gdbreg_t regs,
int  step 
)
inlinestatic

Definition at line 59 of file gdbmach.h.

59  {
60  regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
61  regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
62 }
struct i386_regs regs
Definition: registers.h:15
void step(void)
Single-step a single process.
Definition: process.c:98

References GDBMACH_EFLAGS, regs, and step().

Referenced by gdbstub_continue().

◆ gdbmach_breakpoint()

static void gdbmach_breakpoint ( void  )
inlinestatic

Definition at line 64 of file gdbmach.h.

64  {
65  __asm__ __volatile__ ( "int $3\n" );
66 }
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")

References __asm__(), and __volatile__().

Referenced by gdbstub_start().

◆ gdbmach_set_breakpoint()

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.

135  {
136  unsigned int rwlen;
137  unsigned long mask;
138  int bp;
139 
140  /* Parse breakpoint type */
141  switch ( type ) {
142  case GDBMACH_WATCH:
143  rwlen = DR7_RWLEN_WRITE;
144  break;
145  case GDBMACH_AWATCH:
146  rwlen = DR7_RWLEN_ACCESS;
147  break;
148  default:
149  return -ENOTSUP;
150  }
151 
152  /* Parse breakpoint length */
153  switch ( len ) {
154  case 1:
155  rwlen |= DR7_RWLEN_1;
156  break;
157  case 2:
158  rwlen |= DR7_RWLEN_2;
159  break;
160  case 4:
161  rwlen |= DR7_RWLEN_4;
162  break;
163  case 8:
164  rwlen |= DR7_RWLEN_8;
165  break;
166  default:
167  return -ENOTSUP;
168  }
169 
170  /* Convert to linear address */
171  if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
172  addr = virt_to_phys ( ( void * ) addr );
173 
174  /* Find reusable or available hardware breakpoint */
175  bp = gdbmach_find ( addr, rwlen );
176  if ( bp < 0 )
177  return ( enable ? -ENOBUFS : 0 );
178 
179  /* Configure this breakpoint */
180  DBGC ( &dr[0], "GDB bp %d at %p+%zx type %d (%sabled)\n",
181  bp, ( ( void * ) addr ), len, type, ( enable ? "en" : "dis" ) );
182  dr[bp] = addr;
183  mask = DR7_RWLEN_MASK ( bp );
184  dr7 = ( ( dr7 & ~mask ) | ( rwlen & mask ) );
185  mask = DR7_G ( bp );
186  dr7 &= ~mask;
187  if ( enable )
188  dr7 |= mask;
189 
190  /* Update debug registers */
191  gdbmach_update();
192 
193  return 0;
194 }
#define DR7_RWLEN_MASK(bp)
Debug register 7: Breakpoint R/W and length mask.
Definition: gdbmach.c:70
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
uint16_t bp
Definition: registers.h:23
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define DR7_RWLEN_1
Debug register 7: One-byte length.
Definition: gdbmach.c:58
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static int gdbmach_find(unsigned long addr, unsigned int rwlen)
Find reusable or available hardware breakpoint.
Definition: gdbmach.c:99
#define DR7_RWLEN_ACCESS
Debug register 7: Break on data access.
Definition: gdbmach.c:55
u32 addr
Definition: sky2.h:8
static unsigned long dr[NUM_HWBP]
Hardware breakpoint addresses (debug registers 0-3)
Definition: gdbmach.c:73
unsigned int uint32_t
Definition: stdint.h:12
unsigned long physaddr_t
Definition: stdint.h:20
#define DR7_RWLEN_2
Debug register 7: Two-byte length.
Definition: gdbmach.c:61
#define DR7_G(bp)
Debug register 7: Global breakpoint enable.
Definition: gdbmach.c:46
uint32_t len
Length.
Definition: ena.h:14
static void gdbmach_update(void)
Update debug registers.
Definition: gdbmach.c:82
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
static unsigned long dr7
Active value of debug register 7.
Definition: gdbmach.c:76
#define DR7_RWLEN_8
Debug register 7: Eight-byte length.
Definition: gdbmach.c:67
#define DR7_RWLEN_WRITE
Debug register 7: Break on data writes.
Definition: gdbmach.c:52
#define DR7_RWLEN_4
Debug register 7: Four-byte length.
Definition: gdbmach.c:64

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, len, type, and virt_to_phys().

Referenced by gdbstub_breakpoint().

◆ gdbmach_init()

void gdbmach_init ( void  )

Initialise GDB.

Definition at line 242 of file gdbmach.c.

242  {
243  unsigned int i;
244 
245  /* Hook CPU exception vectors */
246  for ( i = 0 ; i < ( sizeof ( gdbmach_vectors ) /
247  sizeof ( gdbmach_vectors[0] ) ) ; i++ ) {
248  if ( gdbmach_vectors[i] )
250  }
251 }
static void * gdbmach_vectors[]
CPU exception vectors.
Definition: gdbmach.c:229
void set_interrupt_vector(unsigned int intr, void *vector)
Set interrupt vector.
Definition: librm_mgmt.c:93

References gdbmach_vectors, and set_interrupt_vector().

Referenced by gdbstub_start().