1 /*
2 * x86_64 -specific gdb stub routines
3 *
4 * Copyright (C) 2007 Dan Doucette ddoucette@teradici.com
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <asm/debugger.h>
21
22 #define GDB_REG64(r) gdb_write_to_packet_hex(r, sizeof(u64), ctx)
23 #define GDB_REG32(r) gdb_write_to_packet_hex(r, sizeof(u32), ctx)
24
25 void
gdb_arch_read_reg_array(struct cpu_user_regs * regs,struct gdb_context * ctx)26 gdb_arch_read_reg_array(struct cpu_user_regs *regs, struct gdb_context *ctx)
27 {
28 GDB_REG64(regs->rax);
29 GDB_REG64(regs->rbx);
30 GDB_REG64(regs->rcx);
31 GDB_REG64(regs->rdx);
32 GDB_REG64(regs->rsi);
33 GDB_REG64(regs->rdi);
34 GDB_REG64(regs->rbp);
35 GDB_REG64(regs->rsp);
36
37 GDB_REG64(regs->r8);
38 GDB_REG64(regs->r9);
39 GDB_REG64(regs->r10);
40 GDB_REG64(regs->r11);
41 GDB_REG64(regs->r12);
42 GDB_REG64(regs->r13);
43 GDB_REG64(regs->r14);
44 GDB_REG64(regs->r15);
45
46 GDB_REG64(regs->rip);
47 GDB_REG32(regs->eflags);
48
49 GDB_REG32(regs->cs);
50 GDB_REG32(regs->ss);
51 GDB_REG32(regs->ds);
52 GDB_REG32(regs->es);
53 GDB_REG32(regs->fs);
54 GDB_REG32(regs->gs);
55
56 gdb_send_packet(ctx);
57 }
58
59 void
gdb_arch_write_reg_array(struct cpu_user_regs * regs,const char * buf,struct gdb_context * ctx)60 gdb_arch_write_reg_array(struct cpu_user_regs *regs, const char* buf,
61 struct gdb_context *ctx)
62 {
63 gdb_send_reply("", ctx);
64 }
65
66 void
gdb_arch_read_reg(unsigned long regnum,struct cpu_user_regs * regs,struct gdb_context * ctx)67 gdb_arch_read_reg(unsigned long regnum, struct cpu_user_regs *regs,
68 struct gdb_context *ctx)
69 {
70 switch (regnum)
71 {
72 case 0: GDB_REG64(regs->rax); break;
73 case 1: GDB_REG64(regs->rbx); break;
74 case 2: GDB_REG64(regs->rcx); break;
75 case 3: GDB_REG64(regs->rdx); break;
76 case 4: GDB_REG64(regs->rsi); break;
77 case 5: GDB_REG64(regs->rdi); break;
78 case 6: GDB_REG64(regs->rbp); break;
79 case 7: GDB_REG64(regs->rsp); break;
80
81 case 8: GDB_REG64(regs->r8); break;
82 case 9: GDB_REG64(regs->r9); break;
83 case 10: GDB_REG64(regs->r10); break;
84 case 11: GDB_REG64(regs->r11); break;
85 case 12: GDB_REG64(regs->r12); break;
86 case 13: GDB_REG64(regs->r13); break;
87 case 14: GDB_REG64(regs->r14); break;
88 case 15: GDB_REG64(regs->r15); break;
89
90 case 16: GDB_REG64(regs->rip); break;
91 case 17: GDB_REG32(regs->rflags); break;
92 case 18: GDB_REG32(regs->cs); break;
93 case 19: GDB_REG32(regs->ss); break;
94 case 20: GDB_REG32(regs->ds); break;
95 case 21: GDB_REG32(regs->es); break;
96 case 22: GDB_REG32(regs->fs); break;
97 case 23: GDB_REG32(regs->gs); break;
98 default:
99 GDB_REG64(0xbaadf00ddeadbeef);
100 break;
101 }
102 gdb_send_packet(ctx);
103 }
104
105 void
gdb_arch_write_reg(unsigned long regnum,unsigned long val,struct cpu_user_regs * regs,struct gdb_context * ctx)106 gdb_arch_write_reg(unsigned long regnum, unsigned long val,
107 struct cpu_user_regs *regs, struct gdb_context *ctx)
108 {
109 switch (regnum)
110 {
111 case 0: regs->rax = val; break;
112 case 1: regs->rbx = val; break;
113 case 2: regs->rcx = val; break;
114 case 3: regs->rdx = val; break;
115 case 4: regs->rsi = val; break;
116 case 5: regs->rdi = val; break;
117 case 6: regs->rbp = val; break;
118 case 7: regs->rsp = val; break;
119
120 case 8: regs->r8 = val; break;
121 case 9: regs->r9 = val; break;
122 case 10: regs->r10 = val; break;
123 case 11: regs->r11 = val; break;
124 case 12: regs->r12 = val; break;
125 case 13: regs->r13 = val; break;
126 case 14: regs->r14 = val; break;
127 case 15: regs->r15 = val; break;
128
129 case 16: regs->rip = val; break;
130 case 17: regs->rflags = (u32)val; break;
131 case 18: regs->cs = (u16)val; break;
132 case 19: regs->ss = (u16)val; break;
133 case 20: regs->ds = (u16)val; break;
134 case 21: regs->es = (u16)val; break;
135 case 22: regs->fs = (u16)val; break;
136 case 23: regs->gs = (u16)val; break;
137 default:
138 break;
139 }
140 gdb_send_reply("OK", ctx);
141 }
142
143 /*
144 * Local variables:
145 * mode: C
146 * c-file-style: "BSD"
147 * c-basic-offset: 4
148 * tab-width: 4
149 * End:
150 */
151