Skip to content

Commit 12bfa3d

Browse files
committed
kgdb,x86: Individual register get/set for x86
Implement the ability to individually get and set registers for kdb and kgdb for x86. Signed-off-by: Jason Wessel <jason.wessel@windriver.com> Acked-by: H. Peter Anvin <hpa@zytor.com> CC: Ingo Molnar <mingo@redhat.com> CC: x86@kernel.org
1 parent 534af10 commit 12bfa3d

2 files changed

Lines changed: 94 additions & 94 deletions

File tree

‎arch/x86/include/asm/kgdb.h‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ enum regnames {
3939
GDB_FS, /* 14 */
4040
GDB_GS, /* 15 */
4141
};
42+
#define GDB_ORIG_AX 41
43+
#define DBG_MAX_REG_NUM 16
4244
#define NUMREGBYTES ((GDB_GS+1)*4)
4345
#else /* ! CONFIG_X86_32 */
44-
enum regnames64 {
46+
enum regnames {
4547
GDB_AX, /* 0 */
4648
GDB_BX, /* 1 */
4749
GDB_CX, /* 2 */
@@ -59,15 +61,15 @@ enum regnames64 {
5961
GDB_R14, /* 14 */
6062
GDB_R15, /* 15 */
6163
GDB_PC, /* 16 */
64+
GDB_PS, /* 17 */
65+
GDB_CS, /* 18 */
66+
GDB_SS, /* 19 */
6267
};
63-
64-
enum regnames32 {
65-
GDB_PS = 34,
66-
GDB_CS,
67-
GDB_SS,
68-
};
69-
#define NUMREGBYTES ((GDB_SS+1)*4)
70-
#endif /* CONFIG_X86_32 */
68+
#define GDB_ORIG_AX 57
69+
#define DBG_MAX_REG_NUM 20
70+
/* 17 64 bit regs and 3 32 bit regs */
71+
#define NUMREGBYTES ((17 * 8) + (3 * 4))
72+
#endif /* ! CONFIG_X86_32 */
7173

7274
static inline void arch_kgdb_breakpoint(void)
7375
{

‎arch/x86/kernel/kgdb.c‎

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,94 @@
4949
#include <asm/system.h>
5050
#include <asm/apic.h>
5151

52-
/**
53-
* pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
54-
* @gdb_regs: A pointer to hold the registers in the order GDB wants.
55-
* @regs: The &struct pt_regs of the current process.
56-
*
57-
* Convert the pt_regs in @regs into the format for registers that
58-
* GDB expects, stored in @gdb_regs.
59-
*/
60-
void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
52+
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
6153
{
62-
#ifndef CONFIG_X86_32
63-
u32 *gdb_regs32 = (u32 *)gdb_regs;
54+
#ifdef CONFIG_X86_32
55+
{ "ax", 4, offsetof(struct pt_regs, ax) },
56+
{ "cx", 4, offsetof(struct pt_regs, cx) },
57+
{ "dx", 4, offsetof(struct pt_regs, dx) },
58+
{ "bx", 4, offsetof(struct pt_regs, bx) },
59+
{ "sp", 4, offsetof(struct pt_regs, sp) },
60+
{ "bp", 4, offsetof(struct pt_regs, bp) },
61+
{ "si", 4, offsetof(struct pt_regs, si) },
62+
{ "di", 4, offsetof(struct pt_regs, di) },
63+
{ "ip", 4, offsetof(struct pt_regs, ip) },
64+
{ "flags", 4, offsetof(struct pt_regs, flags) },
65+
{ "cs", 4, offsetof(struct pt_regs, cs) },
66+
{ "ss", 4, offsetof(struct pt_regs, ss) },
67+
{ "ds", 4, offsetof(struct pt_regs, ds) },
68+
{ "es", 4, offsetof(struct pt_regs, es) },
69+
{ "fs", 4, -1 },
70+
{ "gs", 4, -1 },
71+
#else
72+
{ "ax", 8, offsetof(struct pt_regs, ax) },
73+
{ "bx", 8, offsetof(struct pt_regs, bx) },
74+
{ "cx", 8, offsetof(struct pt_regs, cx) },
75+
{ "dx", 8, offsetof(struct pt_regs, dx) },
76+
{ "si", 8, offsetof(struct pt_regs, dx) },
77+
{ "di", 8, offsetof(struct pt_regs, di) },
78+
{ "bp", 8, offsetof(struct pt_regs, bp) },
79+
{ "sp", 8, offsetof(struct pt_regs, sp) },
80+
{ "r8", 8, offsetof(struct pt_regs, r8) },
81+
{ "r9", 8, offsetof(struct pt_regs, r9) },
82+
{ "r10", 8, offsetof(struct pt_regs, r10) },
83+
{ "r11", 8, offsetof(struct pt_regs, r11) },
84+
{ "r12", 8, offsetof(struct pt_regs, r12) },
85+
{ "r13", 8, offsetof(struct pt_regs, r13) },
86+
{ "r14", 8, offsetof(struct pt_regs, r14) },
87+
{ "r15", 8, offsetof(struct pt_regs, r15) },
88+
{ "ip", 8, offsetof(struct pt_regs, ip) },
89+
{ "flags", 4, offsetof(struct pt_regs, flags) },
90+
{ "cs", 4, offsetof(struct pt_regs, cs) },
91+
{ "ss", 4, offsetof(struct pt_regs, ss) },
6492
#endif
65-
gdb_regs[GDB_AX] = regs->ax;
66-
gdb_regs[GDB_BX] = regs->bx;
67-
gdb_regs[GDB_CX] = regs->cx;
68-
gdb_regs[GDB_DX] = regs->dx;
69-
gdb_regs[GDB_SI] = regs->si;
70-
gdb_regs[GDB_DI] = regs->di;
71-
gdb_regs[GDB_BP] = regs->bp;
72-
gdb_regs[GDB_PC] = regs->ip;
93+
};
94+
95+
int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
96+
{
97+
if (
7398
#ifdef CONFIG_X86_32
74-
gdb_regs[GDB_PS] = regs->flags;
75-
gdb_regs[GDB_DS] = regs->ds;
76-
gdb_regs[GDB_ES] = regs->es;
77-
gdb_regs[GDB_CS] = regs->cs;
78-
gdb_regs[GDB_FS] = 0xFFFF;
79-
gdb_regs[GDB_GS] = 0xFFFF;
80-
if (user_mode_vm(regs)) {
81-
gdb_regs[GDB_SS] = regs->ss;
82-
gdb_regs[GDB_SP] = regs->sp;
83-
} else {
84-
gdb_regs[GDB_SS] = __KERNEL_DS;
85-
gdb_regs[GDB_SP] = kernel_stack_pointer(regs);
99+
regno == GDB_SS || regno == GDB_FS || regno == GDB_GS ||
100+
#endif
101+
regno == GDB_SP || regno == GDB_ORIG_AX)
102+
return 0;
103+
104+
if (dbg_reg_def[regno].offset != -1)
105+
memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
106+
dbg_reg_def[regno].size);
107+
return 0;
108+
}
109+
110+
char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
111+
{
112+
if (regno == GDB_ORIG_AX) {
113+
memcpy(mem, &regs->orig_ax, sizeof(regs->orig_ax));
114+
return "orig_ax";
86115
}
87-
#else
88-
gdb_regs[GDB_R8] = regs->r8;
89-
gdb_regs[GDB_R9] = regs->r9;
90-
gdb_regs[GDB_R10] = regs->r10;
91-
gdb_regs[GDB_R11] = regs->r11;
92-
gdb_regs[GDB_R12] = regs->r12;
93-
gdb_regs[GDB_R13] = regs->r13;
94-
gdb_regs[GDB_R14] = regs->r14;
95-
gdb_regs[GDB_R15] = regs->r15;
96-
gdb_regs32[GDB_PS] = regs->flags;
97-
gdb_regs32[GDB_CS] = regs->cs;
98-
gdb_regs32[GDB_SS] = regs->ss;
99-
gdb_regs[GDB_SP] = kernel_stack_pointer(regs);
116+
if (regno >= DBG_MAX_REG_NUM || regno < 0)
117+
return NULL;
118+
119+
if (dbg_reg_def[regno].offset != -1)
120+
memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
121+
dbg_reg_def[regno].size);
122+
123+
switch (regno) {
124+
#ifdef CONFIG_X86_32
125+
case GDB_SS:
126+
if (!user_mode_vm(regs))
127+
*(unsigned long *)mem = __KERNEL_DS;
128+
break;
129+
case GDB_SP:
130+
if (!user_mode_vm(regs))
131+
*(unsigned long *)mem = kernel_stack_pointer(regs);
132+
break;
133+
case GDB_GS:
134+
case GDB_FS:
135+
*(unsigned long *)mem = 0xFFFF;
136+
break;
100137
#endif
138+
}
139+
return dbg_reg_def[regno].name;
101140
}
102141

103142
/**
@@ -150,47 +189,6 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
150189
gdb_regs[GDB_SP] = p->thread.sp;
151190
}
152191

153-
/**
154-
* gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
155-
* @gdb_regs: A pointer to hold the registers we've received from GDB.
156-
* @regs: A pointer to a &struct pt_regs to hold these values in.
157-
*
158-
* Convert the GDB regs in @gdb_regs into the pt_regs, and store them
159-
* in @regs.
160-
*/
161-
void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
162-
{
163-
#ifndef CONFIG_X86_32
164-
u32 *gdb_regs32 = (u32 *)gdb_regs;
165-
#endif
166-
regs->ax = gdb_regs[GDB_AX];
167-
regs->bx = gdb_regs[GDB_BX];
168-
regs->cx = gdb_regs[GDB_CX];
169-
regs->dx = gdb_regs[GDB_DX];
170-
regs->si = gdb_regs[GDB_SI];
171-
regs->di = gdb_regs[GDB_DI];
172-
regs->bp = gdb_regs[GDB_BP];
173-
regs->ip = gdb_regs[GDB_PC];
174-
#ifdef CONFIG_X86_32
175-
regs->flags = gdb_regs[GDB_PS];
176-
regs->ds = gdb_regs[GDB_DS];
177-
regs->es = gdb_regs[GDB_ES];
178-
regs->cs = gdb_regs[GDB_CS];
179-
#else
180-
regs->r8 = gdb_regs[GDB_R8];
181-
regs->r9 = gdb_regs[GDB_R9];
182-
regs->r10 = gdb_regs[GDB_R10];
183-
regs->r11 = gdb_regs[GDB_R11];
184-
regs->r12 = gdb_regs[GDB_R12];
185-
regs->r13 = gdb_regs[GDB_R13];
186-
regs->r14 = gdb_regs[GDB_R14];
187-
regs->r15 = gdb_regs[GDB_R15];
188-
regs->flags = gdb_regs32[GDB_PS];
189-
regs->cs = gdb_regs32[GDB_CS];
190-
regs->ss = gdb_regs32[GDB_SS];
191-
#endif
192-
}
193-
194192
static struct hw_breakpoint {
195193
unsigned enabled;
196194
unsigned long addr;

0 commit comments

Comments
 (0)