diff --git a/target/i386/windbgstub.c b/target/i386/windbgstub.c
index a3ec5c1c6a..490dadbae1 100755
--- a/target/i386/windbgstub.c
+++ b/target/i386/windbgstub.c
@@ -271,6 +271,12 @@ typedef struct _CPU_KPROCESSOR_STATE {
 
 #endif
 
+static void windbg_set_dr(CPUState *cpu, int index, target_ulong value)
+{}
+
+static void windbg_set_sr(CPUState *cpu, int sr, uint16_t selector)
+{}
+
 static int windbg_read_context(CPUState *cpu, uint8_t *buf, int buf_size,
                                int offset, int len)
 {
@@ -376,6 +382,212 @@ static int windbg_read_context(CPUState *cpu, uint8_t *buf, int buf_size,
 static int windbg_write_context(CPUState *cpu, uint8_t *buf, int buf_size,
                                 int offset, int len)
 {
+    CPUArchState *env = cpu->env_ptr;
+    int mem_size, i, tmp;
+    uint8_t *mem_ptr = buf;
+
+    if (len < 0 || len > buf_size) {
+        WINDBG_ERROR("windbg_write_context: incorrect length %d", len);
+        return 1;
+    }
+
+    if (offset < 0 || offset + len > sizeof(CPU_CONTEXT)) {
+        WINDBG_ERROR("windbg_write_context: incorrect offset %d", offset);
+        return 2;
+    }
+
+    while (len > 0 && offset < sizeof(CPU_CONTEXT)) {
+        mem_size = 1;
+        switch (offset) {
+
+        case offsetof(CPU_CONTEXT, ContextFlags):
+            mem_size = sizeof_field(CPU_CONTEXT, ContextFlags);
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr0):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr0);
+            windbg_set_dr(cpu, 0, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr1):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr1);
+            windbg_set_dr(cpu, 1, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr2):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr2);
+            windbg_set_dr(cpu, 2, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr3):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr3);
+            windbg_set_dr(cpu, 3, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr6):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr6);
+            windbg_set_dr(cpu, 6, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Dr7):
+            mem_size = sizeof_field(CPU_CONTEXT, Dr7);
+            windbg_set_dr(cpu, 7, ldtul_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.ControlWord):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.ControlWord);
+            cpu_set_fpuc(env, ldl_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.StatusWord):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.StatusWord);
+            tmp = ldl_p(buf + offset);
+            env->fpstt = (tmp >> 11) & 7;
+            env->fpus = tmp & ~0x3800;
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.TagWord):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.TagWord);
+            tmp = ldl_p(buf + offset);
+            for (i = 0; i < 8; ++i) {
+                env->fptags[i] = !((tmp >> i) & 1);
+            }
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.ErrorOffset):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.ErrorOffset);
+            UINT32_P(&env->fpip)[0] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.ErrorSelector):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.ErrorSelector);
+            UINT32_P(&env->fpip)[1] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.DataOffset):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.DataOffset);
+            UINT32_P(&env->fpdp)[0] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.DataSelector):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.DataSelector);
+            UINT32_P(&env->fpdp)[1] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.RegisterArea):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.RegisterArea);
+            for (i = 0; i < 8; ++i) {
+                memcpy(PTR(env->fpregs[i]), mem_ptr + i * 10, 10);
+            }
+            break;
+
+        case offsetof(CPU_CONTEXT, FloatSave.Cr0NpxState):
+            mem_size = sizeof_field(CPU_CONTEXT, FloatSave.Cr0NpxState);
+            env->xcr0 = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, SegGs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegGs);
+            windbg_set_sr(cpu, R_GS, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, SegFs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegFs);
+            windbg_set_sr(cpu, R_FS, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, SegEs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegEs);
+            windbg_set_sr(cpu, R_ES, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, SegDs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegDs);
+            windbg_set_sr(cpu, R_DS, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, Edi):
+            mem_size = sizeof_field(CPU_CONTEXT, Edi);
+            env->regs[R_EDI] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Esi):
+            mem_size = sizeof_field(CPU_CONTEXT, Esi);
+            env->regs[R_ESI] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Ebx):
+            mem_size = sizeof_field(CPU_CONTEXT, Ebx);
+            env->regs[R_EBX] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Edx):
+            mem_size = sizeof_field(CPU_CONTEXT, Edx);
+            env->regs[R_EDX] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Ecx):
+            mem_size = sizeof_field(CPU_CONTEXT, Ecx);
+            env->regs[R_ECX] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Eax):
+            mem_size = sizeof_field(CPU_CONTEXT, Eax);
+            env->regs[R_EAX] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Ebp):
+            mem_size = sizeof_field(CPU_CONTEXT, Ebp);
+            env->regs[R_EBP] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Eip):
+            mem_size = sizeof_field(CPU_CONTEXT, Eip);
+            env->eip = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, SegCs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegCs);
+            windbg_set_sr(cpu, R_CS, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, EFlags):
+            mem_size = sizeof_field(CPU_CONTEXT, EFlags);
+            env->eflags = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, Esp):
+            mem_size = sizeof_field(CPU_CONTEXT, Esp);
+            env->regs[R_ESP] = ldl_p(buf + offset);
+            break;
+
+        case offsetof(CPU_CONTEXT, SegSs):
+            mem_size = sizeof_field(CPU_CONTEXT, SegSs);
+            windbg_set_sr(cpu, R_SS, lduw_p(buf + offset));
+            break;
+
+        case offsetof(CPU_CONTEXT, ExtendedRegisters):
+            mem_size = sizeof_field(CPU_CONTEXT, ExtendedRegisters);
+
+            uint8_t *ptr = mem_ptr + 160;
+            for (i = 0; i < 8; ++i, ptr += 16) {
+                env->xmm_regs[i].ZMM_Q(0) = ldl_p(ptr);
+                env->xmm_regs[i].ZMM_Q(1) = ldl_p(ptr + 8);
+            }
+
+            cpu_set_mxcsr(env, ldl_p(mem_ptr + 24));
+            break;
+
+        default:
+            WINDBG_ERROR("write_context: Unknown offset %d", offset);
+            return -1;
+        }
+
+        mem_ptr += mem_size;
+        offset += mem_size;
+        len -= mem_size;
+    }
+
     return 0;
 }
 
