2002-08-27 Andrew Cagney * i386-tdep.h (EFLAGS_REGNUM): Define. * i386-tdep.c (builtin_type_i386_eflags): New function. Based on code by Fernando Nasser. (i386_register_virtual_type): Return builtin_type_i386_eflags when EFLAGS_REGNUM. Index: i386-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-tdep.c,v retrieving revision 1.83 diff -u -r1.83 i386-tdep.c --- i386-tdep.c 23 Aug 2002 19:26:14 -0000 1.83 +++ i386-tdep.c 27 Aug 2002 19:06:18 -0000 @@ -1090,6 +1090,174 @@ type); } +/* Construct some standard GDB types. */ + +static struct type * +builtin_type_i386_eflags (void) +{ + /* Construct a type for the EFLAGS register. The type we're + building is this: */ +#if 0 + union builtin_type_i386_eflags + { + int32_t eflags; + struct __builtin_i386_eflags_bits + { + /* We skip the 10 reserved bits here. */ + unsigned ID:1; + unsigned VIP:1; + unsigned VIF:1; + unsigned AC:1; + unsigned VM:1; + unsigned RF:1; + /* We skip one reserved bit here. */ + unsigned NT:1; + unsigned IOPL:2; + unsigned OF:1; + unsigned DF:1; + unsigned IF:1; + unsigned TF:1; + unsigned SF:1; + unsigned ZF:1; + /* We skip one reserved bit here. */ + unsigned AF:1; + /* We skip one reserved bit here. */ + unsigned PF:1; + /* We skip one reserved bit here. */ + unsigned CF:1; + } bits; + }; +#endif + /* Note that we cannot create a structure like that in C because we + could not skip the reserved bits and the order would be the + reverse of what we want (we want to see bit names from left to + right, as in a manual figure). */ + + static struct type *t; /* The type we are creating. */ + struct type *tp; /* The type of the pointer part. */ + struct type *tb; /* The type of the bitfields part. */ + struct field *fu; /* Fields of the union. */ + struct field *fs; /* Fields of the struct. */ + + if (t != NULL) + return t; + + /* Create fields for each group of bits. */ + fs = (struct field *) xmalloc (sizeof (*fs) * 17); + memset (fs, 0, sizeof (*fs) * 17); + + /* Note that we reverse the order of the fields so they are printed + as we would see then in a manual figure, left to right. */ + + FIELD_TYPE (fs[16]) = builtin_type_unsigned_int; + FIELD_NAME (fs[16]) = "CF"; + FIELD_BITPOS (fs[16]) = 0; + FIELD_BITSIZE (fs[16]) = 1; + + FIELD_TYPE (fs[15]) = builtin_type_unsigned_int; + FIELD_NAME (fs[15]) = "PF"; + FIELD_BITPOS (fs[15]) = 2; + FIELD_BITSIZE (fs[15]) = 1; + + FIELD_TYPE (fs[14]) = builtin_type_unsigned_int; + FIELD_NAME (fs[14]) = "AF"; + FIELD_BITPOS (fs[14]) = 4; + FIELD_BITSIZE (fs[14]) = 1; + + FIELD_TYPE (fs[13]) = builtin_type_unsigned_int; + FIELD_NAME (fs[13]) = "ZF"; + FIELD_BITPOS (fs[13]) = 6; + FIELD_BITSIZE (fs[13]) = 1; + + FIELD_TYPE (fs[12]) = builtin_type_unsigned_int; + FIELD_NAME (fs[12]) = "SF"; + FIELD_BITPOS (fs[12]) = 7; + FIELD_BITSIZE (fs[12]) = 1; + + FIELD_TYPE (fs[11]) = builtin_type_unsigned_int; + FIELD_NAME (fs[11]) = "TF"; + FIELD_BITPOS (fs[11]) = 8; + FIELD_BITSIZE (fs[11]) = 1; + + FIELD_TYPE (fs[10]) = builtin_type_unsigned_int; + FIELD_NAME (fs[10]) = "IF"; + FIELD_BITPOS (fs[10]) = 9; + FIELD_BITSIZE (fs[10]) = 1; + + FIELD_TYPE (fs[9]) = builtin_type_unsigned_int; + FIELD_NAME (fs[9]) = "DF"; + FIELD_BITPOS (fs[9]) = 10; + FIELD_BITSIZE (fs[9]) = 1; + + FIELD_TYPE (fs[8]) = builtin_type_unsigned_int; + FIELD_NAME (fs[8]) = "OF"; + FIELD_BITPOS (fs[8]) = 11; + FIELD_BITSIZE (fs[8]) = 1; + + FIELD_TYPE (fs[7]) = builtin_type_unsigned_int; + FIELD_NAME (fs[7]) = "IOPL"; + FIELD_BITPOS (fs[7]) = 12; + FIELD_BITSIZE (fs[7]) = 2; + + FIELD_TYPE (fs[6]) = builtin_type_unsigned_int; + FIELD_NAME (fs[6]) = "NT"; + FIELD_BITPOS (fs[6]) = 14; + FIELD_BITSIZE (fs[6]) = 1; + + FIELD_TYPE (fs[5]) = builtin_type_unsigned_int; + FIELD_NAME (fs[5]) = "RF"; + FIELD_BITPOS (fs[5]) = 16; + FIELD_BITSIZE (fs[5]) = 1; + + FIELD_TYPE (fs[4]) = builtin_type_unsigned_int; + FIELD_NAME (fs[4]) = "VM"; + FIELD_BITPOS (fs[4]) = 17; + FIELD_BITSIZE (fs[4]) = 1; + + FIELD_TYPE (fs[3]) = builtin_type_unsigned_int; + FIELD_NAME (fs[3]) = "AC"; + FIELD_BITPOS (fs[3]) = 18; + FIELD_BITSIZE (fs[3]) = 1; + + FIELD_TYPE (fs[2]) = builtin_type_unsigned_int; + FIELD_NAME (fs[2]) = "VIF"; + FIELD_BITPOS (fs[2]) = 19; + FIELD_BITSIZE (fs[2]) = 1; + + FIELD_TYPE (fs[1]) = builtin_type_unsigned_int; + FIELD_NAME (fs[1]) = "VIP"; + FIELD_BITPOS (fs[1]) = 20; + FIELD_BITSIZE (fs[1]) = 1; + + FIELD_TYPE (fs[0]) = builtin_type_unsigned_int; + FIELD_NAME (fs[0]) = "ID"; + FIELD_BITPOS (fs[0]) = 21; + FIELD_BITSIZE (fs[0]) = 1; + + /* Build a struct type with these bitfields. */ + tb = init_type (TYPE_CODE_STRUCT, 4, 0, 0, 0); + TYPE_NFIELDS (tb) = 17; + TYPE_FIELDS (tb) = fs; + TYPE_TAG_NAME (tb) = "builtin_type_i386_eflags_bits"; + + /* Now make our type as the union of the pointer and the bitfield parts. */ + fu = (struct field *) xmalloc (sizeof (*fu) * 2); + memset (fu, 0, sizeof (*fu) * 2); + + FIELD_TYPE (fu[0]) = builtin_type_int32; + FIELD_NAME (fu[0]) = "eflags"; + + FIELD_TYPE (fu[1]) = tb; + FIELD_NAME (fu[1]) = "bits"; + + /* Build a union type with those fields. */ + t = init_type (TYPE_CODE_UNION, 4, 0, 0, 0); + TYPE_NFIELDS (t) = 2; + TYPE_FIELDS (t) = fu; + TYPE_TAG_NAME (t) = "builtin_type_i386_eflags"; + + return t; +} /* Return the GDB type object for the "standard" data type of data in register REGNUM. Perhaps %esi and %edi should go here, but @@ -1100,6 +1268,9 @@ { if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM) return lookup_pointer_type (builtin_type_void); + + if (regnum == EFLAGS_REGNUM) + return builtin_type_i386_eflags (); if (IS_FP_REGNUM (regnum)) return builtin_type_i387_ext; Index: i386-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/i386-tdep.h,v retrieving revision 1.13 diff -u -r1.13 i386-tdep.h --- i386-tdep.h 20 Aug 2002 17:59:50 -0000 1.13 +++ i386-tdep.h 27 Aug 2002 19:06:18 -0000 @@ -77,6 +77,9 @@ int sc_sp_offset; }; +/* The EFLAGS register. */ +enum { EFLAGS_REGNUM = 9 }; + /* Floating-point registers. */ #define FPU_REG_RAW_SIZE 10