gdb/ 2008-01-24 Thiago Jung Bauermann * ppc-sysv-tdep.c (ppc_sysv_abi_push_dummy_call): Add support for TYPE_CODE_DECFLOAT arguments. (ppc64_sysv_abi_push_dummy_call) Likewise. (get_decimal_float_return_value): New function. (do_ppc_sysv_return_value): Add support for TYPE_CODE_DECFLOAT return values by calling get_decimal_float_return_value. (ppc64_sysv_abi_return_value): Likewise. gdb/testsuite/ 2008-01-24 Thiago Jung Bauermann * dfp-test.c (DELTA, DELTA_B): New definitions. (double_val1, double_val2, double_val3, double_val4, double_val5, double_val6, double_val7, double_val8, double_val9, double_val10, double_val11, double_val12, double_val13, double_val14, dec32_val1, dec32_val2, dec32_val3, dec32_val4, dec32_val5, dec32_val6, dec32_val7, dec32_val8, dec32_val9, dec32_val10, dec32_val11, dec32_val12, dec32_val13, dec32_val14, dec32_val15, dec32_val16, dec64_val1, dec64_val2, dec64_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec64_val8, dec64_val9, dec64_val10, dec64_val11, dec64_val12, dec64_val13, dec64_val14, dec64_val15, dec64_val16, dec128_val1, dec128_val2, dec128_val3, dec128_val4, dec128_val5, dec128_val6, dec128_val7, dec128_val8, dec128_val9, dec128_val10, dec128_val11, dec128_val12, dec128_val13, dec128_val14, dec128_val15, dec128_val16): New global variables. (decimal_dec128_align): New function. (decimal_mixed): Likewise. (decimal_many_args_dec32): Likewise. (decimal_many_args_dec64): Likewise. (decimal_many_args_dec128): Likewise. (decimal_many_args_mixed): Likewise. * dfp-test.exp: Add tests calling new inferior functions. diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index c2952f5..c9646eb 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -241,6 +241,81 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 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) @@ -386,6 +461,70 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, return sp; } +/* Handle the return-value conventions for Decimal Floating Point values + in both ppc32 and ppc64, which are the same. */ +static int +get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype, + struct regcache *regcache, gdb_byte *readbuf, + const gdb_byte *writebuf) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (TYPE_CODE (valtype) == TYPE_CODE_DECFLOAT); + + /* 32-bit and 64-bit decimal floats in f1. */ + if (TYPE_LENGTH (valtype) <= 8) + { + if (writebuf != NULL) + { + gdb_byte regval[MAX_REGISTER_SIZE]; + const gdb_byte *p; + + /* 32-bit decimal float is right aligned in the doubleword. */ + if (TYPE_LENGTH (valtype) == 4) + { + memcpy (regval + 4, writebuf, 4); + p = regval; + } + else + p = writebuf; + + regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, p); + } + if (readbuf != NULL) + { + regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, readbuf); + + /* Left align 32-bit decimal float. */ + if (TYPE_LENGTH (valtype) == 4) + memcpy (readbuf, readbuf + 4, 4); + } + } + /* 128-bit decimal floats in f2,f3. */ + else if (TYPE_LENGTH (valtype) == 16) + { + if (writebuf != NULL || readbuf != NULL) + { + int i; + + for (i = 0; i < 2; i++) + { + if (writebuf != NULL) + regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 2 + i, + writebuf + i * 8); + if (readbuf != NULL) + regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 2 + i, + readbuf + i * 8); + } + } + } + else + /* Can't happen. */ + internal_error (__FILE__, __LINE__, "Unknown decimal float size."); + + return RETURN_VALUE_REGISTER_CONVENTION; +} + /* Handle the return-value conventions specified by the SysV 32-bit PowerPC ABI (including all the supplements): @@ -501,6 +640,9 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type, } 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 @@ -906,6 +1048,63 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 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) @@ -1133,6 +1332,9 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *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) diff --git a/gdb/testsuite/gdb.base/dfp-test.c b/gdb/testsuite/gdb.base/dfp-test.c index 504833a..d98d1d5 100644 --- a/gdb/testsuite/gdb.base/dfp-test.c +++ b/gdb/testsuite/gdb.base/dfp-test.c @@ -18,6 +18,75 @@ #include #include +#define DELTA (0.0001df) +#define DELTA_B (0.001) + +double double_val1 = 45.125; +double double_val2 = -67.75; +double double_val3 = 0.25; +double double_val4 = 1.25; +double double_val5 = 2.25; +double double_val6 = 3.25; +double double_val7 = 4.25; +double double_val8 = 5.25; +double double_val9 = 6.25; +double double_val10 = 7.25; +double double_val11 = 8.25; +double double_val12 = 9.25; +double double_val13 = 10.25; +double double_val14 = 11.25; + +_Decimal32 dec32_val1 = 3.14159df; +_Decimal32 dec32_val2 = -2.3765df; +_Decimal32 dec32_val3 = 0.2df; +_Decimal32 dec32_val4 = 1.2df; +_Decimal32 dec32_val5 = 2.2df; +_Decimal32 dec32_val6 = 3.2df; +_Decimal32 dec32_val7 = 4.2df; +_Decimal32 dec32_val8 = 5.2df; +_Decimal32 dec32_val9 = 6.2df; +_Decimal32 dec32_val10 = 7.2df; +_Decimal32 dec32_val11 = 8.2df; +_Decimal32 dec32_val12 = 9.2df; +_Decimal32 dec32_val13 = 10.2df; +_Decimal32 dec32_val14 = 11.2df; +_Decimal32 dec32_val15 = 12.2df; +_Decimal32 dec32_val16 = 13.2df; + +_Decimal64 dec64_val1 = 3.14159dd; +_Decimal64 dec64_val2 = -2.3765dd; +_Decimal64 dec64_val3 = 0.2dd; +_Decimal64 dec64_val4 = 1.2dd; +_Decimal64 dec64_val5 = 2.2dd; +_Decimal64 dec64_val6 = 3.2dd; +_Decimal64 dec64_val7 = 4.2dd; +_Decimal64 dec64_val8 = 5.2dd; +_Decimal64 dec64_val9 = 6.2dd; +_Decimal64 dec64_val10 = 7.2dd; +_Decimal64 dec64_val11 = 8.2dd; +_Decimal64 dec64_val12 = 9.2dd; +_Decimal64 dec64_val13 = 10.2dd; +_Decimal64 dec64_val14 = 11.2dd; +_Decimal64 dec64_val15 = 12.2dd; +_Decimal64 dec64_val16 = 13.2dd; + +_Decimal128 dec128_val1 = 3.14159dl; +_Decimal128 dec128_val2 = -2.3765dl; +_Decimal128 dec128_val3 = 0.2dl; +_Decimal128 dec128_val4 = 1.2dl; +_Decimal128 dec128_val5 = 2.2dl; +_Decimal128 dec128_val6 = 3.2dl; +_Decimal128 dec128_val7 = 4.2dl; +_Decimal128 dec128_val8 = 5.2dl; +_Decimal128 dec128_val9 = 6.2dl; +_Decimal128 dec128_val10 = 7.2dl; +_Decimal128 dec128_val11 = 8.2dl; +_Decimal128 dec128_val12 = 9.2dl; +_Decimal128 dec128_val13 = 10.2dl; +_Decimal128 dec128_val14 = 11.2dl; +_Decimal128 dec128_val15 = 12.2dl; +_Decimal128 dec128_val16 = 13.2dl; + volatile _Decimal32 d32; volatile _Decimal64 d64; volatile _Decimal128 d128; @@ -54,6 +123,148 @@ arg0_128 (_Decimal128 arg0, _Decimal128 arg1, _Decimal128 arg2, return arg0; } +/* Function to test if _Decimal128 argument interferes with stack slots + because of alignment. */ +int +decimal_dec128_align (double arg0, _Decimal128 arg1, double arg2, double arg3, + double arg4, double arg5, double arg6, double arg7, + double arg8, double arg9, double arg10, double arg11, + double arg12, double arg13) +{ + return ((arg0 - double_val1) < DELTA_B + && (arg0 - double_val1) > -DELTA_B + && (arg1 - dec128_val2) < DELTA + && (arg1 - dec128_val2) > -DELTA + && (arg2 - double_val3) < DELTA_B + && (arg2 - double_val3) > -DELTA_B + && (arg3 - double_val4) < DELTA_B + && (arg3 - double_val4) > -DELTA_B + && (arg4 - double_val5) < DELTA_B + && (arg4 - double_val5) > -DELTA_B + && (arg5 - double_val6) < DELTA_B + && (arg5 - double_val6) > -DELTA_B + && (arg6 - double_val7) < DELTA_B + && (arg6 - double_val7) > -DELTA_B + && (arg7 - double_val8) < DELTA_B + && (arg7 - double_val8) > -DELTA_B + && (arg8 - double_val9) < DELTA_B + && (arg8 - double_val9) > -DELTA_B + && (arg9 - double_val10) < DELTA_B + && (arg9 - double_val10) > -DELTA_B + && (arg10 - double_val11) < DELTA_B + && (arg10 - double_val11) > -DELTA_B + && (arg11 - double_val12) < DELTA_B + && (arg11 - double_val12) > -DELTA_B + && (arg12 - double_val13) < DELTA_B + && (arg12 - double_val13) > -DELTA_B + && (arg13 - double_val14) < DELTA_B + && (arg13 - double_val14) > -DELTA_B); +} + +int +decimal_mixed (_Decimal32 arg0, _Decimal64 arg1, _Decimal128 arg2) +{ + return ((arg0 - dec32_val1) < DELTA + && (arg0 - dec32_val1) > -DELTA + && (arg1 - dec64_val1) < DELTA + && (arg1 - dec64_val1) > -DELTA + && (arg2 - dec128_val1) < DELTA + && (arg2 - dec128_val1) > -DELTA); +} + +/* These functions have many arguments to force some of them to be passed via + the stack instead of registers, to test that GDB can construct correctly + the parameter save area. Note that Linux/ppc32 has 8 float registers to use + for float parameter passing and Linux/ppc64 has 13, so the number of + arguments has to be at least 14 to contemplate these platforms. */ + +int +decimal_many_args_dec32 (_Decimal32 f1, _Decimal32 f2, _Decimal32 f3, + _Decimal32 f4, _Decimal32 f5, _Decimal32 f6, + _Decimal32 f7, _Decimal32 f8, _Decimal32 f9, + _Decimal32 f10, _Decimal32 f11, _Decimal32 f12, + _Decimal32 f13, _Decimal32 f14, _Decimal32 f15, + _Decimal32 f16) +{ + _Decimal32 sum_args; + _Decimal32 sum_values; + + sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + + f13 + f14 + f15 + f16; + sum_values = dec32_val1 + dec32_val2 + dec32_val3 + dec32_val4 + dec32_val5 + + dec32_val6 + dec32_val7 + dec32_val8 + dec32_val9 + + dec32_val10 + dec32_val11 + dec32_val12 + dec32_val13 + + dec32_val14 + dec32_val15 + dec32_val16; + + return ((sum_args - sum_values) < DELTA + && (sum_args - sum_values) > -DELTA); +} + +int +decimal_many_args_dec64 (_Decimal64 f1, _Decimal64 f2, _Decimal64 f3, + _Decimal64 f4, _Decimal64 f5, _Decimal64 f6, + _Decimal64 f7, _Decimal64 f8, _Decimal64 f9, + _Decimal64 f10, _Decimal64 f11, _Decimal64 f12, + _Decimal64 f13, _Decimal64 f14, _Decimal64 f15, + _Decimal64 f16) +{ + _Decimal64 sum_args; + _Decimal64 sum_values; + + sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + + f13 + f14 + f15 + f16; + sum_values = dec64_val1 + dec64_val2 + dec64_val3 + dec64_val4 + dec64_val5 + + dec64_val6 + dec64_val7 + dec64_val8 + dec64_val9 + + dec64_val10 + dec64_val11 + dec64_val12 + dec64_val13 + + dec64_val14 + dec64_val15 + dec64_val16; + + return ((sum_args - sum_values) < DELTA + && (sum_args - sum_values) > -DELTA); +} + +int +decimal_many_args_dec128 (_Decimal128 f1, _Decimal128 f2, _Decimal128 f3, + _Decimal128 f4, _Decimal128 f5, _Decimal128 f6, + _Decimal128 f7, _Decimal128 f8, _Decimal128 f9, + _Decimal128 f10, _Decimal128 f11, _Decimal128 f12, + _Decimal128 f13, _Decimal128 f14, _Decimal128 f15, + _Decimal128 f16) +{ + _Decimal128 sum_args; + _Decimal128 sum_values; + + sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + + f13 + f14 + f15 + f16; + sum_values = dec128_val1 + dec128_val2 + dec128_val3 + dec128_val4 + dec128_val5 + + dec128_val6 + dec128_val7 + dec128_val8 + dec128_val9 + + dec128_val10 + dec128_val11 + dec128_val12 + dec128_val13 + + dec128_val14 + dec128_val15 + dec128_val16; + + return ((sum_args - sum_values) < DELTA + && (sum_args - sum_values) > -DELTA); +} + +int +decimal_many_args_mixed (_Decimal32 f1, _Decimal32 f2, _Decimal32 f3, + _Decimal64 f4, _Decimal64 f5, _Decimal64 f6, + _Decimal64 f7, _Decimal128 f8, _Decimal128 f9, + _Decimal128 f10, _Decimal32 f11, _Decimal64 f12, + _Decimal32 f13, _Decimal64 f14, _Decimal128 f15) +{ + _Decimal128 sum_args; + _Decimal128 sum_values; + + sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + + f13 + f14 + f15; + sum_values = dec32_val1 + dec32_val2 + dec32_val3 + dec64_val4 + dec64_val5 + + dec64_val6 + dec64_val7 + dec128_val8 + dec128_val9 + + dec128_val10 + dec32_val11 + dec64_val12 + dec32_val13 + + dec64_val14 + dec128_val15; + + return ((sum_args - sum_values) < DELTA + && (sum_args - sum_values) > -DELTA); +} + int main() { /* An finite 32-bits decimal floating point. */ diff --git a/gdb/testsuite/gdb.base/dfp-test.exp b/gdb/testsuite/gdb.base/dfp-test.exp index 2d8f9ea..0402099 100644 --- a/gdb/testsuite/gdb.base/dfp-test.exp +++ b/gdb/testsuite/gdb.base/dfp-test.exp @@ -250,6 +250,38 @@ gdb_breakpoint arg0_128 gdb_continue_to_breakpoint "entry to arg0_128" gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_128" +# Test calling inferior function with DFP arguments or return value. + +send_gdb "call arg0_32 (1.2df, 2.2df, 3.2df, 4.2df, 5.2df, 6.2df)\n" +gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_32 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "Call function with correct _Decimal32 arguments." +gdb_test "finish" " = 1.2" "Correct _Decimal32 return value from called function." + +send_gdb "call arg0_64 (1.2dd, 2.2dd, 3.2dd, 4.2dd, 5.2dd, 6.2dd)\n" +gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_64 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "Call function with correct _Decimal64 arguments." +gdb_test "finish" " = 1.2" "Correct _Decimal64 return value from called function." + +send_gdb "call arg0_128 (1.2dl, 2.2dl, 3.2dl, 4.2dl, 5.2dl, 6.2dl)\n" +gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_128 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "Call function with correct _Decimal128 arguments." +gdb_test "finish" " = 1.2" "Correct _Decimal128 return value from called function." + +gdb_test "call decimal_dec128_align (double_val1, dec128_val2, double_val3, double_val4, double_val5, double_val6, double_val7, double_val8, double_val9, double_val10, double_val11, double_val12, double_val13, double_val14)" " = 1" \ + "Call function with mixed decimal float arguments TEST." + +gdb_test "call decimal_mixed (dec32_val1, dec64_val1, dec128_val1)" " = 1" \ + "Call function with mixed decimal float arguments." + +gdb_test "call decimal_many_args_dec32 (dec32_val1, dec32_val2, dec32_val3, dec32_val4, dec32_val5, dec32_val6, dec32_val7, dec32_val8, dec32_val9, dec32_val10, dec32_val11, dec32_val12, dec32_val13, dec32_val14, dec32_val15, dec32_val16)" " = 1" \ + "Call function with many _Decimal32 arguments." + +gdb_test "call decimal_many_args_dec64 (dec64_val1, dec64_val2, dec64_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec64_val8, dec64_val9, dec64_val10, dec64_val11, dec64_val12, dec64_val13, dec64_val14, dec64_val15, dec64_val16)" " = 1" \ + "Call function with many _Decimal64 arguments." + +gdb_test "call decimal_many_args_dec128 (dec128_val1, dec128_val2, dec128_val3, dec128_val4, dec128_val5, dec128_val6, dec128_val7, dec128_val8, dec128_val9, dec128_val10, dec128_val11, dec128_val12, dec128_val13, dec128_val14, dec128_val15, dec128_val16)" " = 1" \ + "Call function with many _Decimal128 arguments." + +gdb_test "call decimal_many_args_mixed (dec32_val1, dec32_val2, dec32_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec128_val8, dec128_val9, dec128_val10, dec32_val11, dec64_val12, dec32_val13, dec64_val14, dec128_val15)" " = 1" \ + "Call function with many mixed decimal float arguments." + # The following tests are intended to verify that gdb can handle DFP types # correctly in struct.