| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "extract-store-integer.h" |
| 19 |
#include "osabi.h" |
| 20 |
#include "regcache.h" |
| 21 |
#include "gdbcore.h" |
| 22 |
#include "gdbtypes.h" |
| 23 |
#include "infcall.h" |
| 24 |
#include "ppc-tdep.h" |
| 25 |
#include "target-float.h" |
| 26 |
#include "value.h" |
| 27 |
#include "xcoffread.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
static CORE_ADDR |
| 32 |
rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch, |
| 33 |
struct value *function, |
| 34 |
struct regcache *regcache, CORE_ADDR bp_addr, |
| 35 |
int nargs, struct value **args, CORE_ADDR sp, |
| 36 |
function_call_return_method return_method, |
| 37 |
CORE_ADDR struct_addr) |
| 38 |
{ |
| 39 |
ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); |
| 40 |
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 41 |
int ii; |
| 42 |
int len = 0; |
| 43 |
int argno; |
| 44 |
int argbytes; |
| 45 |
gdb_byte tmp_buffer[50]; |
| 46 |
int f_argno = 0; |
| 47 |
int wordsize = tdep->wordsize; |
| 48 |
|
| 49 |
struct value *arg = 0; |
| 50 |
struct type *type; |
| 51 |
|
| 52 |
ULONGEST saved_sp; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
gdb_assert (ppc_floating_point_unit_p (gdbarch)); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ii = 0; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (return_method == return_method_struct) |
| 68 |
{ |
| 69 |
regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, |
| 70 |
struct_addr); |
| 71 |
ii++; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii) |
| 92 |
{ |
| 93 |
int reg_size = register_size (gdbarch, ii + 3); |
| 94 |
|
| 95 |
arg = args[argno]; |
| 96 |
type = check_typedef (arg->type ()); |
| 97 |
len = type->length (); |
| 98 |
|
| 99 |
if (type->code () == TYPE_CODE_FLT) |
| 100 |
{ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno; |
| 109 |
gdb_byte reg_val[PPC_MAX_REGISTER_SIZE]; |
| 110 |
struct type *reg_type = register_type (gdbarch, fp_regnum); |
| 111 |
|
| 112 |
gdb_assert (len <= 8); |
| 113 |
|
| 114 |
target_float_convert (arg->contents ().data (), type, reg_val, |
| 115 |
reg_type); |
| 116 |
regcache->cooked_write (fp_regnum, reg_val); |
| 117 |
++f_argno; |
| 118 |
} |
| 119 |
|
| 120 |
if (len > reg_size) |
| 121 |
{ |
| 122 |
|
| 123 |
|
| 124 |
while (argbytes < len) |
| 125 |
{ |
| 126 |
gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
| 127 |
memset (word, 0, reg_size); |
| 128 |
memcpy (word, |
| 129 |
((char *) arg->contents ().data ()) + argbytes, |
| 130 |
(len - argbytes) > reg_size |
| 131 |
? reg_size : len - argbytes); |
| 132 |
regcache->cooked_write (tdep->ppc_gp0_regnum + 3 + ii, word); |
| 133 |
++ii, argbytes += reg_size; |
| 134 |
|
| 135 |
if (ii >= 8) |
| 136 |
goto ran_out_of_registers_for_arguments; |
| 137 |
} |
| 138 |
argbytes = 0; |
| 139 |
--ii; |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
|
| 144 |
gdb_byte word[PPC_MAX_REGISTER_SIZE]; |
| 145 |
|
| 146 |
memset (word, 0, reg_size); |
| 147 |
memcpy (word, arg->contents ().data (), len); |
| 148 |
regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word); |
| 149 |
} |
| 150 |
++argno; |
| 151 |
} |
| 152 |
|
| 153 |
ran_out_of_registers_for_arguments: |
| 154 |
|
| 155 |
regcache_cooked_read_unsigned (regcache, |
| 156 |
gdbarch_sp_regnum (gdbarch), |
| 157 |
&saved_sp); |
| 158 |
|
| 159 |
|
| 160 |
sp -= wordsize * 8; |
| 161 |
|
| 162 |
|
| 163 |
sp -= wordsize * 6; |
| 164 |
|
| 165 |
|
| 166 |
sp = align_down (sp, 16); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
if ((argno < nargs) || argbytes) |
| 172 |
{ |
| 173 |
int space = 0, jj; |
| 174 |
|
| 175 |
if (argbytes) |
| 176 |
{ |
| 177 |
space += align_up (len - argbytes, 4); |
| 178 |
jj = argno + 1; |
| 179 |
} |
| 180 |
else |
| 181 |
jj = argno; |
| 182 |
|
| 183 |
for (; jj < nargs; ++jj) |
| 184 |
{ |
| 185 |
struct value *val = args[jj]; |
| 186 |
|
| 187 |
space += align_up (val->type ()->length (), 4); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
space = align_up (space, 16); |
| 192 |
sp -= space; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
regcache_raw_write_signed (regcache, |
| 201 |
gdbarch_sp_regnum (gdbarch), sp); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
if (argbytes) |
| 207 |
{ |
| 208 |
write_memory (sp + 24 + (ii * 4), |
| 209 |
arg->contents ().data () + argbytes, |
| 210 |
len - argbytes); |
| 211 |
++argno; |
| 212 |
ii += align_up (len - argbytes, 4) / 4; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
for (; argno < nargs; ++argno) |
| 217 |
{ |
| 218 |
|
| 219 |
arg = args[argno]; |
| 220 |
type = check_typedef (arg->type ()); |
| 221 |
len = type->length (); |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
if (type->code () == TYPE_CODE_FLT && f_argno < 13) |
| 227 |
{ |
| 228 |
|
| 229 |
gdb_assert (len <= 8); |
| 230 |
|
| 231 |
regcache->cooked_write (tdep->ppc_fp0_regnum + 1 + f_argno, |
| 232 |
arg->contents ().data ()); |
| 233 |
++f_argno; |
| 234 |
} |
| 235 |
|
| 236 |
write_memory (sp + 24 + (ii * 4), arg->contents ().data (), len); |
| 237 |
ii += align_up (len, 4) / 4; |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp); |
| 248 |
|
| 249 |
|
| 250 |
store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp); |
| 251 |
write_memory (sp, tmp_buffer, wordsize); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr); |
| 256 |
|
| 257 |
target_store_registers (regcache, -1); |
| 258 |
return sp; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
static enum return_value_convention |
| 264 |
rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function, |
| 265 |
struct type *valtype, struct regcache *regcache, |
| 266 |
gdb_byte *readbuf, const gdb_byte *writebuf) |
| 267 |
{ |
| 268 |
ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); |
| 269 |
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
gdb_assert (ppc_floating_point_unit_p (gdbarch)); |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
if (valtype->code () == TYPE_CODE_ARRAY && valtype->is_vector () |
| 279 |
&& valtype->length () == 16) |
| 280 |
{ |
| 281 |
if (readbuf) |
| 282 |
regcache->cooked_read (tdep->ppc_vr0_regnum + 2, readbuf); |
| 283 |
if (writebuf) |
| 284 |
regcache->cooked_write (tdep->ppc_vr0_regnum + 2, writebuf); |
| 285 |
|
| 286 |
return RETURN_VALUE_REGISTER_CONVENTION; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
if (valtype->code () == TYPE_CODE_STRUCT |
| 295 |
|| valtype->code () == TYPE_CODE_UNION |
| 296 |
|| valtype->code () == TYPE_CODE_ARRAY) |
| 297 |
return RETURN_VALUE_STRUCT_CONVENTION; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
if (valtype->code () == TYPE_CODE_FLT |
| 304 |
&& (valtype->length () == 4 || valtype->length () == 8)) |
| 305 |
{ |
| 306 |
struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); |
| 307 |
gdb_byte regval[8]; |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
if (readbuf) |
| 313 |
{ |
| 314 |
regcache->cooked_read (tdep->ppc_fp0_regnum + 1, regval); |
| 315 |
target_float_convert (regval, regtype, readbuf, valtype); |
| 316 |
} |
| 317 |
if (writebuf) |
| 318 |
{ |
| 319 |
target_float_convert (writebuf, valtype, regval, regtype); |
| 320 |
regcache->cooked_write (tdep->ppc_fp0_regnum + 1, regval); |
| 321 |
} |
| 322 |
|
| 323 |
return RETURN_VALUE_REGISTER_CONVENTION; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
if (valtype->length () <= tdep->wordsize) |
| 332 |
{ |
| 333 |
if (readbuf) |
| 334 |
{ |
| 335 |
ULONGEST regval; |
| 336 |
|
| 337 |
|
| 338 |
regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3, |
| 339 |
®val); |
| 340 |
store_unsigned_integer (readbuf, valtype->length (), byte_order, |
| 341 |
regval); |
| 342 |
} |
| 343 |
if (writebuf) |
| 344 |
{ |
| 345 |
|
| 346 |
|
| 347 |
regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3, |
| 348 |
unpack_long (valtype, writebuf)); |
| 349 |
} |
| 350 |
|
| 351 |
return RETURN_VALUE_REGISTER_CONVENTION; |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
if (valtype->length () == 8) |
| 358 |
{ |
| 359 |
gdb_assert (valtype->code () != TYPE_CODE_FLT); |
| 360 |
gdb_assert (tdep->wordsize == 4); |
| 361 |
|
| 362 |
if (readbuf) |
| 363 |
{ |
| 364 |
gdb_byte regval[8]; |
| 365 |
|
| 366 |
regcache->cooked_read (tdep->ppc_gp0_regnum + 3, regval); |
| 367 |
regcache->cooked_read (tdep->ppc_gp0_regnum + 4, regval + 4); |
| 368 |
memcpy (readbuf, regval, 8); |
| 369 |
} |
| 370 |
if (writebuf) |
| 371 |
{ |
| 372 |
regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf); |
| 373 |
regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4); |
| 374 |
} |
| 375 |
|
| 376 |
return RETURN_VALUE_REGISTER_CONVENTION; |
| 377 |
} |
| 378 |
|
| 379 |
return RETURN_VALUE_STRUCT_CONVENTION; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
static enum gdb_osabi |
| 385 |
rs6000_lynx178_osabi_sniffer (bfd *abfd) |
| 386 |
{ |
| 387 |
if (bfd_get_flavour (abfd) != bfd_target_xcoff_flavour) |
| 388 |
return GDB_OSABI_UNKNOWN; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
if (xcoff_get_n_import_files (abfd) != 0) |
| 395 |
return GDB_OSABI_UNKNOWN; |
| 396 |
|
| 397 |
return GDB_OSABI_LYNXOS178; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
static void |
| 403 |
rs6000_lynx178_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 404 |
{ |
| 405 |
set_gdbarch_push_dummy_call (gdbarch, rs6000_lynx178_push_dummy_call); |
| 406 |
set_gdbarch_return_value (gdbarch, rs6000_lynx178_return_value); |
| 407 |
set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
| 408 |
} |
| 409 |
|
| 410 |
void _initialize_rs6000_lynx178_tdep (); |
| 411 |
void |
| 412 |
_initialize_rs6000_lynx178_tdep () |
| 413 |
{ |
| 414 |
gdbarch_register_osabi_sniffer (bfd_arch_rs6000, |
| 415 |
bfd_target_xcoff_flavour, |
| 416 |
rs6000_lynx178_osabi_sniffer); |
| 417 |
gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_LYNXOS178, |
| 418 |
rs6000_lynx178_init_osabi); |
| 419 |
} |
| 420 |
|