iPXE
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

 FILE_SECBOOT (FORBIDDEN)
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

◆ gdbreg_t

typedef unsigned long gdbreg_t

Definition at line 17 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 21 of file gdbmach.h.

21 {
40};
unsigned long gdbreg_t
Definition gdbmach.h:17
@ GDBMACH_SS
Definition gdbmach.h:33
@ GDBMACH_ES
Definition gdbmach.h:35
@ GDBMACH_EFLAGS
Definition gdbmach.h:31
@ GDBMACH_GS
Definition gdbmach.h:37
@ GDBMACH_CS
Definition gdbmach.h:32
@ GDBMACH_EBP
Definition gdbmach.h:27
@ GDBMACH_EAX
Definition gdbmach.h:22
@ GDBMACH_ESP
Definition gdbmach.h:26
@ GDBMACH_DS
Definition gdbmach.h:34
@ GDBMACH_NREGS
Definition gdbmach.h:38
@ GDBMACH_ECX
Definition gdbmach.h:23
@ GDBMACH_EBX
Definition gdbmach.h:25
@ GDBMACH_ESI
Definition gdbmach.h:28
@ GDBMACH_EDI
Definition gdbmach.h:29
@ GDBMACH_EDX
Definition gdbmach.h:24
@ GDBMACH_EIP
Definition gdbmach.h:30
@ GDBMACH_FS
Definition gdbmach.h:36
#define GDBMACH_SIZEOF_REGS
Definition gdbmach.h:25

◆ anonymous enum

anonymous enum
Enumerator
GDBMACH_BPMEM 
GDBMACH_BPHW 
GDBMACH_WATCH 
GDBMACH_RWATCH 
GDBMACH_AWATCH 

Definition at line 43 of file gdbmach.h.

43 {
49};
@ GDBMACH_BPMEM
Definition gdbmach.h:44
@ GDBMACH_WATCH
Definition gdbmach.h:46
@ GDBMACH_BPHW
Definition gdbmach.h:45
@ GDBMACH_RWATCH
Definition gdbmach.h:47
@ GDBMACH_AWATCH
Definition gdbmach.h:48

Function Documentation

◆ FILE_SECBOOT()

FILE_SECBOOT ( FORBIDDEN )

◆ gdbmach_sigfpe()

void gdbmach_sigfpe ( void )
extern

◆ gdbmach_sigtrap()

void gdbmach_sigtrap ( void )
extern

◆ gdbmach_sigstkflt()

void gdbmach_sigstkflt ( void )
extern

◆ gdbmach_sigill()

void gdbmach_sigill ( void )
extern

◆ gdbmach_set_pc()

void gdbmach_set_pc ( gdbreg_t * regs,
gdbreg_t pc )
inlinestatic

Definition at line 57 of file gdbmach.h.

57 {
58 regs [ GDBMACH_EIP ] = pc;
59}
struct i386_regs regs
Definition registers.h:1

References GDBMACH_EIP, and regs.

Referenced by gdbstub_continue().

◆ gdbmach_set_single_step()

void gdbmach_set_single_step ( gdbreg_t * regs,
int step )
inlinestatic

Definition at line 61 of file gdbmach.h.

61 {
62 regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
63 regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
64}
void step(void)
Single-step a single process.
Definition process.c:99

References GDBMACH_EFLAGS, regs, and step().

Referenced by gdbstub_continue().

◆ gdbmach_breakpoint()

void gdbmach_breakpoint ( void )
inlinestatic

Definition at line 66 of file gdbmach.h.

66 {
67 __asm__ __volatile__ ( "int $3\n" );
68}
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
__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 )
extern

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 */
192
193 return 0;
194}
unsigned int uint32_t
Definition stdint.h:12
unsigned long physaddr_t
Definition stdint.h:20
ring len
Length.
Definition dwmac.h:226
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint32_t type
Operating system type.
Definition ena.h:1
static void gdbmach_update(void)
Update debug registers.
Definition gdbmach.c:82
#define DR7_RWLEN_2
Debug register 7: Two-byte length.
Definition gdbmach.c:61
static int gdbmach_find(unsigned long addr, unsigned int rwlen)
Find reusable or available hardware breakpoint.
Definition gdbmach.c:99
static unsigned long dr7
Active value of debug register 7.
Definition gdbmach.c:76
static unsigned long dr[NUM_HWBP]
Hardware breakpoint addresses (debug registers 0-3)
Definition gdbmach.c:73
#define DR7_RWLEN_4
Debug register 7: Four-byte length.
Definition gdbmach.c:64
#define DR7_RWLEN_1
Debug register 7: One-byte length.
Definition gdbmach.c:58
#define DR7_G(bp)
Debug register 7: Global breakpoint enable.
Definition gdbmach.c:46
#define DR7_RWLEN_8
Debug register 7: Eight-byte length.
Definition gdbmach.c:67
#define DR7_RWLEN_ACCESS
Debug register 7: Break on data access.
Definition gdbmach.c:55
#define DR7_RWLEN_MASK(bp)
Debug register 7: Breakpoint R/W and length mask.
Definition gdbmach.c:70
#define DR7_RWLEN_WRITE
Debug register 7: Break on data writes.
Definition gdbmach.c:52
#define DBGC(...)
Definition compiler.h:505
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ENOBUFS
No buffer space available.
Definition errno.h:499
uint16_t bp
Definition registers.h:9

◆ gdbmach_init()

void gdbmach_init ( void )
extern

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:98