From 2b82007571dbe02b85338dc9fa85251cd5d68028 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 4 Sep 2024 13:29:30 +0100 Subject: [gdb] Allow CPU architectures to omit support for GDB Move the file to , and provide a common dummy implementation for all architectures that have not yet implemented support for GDB. Signed-off-by: Michael Brown --- src/arch/arm32/include/gdbmach.h | 45 ------------------- src/arch/arm64/include/gdbmach.h | 45 ------------------- src/arch/i386/include/bits/gdbmach.h | 72 ++++++++++++++++++++++++++++++ src/arch/i386/include/gdbmach.h | 72 ------------------------------ src/arch/loong64/include/gdbmach.h | 45 ------------------- src/arch/x86/core/gdbmach.c | 1 - src/arch/x86_64/include/bits/gdbmach.h | 80 ++++++++++++++++++++++++++++++++++ src/arch/x86_64/include/gdbmach.h | 80 ---------------------------------- src/core/gdbstub.c | 1 - src/include/bits/gdbmach.h | 45 +++++++++++++++++++ src/include/ipxe/gdbstub.h | 2 +- 11 files changed, 198 insertions(+), 290 deletions(-) delete mode 100644 src/arch/arm32/include/gdbmach.h delete mode 100644 src/arch/arm64/include/gdbmach.h create mode 100644 src/arch/i386/include/bits/gdbmach.h delete mode 100644 src/arch/i386/include/gdbmach.h delete mode 100644 src/arch/loong64/include/gdbmach.h create mode 100644 src/arch/x86_64/include/bits/gdbmach.h delete mode 100644 src/arch/x86_64/include/gdbmach.h create mode 100644 src/include/bits/gdbmach.h diff --git a/src/arch/arm32/include/gdbmach.h b/src/arch/arm32/include/gdbmach.h deleted file mode 100644 index cd152eedd..000000000 --- a/src/arch/arm32/include/gdbmach.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - /* Not yet implemented */ - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) step; -} - -static inline void gdbmach_breakpoint ( void ) { - /* Not yet implemented */ -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/src/arch/arm64/include/gdbmach.h b/src/arch/arm64/include/gdbmach.h deleted file mode 100644 index cd152eedd..000000000 --- a/src/arch/arm64/include/gdbmach.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - /* Not yet implemented */ - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) step; -} - -static inline void gdbmach_breakpoint ( void ) { - /* Not yet implemented */ -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/src/arch/i386/include/bits/gdbmach.h b/src/arch/i386/include/bits/gdbmach.h new file mode 100644 index 000000000..52cce7833 --- /dev/null +++ b/src/arch/i386/include/bits/gdbmach.h @@ -0,0 +1,72 @@ +#ifndef GDBMACH_H +#define GDBMACH_H + +/** @file + * + * GDB architecture specifics + * + * This file declares functions for manipulating the machine state and + * debugging context. + * + */ + +#include + +typedef unsigned long gdbreg_t; + +/* The register snapshot, this must be in sync with interrupt handler and the + * GDB protocol. */ +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 ) +}; + +/* Breakpoint types */ +enum { + GDBMACH_BPMEM, + GDBMACH_BPHW, + GDBMACH_WATCH, + GDBMACH_RWATCH, + GDBMACH_AWATCH, +}; + +/* Interrupt vectors */ +extern void gdbmach_sigfpe ( void ); +extern void gdbmach_sigtrap ( void ); +extern void gdbmach_sigstkflt ( void ); +extern void gdbmach_sigill ( void ); + +static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { + regs [ GDBMACH_EIP ] = pc; +} + +static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { + regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */ + regs [ GDBMACH_EFLAGS ] |= ( step << 8 ); +} + +static inline void gdbmach_breakpoint ( void ) { + __asm__ __volatile__ ( "int $3\n" ); +} + +extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ); + +extern void gdbmach_init ( void ); + +#endif /* GDBMACH_H */ diff --git a/src/arch/i386/include/gdbmach.h b/src/arch/i386/include/gdbmach.h deleted file mode 100644 index 52cce7833..000000000 --- a/src/arch/i386/include/gdbmach.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include - -typedef unsigned long gdbreg_t; - -/* The register snapshot, this must be in sync with interrupt handler and the - * GDB protocol. */ -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 ) -}; - -/* Breakpoint types */ -enum { - GDBMACH_BPMEM, - GDBMACH_BPHW, - GDBMACH_WATCH, - GDBMACH_RWATCH, - GDBMACH_AWATCH, -}; - -/* Interrupt vectors */ -extern void gdbmach_sigfpe ( void ); -extern void gdbmach_sigtrap ( void ); -extern void gdbmach_sigstkflt ( void ); -extern void gdbmach_sigill ( void ); - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - regs [ GDBMACH_EIP ] = pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */ - regs [ GDBMACH_EFLAGS ] |= ( step << 8 ); -} - -static inline void gdbmach_breakpoint ( void ) { - __asm__ __volatile__ ( "int $3\n" ); -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ); - -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/src/arch/loong64/include/gdbmach.h b/src/arch/loong64/include/gdbmach.h deleted file mode 100644 index cd152eedd..000000000 --- a/src/arch/loong64/include/gdbmach.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - /* Not yet implemented */ - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) step; -} - -static inline void gdbmach_breakpoint ( void ) { - /* Not yet implemented */ -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/src/arch/x86/core/gdbmach.c b/src/arch/x86/core/gdbmach.c index af6abfedd..d4d187e35 100644 --- a/src/arch/x86/core/gdbmach.c +++ b/src/arch/x86/core/gdbmach.c @@ -31,7 +31,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include /** @file * diff --git a/src/arch/x86_64/include/bits/gdbmach.h b/src/arch/x86_64/include/bits/gdbmach.h new file mode 100644 index 000000000..367405fd6 --- /dev/null +++ b/src/arch/x86_64/include/bits/gdbmach.h @@ -0,0 +1,80 @@ +#ifndef GDBMACH_H +#define GDBMACH_H + +/** @file + * + * GDB architecture specifics + * + * This file declares functions for manipulating the machine state and + * debugging context. + * + */ + +#include + +typedef unsigned long gdbreg_t; + +/* Register snapshot */ +enum { + GDBMACH_RAX, + GDBMACH_RBX, + GDBMACH_RCX, + GDBMACH_RDX, + GDBMACH_RSI, + GDBMACH_RDI, + GDBMACH_RBP, + GDBMACH_RSP, + GDBMACH_R8, + GDBMACH_R9, + GDBMACH_R10, + GDBMACH_R11, + GDBMACH_R12, + GDBMACH_R13, + GDBMACH_R14, + GDBMACH_R15, + GDBMACH_RIP, + GDBMACH_RFLAGS, + GDBMACH_CS, + GDBMACH_SS, + GDBMACH_DS, + GDBMACH_ES, + GDBMACH_FS, + GDBMACH_GS, + GDBMACH_NREGS, +}; + +#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) + +/* Breakpoint types */ +enum { + GDBMACH_BPMEM, + GDBMACH_BPHW, + GDBMACH_WATCH, + GDBMACH_RWATCH, + GDBMACH_AWATCH, +}; + +/* Exception vectors */ +extern void gdbmach_sigfpe ( void ); +extern void gdbmach_sigtrap ( void ); +extern void gdbmach_sigstkflt ( void ); +extern void gdbmach_sigill ( void ); + +static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { + regs[GDBMACH_RIP] = pc; +} + +static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { + regs[GDBMACH_RFLAGS] &= ~( 1 << 8 ); /* Trace Flag (TF) */ + regs[GDBMACH_RFLAGS] |= ( step << 8 ); +} + +static inline void gdbmach_breakpoint ( void ) { + __asm__ __volatile__ ( "int $3\n" ); +} + +extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, + int enable ); +extern void gdbmach_init ( void ); + +#endif /* GDBMACH_H */ diff --git a/src/arch/x86_64/include/gdbmach.h b/src/arch/x86_64/include/gdbmach.h deleted file mode 100644 index 367405fd6..000000000 --- a/src/arch/x86_64/include/gdbmach.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - GDBMACH_RAX, - GDBMACH_RBX, - GDBMACH_RCX, - GDBMACH_RDX, - GDBMACH_RSI, - GDBMACH_RDI, - GDBMACH_RBP, - GDBMACH_RSP, - GDBMACH_R8, - GDBMACH_R9, - GDBMACH_R10, - GDBMACH_R11, - GDBMACH_R12, - GDBMACH_R13, - GDBMACH_R14, - GDBMACH_R15, - GDBMACH_RIP, - GDBMACH_RFLAGS, - GDBMACH_CS, - GDBMACH_SS, - GDBMACH_DS, - GDBMACH_ES, - GDBMACH_FS, - GDBMACH_GS, - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -/* Breakpoint types */ -enum { - GDBMACH_BPMEM, - GDBMACH_BPHW, - GDBMACH_WATCH, - GDBMACH_RWATCH, - GDBMACH_AWATCH, -}; - -/* Exception vectors */ -extern void gdbmach_sigfpe ( void ); -extern void gdbmach_sigtrap ( void ); -extern void gdbmach_sigstkflt ( void ); -extern void gdbmach_sigill ( void ); - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - regs[GDBMACH_RIP] = pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - regs[GDBMACH_RFLAGS] &= ~( 1 << 8 ); /* Trace Flag (TF) */ - regs[GDBMACH_RFLAGS] |= ( step << 8 ); -} - -static inline void gdbmach_breakpoint ( void ) { - __asm__ __volatile__ ( "int $3\n" ); -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/src/core/gdbstub.c b/src/core/gdbstub.c index 8b57ddf56..d668f454a 100644 --- a/src/core/gdbstub.c +++ b/src/core/gdbstub.c @@ -36,7 +36,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include "gdbmach.h" enum { POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */ diff --git a/src/include/bits/gdbmach.h b/src/include/bits/gdbmach.h new file mode 100644 index 000000000..7e349856f --- /dev/null +++ b/src/include/bits/gdbmach.h @@ -0,0 +1,45 @@ +#ifndef _BITS_GDBMACH_H +#define _BITS_GDBMACH_H + +/** @file + * + * Dummy GDB architecture specifics + * + * This file is included only if the architecture does not provide its + * own version of this file. + * + */ + +#include + +typedef unsigned long gdbreg_t; + +/* Register snapshot */ +enum { + /* Not yet implemented */ + GDBMACH_NREGS, +}; + +#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) + +static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { + /* Not yet implemented */ + ( void ) regs; + ( void ) pc; +} + +static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { + /* Not yet implemented */ + ( void ) regs; + ( void ) step; +} + +static inline void gdbmach_breakpoint ( void ) { + /* Not yet implemented */ +} + +extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, + int enable ); +extern void gdbmach_init ( void ); + +#endif /* _BITS_GDBMACH_H */ diff --git a/src/include/ipxe/gdbstub.h b/src/include/ipxe/gdbstub.h index 13ca33ddb..2240cca42 100644 --- a/src/include/ipxe/gdbstub.h +++ b/src/include/ipxe/gdbstub.h @@ -11,7 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include -#include +#include /** * A transport mechanism for the GDB protocol -- cgit