X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fs12z-tdep.c;h=277dd78119a0c57793524f4571ed874b7e113354;hb=be6d4f74c77c6f521afc873d226480e001cb99c2;hp=79f5772035db09d91b081192bfa9b19ee65c59ef;hpb=51d21d60b37f1e1a0aa6fd1f5439b22591fa6d5f;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c index 79f5772035..277dd78119 100644 --- a/gdb/s12z-tdep.c +++ b/gdb/s12z-tdep.c @@ -1,5 +1,5 @@ /* Target-dependent code for the S12Z, for the GDB. - Copyright (C) 2018 Free Software Foundation, Inc. + Copyright (C) 2018-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -37,7 +37,9 @@ #define N_PHYSICAL_REGISTERS (S12Z_N_REGISTERS - 2) -/* A permutation of all the physical registers. */ +/* A permutation of all the physical registers. Indexing this array + with an integer from gdb's internal representation will return the + register enum. */ static const int reg_perm[N_PHYSICAL_REGISTERS] = { REG_D0, @@ -55,6 +57,16 @@ static const int reg_perm[N_PHYSICAL_REGISTERS] = REG_CCW }; +/* The inverse of the above permutation. Indexing this + array with a register enum (e.g. REG_D2) will return the register + number in gdb's internal representation. */ +static const int inv_reg_perm[N_PHYSICAL_REGISTERS] = + { + 2, 3, 4, 5, /* d2, d3, d4, d5 */ + 0, 1, /* d0, d1 */ + 6, 7, /* d6, d7 */ + 8, 9, 10, 11, 12 /* x, y, s, p, ccw */ + }; /* Return the name of the register REGNUM. */ static const char * @@ -320,6 +332,7 @@ s12z_frame_cache (struct frame_info *this_frame, void **prologue_cache) } else { + gdb_assert (this_sp == this_sp_for_id); /* The stack pointer of the prev frame is frame_size greater than the stack pointer of this frame plus one address size (caused by the JSR or BSR). */ @@ -466,11 +479,56 @@ s12z_print_registers_info (struct gdbarch *gdbarch, + +static void +s12z_extract_return_value (struct type *type, struct regcache *regcache, + void *valbuf) +{ + int reg = -1; + + switch (TYPE_LENGTH (type)) + { + case 0: /* Nothing to do */ + return; + + case 1: + reg = REG_D0; + break; + + case 2: + reg = REG_D2; + break; + + case 3: + reg = REG_X; + break; + + case 4: + reg = REG_D6; + break; + + default: + error (_("bad size for return value")); + return; + } + + regcache->cooked_read (inv_reg_perm[reg], (gdb_byte *) valbuf); +} + static enum return_value_convention s12z_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) { + if (TYPE_CODE (type) == TYPE_CODE_STRUCT + || TYPE_CODE (type) == TYPE_CODE_UNION + || TYPE_CODE (type) == TYPE_CODE_ARRAY + || TYPE_LENGTH (type) > 4) + return RETURN_VALUE_STRUCT_CONVENTION; + + if (readbuf) + s12z_extract_return_value (type, regcache, readbuf); + return RETURN_VALUE_REGISTER_CONVENTION; }