|
49 | 49 | #include <asm/system.h> |
50 | 50 | #include <asm/apic.h> |
51 | 51 |
|
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] = |
61 | 53 | { |
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) }, |
64 | 92 | #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 ( |
73 | 98 | #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, ®s->orig_ax, sizeof(regs->orig_ax)); |
| 114 | + return "orig_ax"; |
86 | 115 | } |
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; |
100 | 137 | #endif |
| 138 | + } |
| 139 | + return dbg_reg_def[regno].name; |
101 | 140 | } |
102 | 141 |
|
103 | 142 | /** |
@@ -150,47 +189,6 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) |
150 | 189 | gdb_regs[GDB_SP] = p->thread.sp; |
151 | 190 | } |
152 | 191 |
|
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 | | - |
194 | 192 | static struct hw_breakpoint { |
195 | 193 | unsigned enabled; |
196 | 194 | unsigned long addr; |
|
0 commit comments