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 817b0f97baSDoug Gale 82a010bdbeSAlex Bennée int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) 83fcf5ef2aSThomas Huth { 84fcf5ef2aSThomas Huth X86CPU *cpu = X86_CPU(cs); 85fcf5ef2aSThomas Huth CPUX86State *env = &cpu->env; 86fcf5ef2aSThomas Huth 877b0f97baSDoug Gale uint64_t tpr; 887b0f97baSDoug Gale 89e3592bc9SDoug Evans /* N.B. GDB can't deal with changes in registers or sizes in the middle 90e3592bc9SDoug Evans of a session. So if we're in 32-bit mode on a 64-bit cpu, still act 91e3592bc9SDoug Evans as if we're on a 64-bit cpu. */ 92e3592bc9SDoug Evans 93fcf5ef2aSThomas Huth if (n < CPU_NB_REGS) { 94e3592bc9SDoug Evans if (TARGET_LONG_BITS == 64) { 95e3592bc9SDoug Evans if (env->hflags & HF_CS64_MASK) { 96fcf5ef2aSThomas Huth return gdb_get_reg64(mem_buf, env->regs[gpr_map[n]]); 97fcf5ef2aSThomas Huth } else if (n < CPU_NB_REGS32) { 98e3592bc9SDoug Evans return gdb_get_reg64(mem_buf, 99e3592bc9SDoug Evans env->regs[gpr_map[n]] & 0xffffffffUL); 100e3592bc9SDoug Evans } else { 101b7b8756aSAlex Bennée return gdb_get_regl(mem_buf, 0); 102e3592bc9SDoug Evans } 103e3592bc9SDoug Evans } else { 104fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]); 105fcf5ef2aSThomas Huth } 106fcf5ef2aSThomas Huth } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) { 107b7b8756aSAlex Bennée floatx80 *fp = (floatx80 *) &env->fpregs[n - IDX_FP_REGS]; 108b7b8756aSAlex Bennée int len = gdb_get_reg64(mem_buf, cpu_to_le64(fp->low)); 109bbc40fefSPeter Xu len += gdb_get_reg16(mem_buf, cpu_to_le16(fp->high)); 110b7b8756aSAlex Bennée return len; 111fcf5ef2aSThomas Huth } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) { 112fcf5ef2aSThomas Huth n -= IDX_XMM_REGS; 113e3592bc9SDoug Evans if (n < CPU_NB_REGS32 || TARGET_LONG_BITS == 64) { 114b7b8756aSAlex Bennée return gdb_get_reg128(mem_buf, 115b7b8756aSAlex Bennée env->xmm_regs[n].ZMM_Q(0), 116b7b8756aSAlex Bennée env->xmm_regs[n].ZMM_Q(1)); 117fcf5ef2aSThomas Huth } 118fcf5ef2aSThomas Huth } else { 119fcf5ef2aSThomas Huth switch (n) { 120fcf5ef2aSThomas Huth case IDX_IP_REG: 121e3592bc9SDoug Evans if (TARGET_LONG_BITS == 64) { 122e3592bc9SDoug Evans if (env->hflags & HF_CS64_MASK) { 123fcf5ef2aSThomas Huth return gdb_get_reg64(mem_buf, env->eip); 124fcf5ef2aSThomas Huth } else { 125e3592bc9SDoug Evans return gdb_get_reg64(mem_buf, env->eip & 0xffffffffUL); 126e3592bc9SDoug Evans } 127e3592bc9SDoug Evans } else { 128fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->eip); 129fcf5ef2aSThomas Huth } 130fcf5ef2aSThomas Huth case IDX_FLAGS_REG: 131fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->eflags); 132fcf5ef2aSThomas Huth 133fcf5ef2aSThomas Huth case IDX_SEG_REGS: 134fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_CS].selector); 135fcf5ef2aSThomas Huth case IDX_SEG_REGS + 1: 136fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_SS].selector); 137fcf5ef2aSThomas Huth case IDX_SEG_REGS + 2: 138fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_DS].selector); 139fcf5ef2aSThomas Huth case IDX_SEG_REGS + 3: 140fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_ES].selector); 141fcf5ef2aSThomas Huth case IDX_SEG_REGS + 4: 142fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_FS].selector); 143fcf5ef2aSThomas Huth case IDX_SEG_REGS + 5: 144fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->segs[R_GS].selector); 145fcf5ef2aSThomas Huth 1467b0f97baSDoug Gale case IDX_SEG_REGS + 6: 1477b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 1487b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->segs[R_FS].base); 1497b0f97baSDoug Gale } 1507b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->segs[R_FS].base); 1517b0f97baSDoug Gale 1527b0f97baSDoug Gale case IDX_SEG_REGS + 7: 1537b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 1547b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->segs[R_GS].base); 1557b0f97baSDoug Gale } 1567b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->segs[R_GS].base); 1577b0f97baSDoug Gale 1587b0f97baSDoug Gale case IDX_SEG_REGS + 8: 1597b0f97baSDoug Gale #ifdef TARGET_X86_64 1607b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 1617b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->kernelgsbase); 1627b0f97baSDoug Gale } 1637b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->kernelgsbase); 1647b0f97baSDoug Gale #else 1657b0f97baSDoug Gale return gdb_get_reg32(mem_buf, 0); 1667b0f97baSDoug Gale #endif 1677b0f97baSDoug Gale 168fcf5ef2aSThomas Huth case IDX_FP_REGS + 8: 169fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->fpuc); 170fcf5ef2aSThomas Huth case IDX_FP_REGS + 9: 171fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, (env->fpus & ~0x3800) | 172fcf5ef2aSThomas Huth (env->fpstt & 0x7) << 11); 173fcf5ef2aSThomas Huth case IDX_FP_REGS + 10: 174fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* ftag */ 175fcf5ef2aSThomas Huth case IDX_FP_REGS + 11: 176fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* fiseg */ 177fcf5ef2aSThomas Huth case IDX_FP_REGS + 12: 178fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* fioff */ 179fcf5ef2aSThomas Huth case IDX_FP_REGS + 13: 180fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* foseg */ 181fcf5ef2aSThomas Huth case IDX_FP_REGS + 14: 182fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* fooff */ 183fcf5ef2aSThomas Huth case IDX_FP_REGS + 15: 184fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, 0); /* fop */ 185fcf5ef2aSThomas Huth 186fcf5ef2aSThomas Huth case IDX_MXCSR_REG: 187418b0f93SJoseph Myers update_mxcsr_from_sse_status(env); 188fcf5ef2aSThomas Huth return gdb_get_reg32(mem_buf, env->mxcsr); 1897b0f97baSDoug Gale 1907b0f97baSDoug Gale case IDX_CTL_CR0_REG: 1917b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 1927b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->cr[0]); 1937b0f97baSDoug Gale } 1947b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->cr[0]); 1957b0f97baSDoug Gale 1967b0f97baSDoug Gale case IDX_CTL_CR2_REG: 1977b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 1987b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->cr[2]); 1997b0f97baSDoug Gale } 2007b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->cr[2]); 2017b0f97baSDoug Gale 2027b0f97baSDoug Gale case IDX_CTL_CR3_REG: 2037b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 2047b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->cr[3]); 2057b0f97baSDoug Gale } 2067b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->cr[3]); 2077b0f97baSDoug Gale 2087b0f97baSDoug Gale case IDX_CTL_CR4_REG: 2097b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 2107b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->cr[4]); 2117b0f97baSDoug Gale } 2127b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->cr[4]); 2137b0f97baSDoug Gale 2147b0f97baSDoug Gale case IDX_CTL_CR8_REG: 2157b0f97baSDoug Gale #ifdef CONFIG_SOFTMMU 2167b0f97baSDoug Gale tpr = cpu_get_apic_tpr(cpu->apic_state); 2177b0f97baSDoug Gale #else 2187b0f97baSDoug Gale tpr = 0; 2197b0f97baSDoug Gale #endif 2207b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 2217b0f97baSDoug Gale return gdb_get_reg64(mem_buf, tpr); 2227b0f97baSDoug Gale } 2237b0f97baSDoug Gale return gdb_get_reg32(mem_buf, tpr); 2247b0f97baSDoug Gale 2257b0f97baSDoug Gale case IDX_CTL_EFER_REG: 2267b0f97baSDoug Gale if ((env->hflags & HF_CS64_MASK) || GDB_FORCE_64) { 2277b0f97baSDoug Gale return gdb_get_reg64(mem_buf, env->efer); 2287b0f97baSDoug Gale } 2297b0f97baSDoug Gale return gdb_get_reg32(mem_buf, env->efer); 230fcf5ef2aSThomas Huth } 231fcf5ef2aSThomas Huth } 232fcf5ef2aSThomas Huth return 0; 233fcf5ef2aSThomas Huth } 234fcf5ef2aSThomas Huth 235*c117e5b1SPhilippe Mathieu-Daudé static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf) 236fcf5ef2aSThomas Huth { 237fcf5ef2aSThomas Huth CPUX86State *env = &cpu->env; 238fcf5ef2aSThomas Huth uint16_t selector = ldl_p(mem_buf); 239fcf5ef2aSThomas Huth 240fcf5ef2aSThomas Huth if (selector != env->segs[sreg].selector) { 241fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY) 242fcf5ef2aSThomas Huth cpu_x86_load_seg(env, sreg, selector); 243fcf5ef2aSThomas Huth #else 244fcf5ef2aSThomas Huth unsigned int limit, flags; 245fcf5ef2aSThomas Huth target_ulong base; 246fcf5ef2aSThomas Huth 247fcf5ef2aSThomas Huth if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { 248fcf5ef2aSThomas Huth int dpl = (env->eflags & VM_MASK) ? 3 : 0; 249fcf5ef2aSThomas Huth base = selector << 4; 250fcf5ef2aSThomas Huth limit = 0xffff; 251fcf5ef2aSThomas Huth flags = DESC_P_MASK | DESC_S_MASK | DESC_W_MASK | 252fcf5ef2aSThomas Huth DESC_A_MASK | (dpl << DESC_DPL_SHIFT); 253fcf5ef2aSThomas Huth } else { 254fcf5ef2aSThomas Huth if (!cpu_x86_get_descr_debug(env, selector, &base, &limit, 255fcf5ef2aSThomas Huth &flags)) { 256fcf5ef2aSThomas Huth return 4; 257fcf5ef2aSThomas Huth } 258fcf5ef2aSThomas Huth } 259fcf5ef2aSThomas Huth cpu_x86_load_seg_cache(env, sreg, selector, base, limit, flags); 260fcf5ef2aSThomas Huth #endif 261fcf5ef2aSThomas Huth } 262fcf5ef2aSThomas Huth return 4; 263fcf5ef2aSThomas Huth } 264fcf5ef2aSThomas Huth 265fcf5ef2aSThomas Huth int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) 266fcf5ef2aSThomas Huth { 267fcf5ef2aSThomas Huth X86CPU *cpu = X86_CPU(cs); 268fcf5ef2aSThomas Huth CPUX86State *env = &cpu->env; 269fcf5ef2aSThomas Huth uint32_t tmp; 270fcf5ef2aSThomas Huth 271e3592bc9SDoug Evans /* N.B. GDB can't deal with changes in registers or sizes in the middle 272e3592bc9SDoug Evans of a session. So if we're in 32-bit mode on a 64-bit cpu, still act 273e3592bc9SDoug Evans as if we're on a 64-bit cpu. */ 274e3592bc9SDoug Evans 275fcf5ef2aSThomas Huth if (n < CPU_NB_REGS) { 276e3592bc9SDoug Evans if (TARGET_LONG_BITS == 64) { 277e3592bc9SDoug Evans if (env->hflags & HF_CS64_MASK) { 278fcf5ef2aSThomas Huth env->regs[gpr_map[n]] = ldtul_p(mem_buf); 279e3592bc9SDoug Evans } else if (n < CPU_NB_REGS32) { 280e3592bc9SDoug Evans env->regs[gpr_map[n]] = ldtul_p(mem_buf) & 0xffffffffUL; 281e3592bc9SDoug Evans } 282fcf5ef2aSThomas Huth return sizeof(target_ulong); 283fcf5ef2aSThomas Huth } else if (n < CPU_NB_REGS32) { 284fcf5ef2aSThomas Huth n = gpr_map32[n]; 285fcf5ef2aSThomas Huth env->regs[n] &= ~0xffffffffUL; 286fcf5ef2aSThomas Huth env->regs[n] |= (uint32_t)ldl_p(mem_buf); 287fcf5ef2aSThomas Huth return 4; 288fcf5ef2aSThomas Huth } 289fcf5ef2aSThomas Huth } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) { 290b7b8756aSAlex Bennée floatx80 *fp = (floatx80 *) &env->fpregs[n - IDX_FP_REGS]; 291b7b8756aSAlex Bennée fp->low = le64_to_cpu(* (uint64_t *) mem_buf); 292b7b8756aSAlex Bennée fp->high = le16_to_cpu(* (uint16_t *) (mem_buf + 8)); 293fcf5ef2aSThomas Huth return 10; 294fcf5ef2aSThomas Huth } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) { 295fcf5ef2aSThomas Huth n -= IDX_XMM_REGS; 296e3592bc9SDoug Evans if (n < CPU_NB_REGS32 || TARGET_LONG_BITS == 64) { 297fcf5ef2aSThomas Huth env->xmm_regs[n].ZMM_Q(0) = ldq_p(mem_buf); 298fcf5ef2aSThomas Huth env->xmm_regs[n].ZMM_Q(1) = ldq_p(mem_buf + 8); 299fcf5ef2aSThomas Huth return 16; 300fcf5ef2aSThomas Huth } 301fcf5ef2aSThomas Huth } else { 302fcf5ef2aSThomas Huth switch (n) { 303fcf5ef2aSThomas Huth case IDX_IP_REG: 304e3592bc9SDoug Evans if (TARGET_LONG_BITS == 64) { 305e3592bc9SDoug Evans if (env->hflags & HF_CS64_MASK) { 306fcf5ef2aSThomas Huth env->eip = ldq_p(mem_buf); 307e3592bc9SDoug Evans } else { 308e3592bc9SDoug Evans env->eip = ldq_p(mem_buf) & 0xffffffffUL; 309e3592bc9SDoug Evans } 310fcf5ef2aSThomas Huth return 8; 311fcf5ef2aSThomas Huth } else { 312fcf5ef2aSThomas Huth env->eip &= ~0xffffffffUL; 313fcf5ef2aSThomas Huth env->eip |= (uint32_t)ldl_p(mem_buf); 314fcf5ef2aSThomas Huth return 4; 315fcf5ef2aSThomas Huth } 316fcf5ef2aSThomas Huth case IDX_FLAGS_REG: 317fcf5ef2aSThomas Huth env->eflags = ldl_p(mem_buf); 318fcf5ef2aSThomas Huth return 4; 319fcf5ef2aSThomas Huth 320fcf5ef2aSThomas Huth case IDX_SEG_REGS: 321fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_CS, mem_buf); 322fcf5ef2aSThomas Huth case IDX_SEG_REGS + 1: 323fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_SS, mem_buf); 324fcf5ef2aSThomas Huth case IDX_SEG_REGS + 2: 325fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_DS, mem_buf); 326fcf5ef2aSThomas Huth case IDX_SEG_REGS + 3: 327fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_ES, mem_buf); 328fcf5ef2aSThomas Huth case IDX_SEG_REGS + 4: 329fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_FS, mem_buf); 330fcf5ef2aSThomas Huth case IDX_SEG_REGS + 5: 331fcf5ef2aSThomas Huth return x86_cpu_gdb_load_seg(cpu, R_GS, mem_buf); 332fcf5ef2aSThomas Huth 3337b0f97baSDoug Gale case IDX_SEG_REGS + 6: 3347b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 3357b0f97baSDoug Gale env->segs[R_FS].base = ldq_p(mem_buf); 3367b0f97baSDoug Gale return 8; 3377b0f97baSDoug Gale } 3387b0f97baSDoug Gale env->segs[R_FS].base = ldl_p(mem_buf); 3397b0f97baSDoug Gale return 4; 3407b0f97baSDoug Gale 3417b0f97baSDoug Gale case IDX_SEG_REGS + 7: 3427b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 3437b0f97baSDoug Gale env->segs[R_GS].base = ldq_p(mem_buf); 3447b0f97baSDoug Gale return 8; 3457b0f97baSDoug Gale } 3467b0f97baSDoug Gale env->segs[R_GS].base = ldl_p(mem_buf); 3477b0f97baSDoug Gale return 4; 3487b0f97baSDoug Gale 3497b0f97baSDoug Gale case IDX_SEG_REGS + 8: 3505a07192aSmkdolata@us.ibm.com #ifdef TARGET_X86_64 3517b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 3527b0f97baSDoug Gale env->kernelgsbase = ldq_p(mem_buf); 3537b0f97baSDoug Gale return 8; 3547b0f97baSDoug Gale } 3557b0f97baSDoug Gale env->kernelgsbase = ldl_p(mem_buf); 3567b0f97baSDoug Gale #endif 3575a07192aSmkdolata@us.ibm.com return 4; 3587b0f97baSDoug Gale 359fcf5ef2aSThomas Huth case IDX_FP_REGS + 8: 360fcf5ef2aSThomas Huth cpu_set_fpuc(env, ldl_p(mem_buf)); 361fcf5ef2aSThomas Huth return 4; 362fcf5ef2aSThomas Huth case IDX_FP_REGS + 9: 363fcf5ef2aSThomas Huth tmp = ldl_p(mem_buf); 364fcf5ef2aSThomas Huth env->fpstt = (tmp >> 11) & 7; 365fcf5ef2aSThomas Huth env->fpus = tmp & ~0x3800; 366fcf5ef2aSThomas Huth return 4; 367fcf5ef2aSThomas Huth case IDX_FP_REGS + 10: /* ftag */ 368fcf5ef2aSThomas Huth return 4; 369fcf5ef2aSThomas Huth case IDX_FP_REGS + 11: /* fiseg */ 370fcf5ef2aSThomas Huth return 4; 371fcf5ef2aSThomas Huth case IDX_FP_REGS + 12: /* fioff */ 372fcf5ef2aSThomas Huth return 4; 373fcf5ef2aSThomas Huth case IDX_FP_REGS + 13: /* foseg */ 374fcf5ef2aSThomas Huth return 4; 375fcf5ef2aSThomas Huth case IDX_FP_REGS + 14: /* fooff */ 376fcf5ef2aSThomas Huth return 4; 377fcf5ef2aSThomas Huth case IDX_FP_REGS + 15: /* fop */ 378fcf5ef2aSThomas Huth return 4; 379fcf5ef2aSThomas Huth 380fcf5ef2aSThomas Huth case IDX_MXCSR_REG: 381fcf5ef2aSThomas Huth cpu_set_mxcsr(env, ldl_p(mem_buf)); 382fcf5ef2aSThomas Huth return 4; 3837b0f97baSDoug Gale 3847b0f97baSDoug Gale case IDX_CTL_CR0_REG: 3857b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 3867b0f97baSDoug Gale cpu_x86_update_cr0(env, ldq_p(mem_buf)); 3877b0f97baSDoug Gale return 8; 3887b0f97baSDoug Gale } 3897b0f97baSDoug Gale cpu_x86_update_cr0(env, ldl_p(mem_buf)); 3907b0f97baSDoug Gale return 4; 3917b0f97baSDoug Gale 3927b0f97baSDoug Gale case IDX_CTL_CR2_REG: 3937b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 3947b0f97baSDoug Gale env->cr[2] = ldq_p(mem_buf); 3957b0f97baSDoug Gale return 8; 3967b0f97baSDoug Gale } 3977b0f97baSDoug Gale env->cr[2] = ldl_p(mem_buf); 3987b0f97baSDoug Gale return 4; 3997b0f97baSDoug Gale 4007b0f97baSDoug Gale case IDX_CTL_CR3_REG: 4017b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 4027b0f97baSDoug Gale cpu_x86_update_cr3(env, ldq_p(mem_buf)); 4037b0f97baSDoug Gale return 8; 4047b0f97baSDoug Gale } 4057b0f97baSDoug Gale cpu_x86_update_cr3(env, ldl_p(mem_buf)); 4067b0f97baSDoug Gale return 4; 4077b0f97baSDoug Gale 4087b0f97baSDoug Gale case IDX_CTL_CR4_REG: 4097b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 4107b0f97baSDoug Gale cpu_x86_update_cr4(env, ldq_p(mem_buf)); 4117b0f97baSDoug Gale return 8; 4127b0f97baSDoug Gale } 4137b0f97baSDoug Gale cpu_x86_update_cr4(env, ldl_p(mem_buf)); 4147b0f97baSDoug Gale return 4; 4157b0f97baSDoug Gale 4167b0f97baSDoug Gale case IDX_CTL_CR8_REG: 4177b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 4187b0f97baSDoug Gale #ifdef CONFIG_SOFTMMU 4197b0f97baSDoug Gale cpu_set_apic_tpr(cpu->apic_state, ldq_p(mem_buf)); 4207b0f97baSDoug Gale #endif 4217b0f97baSDoug Gale return 8; 4227b0f97baSDoug Gale } 4237b0f97baSDoug Gale #ifdef CONFIG_SOFTMMU 4247b0f97baSDoug Gale cpu_set_apic_tpr(cpu->apic_state, ldl_p(mem_buf)); 4257b0f97baSDoug Gale #endif 4267b0f97baSDoug Gale return 4; 4277b0f97baSDoug Gale 4287b0f97baSDoug Gale case IDX_CTL_EFER_REG: 4297b0f97baSDoug Gale if (env->hflags & HF_CS64_MASK) { 4307b0f97baSDoug Gale cpu_load_efer(env, ldq_p(mem_buf)); 4317b0f97baSDoug Gale return 8; 4327b0f97baSDoug Gale } 4337b0f97baSDoug Gale cpu_load_efer(env, ldl_p(mem_buf)); 4347b0f97baSDoug Gale return 4; 4357b0f97baSDoug Gale 436fcf5ef2aSThomas Huth } 437fcf5ef2aSThomas Huth } 438fcf5ef2aSThomas Huth /* Unrecognised register. */ 439fcf5ef2aSThomas Huth return 0; 440fcf5ef2aSThomas Huth } 441