2002-08-10 Andrew Cagney * i386-tdep.h (i386_register_byte, i386_register_raw_size): Delete declarations. * i386-tdep.c (i386_register_name): Handle mmx registers. (is_mmx_regnum): New function. (i386_mmx_names): New array. (nr_mmx_regs): New variable. (i386_pseudo_register_read): New function. (i386_pseudo_register_write): New function. (mmx_regnum_to_fp_regnum): New function. Code from Fernando Nasser. diff --exclude *CVS* --exclude *#* --exclude *~* --exclude *%* --exclude *.orig --exclude *.rej --exclude *diffs --exclude new-* --exclude old-* --exclude *-new --exclude *-old -u /home/cagney/2002-08-09-p4-cleanup/src/gdb/i386-tdep.c ./i386-tdep.c --- /home/cagney/2002-08-09-p4-cleanup/src/gdb/i386-tdep.c Fri Aug 9 20:44:31 2002 +++ ./i386-tdep.c Sat Aug 10 02:02:14 2002 @@ -56,6 +56,23 @@ "mxcsr" }; +/* MMX registers. */ + +static char *i386_mmx_names[] = +{ + "mm0", "mm1", "mm2", "mm3", + "mm4", "mm5", "mm6", "mm7" +}; +static const int nr_mmx_regs = (sizeof (i386_mmx_names) + / sizeof (i386_mmx_names[0])); +#define MM0_REGNUM (NUM_REGS) + +static int +is_mmx_regnum (int reg) +{ + return (reg >= MM0_REGNUM && reg < MM0_REGNUM + nr_mmx_regs); +} + /* Return the name of register REG. */ const char * @@ -63,9 +80,10 @@ { if (reg < 0) return NULL; + if (is_mmx_regnum (reg)) + return i386_mmx_names[reg - MM0_REGNUM]; if (reg >= sizeof (i386_register_names) / sizeof (*i386_register_names)) return NULL; - return i386_register_names[reg]; } @@ -1079,9 +1097,60 @@ if (IS_SSE_REGNUM (regnum)) return builtin_type_vec128i; + if (is_mmx_regnum (regnum)) + return builtin_type_vec64i; + return builtin_type_int; } +/* Map a cooked register onto a raw register or memory. For the i386, + the MMX registers need to be mapped onto floating point registers. */ + +static int +mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum) +{ + int mmxi = regnum - MM0_REGNUM; + int fstat = regcache_raw_read_as_address (regcache, FSTAT_REGNUM); + int tos = (fstat >> 11) & 0x7; + int fpi = (mmxi + tos) % 8; + return FP0_REGNUM + fpi; +} + +static void +i386_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, + int regnum, void *buf) +{ + if (is_mmx_regnum (regnum)) + { + char *mmx_buf = alloca (MAX_REGISTER_RAW_SIZE); + int fpnum = mmx_regnum_to_fp_regnum (regcache, regnum); + regcache_raw_read (regcache, fpnum, mmx_buf); + /* Extract (always little endian). */ + memcpy (buf, mmx_buf, REGISTER_RAW_SIZE (regnum)); + } + else + regcache_raw_read (regcache, regnum, buf); +} + +static void +i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, + int regnum, const void *buf) +{ + if (is_mmx_regnum (regnum)) + { + char *mmx_buf = alloca (MAX_REGISTER_RAW_SIZE); + int fpnum = mmx_regnum_to_fp_regnum (regcache, regnum); + /* Read ... */ + regcache_raw_read (regcache, fpnum, mmx_buf); + /* ... Modify ... (always little endian). */ + memcpy (mmx_buf, buf, REGISTER_RAW_SIZE (regnum)); + /* ... Write. */ + regcache_raw_write (regcache, fpnum, mmx_buf); + } + else + regcache_raw_write (regcache, regnum, buf); +} + /* Return true iff register REGNUM's virtual format is different from its raw format. Note that this definition assumes that the host supports IEEE 32-bit floats, since it doesn't say that SSE @@ -1474,6 +1543,11 @@ set_gdbarch_saved_pc_after_call (gdbarch, i386_saved_pc_after_call); set_gdbarch_frame_num_args (gdbarch, i386_frame_num_args); set_gdbarch_pc_in_sigtramp (gdbarch, i386_pc_in_sigtramp); + + /* Wire in the MMX registers. */ + set_gdbarch_num_pseudo_regs (gdbarch, nr_mmx_regs); + set_gdbarch_pseudo_register_read (gdbarch, i386_pseudo_register_read); + set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write); /* Hook in ABI-specific overrides, if they have been registered. */ gdbarch_init_osabi (info, gdbarch, osabi);