static gcc_type compile_cplus_convert_array (compile_cplus_instance *instance, struct type *type) { struct type *range = TYPE_INDEX_TYPE (type); gcc_type element_type = instance->convert_type (TYPE_TARGET_TYPE (type)); if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST) { const char *s = _("array type with non-constant" " lower bound is not supported"); return instance->plugin ().error (s); } if (TYPE_LOW_BOUND (range) != 0) { const char *s = _("cannot convert array type with " "non-zero lower bound to C"); return instance->plugin ().error (s); } if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST) { if (TYPE_VECTOR (type)) { const char *s = _("variably-sized vector type is not supported"); return instance->plugin ().error (s); } std::string upper_bound = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high); return instance->plugin ().build_vla_array_type (element_type, upper_bound.c_str ()); } else { LONGEST low_bound, high_bound, count; if (get_array_bounds (type, &low_bound, &high_bound) == 0) count = -1; else { gdb_assert (low_bound == 0); /* Ensured above. */ count = high_bound + 1; } if (TYPE_VECTOR (type)) return instance->plugin ().build_vector_type (element_type, count); return instance->plugin ().build_array_type (element_type, count); } }
static int i386_darwin_arg_type_alignment (struct type *type) { type = check_typedef (type); /* According to Mac OS X ABI document (passing arguments): 6. The caller places 64-bit vectors (__m64) on the parameter area, aligned to 8-byte boundaries. 7. [...] The caller aligns 128-bit vectors in the parameter area to 16-byte boundaries. */ if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type)) return TYPE_LENGTH (type); /* 4. The caller places all the fields of structures (or unions) with no vector elements in the parameter area. These structures are 4-byte aligned. 5. The caller places structures with vector elements on the stack, 16-byte aligned. */ if (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION) { int i; int res = 4; for (i = 0; i < TYPE_NFIELDS (type); i++) res = max (res, i386_darwin_arg_type_alignment (TYPE_FIELD_TYPE (type, i))); return res; } /* 2. The caller aligns nonvector arguments to 4-byte boundaries. */ return 4; }
void c_print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) { enum type_code code; int demangled_args; int need_post_space; const char *local_name; if (show > 0) CHECK_TYPEDEF (type); local_name = find_typedef_in_hash (flags, type); if (local_name != NULL) { fputs_filtered (local_name, stream); if (varstring != NULL && *varstring != '\0') fputs_filtered (" ", stream); } else { c_type_print_base (type, stream, show, level, flags); code = TYPE_CODE (type); if ((varstring != NULL && *varstring != '\0') /* Need a space if going to print stars or brackets; but not if we will print just a type name. */ || ((show > 0 || TYPE_NAME (type) == 0) && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD || (code == TYPE_CODE_ARRAY && !TYPE_VECTOR (type)) || code == TYPE_CODE_MEMBERPTR || code == TYPE_CODE_METHODPTR || code == TYPE_CODE_REF))) fputs_filtered (" ", stream); need_post_space = (varstring != NULL && strcmp (varstring, "") != 0); c_type_print_varspec_prefix (type, stream, show, 0, need_post_space, flags); } if (varstring != NULL) { fputs_filtered (varstring, stream); /* For demangled function names, we have the arglist as part of the name, so don't print an additional pair of ()'s. */ if (local_name == NULL) { demangled_args = strchr (varstring, '(') != NULL; c_type_print_varspec_suffix (type, stream, show, 0, demangled_args, flags); } } }
/* Get the register from the frame and make a printable representation of it in the data element. */ static void tui_register_format (struct gdbarch *gdbarch, struct frame_info *frame, struct tui_data_element *data_element, int regnum) { struct ui_file *stream; struct ui_file *old_stdout; const char *name; struct cleanup *cleanups; char *p, *s; int pos; struct type *type = gdbarch_register_type (gdbarch, regnum); name = gdbarch_register_name (gdbarch, regnum); if (name == 0) { return; } pagination_enabled = 0; old_stdout = gdb_stdout; stream = tui_sfileopen (256); gdb_stdout = stream; cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout); if (TYPE_VECTOR (type) != 0 && 0) { gdb_byte buf[MAX_REGISTER_SIZE]; int len; len = register_size (current_gdbarch, regnum); fprintf_filtered (stream, "%-14s ", name); get_frame_register (frame, regnum, buf); print_scalar_formatted (buf, type, 'f', len, stream); } else { gdbarch_print_registers_info (current_gdbarch, stream, frame, regnum, 1); } /* Save formatted output in the buffer. */ p = tui_file_get_strbuf (stream); /* Remove the possible \n. */ s = strrchr (p, '\n'); if (s && s[1] == 0) *s = 0; xfree (data_element->content); data_element->content = xstrdup (p); do_cleanups (cleanups); }
static enum return_value_convention ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) { if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT || TYPE_CODE (valtype) == TYPE_CODE_UNION) && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) && TYPE_VECTOR (valtype))) return RETURN_VALUE_STRUCT_CONVENTION; else return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache, readbuf, writebuf); }
static enum return_value_convention ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, void *readbuf, const void *writebuf) { if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT || TYPE_CODE (valtype) == TYPE_CODE_UNION) && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) && TYPE_VECTOR (valtype)) && !(TYPE_LENGTH (valtype) == 1 || TYPE_LENGTH (valtype) == 2 || TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8)) return RETURN_VALUE_STRUCT_CONVENTION; else return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache, readbuf, writebuf); }
Qwt3D::Triple Track::operator() (double u, double /*v*/) { for (std::vector<TrackSegment4D*>::iterator it = trackSegments.begin(); it != trackSegments.end(); ++it) { if ((*it)->isTimeInSegment(u)) { TYPE_VECTOR(gsl_spline_ptr) result; (*it)->getGSLSplines(&result); gsl_spline_ptr xSpline = NAME_GET_VECTOR_COORDINATE(gsl_spline_ptr)( &result, xName[0]); gsl_spline_ptr ySpline = NAME_GET_VECTOR_COORDINATE(gsl_spline_ptr)( &result, yName[0]); gsl_spline_ptr zSpline = NAME_GET_VECTOR_COORDINATE(gsl_spline_ptr)( &result, zName[0]); x = gsl_spline_eval (xSpline, u, NULL); y = gsl_spline_eval (ySpline, u, NULL); z = gsl_spline_eval (zSpline, u, NULL); return Qwt3D::Triple(x, y, z); } } return Qwt3D::Triple(x, y, z); }
int c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int format, int deref_ref, int recurse, enum val_prettyprint pretty) { unsigned int i = 0; /* Number of characters printed */ unsigned len; struct type *elttype; unsigned eltlen; LONGEST val; CORE_ADDR addr; int vector_int8s = 0; int vector_floats = 0; CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: elttype = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) { eltlen = TYPE_LENGTH (elttype); len = TYPE_LENGTH (type) / eltlen; if (prettyprint_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } /* APPLE LOCAL: gdb will print the int8_t elements of a vector register as a string or as characters -- neither of which is what the user expects 99% of the time. Instead, detect that we're looking at a vector's int8_t array and treat it specially. */ if (eltlen == 1 && TYPE_VECTOR (type) && TYPE_CODE (elttype) == TYPE_CODE_INT && format == 0) { vector_int8s = 1; } /* APPLE LOCAL: Detect if we're about to print an array of v4_float or v2_doubles in a vector register */ if ((eltlen == 4 || eltlen == 8) && TYPE_VECTOR (type) && TYPE_CODE (elttype) == TYPE_CODE_FLT) { vector_floats = 1; } /* For an array of chars, print with string syntax. */ if (eltlen == 1 && ((TYPE_CODE (elttype) == TYPE_CODE_INT) || ((current_language->la_language == language_m2) && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) && (format == 0 || format == 's') && vector_int8s == 0) { /* If requested, look for the first null char and only print elements up to it. */ if (stop_print_at_null) { unsigned int temp_len; /* Look for a NULL char. */ for (temp_len = 0; (valaddr + embedded_offset)[temp_len] && temp_len < len && temp_len < print_max; temp_len++); len = temp_len; } LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0); i = len; } else { fprintf_filtered (stream, "{"); /* If this is a virtual function table, print the 0th entry specially, and the rest of the members normally. */ if (cp_is_vtbl_ptr_type (elttype)) { i = 1; fprintf_filtered (stream, _("%d vtable entries"), len - 1); } else { i = 0; } /* If this is an array of int8_t's in a vector register, force it to print as decimal by default, not as decimal value + octal escaped char. */ if (format == 0 && vector_int8s) format = 'd'; /* If this is an array of v4_float or v2_doubles in a vector register, force it to print with the '%a' floating point hex formatter when "p/x" is used. Default formatter remains the '%g' style. */ if (format == 'x' && vector_floats) format = 'A'; val_print_array_elements (type, valaddr + embedded_offset, address, stream, format, deref_ref, recurse, pretty, i); fprintf_filtered (stream, "}"); } break; } /* Array of unspecified length: treat like pointer to first elt. */ addr = address; goto print_unpacked_pointer; case TYPE_CODE_PTR: if (format && format != 's') { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); break; } if (vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); print_function_pointer_address (addr, stream); break; } elttype = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (elttype) == TYPE_CODE_METHOD) { cp_print_class_method (valaddr + embedded_offset, type, stream); } else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER) { cp_print_class_member (valaddr + embedded_offset, TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)), stream, "&"); } else { addr = unpack_pointer (type, valaddr + embedded_offset); print_unpacked_pointer: if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) { /* Try to print what function it points to. */ print_function_pointer_address (addr, stream); /* Return value is irrelevant except for string pointers. */ return (0); } if (addressprint && format != 's') { deprecated_print_address_numeric (addr, 1, stream); } /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ /* FIXME: need to handle wchar_t here... */ if (TYPE_LENGTH (elttype) == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT && (format == 0 || format == 's') && addr != 0) { i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); } else if (cp_is_vtbl_member (type)) { /* print vtbl's nicely */ CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (vt_address); if ((msymbol != NULL) && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) { fputs_filtered (" <", stream); fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); fputs_filtered (">", stream); } if (vt_address && vtblprint) { struct value *vt_val; struct symbol *wsym = (struct symbol *) NULL; struct type *wtype; struct block *block = (struct block *) NULL; int is_this_fld; if (msymbol != NULL) wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block, VAR_DOMAIN, &is_this_fld, NULL); if (wsym) { wtype = SYMBOL_TYPE (wsym); } else { wtype = TYPE_TARGET_TYPE (type); } vt_val = value_at (wtype, vt_address); common_val_print (vt_val, stream, format, deref_ref, recurse + 1, pretty); if (pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } } } /* Return number of characters printed, including the terminating '\0' if we reached the end. val_print_string takes care including the terminating '\0' if necessary. */ return i; } break; case TYPE_CODE_MEMBER: error (_("not implemented: member type in c_val_print")); break; case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER) { cp_print_class_member (valaddr + embedded_offset, TYPE_DOMAIN_TYPE (elttype), stream, ""); break; } if (addressprint) { CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); fprintf_filtered (stream, "@"); deprecated_print_address_numeric (addr, 1, stream); if (deref_ref) fputs_filtered (": ", stream); } /* De-reference the reference. */ if (deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { struct value *deref_val = value_at (TYPE_TARGET_TYPE (type), unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr + embedded_offset)); common_val_print (deref_val, stream, format, deref_ref, recurse, pretty); } else fputs_filtered ("???", stream); } break; case TYPE_CODE_UNION: if (recurse && !unionprint) { fprintf_filtered (stream, "{...}"); break; } /* Fall through. */ case TYPE_CODE_STRUCT: /*FIXME: Abstract this away */ if (vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if NOT using -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ int offset = (embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8); struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET); CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type); print_function_pointer_address (addr, stream); } else cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format, recurse, pretty, NULL, 0); break; case TYPE_CODE_ENUM: if (format) { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); break; } len = TYPE_NFIELDS (type); val = unpack_long (type, valaddr + embedded_offset); for (i = 0; i < len; i++) { QUIT; if (val == TYPE_FIELD_BITPOS (type, i)) { break; } } if (i < len) { fputs_filtered (TYPE_FIELD_NAME (type, i), stream); } else { print_longest (stream, 'd', 0, val); } break; case TYPE_CODE_FUNC: if (format) { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); break; } /* FIXME, we should consider, at least for ANSI C language, eliminating the distinction made between FUNCs and POINTERs to FUNCs. */ fprintf_filtered (stream, "{"); type_print (type, "", stream, -1); fprintf_filtered (stream, "} "); /* Try to print what function it points to, and its address. */ print_address_demangle (address, stream, demangle); break; case TYPE_CODE_BOOL: format = format ? format : output_format; if (format) print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); else { val = unpack_long (type, valaddr + embedded_offset); if (val == 0) fputs_filtered ("false", stream); else if (val == 1) fputs_filtered ("true", stream); else print_longest (stream, 'd', 0, val); } break; case TYPE_CODE_RANGE: /* FIXME: create_range_type does not set the unsigned bit in a range type (I think it probably should copy it from the target type), so we won't print values which are too large to fit in a signed integer correctly. */ /* FIXME: Doesn't handle ranges of enums correctly. (Can't just print with the target type, though, because the size of our type and the target type might differ). */ /* FALLTHROUGH */ case TYPE_CODE_INT: format = format ? format : output_format; if (format) { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); } else { val_print_type_code_int (type, valaddr + embedded_offset, stream); /* C and C++ has no single byte int type, char is used instead. Since we don't know whether the value is really intended to be used as an integer or a character, print the character equivalent as well. */ if (TYPE_LENGTH (type) == 1) { fputs_filtered (" ", stream); LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset), stream); } } break; case TYPE_CODE_CHAR: format = format ? format : output_format; if (format) { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); } else { val = unpack_long (type, valaddr + embedded_offset); if (TYPE_UNSIGNED (type)) fprintf_filtered (stream, "%u", (unsigned int) val); else fprintf_filtered (stream, "%d", (int) val); fputs_filtered (" ", stream); LA_PRINT_CHAR ((unsigned char) val, stream); } break; case TYPE_CODE_FLT: if (format) { print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); } else { print_floating (valaddr + embedded_offset, type, stream); } break; case TYPE_CODE_METHOD: { struct value *v = value_at (type, address); cp_print_class_method (value_contents (value_addr (v)), lookup_pointer_type (type), stream); break; } case TYPE_CODE_VOID: fprintf_filtered (stream, "void"); break; case TYPE_CODE_ERROR: /* APPLE LOCAL display error as unknown type */ fprintf_filtered (stream, _("<unknown type>")); break; case TYPE_CODE_UNDEF: /* This happens (without TYPE_FLAG_STUB set) on systems which don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" and no complete type for struct foo in that file. */ fprintf_filtered (stream, _("<incomplete type>")); break; case TYPE_CODE_COMPLEX: if (format) print_scalar_formatted (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), format, 0, stream); else print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), stream); fprintf_filtered (stream, " + "); if (format) print_scalar_formatted (valaddr + embedded_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), TYPE_TARGET_TYPE (type), format, 0, stream); else print_floating (valaddr + embedded_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), TYPE_TARGET_TYPE (type), stream); fprintf_filtered (stream, " * I"); break; default: error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type)); } gdb_flush (stream); return (0); }
static enum return_value_convention rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); /* The calling convention this function implements assumes the processor has floating-point registers. We shouldn't be using it on PowerPC variants that lack them. */ gdb_assert (ppc_floating_point_unit_p (gdbarch)); /* AltiVec extension: Functions that declare a vector data type as a return value place that return value in VR2. */ if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype) && TYPE_LENGTH (valtype) == 16) { if (readbuf) regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); if (writebuf) regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); return RETURN_VALUE_REGISTER_CONVENTION; } /* If the called subprogram returns an aggregate, there exists an implicit first argument, whose value is the address of a caller- allocated buffer into which the callee is assumed to store its return value. All explicit parameters are appropriately relabeled. */ if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT || TYPE_CODE (valtype) == TYPE_CODE_UNION || TYPE_CODE (valtype) == TYPE_CODE_ARRAY) return RETURN_VALUE_STRUCT_CONVENTION; /* Scalar floating-point values are returned in FPR1 for float or double, and in FPR1:FPR2 for quadword precision. Fortran complex*8 and complex*16 are returned in FPR1:FPR2, and complex*32 is returned in FPR1:FPR4. */ if (TYPE_CODE (valtype) == TYPE_CODE_FLT && (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8)) { struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); gdb_byte regval[8]; /* FIXME: kettenis/2007-01-01: Add support for quadword precision and complex. */ if (readbuf) { regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); convert_typed_floating (regval, regtype, readbuf, valtype); } if (writebuf) { convert_typed_floating (writebuf, valtype, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); } return RETURN_VALUE_REGISTER_CONVENTION; } /* Values of the types int, long, short, pointer, and char (length is less than or equal to four bytes), as well as bit values of lengths less than or equal to 32 bits, must be returned right justified in GPR3 with signed values sign extended and unsigned values zero extended, as necessary. */ if (TYPE_LENGTH (valtype) <= tdep->wordsize) { if (readbuf) { ULONGEST regval; /* For reading we don't have to worry about sign extension. */ regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, ®val); store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order, regval); } if (writebuf) { /* For writing, use unpack_long since that should handle any required sign extension. */ regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, unpack_long (valtype, writebuf)); } return RETURN_VALUE_REGISTER_CONVENTION; } /* Eight-byte non-floating-point scalar values must be returned in GPR3:GPR4. */ if (TYPE_LENGTH (valtype) == 8) { gdb_assert (TYPE_CODE (valtype) != TYPE_CODE_FLT); gdb_assert (tdep->wordsize == 4); if (readbuf) { gdb_byte regval[8]; regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regval); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, regval + 4); memcpy (readbuf, regval, 8); } if (writebuf) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, writebuf + 4); } return RETURN_VALUE_REGISTER_CONVENTION; } return RETURN_VALUE_STRUCT_CONVENTION; }
static enum return_value_convention do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type, /* APPLE LOCAL gdb_byte */ struct regcache *regcache, gdb_byte *readbuf, /* APPLE LOCAL gdb_byte */ const gdb_byte *writebuf, int broken_gcc) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); gdb_assert (tdep->wordsize == 4); if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8 && ppc_floating_point_unit_p (gdbarch)) { if (readbuf) { /* Floats and doubles stored in "f1". Convert the value to the required type. */ gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum + 1); regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); convert_typed_floating (regval, regtype, readbuf, type); } if (writebuf) { /* Floats and doubles stored in "f1". Convert the value to the register's "double" type. */ gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); convert_typed_floating (writebuf, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); } return RETURN_VALUE_REGISTER_CONVENTION; } /* APPLE LOCAL: gcc 3.3 had 8 byte long doubles, but gcc 4.0 uses 16 byte long doubles even for 32 bit ppc. They are stored across f1 & f2. */ /* Big floating point values get stored in adjacent floating point registers. */ if (TYPE_CODE (type) == TYPE_CODE_FLT && (TYPE_LENGTH (type) == 16 || TYPE_LENGTH (type) == 32)) { if (writebuf || readbuf != NULL) { int i; for (i = 0; i < TYPE_LENGTH (type) / 8; i++) { if (writebuf != NULL) regcache_cooked_write (regcache, FP0_REGNUM + 1 + i, (const bfd_byte *) writebuf + i * 8); if (readbuf != NULL) regcache_cooked_read (regcache, FP0_REGNUM + 1 + i, (bfd_byte *) readbuf + i * 8); } } return RETURN_VALUE_REGISTER_CONVENTION; } /* END APPLE LOCAL */ if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)) { if (readbuf) { /* A long long, or a double stored in the 32 bit r3/r4. */ ppc_copy_from_greg (regcache, tdep->ppc_gp0_regnum + 3, tdep->wordsize, 8, (bfd_byte *) readbuf); } if (writebuf) { /* A long long, or a double stored in the 32 bit r3/r4. */ ppc_copy_into_greg (regcache, tdep->ppc_gp0_regnum + 3, tdep->wordsize, 8, writebuf); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) <= tdep->wordsize) { if (readbuf) { /* Some sort of integer stored in r3. Since TYPE isn't bigger than the register, sign extension isn't a problem - just do everything unsigned. */ ULONGEST regval; regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, ®val); store_unsigned_integer (readbuf, TYPE_LENGTH (type), regval); } if (writebuf) { /* Some sort of integer stored in r3. Use unpack_long since that should handle any required sign extension. */ regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, unpack_long (type, writebuf)); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 16 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0) { if (readbuf) { /* Altivec places the return value in "v2". */ regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); } if (writebuf) { /* Altivec places the return value in "v2". */ regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 8 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0) { /* The e500 ABI places return values for the 64-bit DSP types (__ev64_opaque__) in r3. However, in GDB-speak, ev3 corresponds to the entire r3 value for e500, whereas GDB's r3 only corresponds to the least significant 32-bits. So place the 64-bit DSP type's value in ev3. */ if (readbuf) regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf); if (writebuf) regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf); return RETURN_VALUE_REGISTER_CONVENTION; } if (broken_gcc && TYPE_LENGTH (type) <= 8) { if (readbuf) { /* GCC screwed up. The last register isn't "left" aligned. Need to extract the least significant part of each register and then store that. */ /* Transfer any full words. */ int word = 0; while (1) { ULONGEST reg; int len = TYPE_LENGTH (type) - word * tdep->wordsize; if (len <= 0) break; if (len > tdep->wordsize) len = tdep->wordsize; regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3 + word, ®); store_unsigned_integer (((bfd_byte *) readbuf + word * tdep->wordsize), len, reg); word++; } } if (writebuf) { /* GCC screwed up. The last register isn't "left" aligned. Need to extract the least significant part of each register and then store that. */ /* Transfer any full words. */ int word = 0; while (1) { ULONGEST reg; int len = TYPE_LENGTH (type) - word * tdep->wordsize; if (len <= 0) break; if (len > tdep->wordsize) len = tdep->wordsize; reg = extract_unsigned_integer (((const bfd_byte *) writebuf + word * tdep->wordsize), len); regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3 + word, reg); word++; } } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) <= 8) { if (readbuf) { /* This matches SVr4 PPC, it does not match GCC. */ /* The value is right-padded to 8 bytes and then loaded, as two "words", into r3/r4. */ ppc_copy_from_greg (regcache, tdep->ppc_gp0_regnum + 3, tdep->wordsize, TYPE_LENGTH (type), readbuf); } if (writebuf) { /* This matches SVr4 PPC, it does not match GCC. */ /* The value is padded out to 8 bytes and then loaded, as two "words" into r3/r4. */ gdb_byte regvals[MAX_REGISTER_SIZE * 2]; memset (regvals, 0, sizeof regvals); memcpy (regvals, writebuf, TYPE_LENGTH (type)); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, regvals + 0 * tdep->wordsize); if (TYPE_LENGTH (type) > tdep->wordsize) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, regvals + 1 * tdep->wordsize); } return RETURN_VALUE_REGISTER_CONVENTION; } return RETURN_VALUE_STRUCT_CONVENTION; }
CORE_ADDR ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr) { CORE_ADDR func_addr = find_function_addr (function, NULL); struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); /* By this stage in the proceedings, SP has been decremented by "red zone size" + "struct return size". Fetch the stack-pointer from before this and use that as the BACK_CHAIN. */ const CORE_ADDR back_chain = read_sp (); /* See for-loop comment below. */ int write_pass; /* Size of the Altivec's vector parameter region, the final value is computed in the for-loop below. */ LONGEST vparam_size = 0; /* Size of the general parameter region, the final value is computed in the for-loop below. */ LONGEST gparam_size = 0; /* Kevin writes ... I don't mind seeing tdep->wordsize used in the calls to align_up(), align_down(), etc. because this makes it easier to reuse this code (in a copy/paste sense) in the future, but it is a 64-bit ABI and asserting that the wordsize is 8 bytes at some point makes it easier to verify that this function is correct without having to do a non-local analysis to figure out the possible values of tdep->wordsize. */ gdb_assert (tdep->wordsize == 8); /* Go through the argument list twice. Pass 1: Compute the function call's stack space and register requirements. Pass 2: Replay the same computation but this time also write the values out to the target. */ for (write_pass = 0; write_pass < 2; write_pass++) { int argno; /* Next available floating point register for float and double arguments. */ int freg = 1; /* Next available general register for non-vector (but possibly float) arguments. */ int greg = 3; /* Next available vector register for vector arguments. */ int vreg = 2; /* The address, at which the next general purpose parameter (integer, struct, float, ...) should be saved. */ CORE_ADDR gparam; /* Address, at which the next Altivec vector parameter should be saved. */ CORE_ADDR vparam; if (!write_pass) { /* During the first pass, GPARAM and VPARAM are more like offsets (start address zero) than addresses. That way the accumulate the total stack space each region requires. */ gparam = 0; vparam = 0; } else { /* Decrement the stack pointer making space for the Altivec and general on-stack parameters. Set vparam and gparam to their corresponding regions. */ vparam = align_down (sp - vparam_size, 16); gparam = align_down (vparam - gparam_size, 16); /* Add in space for the TOC, link editor double word, compiler double word, LR save area, CR save area. */ sp = align_down (gparam - 48, 16); } /* If the function is returning a `struct', then there is an extra hidden parameter (which will be passed in r3) containing the address of that struct.. In that case we should advance one word and start from r4 register to copy parameters. This also consumes one on-stack parameter slot. */ if (struct_return) { if (write_pass) regcache_cooked_write_signed (regcache, tdep->ppc_gp0_regnum + greg, struct_addr); greg++; gparam = align_up (gparam + tdep->wordsize, tdep->wordsize); } for (argno = 0; argno < nargs; argno++) { struct value *arg = args[argno]; struct type *type = check_typedef (value_type (arg)); const bfd_byte *val = value_contents (arg); if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8) { /* Floats and Doubles go in f1 .. f13. They also consume a left aligned GREG,, and can end up in memory. */ if (write_pass) { if (ppc_floating_point_unit_p (current_gdbarch) && freg <= 13) { gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval); } if (greg <= 10) { /* The ABI states "Single precision floating point values are mapped to the first word in a single doubleword" and "... floating point values mapped to the first eight doublewords of the parameter save area are also passed in general registers"). This code interprets that to mean: store it, left aligned, in the general register. */ gdb_byte regval[MAX_REGISTER_SIZE]; memset (regval, 0, sizeof regval); memcpy (regval, val, TYPE_LENGTH (type)); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, regval); } write_memory (gparam, val, TYPE_LENGTH (type)); } /* Always consume parameter stack space. */ freg++; greg++; gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type) && TYPE_CODE (type) == TYPE_CODE_ARRAY && tdep->ppc_vr0_regnum >= 0) { /* In the Altivec ABI, vectors go in the vector registers v2 .. v13, or when that runs out, a vector annex which goes above all the normal parameters. NOTE: cagney/2003-09-21: This is a guess based on the PowerOpen Altivec ABI. */ if (vreg <= 13) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + vreg, val); vreg++; } else { if (write_pass) write_memory (vparam, val, TYPE_LENGTH (type)); vparam = align_up (vparam + TYPE_LENGTH (type), 16); } } else if ((TYPE_CODE (type) == TYPE_CODE_INT || TYPE_CODE (type) == TYPE_CODE_ENUM || TYPE_CODE (type) == TYPE_CODE_PTR) && TYPE_LENGTH (type) <= 8) { /* Scalars and Pointers get sign[un]extended and go in gpr3 .. gpr10. They can also end up in memory. */ if (write_pass) { /* Sign extend the value, then store it unsigned. */ ULONGEST word = unpack_long (type, val); /* Convert any function code addresses into descriptors. */ if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC) { CORE_ADDR desc = word; convert_code_addr_to_desc_addr (word, &desc); word = desc; } if (greg <= 10) regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + greg, word); write_memory_unsigned_integer (gparam, tdep->wordsize, word); } greg++; gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } else { int byte; for (byte = 0; byte < TYPE_LENGTH (type); byte += tdep->wordsize) { if (write_pass && greg <= 10) { gdb_byte regval[MAX_REGISTER_SIZE]; int len = TYPE_LENGTH (type) - byte; if (len > tdep->wordsize) len = tdep->wordsize; memset (regval, 0, sizeof regval); /* WARNING: cagney/2003-09-21: As best I can tell, the ABI specifies that the value should be left aligned. Unfortunately, GCC doesn't do this - it instead right aligns even sized values and puts odd sized values on the stack. Work around that by putting both a left and right aligned value into the register (hopefully no one notices :-^). Arrrgh! */ /* Left aligned (8 byte values such as pointers fill the buffer). */ memcpy (regval, val + byte, len); /* Right aligned (but only if even). */ if (len == 1 || len == 2 || len == 4) memcpy (regval + tdep->wordsize - len, val + byte, len); regcache_cooked_write (regcache, greg, regval); } greg++; } if (write_pass) /* WARNING: cagney/2003-09-21: Strictly speaking, this isn't necessary, unfortunately, GCC appears to get "struct convention" parameter passing wrong putting odd sized structures in memory instead of in a register. Work around this by always writing the value to memory. Fortunately, doing this simplifies the code. */ write_memory (gparam, val, TYPE_LENGTH (type)); if (write_pass) /* WARNING: cagney/2004-06-20: It appears that GCC likes to put structures containing a single floating-point member in an FP register instead of general general purpose. */ /* Always consume parameter stack space. */ gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } } if (!write_pass) { /* Save the true region sizes ready for the second pass. */ vparam_size = vparam; /* Make certain that the general parameter save area is at least the minimum 8 registers (or doublewords) in size. */ if (greg < 8) gparam_size = 8 * tdep->wordsize; else gparam_size = gparam; } } /* Update %sp. */ regcache_cooked_write_signed (regcache, SP_REGNUM, sp); /* Write the backchain (it occupies WORDSIZED bytes). */ write_memory_signed_integer (sp, tdep->wordsize, back_chain); /* Point the inferior function call's return address at the dummy's breakpoint. */ regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); /* Use the func_addr to find the descriptor, and use that to find the TOC. */ { CORE_ADDR desc_addr; if (convert_code_addr_to_desc_addr (func_addr, &desc_addr)) { /* The TOC is the second double word in the descriptor. */ CORE_ADDR toc = read_memory_unsigned_integer (desc_addr + tdep->wordsize, tdep->wordsize); regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 2, toc); } } return sp; }
/* The 64 bit ABI return value convention. Return non-zero if the return-value is stored in a register, return 0 if the return-value is instead stored on the stack (a.k.a., struct return convention). For a return-value stored in a register: when WRITEBUF is non-NULL, copy the buffer to the corresponding register return-value location location; when READBUF is non-NULL, fill the buffer from the corresponding register return-value location. */ enum return_value_convention ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); /* This function exists to support a calling convention that requires floating-point registers. It shouldn't be used on processors that lack them. */ gdb_assert (ppc_floating_point_unit_p (gdbarch)); /* Floats and doubles in F1. */ if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8) { gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); if (writebuf != NULL) { convert_typed_floating (writebuf, valtype, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); } if (readbuf != NULL) { regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); convert_typed_floating (regval, regtype, readbuf, valtype); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT) return get_decimal_float_return_value (gdbarch, valtype, regcache, readbuf, writebuf); /* Integers in r3. */ if ((TYPE_CODE (valtype) == TYPE_CODE_INT || TYPE_CODE (valtype) == TYPE_CODE_ENUM || TYPE_CODE (valtype) == TYPE_CODE_CHAR || TYPE_CODE (valtype) == TYPE_CODE_BOOL) && TYPE_LENGTH (valtype) <= 8) { if (writebuf != NULL) { /* Be careful to sign extend the value. */ regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, unpack_long (valtype, writebuf)); } if (readbuf != NULL) { /* Extract the integer from r3. Since this is truncating the value, there isn't a sign extension problem. */ ULONGEST regval; regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, ®val); store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order, regval); } return RETURN_VALUE_REGISTER_CONVENTION; } /* All pointers live in r3. */ if (TYPE_CODE (valtype) == TYPE_CODE_PTR || TYPE_CODE (valtype) == TYPE_CODE_REF) { /* All pointers live in r3. */ if (writebuf != NULL) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); if (readbuf != NULL) regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); return RETURN_VALUE_REGISTER_CONVENTION; } /* Array type has more than one use. */ if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY) { /* Small character arrays are returned, right justified, in r3. */ if (TYPE_LENGTH (valtype) <= 8 && TYPE_CODE (TYPE_TARGET_TYPE (valtype)) == TYPE_CODE_INT && TYPE_LENGTH (TYPE_TARGET_TYPE (valtype)) == 1) { int offset = (register_size (gdbarch, tdep->ppc_gp0_regnum + 3) - TYPE_LENGTH (valtype)); if (writebuf != NULL) regcache_cooked_write_part (regcache, tdep->ppc_gp0_regnum + 3, offset, TYPE_LENGTH (valtype), writebuf); if (readbuf != NULL) regcache_cooked_read_part (regcache, tdep->ppc_gp0_regnum + 3, offset, TYPE_LENGTH (valtype), readbuf); return RETURN_VALUE_REGISTER_CONVENTION; } /* A VMX vector is returned in v2. */ if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype) && tdep->ppc_vr0_regnum >= 0) { if (readbuf) regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); if (writebuf) regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); return RETURN_VALUE_REGISTER_CONVENTION; } } /* Big floating point values get stored in adjacent floating point registers, starting with F1. */ if (TYPE_CODE (valtype) == TYPE_CODE_FLT && (TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 32)) { if (writebuf || readbuf != NULL) { int i; for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++) { if (writebuf != NULL) regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, (const bfd_byte *) writebuf + i * 8); if (readbuf != NULL) regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, (bfd_byte *) readbuf + i * 8); } } return RETURN_VALUE_REGISTER_CONVENTION; } /* Complex values get returned in f1:f2, need to convert. */ if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && (TYPE_LENGTH (valtype) == 8 || TYPE_LENGTH (valtype) == 16)) { if (regcache != NULL) { int i; for (i = 0; i < 2; i++) { gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); if (writebuf != NULL) { convert_typed_floating ((const bfd_byte *) writebuf + i * (TYPE_LENGTH (valtype) / 2), valtype, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, regval); } if (readbuf != NULL) { regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, regval); convert_typed_floating (regval, regtype, (bfd_byte *) readbuf + i * (TYPE_LENGTH (valtype) / 2), valtype); } } } return RETURN_VALUE_REGISTER_CONVENTION; } /* Big complex values get stored in f1:f4. */ if (TYPE_CODE (valtype) == TYPE_CODE_COMPLEX && TYPE_LENGTH (valtype) == 32) { if (regcache != NULL) { int i; for (i = 0; i < 4; i++) { if (writebuf != NULL) regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i, (const bfd_byte *) writebuf + i * 8); if (readbuf != NULL) regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i, (bfd_byte *) readbuf + i * 8); } } return RETURN_VALUE_REGISTER_CONVENTION; } return RETURN_VALUE_STRUCT_CONVENTION; }
static void ppc_push_argument (struct ppc_stack_abi *abi, struct ppc_stack_context *c, struct value *arg, int argno, int do_copy, int floatonly) { struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); struct type *type = check_typedef (value_type (arg)); int len = TYPE_LENGTH (type); gdb_byte buf[16]; c->argoffset = ROUND_UP (c->argoffset, 4); switch (TYPE_CODE (type)) { case TYPE_CODE_FLT: { if (c->freg <= abi->last_freg) { struct value *rval; struct type *rtype; int rlen; /* APPLE LOCAL: If the thing is already a long double type, don't cast it to a builtin type double, since there are two long double types, and we will pass an 16 byte long double wrong if we assume it is an 8 byte double. */ if (strcmp (TYPE_NAME (type), "long double") != 0) { rval = value_cast (builtin_type_double, arg); rtype = check_typedef (value_type (rval)); rlen = TYPE_LENGTH (rtype); } else { rval = arg; rtype = type; rlen = len; } /* APPLE LOCAL: GCC 4.0 has 16 byte long doubles */ if ((len != 4) && (len != 8) && (len != 16)) error ("floating point parameter had unexpected size"); if (rlen != 8 && rlen != 16) error ("floating point parameter had unexpected size"); if (do_copy) regcache_raw_write (current_regcache, FP0_REGNUM + c->freg, value_contents (rval)); if (do_copy && ! floatonly && abi->fregs_shadow_gregs) ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, len, value_contents (arg)); if (do_copy && ! floatonly && abi->regs_shadow_stack) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->freg++; /* APPLE LOCAL: We took up two registers... */ if (rlen == 16) c->freg++; if (! floatonly && (abi->fregs_shadow_gregs) && (c->greg <= abi->last_greg)) c->greg += len / 4; if (! floatonly && abi->regs_shadow_stack) c->argoffset += len; } else if (! floatonly) { if ((len != 4) && (len != 8) && (len != 16)) error ("floating point parameter had unexpected size"); c->argoffset = ROUND_UP (c->argoffset, len); if (do_copy) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->argoffset += len; } break; } case TYPE_CODE_INT: case TYPE_CODE_ENUM: case TYPE_CODE_PTR: case TYPE_CODE_REF: { int nregs; gdb_byte *val_contents; if (floatonly) break; /* APPLE LOCAL: Huge Hack... The problem is that if we are a 32 bit app on Mac OS X, the registers are really 64 bits, but we don't want to pass all 64 bits. So if we get passed a value that came from a register, and it's length is > the wordsize, cast it to the wordsize first before passing it in. */ if (VALUE_REGNUM (arg) != -1 && len == 8 && tdep->wordsize == 4) { len = 4; val_contents = value_contents (arg) + 4; } else val_contents = value_contents (arg); /* END APPLE LOCAL */ nregs = (len <= 4) ? 1 : 2; if ((len != 1) && (len != 2) && (len != 4) && (len != 8)) error ("integer parameter had unexpected size"); if (c->greg <= abi->last_greg) { /* If the parameter fits in the remaining argument registers, write it to the registers, and to the stack if the abi requires it. */ if (do_copy) { /* Split the argument between registers & the stack if it doesn't fit in the remaining registers. */ int regs_avaliable = abi->last_greg - c->greg + 1; if (regs_avaliable >= nregs) regs_avaliable = nregs; ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, regs_avaliable * 4, val_contents); } if (do_copy && abi->regs_shadow_stack) write_memory (c->sp + c->argoffset, val_contents, len); c->greg += nregs; if (abi->regs_shadow_stack) c->argoffset += (nregs * 4); } else { /* If we've filled up the registers, then just write it on the stack. */ if (do_copy) write_memory (c->sp + c->argoffset, val_contents, len); c->argoffset += (nregs * 4); } break; } case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: { if (! abi->structs_with_args) { if (floatonly) break; if (len > 4) { /* Rounding to the nearest multiple of 8 may not be necessary, but it is safe. Particularly since we don't know the field types of the structure */ c->structoffset = ROUND_UP (c->structoffset, 8); if (do_copy) { write_memory (c->sp + c->structoffset, value_contents (arg), len); store_unsigned_integer (buf, 4, c->sp + c->structoffset); } c->structoffset += ROUND_UP (len, 8); } else if (do_copy) { memset (buf, 0, 4); memcpy (buf, value_contents (arg), len); } if (c->greg <= abi->last_greg) { if (do_copy) ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, 4, buf); c->greg++; } else { if (do_copy) write_memory (c->sp + c->argoffset, buf, 4); c->argoffset += 4; } break; } else { int i; int regspace = (abi->last_greg - c->greg + 1) * 4; int stackspace = (len <= regspace) ? 0 : (len - regspace); int writereg = (regspace > len) ? len : regspace; int writestack = abi->regs_shadow_stack ? len : stackspace; for (i = 0; i < TYPE_NFIELDS (type); i++) { struct value *subarg = value_field (arg, i); ppc_push_argument (abi, c, subarg, argno, do_copy, 1); } if (floatonly) break; if (do_copy) { gdb_byte *ptr = value_contents (arg); if (len < 4) { memset (buf, 0, 4); if ((len == 1) || (len == 2)) memcpy (buf + 4 - len, ptr, len); else memcpy (buf, ptr, len); ptr = buf; } ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, (writereg < 4) ? 4 : writereg, ptr); write_memory (c->sp + c->argoffset, ptr, (writestack < 4) ? 4 : writestack); } c->greg += ROUND_UP (writereg, 4) / 4; c->argoffset += writestack; } break; } case TYPE_CODE_ARRAY: { if (floatonly) break; if (! TYPE_VECTOR (type)) error ("non-vector array type"); if (len != 16) error ("unexpected vector length"); if (c->vreg <= abi->last_vreg) { if (do_copy) regcache_raw_write (current_regcache, tdep->ppc_vr0_regnum + c->vreg, value_contents (arg)); c->vreg++; } else { /* Vector arguments must be aligned to 16 bytes on the stack. */ c->argoffset = ROUND_UP (c->argoffset, 16); if (do_copy) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->argoffset += len; } break; } default: error ("argument %d has unknown type code 0x%x (%s)", argno, TYPE_CODE (type), type_code_name (TYPE_CODE (type))); } return; }
static void initialize_tdesc_powerpc_altivec64 (void) { struct target_desc *result = allocate_target_description (); struct tdesc_feature *feature; struct type *field_type, *type; set_tdesc_architecture (result, bfd_scan_arch ("powerpc:common64")); feature = tdesc_create_feature (result, "org.gnu.gdb.power.core"); tdesc_create_reg (feature, "r0", 0, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r1", 1, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r2", 2, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r3", 3, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r4", 4, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r5", 5, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r6", 6, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r7", 7, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r16", 16, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r17", 17, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r18", 18, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r19", 19, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r20", 20, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r21", 21, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r22", 22, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r23", 23, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r24", 24, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r25", 25, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r26", 26, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r27", 27, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r28", 28, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r29", 29, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r30", 30, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "r31", 31, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "pc", 64, 1, NULL, 64, "code_ptr"); tdesc_create_reg (feature, "msr", 65, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "cr", 66, 1, NULL, 32, "uint32"); tdesc_create_reg (feature, "lr", 67, 1, NULL, 64, "code_ptr"); tdesc_create_reg (feature, "ctr", 68, 1, NULL, 64, "uint64"); tdesc_create_reg (feature, "xer", 69, 1, NULL, 32, "uint32"); feature = tdesc_create_feature (result, "org.gnu.gdb.power.fpu"); tdesc_create_reg (feature, "f0", 32, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f1", 33, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f2", 34, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f3", 35, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f4", 36, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f5", 37, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f6", 38, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f7", 39, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f8", 40, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f9", 41, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f10", 42, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f11", 43, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f12", 44, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f13", 45, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f14", 46, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f15", 47, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f16", 48, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f17", 49, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f18", 50, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f19", 51, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f20", 52, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f21", 53, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f22", 54, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f23", 55, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f24", 56, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f25", 57, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f26", 58, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f27", 59, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f28", 60, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f29", 61, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f30", 62, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "f31", 63, 1, NULL, 64, "ieee_double"); tdesc_create_reg (feature, "fpscr", 70, 1, "float", 32, "int"); feature = tdesc_create_feature (result, "org.gnu.gdb.power.altivec"); field_type = tdesc_named_type (feature, "ieee_single"); type = init_vector_type (field_type, 4); TYPE_NAME (type) = xstrdup ("v4f"); tdesc_record_type (feature, type); field_type = tdesc_named_type (feature, "int32"); type = init_vector_type (field_type, 4); TYPE_NAME (type) = xstrdup ("v4i32"); tdesc_record_type (feature, type); field_type = tdesc_named_type (feature, "int16"); type = init_vector_type (field_type, 8); TYPE_NAME (type) = xstrdup ("v8i16"); tdesc_record_type (feature, type); field_type = tdesc_named_type (feature, "int8"); type = init_vector_type (field_type, 16); TYPE_NAME (type) = xstrdup ("v16i8"); tdesc_record_type (feature, type); type = init_composite_type (NULL, TYPE_CODE_UNION); TYPE_NAME (type) = xstrdup ("vec128"); field_type = tdesc_named_type (feature, "uint128"); append_composite_type_field (type, xstrdup ("uint128"), field_type); field_type = tdesc_named_type (feature, "v4f"); append_composite_type_field (type, xstrdup ("v4_float"), field_type); field_type = tdesc_named_type (feature, "v4i32"); append_composite_type_field (type, xstrdup ("v4_int32"), field_type); field_type = tdesc_named_type (feature, "v8i16"); append_composite_type_field (type, xstrdup ("v8_int16"), field_type); field_type = tdesc_named_type (feature, "v16i8"); append_composite_type_field (type, xstrdup ("v16_int8"), field_type); TYPE_VECTOR (type) = 1; tdesc_record_type (feature, type); tdesc_create_reg (feature, "vr0", 71, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr1", 72, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr2", 73, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr3", 74, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr4", 75, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr5", 76, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr6", 77, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr7", 78, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr8", 79, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr9", 80, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr10", 81, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr11", 82, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr12", 83, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr13", 84, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr14", 85, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr15", 86, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr16", 87, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr17", 88, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr18", 89, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr19", 90, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr20", 91, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr21", 92, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr22", 93, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr23", 94, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr24", 95, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr25", 96, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr26", 97, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr27", 98, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr28", 99, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr29", 100, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr30", 101, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vr31", 102, 1, NULL, 128, "vec128"); tdesc_create_reg (feature, "vscr", 103, 1, "vector", 32, "int"); tdesc_create_reg (feature, "vrsave", 104, 1, "vector", 32, "int"); tdesc_powerpc_altivec64 = result; }
static int i386_m128_p (struct type *type) { return (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && TYPE_LENGTH (type) == 16); }
CORE_ADDR ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr) { struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); const CORE_ADDR saved_sp = read_sp (); int argspace = 0; /* 0 is an initial wrong guess. */ int write_pass; /* Go through the argument list twice. Pass 1: Figure out how much new stack space is required for arguments and pushed values. Unlike the PowerOpen ABI, the SysV ABI doesn't reserve any extra space for parameters which are put in registers, but does always push structures and then pass their address. Pass 2: Replay the same computation but this time also write the values out to the target. */ for (write_pass = 0; write_pass < 2; write_pass++) { int argno; /* Next available floating point register for float and double arguments. */ int freg = 1; /* Next available general register for non-float, non-vector arguments. */ int greg = 3; /* Next available vector register for vector arguments. */ int vreg = 2; /* Arguments start above the "LR save word" and "Back chain". */ int argoffset = 2 * tdep->wordsize; /* Structures start after the arguments. */ int structoffset = argoffset + argspace; /* If the function is returning a `struct', then the first word (which will be passed in r3) is used for struct return address. In that case we should advance one word and start from r4 register to copy parameters. */ if (struct_return) { if (write_pass) regcache_cooked_write_signed (regcache, tdep->ppc_gp0_regnum + greg, struct_addr); greg++; } for (argno = 0; argno < nargs; argno++) { struct value *arg = args[argno]; struct type *type = check_typedef (VALUE_TYPE (arg)); int len = TYPE_LENGTH (type); char *val = VALUE_CONTENTS (arg); if (TYPE_CODE (type) == TYPE_CODE_FLT && ppc_floating_point_unit_p (current_gdbarch) && len <= 8) { /* Floating point value converted to "double" then passed in an FP register, when the registers run out, 8 byte aligned stack is used. */ if (freg <= 8) { if (write_pass) { /* Always store the floating point value using the register's floating-point format. */ char regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum + freg); convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval); } freg++; } else { /* SysV ABI converts floats to doubles before writing them to an 8 byte aligned stack location. */ argoffset = align_up (argoffset, 8); if (write_pass) { char memval[8]; struct type *memtype; switch (TARGET_BYTE_ORDER) { case BFD_ENDIAN_BIG: memtype = builtin_type_ieee_double_big; break; case BFD_ENDIAN_LITTLE: memtype = builtin_type_ieee_double_little; break; default: internal_error (__FILE__, __LINE__, "bad switch"); } convert_typed_floating (val, type, memval, memtype); write_memory (sp + argoffset, val, len); } argoffset += 8; } } else if (len == 8 && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */ || (!ppc_floating_point_unit_p (current_gdbarch) && TYPE_CODE (type) == TYPE_CODE_FLT))) /* double */ { /* "long long" or "double" passed in an odd/even register pair with the low addressed word in the odd register and the high addressed word in the even register, or when the registers run out an 8 byte aligned stack location. */ if (greg > 9) { /* Just in case GREG was 10. */ greg = 11; argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, len); argoffset += 8; } else if (tdep->wordsize == 8) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, val); greg += 1; } else { /* Must start on an odd register - r3/r4 etc. */ if ((greg & 1) == 0) greg++; if (write_pass) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 0, val + 0); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 1, val + 4); } greg += 2; } } else if (len == 16 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0) { /* Vector parameter passed in an Altivec register, or when that runs out, 16 byte aligned stack location. */ if (vreg <= 13) { if (write_pass) regcache_cooked_write (current_regcache, tdep->ppc_vr0_regnum + vreg, val); vreg++; } else { argoffset = align_up (argoffset, 16); if (write_pass) write_memory (sp + argoffset, val, 16); argoffset += 16; } } else if (len == 8 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0) { /* Vector parameter passed in an e500 register, or when that runs out, 8 byte aligned stack location. Note that since e500 vector and general purpose registers both map onto the same underlying register set, a "greg" and not a "vreg" is consumed here. A cooked write stores the value in the correct locations within the raw register cache. */ if (greg <= 10) { if (write_pass) regcache_cooked_write (current_regcache, tdep->ppc_ev0_regnum + greg, val); greg++; } else { argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, 8); argoffset += 8; } } else { /* Reduce the parameter down to something that fits in a "word". */ char word[MAX_REGISTER_SIZE]; memset (word, 0, MAX_REGISTER_SIZE); if (len > tdep->wordsize || TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION) { /* Structs and large values are put on an 8 byte aligned stack ... */ structoffset = align_up (structoffset, 8); if (write_pass) write_memory (sp + structoffset, val, len); /* ... and then a "word" pointing to that address is passed as the parameter. */ store_unsigned_integer (word, tdep->wordsize, sp + structoffset); structoffset += len; } else if (TYPE_CODE (type) == TYPE_CODE_INT) /* Sign or zero extend the "int" into a "word". */ store_unsigned_integer (word, tdep->wordsize, unpack_long (type, val)); else /* Always goes in the low address. */ memcpy (word, val, len); /* Store that "word" in a register, or on the stack. The words have "4" byte alignment. */ if (greg <= 10) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, word); greg++; } else { argoffset = align_up (argoffset, tdep->wordsize); if (write_pass) write_memory (sp + argoffset, word, tdep->wordsize); argoffset += tdep->wordsize; } } } /* Compute the actual stack space requirements. */ if (!write_pass) { /* Remember the amount of space needed by the arguments. */ argspace = argoffset; /* Allocate space for both the arguments and the structures. */ sp -= (argoffset + structoffset); /* Ensure that the stack is still 16 byte aligned. */ sp = align_down (sp, 16); } } /* Update %sp. */ regcache_cooked_write_signed (regcache, SP_REGNUM, sp); /* Write the backchain (it occupies WORDSIZED bytes). */ write_memory_signed_integer (sp, tdep->wordsize, saved_sp); /* Point the inferior function call's return address at the dummy's breakpoint. */ regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); return sp; }
void c_type_print_varspec_suffix (struct type *type, struct ui_file *stream, int show, int passed_a_ptr, int demangled_args) { if (type == 0) return; if (TYPE_NAME (type) && show <= 0) return; QUIT; switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: { LONGEST low_bound, high_bound; int is_vector = TYPE_VECTOR (type); if (passed_a_ptr) fprintf_filtered (stream, ")"); fprintf_filtered (stream, (is_vector ? "__attribute__ ((vector_size(" : "[")); if (get_array_bounds (type, &low_bound, &high_bound)) fprintf_filtered (stream, "%s", plongest (high_bound - low_bound + 1)); fprintf_filtered (stream, (is_vector ? ")))" : "]")); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, 0, 0); } break; case TYPE_CODE_MEMBERPTR: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, 0, 0); break; case TYPE_CODE_METHODPTR: fprintf_filtered (stream, ")"); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, 0, 0); break; case TYPE_CODE_PTR: case TYPE_CODE_REF: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, 1, 0); break; case TYPE_CODE_METHOD: case TYPE_CODE_FUNC: if (passed_a_ptr) fprintf_filtered (stream, ")"); if (!demangled_args) c_type_print_args (type, stream, 0, current_language->la_language); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, passed_a_ptr, 0); break; case TYPE_CODE_TYPEDEF: c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show, passed_a_ptr, 0); break; case TYPE_CODE_UNDEF: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_ENUM: case TYPE_CODE_INT: case TYPE_CODE_FLT: case TYPE_CODE_VOID: case TYPE_CODE_ERROR: case TYPE_CODE_CHAR: case TYPE_CODE_BOOL: case TYPE_CODE_SET: case TYPE_CODE_RANGE: case TYPE_CODE_STRING: case TYPE_CODE_COMPLEX: case TYPE_CODE_NAMESPACE: case TYPE_CODE_DECFLOAT: /* These types do not need a suffix. They are listed so that gcc -Wall will report types that may not have been considered. */ break; default: error (_("type not handled in c_type_print_varspec_suffix()")); break; } }
CORE_ADDR ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); ULONGEST saved_sp; int argspace = 0; /* 0 is an initial wrong guess. */ int write_pass; gdb_assert (tdep->wordsize == 4); regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &saved_sp); /* Go through the argument list twice. Pass 1: Figure out how much new stack space is required for arguments and pushed values. Unlike the PowerOpen ABI, the SysV ABI doesn't reserve any extra space for parameters which are put in registers, but does always push structures and then pass their address. Pass 2: Replay the same computation but this time also write the values out to the target. */ for (write_pass = 0; write_pass < 2; write_pass++) { int argno; /* Next available floating point register for float and double arguments. */ int freg = 1; /* Next available general register for non-float, non-vector arguments. */ int greg = 3; /* Next available vector register for vector arguments. */ int vreg = 2; /* Arguments start above the "LR save word" and "Back chain". */ int argoffset = 2 * tdep->wordsize; /* Structures start after the arguments. */ int structoffset = argoffset + argspace; /* If the function is returning a `struct', then the first word (which will be passed in r3) is used for struct return address. In that case we should advance one word and start from r4 register to copy parameters. */ if (struct_return) { if (write_pass) regcache_cooked_write_signed (regcache, tdep->ppc_gp0_regnum + greg, struct_addr); greg++; } for (argno = 0; argno < nargs; argno++) { struct value *arg = args[argno]; struct type *type = check_typedef (value_type (arg)); int len = TYPE_LENGTH (type); const bfd_byte *val = value_contents (arg); if (TYPE_CODE (type) == TYPE_CODE_FLT && len <= 8 && !tdep->soft_float) { /* Floating point value converted to "double" then passed in an FP register, when the registers run out, 8 byte aligned stack is used. */ if (freg <= 8) { if (write_pass) { /* Always store the floating point value using the register's floating-point format. */ gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum + freg); convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval); } freg++; } else { /* The SysV ABI tells us to convert floats to doubles before writing them to an 8 byte aligned stack location. Unfortunately GCC does not do that, and stores floats into 4 byte aligned locations without converting them to doubles. Since there is no know compiler that actually follows the ABI here, we implement the GCC convention. */ /* Align to 4 bytes or 8 bytes depending on the type of the argument (float or double). */ argoffset = align_up (argoffset, len); if (write_pass) write_memory (sp + argoffset, val, len); argoffset += len; } } else if (TYPE_CODE (type) == TYPE_CODE_FLT && len == 16 && !tdep->soft_float && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) { /* IBM long double passed in two FP registers if available, otherwise 8-byte aligned stack. */ if (freg <= 7) { if (write_pass) { regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, val); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg + 1, val + 8); } freg += 2; } else { argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, len); argoffset += 16; } } else if (len == 8 && (TYPE_CODE (type) == TYPE_CODE_INT /* long long */ || TYPE_CODE (type) == TYPE_CODE_FLT /* double */ || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float))) { /* "long long" or soft-float "double" or "_Decimal64" passed in an odd/even register pair with the low addressed word in the odd register and the high addressed word in the even register, or when the registers run out an 8 byte aligned stack location. */ if (greg > 9) { /* Just in case GREG was 10. */ greg = 11; argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, len); argoffset += 8; } else { /* Must start on an odd register - r3/r4 etc. */ if ((greg & 1) == 0) greg++; if (write_pass) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 0, val + 0); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 1, val + 4); } greg += 2; } } else if (len == 16 && ((TYPE_CODE (type) == TYPE_CODE_FLT && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float))) { /* Soft-float IBM long double or _Decimal128 passed in four consecutive registers, or on the stack. The registers are not necessarily odd/even pairs. */ if (greg > 7) { greg = 11; argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, len); argoffset += 16; } else { if (write_pass) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 0, val + 0); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 1, val + 4); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 2, val + 8); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 3, val + 12); } greg += 4; } } else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len <= 8 && !tdep->soft_float) { /* 32-bit and 64-bit decimal floats go in f1 .. f8. They can end up in memory. */ if (freg <= 8) { if (write_pass) { gdb_byte regval[MAX_REGISTER_SIZE]; const gdb_byte *p; /* 32-bit decimal floats are right aligned in the doubleword. */ if (TYPE_LENGTH (type) == 4) { memcpy (regval + 4, val, 4); p = regval; } else p = val; regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, p); } freg++; } else { argoffset = align_up (argoffset, len); if (write_pass) /* Write value in the stack's parameter save area. */ write_memory (sp + argoffset, val, len); argoffset += len; } } else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && len == 16 && !tdep->soft_float) { /* 128-bit decimal floats go in f2 .. f7, always in even/odd pairs. They can end up in memory, using two doublewords. */ if (freg <= 6) { /* Make sure freg is even. */ freg += freg & 1; if (write_pass) { regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, val); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg + 1, val + 8); } } else { argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, 16); argoffset += 16; } /* If a 128-bit decimal float goes to the stack because only f7 and f8 are free (thus there's no even/odd register pair available), these registers should be marked as occupied. Hence we increase freg even when writing to memory. */ freg += 2; } else if (len == 16 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->vector_abi == POWERPC_VEC_ALTIVEC) { /* Vector parameter passed in an Altivec register, or when that runs out, 16 byte aligned stack location. */ if (vreg <= 13) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + vreg, val); vreg++; } else { argoffset = align_up (argoffset, 16); if (write_pass) write_memory (sp + argoffset, val, 16); argoffset += 16; } } else if (len == 8 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->vector_abi == POWERPC_VEC_SPE) { /* Vector parameter passed in an e500 register, or when that runs out, 8 byte aligned stack location. Note that since e500 vector and general purpose registers both map onto the same underlying register set, a "greg" and not a "vreg" is consumed here. A cooked write stores the value in the correct locations within the raw register cache. */ if (greg <= 10) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + greg, val); greg++; } else { argoffset = align_up (argoffset, 8); if (write_pass) write_memory (sp + argoffset, val, 8); argoffset += 8; } } else { /* Reduce the parameter down to something that fits in a "word". */ gdb_byte word[MAX_REGISTER_SIZE]; memset (word, 0, MAX_REGISTER_SIZE); if (len > tdep->wordsize || TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION) { /* Structs and large values are put in an aligned stack slot ... */ if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && len >= 16) structoffset = align_up (structoffset, 16); else structoffset = align_up (structoffset, 8); if (write_pass) write_memory (sp + structoffset, val, len); /* ... and then a "word" pointing to that address is passed as the parameter. */ store_unsigned_integer (word, tdep->wordsize, byte_order, sp + structoffset); structoffset += len; } else if (TYPE_CODE (type) == TYPE_CODE_INT) /* Sign or zero extend the "int" into a "word". */ store_unsigned_integer (word, tdep->wordsize, byte_order, unpack_long (type, val)); else /* Always goes in the low address. */ memcpy (word, val, len); /* Store that "word" in a register, or on the stack. The words have "4" byte alignment. */ if (greg <= 10) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, word); greg++; } else { argoffset = align_up (argoffset, tdep->wordsize); if (write_pass) write_memory (sp + argoffset, word, tdep->wordsize); argoffset += tdep->wordsize; } } } /* Compute the actual stack space requirements. */ if (!write_pass) { /* Remember the amount of space needed by the arguments. */ argspace = argoffset; /* Allocate space for both the arguments and the structures. */ sp -= (argoffset + structoffset); /* Ensure that the stack is still 16 byte aligned. */ sp = align_down (sp, 16); } /* The psABI says that "A caller of a function that takes a variable argument list shall set condition register bit 6 to 1 if it passes one or more arguments in the floating-point registers. It is strongly recommended that the caller set the bit to 0 otherwise..." Doing this for normal functions too shouldn't hurt. */ if (write_pass) { ULONGEST cr; regcache_cooked_read_unsigned (regcache, tdep->ppc_cr_regnum, &cr); if (freg > 1) cr |= 0x02000000; else cr &= ~0x02000000; regcache_cooked_write_unsigned (regcache, tdep->ppc_cr_regnum, cr); } } /* Update %sp. */ regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); /* Write the backchain (it occupies WORDSIZED bytes). */ write_memory_signed_integer (sp, tdep->wordsize, byte_order, saved_sp); /* Point the inferior function call's return address at the dummy's breakpoint. */ regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); return sp; }
static enum return_value_convention do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf, int broken_gcc) { struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); gdb_assert (tdep->wordsize == 4); if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8 && !tdep->soft_float) { if (readbuf) { /* Floats and doubles stored in "f1". Convert the value to the required type. */ gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum + 1); regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval); convert_typed_floating (regval, regtype, readbuf, type); } if (writebuf) { /* Floats and doubles stored in "f1". Convert the value to the register's "double" type. */ gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); convert_typed_floating (writebuf, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 16 && !tdep->soft_float && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) { /* IBM long double stored in f1 and f2. */ if (readbuf) { regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2, readbuf + 8); } if (writebuf) { regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, writebuf); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2, writebuf + 8); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 16 && ((TYPE_CODE (type) == TYPE_CODE_FLT && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && tdep->soft_float))) { /* Soft-float IBM long double or _Decimal128 stored in r3, r4, r5, r6. */ if (readbuf) { regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, readbuf + 4); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, readbuf + 8); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, readbuf + 12); } if (writebuf) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, writebuf + 4); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, writebuf + 8); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, writebuf + 12); } return RETURN_VALUE_REGISTER_CONVENTION; } if ((TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) || (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) || (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 8 && tdep->soft_float)) { if (readbuf) { /* A long long, double or _Decimal64 stored in the 32 bit r3/r4. */ regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf + 0); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, readbuf + 4); } if (writebuf) { /* A long long, double or _Decimal64 stored in the 32 bit r3/r4. */ regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf + 0); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, writebuf + 4); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && !tdep->soft_float) return get_decimal_float_return_value (gdbarch, type, regcache, readbuf, writebuf); else if ((TYPE_CODE (type) == TYPE_CODE_INT || TYPE_CODE (type) == TYPE_CODE_CHAR || TYPE_CODE (type) == TYPE_CODE_BOOL || TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_CODE (type) == TYPE_CODE_REF || TYPE_CODE (type) == TYPE_CODE_ENUM) && TYPE_LENGTH (type) <= tdep->wordsize) { if (readbuf) { /* Some sort of integer stored in r3. Since TYPE isn't bigger than the register, sign extension isn't a problem - just do everything unsigned. */ ULONGEST regval; regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, ®val); store_unsigned_integer (readbuf, TYPE_LENGTH (type), byte_order, regval); } if (writebuf) { /* Some sort of integer stored in r3. Use unpack_long since that should handle any required sign extension. */ regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, unpack_long (type, writebuf)); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 16 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->vector_abi == POWERPC_VEC_ALTIVEC) { if (readbuf) { /* Altivec places the return value in "v2". */ regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf); } if (writebuf) { /* Altivec places the return value in "v2". */ regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 16 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->vector_abi == POWERPC_VEC_GENERIC) { /* GCC -maltivec -mabi=no-altivec returns vectors in r3/r4/r5/r6. GCC without AltiVec returns them in memory, but it warns about ABI risks in that case; we don't try to support it. */ if (readbuf) { regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, readbuf + 0); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, readbuf + 4); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 5, readbuf + 8); regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 6, readbuf + 12); } if (writebuf) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf + 0); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, writebuf + 4); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 5, writebuf + 8); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 6, writebuf + 12); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) == 8 && TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && tdep->vector_abi == POWERPC_VEC_SPE) { /* The e500 ABI places return values for the 64-bit DSP types (__ev64_opaque__) in r3. However, in GDB-speak, ev3 corresponds to the entire r3 value for e500, whereas GDB's r3 only corresponds to the least significant 32-bits. So place the 64-bit DSP type's value in ev3. */ if (readbuf) regcache_cooked_read (regcache, tdep->ppc_ev0_regnum + 3, readbuf); if (writebuf) regcache_cooked_write (regcache, tdep->ppc_ev0_regnum + 3, writebuf); return RETURN_VALUE_REGISTER_CONVENTION; } if (broken_gcc && TYPE_LENGTH (type) <= 8) { /* GCC screwed up for structures or unions whose size is less than or equal to 8 bytes.. Instead of left-aligning, it right-aligns the data into the buffer formed by r3, r4. */ gdb_byte regvals[MAX_REGISTER_SIZE * 2]; int len = TYPE_LENGTH (type); int offset = (2 * tdep->wordsize - len) % tdep->wordsize; if (readbuf) { regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regvals + 0 * tdep->wordsize); if (len > tdep->wordsize) regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, regvals + 1 * tdep->wordsize); memcpy (readbuf, regvals + offset, len); } if (writebuf) { memset (regvals, 0, sizeof regvals); memcpy (regvals + offset, writebuf, len); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, regvals + 0 * tdep->wordsize); if (len > tdep->wordsize) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, regvals + 1 * tdep->wordsize); } return RETURN_VALUE_REGISTER_CONVENTION; } if (TYPE_LENGTH (type) <= 8) { if (readbuf) { /* This matches SVr4 PPC, it does not match GCC. */ /* The value is right-padded to 8 bytes and then loaded, as two "words", into r3/r4. */ gdb_byte regvals[MAX_REGISTER_SIZE * 2]; regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regvals + 0 * tdep->wordsize); if (TYPE_LENGTH (type) > tdep->wordsize) regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4, regvals + 1 * tdep->wordsize); memcpy (readbuf, regvals, TYPE_LENGTH (type)); } if (writebuf) { /* This matches SVr4 PPC, it does not match GCC. */ /* The value is padded out to 8 bytes and then loaded, as two "words" into r3/r4. */ gdb_byte regvals[MAX_REGISTER_SIZE * 2]; memset (regvals, 0, sizeof regvals); memcpy (regvals, writebuf, TYPE_LENGTH (type)); regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, regvals + 0 * tdep->wordsize); if (TYPE_LENGTH (type) > tdep->wordsize) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4, regvals + 1 * tdep->wordsize); } return RETURN_VALUE_REGISTER_CONVENTION; } return RETURN_VALUE_STRUCT_CONVENTION; }
CORE_ADDR ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr) { CORE_ADDR func_addr = find_function_addr (function, NULL); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); ULONGEST back_chain; /* See for-loop comment below. */ int write_pass; /* Size of the Altivec's vector parameter region, the final value is computed in the for-loop below. */ LONGEST vparam_size = 0; /* Size of the general parameter region, the final value is computed in the for-loop below. */ LONGEST gparam_size = 0; /* Kevin writes ... I don't mind seeing tdep->wordsize used in the calls to align_up(), align_down(), etc. because this makes it easier to reuse this code (in a copy/paste sense) in the future, but it is a 64-bit ABI and asserting that the wordsize is 8 bytes at some point makes it easier to verify that this function is correct without having to do a non-local analysis to figure out the possible values of tdep->wordsize. */ gdb_assert (tdep->wordsize == 8); /* This function exists to support a calling convention that requires floating-point registers. It shouldn't be used on processors that lack them. */ gdb_assert (ppc_floating_point_unit_p (gdbarch)); /* By this stage in the proceedings, SP has been decremented by "red zone size" + "struct return size". Fetch the stack-pointer from before this and use that as the BACK_CHAIN. */ regcache_cooked_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &back_chain); /* Go through the argument list twice. Pass 1: Compute the function call's stack space and register requirements. Pass 2: Replay the same computation but this time also write the values out to the target. */ for (write_pass = 0; write_pass < 2; write_pass++) { int argno; /* Next available floating point register for float and double arguments. */ int freg = 1; /* Next available general register for non-vector (but possibly float) arguments. */ int greg = 3; /* Next available vector register for vector arguments. */ int vreg = 2; /* The address, at which the next general purpose parameter (integer, struct, float, ...) should be saved. */ CORE_ADDR gparam; /* Address, at which the next Altivec vector parameter should be saved. */ CORE_ADDR vparam; if (!write_pass) { /* During the first pass, GPARAM and VPARAM are more like offsets (start address zero) than addresses. That way they accumulate the total stack space each region requires. */ gparam = 0; vparam = 0; } else { /* Decrement the stack pointer making space for the Altivec and general on-stack parameters. Set vparam and gparam to their corresponding regions. */ vparam = align_down (sp - vparam_size, 16); gparam = align_down (vparam - gparam_size, 16); /* Add in space for the TOC, link editor double word, compiler double word, LR save area, CR save area. */ sp = align_down (gparam - 48, 16); } /* If the function is returning a `struct', then there is an extra hidden parameter (which will be passed in r3) containing the address of that struct.. In that case we should advance one word and start from r4 register to copy parameters. This also consumes one on-stack parameter slot. */ if (struct_return) { if (write_pass) regcache_cooked_write_signed (regcache, tdep->ppc_gp0_regnum + greg, struct_addr); greg++; gparam = align_up (gparam + tdep->wordsize, tdep->wordsize); } for (argno = 0; argno < nargs; argno++) { struct value *arg = args[argno]; struct type *type = check_typedef (value_type (arg)); const bfd_byte *val = value_contents (arg); if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8) { /* Floats and Doubles go in f1 .. f13. They also consume a left aligned GREG,, and can end up in memory. */ if (write_pass) { gdb_byte regval[MAX_REGISTER_SIZE]; const gdb_byte *p; /* Version 1.7 of the 64-bit PowerPC ELF ABI says: "Single precision floating point values are mapped to the first word in a single doubleword." And version 1.9 says: "Single precision floating point values are mapped to the second word in a single doubleword." GDB then writes single precision floating point values at both words in a doubleword, to support both ABIs. */ if (TYPE_LENGTH (type) == 4) { memcpy (regval, val, 4); memcpy (regval + 4, val, 4); p = regval; } else p = val; /* Write value in the stack's parameter save area. */ write_memory (gparam, p, 8); if (freg <= 13) { struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval); } if (greg <= 10) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, regval); } freg++; greg++; /* Always consume parameter stack space. */ gparam = align_up (gparam + 8, tdep->wordsize); } else if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 16 && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) { /* IBM long double stored in two doublewords of the parameter save area and corresponding registers. */ if (write_pass) { if (!tdep->soft_float && freg <= 13) { regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, val); if (freg <= 12) regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg + 1, val + 8); } if (greg <= 10) { regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg, val); if (greg <= 9) regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + greg + 1, val + 8); } write_memory (gparam, val, TYPE_LENGTH (type)); } freg += 2; greg += 2; gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) <= 8) { /* 32-bit and 64-bit decimal floats go in f1 .. f13. They can end up in memory. */ if (write_pass) { gdb_byte regval[MAX_REGISTER_SIZE]; const gdb_byte *p; /* 32-bit decimal floats are right aligned in the doubleword. */ if (TYPE_LENGTH (type) == 4) { memcpy (regval + 4, val, 4); p = regval; } else p = val; /* Write value in the stack's parameter save area. */ write_memory (gparam, p, 8); if (freg <= 13) regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, p); } freg++; greg++; /* Always consume parameter stack space. */ gparam = align_up (gparam + 8, tdep->wordsize); } else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 16) { /* 128-bit decimal floats go in f2 .. f12, always in even/odd pairs. They can end up in memory, using two doublewords. */ if (write_pass) { if (freg <= 12) { /* Make sure freg is even. */ freg += freg & 1; regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, val); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg + 1, val + 8); } write_memory (gparam, val, TYPE_LENGTH (type)); } freg += 2; greg += 2; gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type) && TYPE_CODE (type) == TYPE_CODE_ARRAY && tdep->ppc_vr0_regnum >= 0) { /* In the Altivec ABI, vectors go in the vector registers v2 .. v13, or when that runs out, a vector annex which goes above all the normal parameters. NOTE: cagney/2003-09-21: This is a guess based on the PowerOpen Altivec ABI. */ if (vreg <= 13) { if (write_pass) regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + vreg, val); vreg++; } else { if (write_pass) write_memory (vparam, val, TYPE_LENGTH (type)); vparam = align_up (vparam + TYPE_LENGTH (type), 16); } } else if ((TYPE_CODE (type) == TYPE_CODE_INT || TYPE_CODE (type) == TYPE_CODE_ENUM || TYPE_CODE (type) == TYPE_CODE_BOOL || TYPE_CODE (type) == TYPE_CODE_CHAR || TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_CODE (type) == TYPE_CODE_REF) && TYPE_LENGTH (type) <= 8) { /* Scalars and Pointers get sign[un]extended and go in gpr3 .. gpr10. They can also end up in memory. */ if (write_pass) { /* Sign extend the value, then store it unsigned. */ ULONGEST word = unpack_long (type, val); /* Convert any function code addresses into descriptors. */ if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_CODE (type) == TYPE_CODE_REF) { struct type *target_type; target_type = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (target_type) == TYPE_CODE_FUNC || TYPE_CODE (target_type) == TYPE_CODE_METHOD) { CORE_ADDR desc = word; convert_code_addr_to_desc_addr (word, &desc); word = desc; } } if (greg <= 10) regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + greg, word); write_memory_unsigned_integer (gparam, tdep->wordsize, byte_order, word); } greg++; gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } else { int byte; for (byte = 0; byte < TYPE_LENGTH (type); byte += tdep->wordsize) { if (write_pass && greg <= 10) { gdb_byte regval[MAX_REGISTER_SIZE]; int len = TYPE_LENGTH (type) - byte; if (len > tdep->wordsize) len = tdep->wordsize; memset (regval, 0, sizeof regval); /* The ABI (version 1.9) specifies that values smaller than one doubleword are right-aligned and those larger are left-aligned. GCC versions before 3.4 implemented this incorrectly; see <http://gcc.gnu.org/gcc-3.4/powerpc-abi.html>. */ if (byte == 0) memcpy (regval + tdep->wordsize - len, val + byte, len); else memcpy (regval, val + byte, len); regcache_cooked_write (regcache, greg, regval); } greg++; } if (write_pass) { /* WARNING: cagney/2003-09-21: Strictly speaking, this isn't necessary, unfortunately, GCC appears to get "struct convention" parameter passing wrong putting odd sized structures in memory instead of in a register. Work around this by always writing the value to memory. Fortunately, doing this simplifies the code. */ int len = TYPE_LENGTH (type); if (len < tdep->wordsize) write_memory (gparam + tdep->wordsize - len, val, len); else write_memory (gparam, val, len); } if (freg <= 13 && TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1 && TYPE_LENGTH (type) <= 16) { /* The ABI (version 1.9) specifies that structs containing a single floating-point value, at any level of nesting of single-member structs, are passed in floating-point registers. */ while (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1) type = check_typedef (TYPE_FIELD_TYPE (type, 0)); if (TYPE_CODE (type) == TYPE_CODE_FLT) { if (TYPE_LENGTH (type) <= 8) { if (write_pass) { gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, (tdep->ppc_fp0_regnum + freg), regval); } freg++; } else if (TYPE_LENGTH (type) == 16 && (gdbarch_long_double_format (gdbarch) == floatformats_ibm_long_double)) { if (write_pass) { regcache_cooked_write (regcache, (tdep->ppc_fp0_regnum + freg), val); if (freg <= 12) regcache_cooked_write (regcache, (tdep->ppc_fp0_regnum + freg + 1), val + 8); } freg += 2; } } } /* Always consume parameter stack space. */ gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); } } if (!write_pass) { /* Save the true region sizes ready for the second pass. */ vparam_size = vparam; /* Make certain that the general parameter save area is at least the minimum 8 registers (or doublewords) in size. */ if (greg < 8) gparam_size = 8 * tdep->wordsize; else gparam_size = gparam; } } /* Update %sp. */ regcache_cooked_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); /* Write the backchain (it occupies WORDSIZED bytes). */ write_memory_signed_integer (sp, tdep->wordsize, byte_order, back_chain); /* Point the inferior function call's return address at the dummy's breakpoint. */ regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); /* Use the func_addr to find the descriptor, and use that to find the TOC. If we're calling via a function pointer, the pointer itself identifies the descriptor. */ { struct type *ftype = check_typedef (value_type (function)); CORE_ADDR desc_addr = value_as_address (function); if (TYPE_CODE (ftype) == TYPE_CODE_PTR || convert_code_addr_to_desc_addr (func_addr, &desc_addr)) { /* The TOC is the second double word in the descriptor. */ CORE_ADDR toc = read_memory_unsigned_integer (desc_addr + tdep->wordsize, tdep->wordsize, byte_order); regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 2, toc); } } return sp; }
static void initialize_tdesc_arm_with_iwmmxt (void) { struct target_desc *result = allocate_target_description (); struct tdesc_feature *feature; struct type *field_type, *type; set_tdesc_architecture (result, bfd_scan_arch ("iwmmxt")); feature = tdesc_create_feature (result, "org.gnu.gdb.arm.core"); tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r5", 5, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r6", 6, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r7", 7, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r8", 8, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r9", 9, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r10", 10, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r11", 11, 1, NULL, 32, "int"); tdesc_create_reg (feature, "r12", 12, 1, NULL, 32, "int"); tdesc_create_reg (feature, "sp", 13, 1, NULL, 32, "data_ptr"); tdesc_create_reg (feature, "lr", 14, 1, NULL, 32, "int"); tdesc_create_reg (feature, "pc", 15, 1, NULL, 32, "code_ptr"); tdesc_create_reg (feature, "cpsr", 25, 1, NULL, 32, "int"); feature = tdesc_create_feature (result, "org.gnu.gdb.xscale.iwmmxt"); field_type = tdesc_named_type (feature, "uint8"); type = init_vector_type (field_type, 8); TYPE_NAME (type) = xstrdup ("iwmmxt_v8u8"); tdesc_record_type (feature, type); field_type = tdesc_named_type (feature, "uint16"); type = init_vector_type (field_type, 4); TYPE_NAME (type) = xstrdup ("iwmmxt_v4u16"); tdesc_record_type (feature, type); field_type = tdesc_named_type (feature, "uint32"); type = init_vector_type (field_type, 2); TYPE_NAME (type) = xstrdup ("iwmmxt_v2u32"); tdesc_record_type (feature, type); type = init_composite_type (NULL, TYPE_CODE_UNION); TYPE_NAME (type) = xstrdup ("iwmmxt_vec64i"); field_type = tdesc_named_type (feature, "iwmmxt_v8u8"); append_composite_type_field (type, xstrdup ("u8"), field_type); field_type = tdesc_named_type (feature, "iwmmxt_v4u16"); append_composite_type_field (type, xstrdup ("u16"), field_type); field_type = tdesc_named_type (feature, "iwmmxt_v2u32"); append_composite_type_field (type, xstrdup ("u32"), field_type); field_type = tdesc_named_type (feature, "uint64"); append_composite_type_field (type, xstrdup ("u64"), field_type); TYPE_VECTOR (type) = 1; tdesc_record_type (feature, type); tdesc_create_reg (feature, "wR0", 26, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR1", 27, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR2", 28, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR3", 29, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR4", 30, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR5", 31, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR6", 32, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR7", 33, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR8", 34, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR9", 35, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR10", 36, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR11", 37, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR12", 38, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR13", 39, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR14", 40, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR15", 41, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wCSSF", 42, 1, "vector", 32, "int"); tdesc_create_reg (feature, "wCASF", 43, 1, "vector", 32, "int"); tdesc_create_reg (feature, "wCGR0", 44, 1, "vector", 32, "int"); tdesc_create_reg (feature, "wCGR1", 45, 1, "vector", 32, "int"); tdesc_create_reg (feature, "wCGR2", 46, 1, "vector", 32, "int"); tdesc_create_reg (feature, "wCGR3", 47, 1, "vector", 32, "int"); tdesc_arm_with_iwmmxt = result; }
static struct value * value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, struct type *param_type, int is_prototyped, CORE_ADDR *sp) { const struct builtin_type *builtin = builtin_type (gdbarch); struct type *arg_type = check_typedef (value_type (arg)); struct type *type = param_type ? check_typedef (param_type) : arg_type; /* Perform any Ada-specific coercion first. */ if (current_language->la_language == language_ada) arg = ada_convert_actual (arg, type); /* Force the value to the target if we will need its address. At this point, we could allocate arguments on the stack instead of calling malloc if we knew that their addresses would not be saved by the called function. */ arg = value_coerce_to_target (arg); switch (TYPE_CODE (type)) { case TYPE_CODE_REF: { struct value *new_value; if (TYPE_CODE (arg_type) == TYPE_CODE_REF) return value_cast_pointers (type, arg, 0); /* Cast the value to the reference's target type, and then convert it back to a reference. This will issue an error if the value was not previously in memory - in some cases we should clearly be allowing this, but how? */ new_value = value_cast (TYPE_TARGET_TYPE (type), arg); new_value = value_ref (new_value); return new_value; } case TYPE_CODE_INT: case TYPE_CODE_CHAR: case TYPE_CODE_BOOL: case TYPE_CODE_ENUM: /* If we don't have a prototype, coerce to integer type if necessary. */ if (!is_prototyped) { if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) type = builtin->builtin_int; } /* Currently all target ABIs require at least the width of an integer type for an argument. We may have to conditionalize the following type coercion for future targets. */ if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_int)) type = builtin->builtin_int; break; case TYPE_CODE_FLT: if (!is_prototyped && coerce_float_to_double_p) { if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin->builtin_double)) type = builtin->builtin_double; else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin->builtin_double)) type = builtin->builtin_long_double; } break; case TYPE_CODE_FUNC: type = lookup_pointer_type (type); break; case TYPE_CODE_ARRAY: /* Arrays are coerced to pointers to their first element, unless they are vectors, in which case we want to leave them alone, because they are passed by value. */ if (current_language->c_style_arrays) if (!TYPE_VECTOR (type)) type = lookup_pointer_type (TYPE_TARGET_TYPE (type)); break; case TYPE_CODE_UNDEF: case TYPE_CODE_PTR: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_VOID: case TYPE_CODE_SET: case TYPE_CODE_RANGE: case TYPE_CODE_STRING: case TYPE_CODE_ERROR: case TYPE_CODE_MEMBERPTR: case TYPE_CODE_METHODPTR: case TYPE_CODE_METHOD: case TYPE_CODE_COMPLEX: default: break; } return value_cast (type, arg); }