xref: /qemu/target/i386/gdbstub.c (revision 1852f094)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * x86 gdb server stub
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  * Copyright (c) 2003-2005 Fabrice Bellard
5fcf5ef2aSThomas Huth  * Copyright (c) 2013 SUSE LINUX Products GmbH
6fcf5ef2aSThomas Huth  *
7fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
10d9ff33adSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth  *
12fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
16fcf5ef2aSThomas Huth  *
17fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth #include "qemu/osdep.h"
21fcf5ef2aSThomas Huth #include "cpu.h"
22fcf5ef2aSThomas Huth #include "exec/gdbstub.h"
23fcf5ef2aSThomas Huth 
24fcf5ef2aSThomas Huth #ifdef TARGET_X86_64
25fcf5ef2aSThomas Huth static const int gpr_map[16] = {
26fcf5ef2aSThomas Huth     R_EAX, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI, R_EBP, R_ESP,
27fcf5ef2aSThomas Huth     8, 9, 10, 11, 12, 13, 14, 15
28fcf5ef2aSThomas Huth };
29fcf5ef2aSThomas Huth #else
30fcf5ef2aSThomas Huth #define gpr_map gpr_map32
31fcf5ef2aSThomas Huth #endif
32fcf5ef2aSThomas Huth static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
33fcf5ef2aSThomas Huth 
347b0f97baSDoug Gale /*
357b0f97baSDoug Gale  * Keep these in sync with assignment to
367b0f97baSDoug Gale  * gdb_num_core_regs in target/i386/cpu.c
377b0f97baSDoug Gale  * and with the machine description
387b0f97baSDoug Gale  */
397b0f97baSDoug Gale 
407b0f97baSDoug Gale /*
417b0f97baSDoug Gale  * SEG: 6 segments, plus fs_base, gs_base, kernel_gs_base
427b0f97baSDoug Gale  */
437b0f97baSDoug Gale 
447b0f97baSDoug Gale /*
457b0f97baSDoug Gale  * general regs ----->  8 or 16
467b0f97baSDoug Gale  */
477b0f97baSDoug Gale #define IDX_NB_IP       1
487b0f97baSDoug Gale #define IDX_NB_FLAGS    1
497b0f97baSDoug Gale #define IDX_NB_SEG      (6 + 3)
507b0f97baSDoug Gale #define IDX_NB_CTL      6
517b0f97baSDoug Gale #define IDX_NB_FP       16
527b0f97baSDoug Gale /*
537b0f97baSDoug Gale  * fpu regs ----------> 8 or 16
547b0f97baSDoug Gale  */
557b0f97baSDoug Gale #define IDX_NB_MXCSR    1
567b0f97baSDoug Gale /*
577b0f97baSDoug Gale  *          total ----> 8+1+1+9+6+16+8+1=50 or 16+1+1+9+6+16+16+1=66
587b0f97baSDoug Gale  */
597b0f97baSDoug Gale 
60fcf5ef2aSThomas Huth #define IDX_IP_REG      CPU_NB_REGS
617b0f97baSDoug Gale #define IDX_FLAGS_REG   (IDX_IP_REG + IDX_NB_IP)
627b0f97baSDoug Gale #define IDX_SEG_REGS    (IDX_FLAGS_REG + IDX_NB_FLAGS)
637b0f97baSDoug Gale #define IDX_CTL_REGS    (IDX_SEG_REGS + IDX_NB_SEG)
647b0f97baSDoug Gale #define IDX_FP_REGS     (IDX_CTL_REGS + IDX_NB_CTL)
657b0f97baSDoug Gale #define IDX_XMM_REGS    (IDX_FP_REGS + IDX_NB_FP)
66fcf5ef2aSThomas Huth #define IDX_MXCSR_REG   (IDX_XMM_REGS + CPU_NB_REGS)
67fcf5ef2aSThomas Huth 
687b0f97baSDoug Gale #define IDX_CTL_CR0_REG     (IDX_CTL_REGS + 0)
697b0f97baSDoug Gale #define IDX_CTL_CR2_REG     (IDX_CTL_REGS + 1)
707b0f97baSDoug Gale #define IDX_CTL_CR3_REG     (IDX_CTL_REGS + 2)
717b0f97baSDoug Gale #define IDX_CTL_CR4_REG     (IDX_CTL_REGS + 3)
727b0f97baSDoug Gale #define IDX_CTL_CR8_REG     (IDX_CTL_REGS + 4)
737b0f97baSDoug Gale #define IDX_CTL_EFER_REG    (IDX_CTL_REGS + 5)
747b0f97baSDoug Gale 
757b0f97baSDoug Gale #ifdef TARGET_X86_64
767b0f97baSDoug Gale #define GDB_FORCE_64 1
777b0f97baSDoug Gale #else
787b0f97baSDoug Gale #define GDB_FORCE_64 0
797b0f97baSDoug Gale #endif
807b0f97baSDoug Gale 
814d81e285SClaudio Fontana static int gdb_read_reg_cs64(uint32_t hflags, GByteArray *buf, target_ulong val)
824d81e285SClaudio Fontana {
834d81e285SClaudio Fontana     if ((hflags & HF_CS64_MASK) || GDB_FORCE_64) {
844d81e285SClaudio Fontana         return gdb_get_reg64(buf, val);
854d81e285SClaudio Fontana     }
864d81e285SClaudio Fontana     return gdb_get_reg32(buf, val);
874d81e285SClaudio Fontana }
884d81e285SClaudio Fontana 
894d81e285SClaudio Fontana static int gdb_write_reg_cs64(uint32_t hflags, uint8_t *buf, target_ulong *val)
904d81e285SClaudio Fontana {
914d81e285SClaudio Fontana     if (hflags & HF_CS64_MASK) {
924d81e285SClaudio Fontana         *val = ldq_p(buf);
934d81e285SClaudio Fontana         return 8;
944d81e285SClaudio Fontana     }
954d81e285SClaudio Fontana     *val = ldl_p(buf);
964d81e285SClaudio Fontana     return 4;
974d81e285SClaudio Fontana }
987b0f97baSDoug Gale 
99a010bdbeSAlex Bennée int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
100fcf5ef2aSThomas Huth {
101fcf5ef2aSThomas Huth     X86CPU *cpu = X86_CPU(cs);
102fcf5ef2aSThomas Huth     CPUX86State *env = &cpu->env;
103fcf5ef2aSThomas Huth 
1047b0f97baSDoug Gale     uint64_t tpr;
1057b0f97baSDoug Gale 
106e3592bc9SDoug Evans     /* N.B. GDB can't deal with changes in registers or sizes in the middle
107e3592bc9SDoug Evans        of a session. So if we're in 32-bit mode on a 64-bit cpu, still act
108e3592bc9SDoug Evans        as if we're on a 64-bit cpu. */
109e3592bc9SDoug Evans 
110fcf5ef2aSThomas Huth     if (n < CPU_NB_REGS) {
111e3592bc9SDoug Evans         if (TARGET_LONG_BITS == 64) {
112e3592bc9SDoug Evans             if (env->hflags & HF_CS64_MASK) {
113fcf5ef2aSThomas Huth                 return gdb_get_reg64(mem_buf, env->regs[gpr_map[n]]);
114fcf5ef2aSThomas Huth             } else if (n < CPU_NB_REGS32) {
115e3592bc9SDoug Evans                 return gdb_get_reg64(mem_buf,
116e3592bc9SDoug Evans                                      env->regs[gpr_map[n]] & 0xffffffffUL);
117e3592bc9SDoug Evans             } else {
118b7b8756aSAlex Bennée                 return gdb_get_regl(mem_buf, 0);
119e3592bc9SDoug Evans             }
120e3592bc9SDoug Evans         } else {
121fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]);
122fcf5ef2aSThomas Huth         }
123fcf5ef2aSThomas Huth     } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
124b7b8756aSAlex Bennée         floatx80 *fp = (floatx80 *) &env->fpregs[n - IDX_FP_REGS];
125b7b8756aSAlex Bennée         int len = gdb_get_reg64(mem_buf, cpu_to_le64(fp->low));
126bbc40fefSPeter Xu         len += gdb_get_reg16(mem_buf, cpu_to_le16(fp->high));
127b7b8756aSAlex Bennée         return len;
128fcf5ef2aSThomas Huth     } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) {
129fcf5ef2aSThomas Huth         n -= IDX_XMM_REGS;
130e3592bc9SDoug Evans         if (n < CPU_NB_REGS32 || TARGET_LONG_BITS == 64) {
131b7b8756aSAlex Bennée             return gdb_get_reg128(mem_buf,
132b7b8756aSAlex Bennée                                   env->xmm_regs[n].ZMM_Q(0),
133b7b8756aSAlex Bennée                                   env->xmm_regs[n].ZMM_Q(1));
134fcf5ef2aSThomas Huth         }
135fcf5ef2aSThomas Huth     } else {
136fcf5ef2aSThomas Huth         switch (n) {
137fcf5ef2aSThomas Huth         case IDX_IP_REG:
138e3592bc9SDoug Evans             if (TARGET_LONG_BITS == 64) {
139e3592bc9SDoug Evans                 if (env->hflags & HF_CS64_MASK) {
140fcf5ef2aSThomas Huth                     return gdb_get_reg64(mem_buf, env->eip);
141fcf5ef2aSThomas Huth                 } else {
142e3592bc9SDoug Evans                     return gdb_get_reg64(mem_buf, env->eip & 0xffffffffUL);
143e3592bc9SDoug Evans                 }
144e3592bc9SDoug Evans             } else {
145fcf5ef2aSThomas Huth                 return gdb_get_reg32(mem_buf, env->eip);
146fcf5ef2aSThomas Huth             }
147fcf5ef2aSThomas Huth         case IDX_FLAGS_REG:
148fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->eflags);
149fcf5ef2aSThomas Huth 
150fcf5ef2aSThomas Huth         case IDX_SEG_REGS:
151fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_CS].selector);
152fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 1:
153fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_SS].selector);
154fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 2:
155fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_DS].selector);
156fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 3:
157fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_ES].selector);
158fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 4:
159fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_FS].selector);
160fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 5:
161fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->segs[R_GS].selector);
1627b0f97baSDoug Gale         case IDX_SEG_REGS + 6:
1634d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->segs[R_FS].base);
1647b0f97baSDoug Gale         case IDX_SEG_REGS + 7:
1654d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->segs[R_GS].base);
1667b0f97baSDoug Gale 
1677b0f97baSDoug Gale         case IDX_SEG_REGS + 8:
1687b0f97baSDoug Gale #ifdef TARGET_X86_64
1694d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->kernelgsbase);
1707b0f97baSDoug Gale #else
1717b0f97baSDoug Gale             return gdb_get_reg32(mem_buf, 0);
1727b0f97baSDoug Gale #endif
1737b0f97baSDoug Gale 
174fcf5ef2aSThomas Huth         case IDX_FP_REGS + 8:
175fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->fpuc);
176fcf5ef2aSThomas Huth         case IDX_FP_REGS + 9:
177fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, (env->fpus & ~0x3800) |
178fcf5ef2aSThomas Huth                                           (env->fpstt & 0x7) << 11);
179fcf5ef2aSThomas Huth         case IDX_FP_REGS + 10:
180fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* ftag */
181fcf5ef2aSThomas Huth         case IDX_FP_REGS + 11:
182fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* fiseg */
183fcf5ef2aSThomas Huth         case IDX_FP_REGS + 12:
184fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* fioff */
185fcf5ef2aSThomas Huth         case IDX_FP_REGS + 13:
186fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* foseg */
187fcf5ef2aSThomas Huth         case IDX_FP_REGS + 14:
188fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* fooff */
189fcf5ef2aSThomas Huth         case IDX_FP_REGS + 15:
190fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, 0); /* fop */
191fcf5ef2aSThomas Huth 
192fcf5ef2aSThomas Huth         case IDX_MXCSR_REG:
193418b0f93SJoseph Myers             update_mxcsr_from_sse_status(env);
194fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->mxcsr);
1957b0f97baSDoug Gale 
1967b0f97baSDoug Gale         case IDX_CTL_CR0_REG:
1974d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->cr[0]);
1987b0f97baSDoug Gale         case IDX_CTL_CR2_REG:
1994d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->cr[2]);
2007b0f97baSDoug Gale         case IDX_CTL_CR3_REG:
2014d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->cr[3]);
2027b0f97baSDoug Gale         case IDX_CTL_CR4_REG:
2034d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->cr[4]);
2047b0f97baSDoug Gale         case IDX_CTL_CR8_REG:
2054d81e285SClaudio Fontana #ifndef CONFIG_USER_ONLY
2067b0f97baSDoug Gale             tpr = cpu_get_apic_tpr(cpu->apic_state);
2077b0f97baSDoug Gale #else
2087b0f97baSDoug Gale             tpr = 0;
2097b0f97baSDoug Gale #endif
2104d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, tpr);
2117b0f97baSDoug Gale 
2127b0f97baSDoug Gale         case IDX_CTL_EFER_REG:
2134d81e285SClaudio Fontana             return gdb_read_reg_cs64(env->hflags, mem_buf, env->efer);
214fcf5ef2aSThomas Huth         }
215fcf5ef2aSThomas Huth     }
216fcf5ef2aSThomas Huth     return 0;
217fcf5ef2aSThomas Huth }
218fcf5ef2aSThomas Huth 
219c117e5b1SPhilippe Mathieu-Daudé static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf)
220fcf5ef2aSThomas Huth {
221fcf5ef2aSThomas Huth     CPUX86State *env = &cpu->env;
222fcf5ef2aSThomas Huth     uint16_t selector = ldl_p(mem_buf);
223fcf5ef2aSThomas Huth 
224fcf5ef2aSThomas Huth     if (selector != env->segs[sreg].selector) {
225fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY)
226fcf5ef2aSThomas Huth         cpu_x86_load_seg(env, sreg, selector);
227fcf5ef2aSThomas Huth #else
228fcf5ef2aSThomas Huth         unsigned int limit, flags;
229fcf5ef2aSThomas Huth         target_ulong base;
230fcf5ef2aSThomas Huth 
231fcf5ef2aSThomas Huth         if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) {
232fcf5ef2aSThomas Huth             int dpl = (env->eflags & VM_MASK) ? 3 : 0;
233fcf5ef2aSThomas Huth             base = selector << 4;
234fcf5ef2aSThomas Huth             limit = 0xffff;
235fcf5ef2aSThomas Huth             flags = DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
236fcf5ef2aSThomas Huth                     DESC_A_MASK | (dpl << DESC_DPL_SHIFT);
237fcf5ef2aSThomas Huth         } else {
238fcf5ef2aSThomas Huth             if (!cpu_x86_get_descr_debug(env, selector, &base, &limit,
239fcf5ef2aSThomas Huth                                          &flags)) {
240fcf5ef2aSThomas Huth                 return 4;
241fcf5ef2aSThomas Huth             }
242fcf5ef2aSThomas Huth         }
243fcf5ef2aSThomas Huth         cpu_x86_load_seg_cache(env, sreg, selector, base, limit, flags);
244fcf5ef2aSThomas Huth #endif
245fcf5ef2aSThomas Huth     }
246fcf5ef2aSThomas Huth     return 4;
247fcf5ef2aSThomas Huth }
248fcf5ef2aSThomas Huth 
249fcf5ef2aSThomas Huth int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
250fcf5ef2aSThomas Huth {
251fcf5ef2aSThomas Huth     X86CPU *cpu = X86_CPU(cs);
252fcf5ef2aSThomas Huth     CPUX86State *env = &cpu->env;
2534d81e285SClaudio Fontana     target_ulong tmp;
2544d81e285SClaudio Fontana     int len;
255fcf5ef2aSThomas Huth 
256e3592bc9SDoug Evans     /* N.B. GDB can't deal with changes in registers or sizes in the middle
257e3592bc9SDoug Evans        of a session. So if we're in 32-bit mode on a 64-bit cpu, still act
258e3592bc9SDoug Evans        as if we're on a 64-bit cpu. */
259e3592bc9SDoug Evans 
260fcf5ef2aSThomas Huth     if (n < CPU_NB_REGS) {
261e3592bc9SDoug Evans         if (TARGET_LONG_BITS == 64) {
262e3592bc9SDoug Evans             if (env->hflags & HF_CS64_MASK) {
263fcf5ef2aSThomas Huth                 env->regs[gpr_map[n]] = ldtul_p(mem_buf);
264e3592bc9SDoug Evans             } else if (n < CPU_NB_REGS32) {
265e3592bc9SDoug Evans                 env->regs[gpr_map[n]] = ldtul_p(mem_buf) & 0xffffffffUL;
266e3592bc9SDoug Evans             }
267fcf5ef2aSThomas Huth             return sizeof(target_ulong);
268fcf5ef2aSThomas Huth         } else if (n < CPU_NB_REGS32) {
269fcf5ef2aSThomas Huth             n = gpr_map32[n];
270fcf5ef2aSThomas Huth             env->regs[n] &= ~0xffffffffUL;
271fcf5ef2aSThomas Huth             env->regs[n] |= (uint32_t)ldl_p(mem_buf);
272fcf5ef2aSThomas Huth             return 4;
273fcf5ef2aSThomas Huth         }
274fcf5ef2aSThomas Huth     } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
275b7b8756aSAlex Bennée         floatx80 *fp = (floatx80 *) &env->fpregs[n - IDX_FP_REGS];
276b7b8756aSAlex Bennée         fp->low = le64_to_cpu(* (uint64_t *) mem_buf);
277b7b8756aSAlex Bennée         fp->high = le16_to_cpu(* (uint16_t *) (mem_buf + 8));
278fcf5ef2aSThomas Huth         return 10;
279fcf5ef2aSThomas Huth     } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) {
280fcf5ef2aSThomas Huth         n -= IDX_XMM_REGS;
281e3592bc9SDoug Evans         if (n < CPU_NB_REGS32 || TARGET_LONG_BITS == 64) {
282fcf5ef2aSThomas Huth             env->xmm_regs[n].ZMM_Q(0) = ldq_p(mem_buf);
283fcf5ef2aSThomas Huth             env->xmm_regs[n].ZMM_Q(1) = ldq_p(mem_buf + 8);
284fcf5ef2aSThomas Huth             return 16;
285fcf5ef2aSThomas Huth         }
286fcf5ef2aSThomas Huth     } else {
287fcf5ef2aSThomas Huth         switch (n) {
288fcf5ef2aSThomas Huth         case IDX_IP_REG:
289e3592bc9SDoug Evans             if (TARGET_LONG_BITS == 64) {
290e3592bc9SDoug Evans                 if (env->hflags & HF_CS64_MASK) {
291fcf5ef2aSThomas Huth                     env->eip = ldq_p(mem_buf);
292e3592bc9SDoug Evans                 } else {
293e3592bc9SDoug Evans                     env->eip = ldq_p(mem_buf) & 0xffffffffUL;
294e3592bc9SDoug Evans                 }
295fcf5ef2aSThomas Huth                 return 8;
296fcf5ef2aSThomas Huth             } else {
297fcf5ef2aSThomas Huth                 env->eip &= ~0xffffffffUL;
298fcf5ef2aSThomas Huth                 env->eip |= (uint32_t)ldl_p(mem_buf);
299fcf5ef2aSThomas Huth                 return 4;
300fcf5ef2aSThomas Huth             }
301fcf5ef2aSThomas Huth         case IDX_FLAGS_REG:
302fcf5ef2aSThomas Huth             env->eflags = ldl_p(mem_buf);
303fcf5ef2aSThomas Huth             return 4;
304fcf5ef2aSThomas Huth 
305fcf5ef2aSThomas Huth         case IDX_SEG_REGS:
306fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_CS, mem_buf);
307fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 1:
308fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_SS, mem_buf);
309fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 2:
310fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_DS, mem_buf);
311fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 3:
312fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_ES, mem_buf);
313fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 4:
314fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_FS, mem_buf);
315fcf5ef2aSThomas Huth         case IDX_SEG_REGS + 5:
316fcf5ef2aSThomas Huth             return x86_cpu_gdb_load_seg(cpu, R_GS, mem_buf);
3177b0f97baSDoug Gale         case IDX_SEG_REGS + 6:
3184d81e285SClaudio Fontana             return gdb_write_reg_cs64(env->hflags, mem_buf, &env->segs[R_FS].base);
3197b0f97baSDoug Gale         case IDX_SEG_REGS + 7:
3204d81e285SClaudio Fontana             return gdb_write_reg_cs64(env->hflags, mem_buf, &env->segs[R_GS].base);
3217b0f97baSDoug Gale         case IDX_SEG_REGS + 8:
3225a07192aSmkdolata@us.ibm.com #ifdef TARGET_X86_64
3234d81e285SClaudio Fontana             return gdb_write_reg_cs64(env->hflags, mem_buf, &env->kernelgsbase);
3247b0f97baSDoug Gale #endif
3255a07192aSmkdolata@us.ibm.com             return 4;
3267b0f97baSDoug Gale 
327fcf5ef2aSThomas Huth         case IDX_FP_REGS + 8:
328fcf5ef2aSThomas Huth             cpu_set_fpuc(env, ldl_p(mem_buf));
329fcf5ef2aSThomas Huth             return 4;
330fcf5ef2aSThomas Huth         case IDX_FP_REGS + 9:
331fcf5ef2aSThomas Huth             tmp = ldl_p(mem_buf);
332fcf5ef2aSThomas Huth             env->fpstt = (tmp >> 11) & 7;
333fcf5ef2aSThomas Huth             env->fpus = tmp & ~0x3800;
334fcf5ef2aSThomas Huth             return 4;
335fcf5ef2aSThomas Huth         case IDX_FP_REGS + 10: /* ftag */
336fcf5ef2aSThomas Huth             return 4;
337fcf5ef2aSThomas Huth         case IDX_FP_REGS + 11: /* fiseg */
338fcf5ef2aSThomas Huth             return 4;
339fcf5ef2aSThomas Huth         case IDX_FP_REGS + 12: /* fioff */
340fcf5ef2aSThomas Huth             return 4;
341fcf5ef2aSThomas Huth         case IDX_FP_REGS + 13: /* foseg */
342fcf5ef2aSThomas Huth             return 4;
343fcf5ef2aSThomas Huth         case IDX_FP_REGS + 14: /* fooff */
344fcf5ef2aSThomas Huth             return 4;
345fcf5ef2aSThomas Huth         case IDX_FP_REGS + 15: /* fop */
346fcf5ef2aSThomas Huth             return 4;
347fcf5ef2aSThomas Huth 
348fcf5ef2aSThomas Huth         case IDX_MXCSR_REG:
349fcf5ef2aSThomas Huth             cpu_set_mxcsr(env, ldl_p(mem_buf));
350fcf5ef2aSThomas Huth             return 4;
3517b0f97baSDoug Gale 
3527b0f97baSDoug Gale         case IDX_CTL_CR0_REG:
3534d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
354*1852f094SClaudio Fontana #ifndef CONFIG_USER_ONLY
3554d81e285SClaudio Fontana             cpu_x86_update_cr0(env, tmp);
356*1852f094SClaudio Fontana #endif
3574d81e285SClaudio Fontana             return len;
3587b0f97baSDoug Gale 
3597b0f97baSDoug Gale         case IDX_CTL_CR2_REG:
3604d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
361*1852f094SClaudio Fontana #ifndef CONFIG_USER_ONLY
3624d81e285SClaudio Fontana             env->cr[2] = tmp;
363*1852f094SClaudio Fontana #endif
3644d81e285SClaudio Fontana             return len;
3657b0f97baSDoug Gale 
3667b0f97baSDoug Gale         case IDX_CTL_CR3_REG:
3674d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
368*1852f094SClaudio Fontana #ifndef CONFIG_USER_ONLY
3694d81e285SClaudio Fontana             cpu_x86_update_cr3(env, tmp);
370*1852f094SClaudio Fontana #endif
3714d81e285SClaudio Fontana             return len;
3727b0f97baSDoug Gale 
3737b0f97baSDoug Gale         case IDX_CTL_CR4_REG:
3744d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
375*1852f094SClaudio Fontana #ifndef CONFIG_USER_ONLY
3764d81e285SClaudio Fontana             cpu_x86_update_cr4(env, tmp);
377*1852f094SClaudio Fontana #endif
3784d81e285SClaudio Fontana             return len;
3797b0f97baSDoug Gale 
3807b0f97baSDoug Gale         case IDX_CTL_CR8_REG:
3814d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
3824d81e285SClaudio Fontana #ifndef CONFIG_USER_ONLY
3834d81e285SClaudio Fontana             cpu_set_apic_tpr(cpu->apic_state, tmp);
3847b0f97baSDoug Gale #endif
3854d81e285SClaudio Fontana             return len;
3867b0f97baSDoug Gale 
3877b0f97baSDoug Gale         case IDX_CTL_EFER_REG:
3884d81e285SClaudio Fontana             len = gdb_write_reg_cs64(env->hflags, mem_buf, &tmp);
389*1852f094SClaudio Fontana #ifndef CONFIG_USER_ONLY
3904d81e285SClaudio Fontana             cpu_load_efer(env, tmp);
391*1852f094SClaudio Fontana #endif
3924d81e285SClaudio Fontana             return len;
393fcf5ef2aSThomas Huth         }
394fcf5ef2aSThomas Huth     }
395fcf5ef2aSThomas Huth     /* Unrecognised register.  */
396fcf5ef2aSThomas Huth     return 0;
397fcf5ef2aSThomas Huth }
398