struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
int word_size = gdbarch_ptr_bit (gdbarch) / 8;
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- ULONGEST orig_sp;
int i;
/* If the i'th argument is passed as a reference to a copy, then
copy_addr[i] is the address of the copy we made. */
CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR));
- /* Build the reference-to-copy area. */
+ /* Reserve space for the reference-to-copy area. */
for (i = 0; i < nargs; i++)
{
struct value *arg = args[i];
{
sp -= length;
sp = align_down (sp, alignment_of (type));
- write_memory (sp, value_contents (arg), length);
copy_addr[i] = sp;
}
}
boundary. */
sp = align_down (sp, 8);
+ /* Allocate the standard frame areas: the register save area, the
+ word reserved for the compiler (which seems kind of meaningless),
+ and the back chain pointer. */
+ sp -= 16*word_size + 32;
+
+ /* Now we have the final SP value. Make sure we didn't underflow;
+ on 31-bit, this would result in addresses with the high bit set,
+ which causes confusion elsewhere. Note that if we error out
+ here, stack and registers remain untouched. */
+ if (gdbarch_addr_bits_remove (gdbarch, sp) != sp)
+ error (_("Stack overflow"));
+
+
/* Finally, place the actual parameters, working from SP towards
higher addresses. The code above is supposed to reserve enough
space for this. */
{
int fr = 0;
int gr = 2;
- CORE_ADDR starg = sp;
+ CORE_ADDR starg = sp + 16*word_size + 32;
/* A struct is returned using general register 2. */
if (struct_return)
if (s390_function_arg_pass_by_reference (type))
{
+ /* Actually copy the argument contents to the stack slot
+ that was reserved above. */
+ write_memory (copy_addr[i], value_contents (arg), length);
+
if (gr <= 6)
{
regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr,
}
}
- /* Allocate the standard frame areas: the register save area, the
- word reserved for the compiler (which seems kind of meaningless),
- and the back chain pointer. */
- sp -= 16*word_size + 32;
-
/* Store return address. */
regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr);