+ to_le32(mem_buf + 36 * 4, env->fpuc);
+ fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
+ to_le32(mem_buf + 37 * 4, fpus);
+ to_le32(mem_buf + 38 * 4, 0); /* XXX: convert tags */
+ to_le32(mem_buf + 39 * 4, 0); /* fiseg */
+ to_le32(mem_buf + 40 * 4, 0); /* fioff */
+ to_le32(mem_buf + 41 * 4, 0); /* foseg */
+ to_le32(mem_buf + 42 * 4, 0); /* fooff */
+ to_le32(mem_buf + 43 * 4, 0); /* fop */
+ return 44 * 4;
+}
+
+static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
+{
+ uint32_t *registers = (uint32_t *)mem_buf;
+ int i;
+
+ for(i = 0; i < 8; i++) {
+ env->regs[i] = tswapl(registers[i]);
+ }
+ env->eip = registers[8];
+ env->eflags = registers[9];
+#if defined(CONFIG_USER_ONLY)
+#define LOAD_SEG(index, sreg)\
+ if (tswapl(registers[index]) != env->segs[sreg].selector)\
+ cpu_x86_load_seg(env, sreg, tswapl(registers[index]));
+ LOAD_SEG(10, R_CS);
+ LOAD_SEG(11, R_SS);
+ LOAD_SEG(12, R_DS);
+ LOAD_SEG(13, R_ES);
+ LOAD_SEG(14, R_FS);
+ LOAD_SEG(15, R_GS);
+#endif
+}
+
+#elif defined (TARGET_PPC)
+static void to_le32(uint32_t *buf, uint32_t v)
+{
+ uint8_t *p = (uint8_t *)buf;
+ p[3] = v;
+ p[2] = v >> 8;
+ p[1] = v >> 16;
+ p[0] = v >> 24;
+}
+
+static uint32_t from_le32 (uint32_t *buf)
+{
+ uint8_t *p = (uint8_t *)buf;
+
+ return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
+}
+
+static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
+{
+ uint32_t *registers = (uint32_t *)mem_buf, tmp;
+ int i;
+
+ /* fill in gprs */
+ for(i = 0; i < 32; i++) {
+ to_le32(®isters[i], env->gpr[i]);
+ }
+ /* fill in fprs */
+ for (i = 0; i < 32; i++) {
+ to_le32(®isters[(i * 2) + 32], *((uint32_t *)&env->fpr[i]));
+ to_le32(®isters[(i * 2) + 33], *((uint32_t *)&env->fpr[i] + 1));
+ }
+ /* nip, msr, ccr, lnk, ctr, xer, mq */
+ to_le32(®isters[96], (uint32_t)env->nip/* - 4*/);
+ to_le32(®isters[97], _load_msr(env));
+ tmp = 0;
+ for (i = 0; i < 8; i++)
+ tmp |= env->crf[i] << (32 - ((i + 1) * 4));
+ to_le32(®isters[98], tmp);
+ to_le32(®isters[99], env->lr);
+ to_le32(®isters[100], env->ctr);
+ to_le32(®isters[101], _load_xer(env));
+ to_le32(®isters[102], 0);
+
+ return 103 * 4;
+}
+
+static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
+{
+ uint32_t *registers = (uint32_t *)mem_buf;
+ int i;
+
+ /* fill in gprs */
+ for (i = 0; i < 32; i++) {
+ env->gpr[i] = from_le32(®isters[i]);
+ }
+ /* fill in fprs */
+ for (i = 0; i < 32; i++) {
+ *((uint32_t *)&env->fpr[i]) = from_le32(®isters[(i * 2) + 32]);
+ *((uint32_t *)&env->fpr[i] + 1) = from_le32(®isters[(i * 2) + 33]);
+ }
+ /* nip, msr, ccr, lnk, ctr, xer, mq */
+ env->nip = from_le32(®isters[96]);
+ _store_msr(env, from_le32(®isters[97]));
+ registers[98] = from_le32(®isters[98]);
+ for (i = 0; i < 8; i++)
+ env->crf[i] = (registers[98] >> (32 - ((i + 1) * 4))) & 0xF;
+ env->lr = from_le32(®isters[99]);
+ env->ctr = from_le32(®isters[100]);
+ _store_xer(env, from_le32(®isters[101]));
+}
+#else
+
+static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
+{