Use bfd_set_filename more
[deliverable/binutils-gdb.git] / gdb / spu-linux-nat.c
CommitLineData
771b4502 1/* SPU native-dependent code for GDB, the GNU debugger.
42a4f53d 2 Copyright (C) 2006-2019 Free Software Foundation, Inc.
771b4502
UW
3
4 Contributed by Ulrich Weigand <uweigand@de.ibm.com>.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
771b4502
UW
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
771b4502
UW
20
21#include "defs.h"
22#include "gdbcore.h"
771b4502
UW
23#include "target.h"
24#include "inferior.h"
dab06dbe 25#include "inf-child.h"
771b4502
UW
26#include "inf-ptrace.h"
27#include "regcache.h"
28#include "symfile.h"
268a13a5 29#include "gdbsupport/gdb_wait.h"
d5b25491 30#include "gdbthread.h"
92107356 31#include "gdb_bfd.h"
771b4502 32
5826e159 33#include "nat/gdb_ptrace.h"
771b4502
UW
34#include <asm/ptrace.h>
35#include <sys/types.h>
771b4502
UW
36
37#include "spu-tdep.h"
38
39/* PPU side system calls. */
40#define INSTR_SC 0x44000002
41#define NR_spu_run 0x0116
42
f6ac5f3d
PA
43class spu_linux_nat_target final : public inf_ptrace_target
44{
45public:
46 void fetch_registers (struct regcache *regcache, int regnum) override;
47 void store_registers (struct regcache *regcache, int regnum) override;
48
49 void post_attach (int) override;
50 void post_startup_inferior (ptid_t) override;
51
52 ptid_t wait (ptid_t, struct target_waitstatus *, int options) override;
53
54 enum target_xfer_status xfer_partial (enum target_object object,
55 const char *annex,
56 gdb_byte *readbuf,
57 const gdb_byte *writebuf,
58 ULONGEST offset, ULONGEST len,
59 ULONGEST *xfered_len) override;
60
61 int can_use_hw_breakpoint (enum bptype, int, int) override;
62};
63
64static spu_linux_nat_target the_spu_linux_nat_target;
771b4502
UW
65
66/* Fetch PPU register REGNO. */
4179a487 67static ULONGEST
771b4502
UW
68fetch_ppc_register (int regno)
69{
70 PTRACE_TYPE_RET res;
71
e38504b3 72 int tid = inferior_ptid.lwp ();
771b4502 73 if (tid == 0)
e99b03dc 74 tid = inferior_ptid.pid ();
771b4502
UW
75
76#ifndef __powerpc64__
77 /* If running as a 32-bit process on a 64-bit system, we attempt
78 to get the full 64-bit register content of the target process.
79 If the PPC special ptrace call fails, we're on a 32-bit system;
80 just fall through to the regular ptrace call in that case. */
81 {
82 gdb_byte buf[8];
83
84 errno = 0;
85 ptrace (PPC_PTRACE_PEEKUSR_3264, tid,
86 (PTRACE_TYPE_ARG3) (regno * 8), buf);
87 if (errno == 0)
88 ptrace (PPC_PTRACE_PEEKUSR_3264, tid,
89 (PTRACE_TYPE_ARG3) (regno * 8 + 4), buf + 4);
90 if (errno == 0)
b9efddcd 91 return (ULONGEST) *(uint64_t *)buf;
771b4502
UW
92 }
93#endif
94
95 errno = 0;
96 res = ptrace (PT_READ_U, tid,
97 (PTRACE_TYPE_ARG3) (regno * sizeof (PTRACE_TYPE_RET)), 0);
98 if (errno != 0)
99 {
100 char mess[128];
101 xsnprintf (mess, sizeof mess, "reading PPC register #%d", regno);
102 perror_with_name (_(mess));
103 }
104
4179a487 105 return (ULONGEST) (unsigned long) res;
771b4502
UW
106}
107
108/* Fetch WORD from PPU memory at (aligned) MEMADDR in thread TID. */
109static int
4179a487 110fetch_ppc_memory_1 (int tid, ULONGEST memaddr, PTRACE_TYPE_RET *word)
771b4502
UW
111{
112 errno = 0;
113
114#ifndef __powerpc64__
115 if (memaddr >> 32)
116 {
b9efddcd 117 uint64_t addr_8 = (uint64_t) memaddr;
771b4502
UW
118 ptrace (PPC_PTRACE_PEEKTEXT_3264, tid, (PTRACE_TYPE_ARG3) &addr_8, word);
119 }
120 else
121#endif
122 *word = ptrace (PT_READ_I, tid, (PTRACE_TYPE_ARG3) (size_t) memaddr, 0);
123
124 return errno;
125}
126
127/* Store WORD into PPU memory at (aligned) MEMADDR in thread TID. */
128static int
4179a487 129store_ppc_memory_1 (int tid, ULONGEST memaddr, PTRACE_TYPE_RET word)
771b4502
UW
130{
131 errno = 0;
132
133#ifndef __powerpc64__
134 if (memaddr >> 32)
135 {
b9efddcd 136 uint64_t addr_8 = (uint64_t) memaddr;
771b4502
UW
137 ptrace (PPC_PTRACE_POKEDATA_3264, tid, (PTRACE_TYPE_ARG3) &addr_8, word);
138 }
139 else
140#endif
141 ptrace (PT_WRITE_D, tid, (PTRACE_TYPE_ARG3) (size_t) memaddr, word);
142
143 return errno;
144}
145
146/* Fetch LEN bytes of PPU memory at MEMADDR to MYADDR. */
147static int
4179a487 148fetch_ppc_memory (ULONGEST memaddr, gdb_byte *myaddr, int len)
771b4502
UW
149{
150 int i, ret;
151
4179a487 152 ULONGEST addr = memaddr & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
771b4502
UW
153 int count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
154 / sizeof (PTRACE_TYPE_RET));
155 PTRACE_TYPE_RET *buffer;
156
e38504b3 157 int tid = inferior_ptid.lwp ();
771b4502 158 if (tid == 0)
e99b03dc 159 tid = inferior_ptid.pid ();
771b4502
UW
160
161 buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
162 for (i = 0; i < count; i++, addr += sizeof (PTRACE_TYPE_RET))
b9efddcd
UW
163 {
164 ret = fetch_ppc_memory_1 (tid, addr, &buffer[i]);
165 if (ret)
166 return ret;
167 }
771b4502
UW
168
169 memcpy (myaddr,
170 (char *) buffer + (memaddr & (sizeof (PTRACE_TYPE_RET) - 1)),
171 len);
172
173 return 0;
174}
175
176/* Store LEN bytes from MYADDR to PPU memory at MEMADDR. */
177static int
4179a487 178store_ppc_memory (ULONGEST memaddr, const gdb_byte *myaddr, int len)
771b4502
UW
179{
180 int i, ret;
181
4179a487 182 ULONGEST addr = memaddr & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
771b4502
UW
183 int count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
184 / sizeof (PTRACE_TYPE_RET));
185 PTRACE_TYPE_RET *buffer;
186
e38504b3 187 int tid = inferior_ptid.lwp ();
771b4502 188 if (tid == 0)
e99b03dc 189 tid = inferior_ptid.pid ();
771b4502
UW
190
191 buffer = (PTRACE_TYPE_RET *) alloca (count * sizeof (PTRACE_TYPE_RET));
192
193 if (addr != memaddr || len < (int) sizeof (PTRACE_TYPE_RET))
b9efddcd
UW
194 {
195 ret = fetch_ppc_memory_1 (tid, addr, &buffer[0]);
196 if (ret)
197 return ret;
198 }
771b4502
UW
199
200 if (count > 1)
b9efddcd
UW
201 {
202 ret = fetch_ppc_memory_1 (tid, addr + (count - 1)
771b4502 203 * sizeof (PTRACE_TYPE_RET),
b9efddcd
UW
204 &buffer[count - 1]);
205 if (ret)
206 return ret;
207 }
771b4502
UW
208
209 memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_TYPE_RET) - 1)),
210 myaddr, len);
211
212 for (i = 0; i < count; i++, addr += sizeof (PTRACE_TYPE_RET))
b9efddcd
UW
213 {
214 ret = store_ppc_memory_1 (tid, addr, buffer[i]);
215 if (ret)
216 return ret;
217 }
771b4502
UW
218
219 return 0;
220}
221
222
223/* If the PPU thread is currently stopped on a spu_run system call,
224 return to FD and ADDR the file handle and NPC parameter address
225 used with the system call. Return non-zero if successful. */
226static int
4179a487 227parse_spufs_run (int *fd, ULONGEST *addr)
771b4502 228{
f5656ead 229 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
771b4502 230 gdb_byte buf[4];
4179a487 231 ULONGEST pc = fetch_ppc_register (32); /* nip */
771b4502
UW
232
233 /* Fetch instruction preceding current NIP. */
234 if (fetch_ppc_memory (pc-4, buf, 4) != 0)
235 return 0;
236 /* It should be a "sc" instruction. */
e17a4113 237 if (extract_unsigned_integer (buf, 4, byte_order) != INSTR_SC)
771b4502
UW
238 return 0;
239 /* System call number should be NR_spu_run. */
240 if (fetch_ppc_register (0) != NR_spu_run)
241 return 0;
242
243 /* Register 3 contains fd, register 4 the NPC param pointer. */
244 *fd = fetch_ppc_register (34); /* orig_gpr3 */
245 *addr = fetch_ppc_register (4);
246 return 1;
247}
248
249
edcc890f
YQ
250/* Implement the to_xfer_partial target_ops method for TARGET_OBJECT_SPU.
251 Copy LEN bytes at OFFSET in spufs file ANNEX into/from READBUF or WRITEBUF,
771b4502 252 using the /proc file system. */
edcc890f 253
9b409511 254static enum target_xfer_status
771b4502
UW
255spu_proc_xfer_spu (const char *annex, gdb_byte *readbuf,
256 const gdb_byte *writebuf,
9b409511 257 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
771b4502
UW
258{
259 char buf[128];
260 int fd = 0;
261 int ret = -1;
e99b03dc 262 int pid = inferior_ptid.pid ();
771b4502
UW
263
264 if (!annex)
9b409511 265 return TARGET_XFER_EOF;
771b4502
UW
266
267 xsnprintf (buf, sizeof buf, "/proc/%d/fd/%s", pid, annex);
268 fd = open (buf, writebuf? O_WRONLY : O_RDONLY);
269 if (fd <= 0)
2ed4b548 270 return TARGET_XFER_E_IO;
771b4502
UW
271
272 if (offset != 0
273 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
274 {
275 close (fd);
9b409511 276 return TARGET_XFER_EOF;
771b4502
UW
277 }
278
279 if (writebuf)
280 ret = write (fd, writebuf, (size_t) len);
281 else if (readbuf)
282 ret = read (fd, readbuf, (size_t) len);
283
284 close (fd);
9b409511
YQ
285 if (ret < 0)
286 return TARGET_XFER_E_IO;
287 else if (ret == 0)
288 return TARGET_XFER_EOF;
289 else
290 {
291 *xfered_len = (ULONGEST) ret;
292 return TARGET_XFER_OK;
293 }
771b4502
UW
294}
295
296
297/* Inferior memory should contain an SPE executable image at location ADDR.
298 Allocate a BFD representing that executable. Return NULL on error. */
299
300static void *
301spu_bfd_iovec_open (struct bfd *nbfd, void *open_closure)
302{
303 return open_closure;
304}
305
306static int
307spu_bfd_iovec_close (struct bfd *nbfd, void *stream)
308{
309 xfree (stream);
39ed5604
JK
310
311 /* Zero means success. */
312 return 0;
771b4502
UW
313}
314
315static file_ptr
316spu_bfd_iovec_pread (struct bfd *abfd, void *stream, void *buf,
317 file_ptr nbytes, file_ptr offset)
318{
4179a487 319 ULONGEST addr = *(ULONGEST *)stream;
771b4502 320
c1aebf87 321 if (fetch_ppc_memory (addr + offset, (gdb_byte *)buf, nbytes) != 0)
771b4502
UW
322 {
323 bfd_set_error (bfd_error_invalid_operation);
324 return -1;
325 }
326
327 return nbytes;
328}
329
f6cf9273
AM
330static int
331spu_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
332{
333 /* We don't have an easy way of finding the size of embedded spu
334 images. We could parse the in-memory ELF header and section
335 table to find the extent of the last section but that seems
336 pointless when the size is needed only for checks of other
337 parsed values in dbxread.c. */
326a5c7e 338 memset (sb, 0, sizeof (struct stat));
f6cf9273
AM
339 sb->st_size = INT_MAX;
340 return 0;
341}
342
192b62ce 343static gdb_bfd_ref_ptr
4179a487 344spu_bfd_open (ULONGEST addr)
771b4502 345{
9592c5d0 346 asection *spu_name;
771b4502 347
8d749320 348 ULONGEST *open_closure = XNEW (ULONGEST);
771b4502
UW
349 *open_closure = addr;
350
192b62ce
TT
351 gdb_bfd_ref_ptr nbfd (gdb_bfd_openr_iovec ("<in-memory>", "elf32-spu",
352 spu_bfd_iovec_open, open_closure,
353 spu_bfd_iovec_pread,
354 spu_bfd_iovec_close,
355 spu_bfd_iovec_stat));
356 if (nbfd == NULL)
771b4502
UW
357 return NULL;
358
192b62ce
TT
359 if (!bfd_check_format (nbfd.get (), bfd_object))
360 return NULL;
771b4502 361
9592c5d0 362 /* Retrieve SPU name note and update BFD name. */
192b62ce 363 spu_name = bfd_get_section_by_name (nbfd.get (), ".note.spu_name");
9592c5d0
UW
364 if (spu_name)
365 {
192b62ce 366 int sect_size = bfd_section_size (nbfd.get (), spu_name);
9592c5d0
UW
367 if (sect_size > 20)
368 {
c1aebf87 369 char *buf = (char *)alloca (sect_size - 20 + 1);
192b62ce
TT
370 bfd_get_section_contents (nbfd.get (), spu_name, buf, 20,
371 sect_size - 20);
9592c5d0
UW
372 buf[sect_size - 20] = '\0';
373
90d92a63 374 bfd_set_filename (nbfd.get (), xstrdup (buf));
9592c5d0
UW
375 }
376 }
377
771b4502
UW
378 return nbfd;
379}
380
381/* INFERIOR_FD is a file handle passed by the inferior to the
382 spu_run system call. Assuming the SPE context was allocated
383 by the libspe library, try to retrieve the main SPE executable
384 file from its copy within the target process. */
385static void
386spu_symbol_file_add_from_memory (int inferior_fd)
387{
4179a487 388 ULONGEST addr;
771b4502 389
22c90ac1 390 gdb_byte id[128];
771b4502 391 char annex[32];
9b409511
YQ
392 ULONGEST len;
393 enum target_xfer_status status;
771b4502
UW
394
395 /* Read object ID. */
396 xsnprintf (annex, sizeof annex, "%d/object-id", inferior_fd);
9b409511
YQ
397 status = spu_proc_xfer_spu (annex, id, NULL, 0, sizeof id, &len);
398 if (status != TARGET_XFER_OK || len >= sizeof id)
771b4502
UW
399 return;
400 id[len] = 0;
22c90ac1 401 addr = strtoulst ((const char *) id, NULL, 16);
b9efddcd 402 if (!addr)
771b4502
UW
403 return;
404
405 /* Open BFD representing SPE executable and read its symbols. */
192b62ce
TT
406 gdb_bfd_ref_ptr nbfd (spu_bfd_open (addr));
407 if (nbfd != NULL)
8ac244b4 408 {
192b62ce 409 symbol_file_add_from_bfd (nbfd.get (), bfd_get_filename (nbfd),
d64ad97c 410 SYMFILE_VERBOSE | SYMFILE_MAINLINE,
8ac244b4 411 NULL, 0, NULL);
8ac244b4 412 }
771b4502
UW
413}
414
415
416/* Override the post_startup_inferior routine to continue running
417 the inferior until the first spu_run system call. */
f6ac5f3d
PA
418void
419spu_linux_nat_target::post_startup_inferior (ptid_t ptid)
771b4502
UW
420{
421 int fd;
4179a487 422 ULONGEST addr;
771b4502 423
e38504b3 424 int tid = ptid.lwp ();
771b4502 425 if (tid == 0)
e99b03dc 426 tid = ptid.pid ();
771b4502
UW
427
428 while (!parse_spufs_run (&fd, &addr))
429 {
430 ptrace (PT_SYSCALL, tid, (PTRACE_TYPE_ARG3) 0, 0);
431 waitpid (tid, NULL, __WALL | __WNOTHREAD);
432 }
433}
434
435/* Override the post_attach routine to try load the SPE executable
436 file image from its copy inside the target process. */
f6ac5f3d
PA
437void
438spu_linux_nat_target::post_attach (int pid)
771b4502
UW
439{
440 int fd;
4179a487 441 ULONGEST addr;
771b4502
UW
442
443 /* Like child_post_startup_inferior, if we happened to attach to
444 the inferior while it wasn't currently in spu_run, continue
445 running it until we get back there. */
446 while (!parse_spufs_run (&fd, &addr))
447 {
448 ptrace (PT_SYSCALL, pid, (PTRACE_TYPE_ARG3) 0, 0);
449 waitpid (pid, NULL, __WALL | __WNOTHREAD);
450 }
451
452 /* If the user has not provided an executable file, try to extract
453 the image from inside the target process. */
454 if (!get_exec_file (0))
455 spu_symbol_file_add_from_memory (fd);
456}
457
458/* Wait for child PTID to do something. Return id of the child,
459 minus_one_ptid in case of error; store status into *OURSTATUS. */
f6ac5f3d 460ptid_t
2be4d7f0
UW
461spu_linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
462 int options)
771b4502
UW
463{
464 int save_errno;
465 int status;
466 pid_t pid;
467
468 do
469 {
470 set_sigint_trap (); /* Causes SIGINT to be passed on to the
471 attached process. */
771b4502 472
e99b03dc 473 pid = waitpid (ptid.pid (), &status, 0);
771b4502
UW
474 if (pid == -1 && errno == ECHILD)
475 /* Try again with __WCLONE to check cloned processes. */
e99b03dc 476 pid = waitpid (ptid.pid (), &status, __WCLONE);
771b4502
UW
477
478 save_errno = errno;
479
480 /* Make sure we don't report an event for the exit of the
481 original program, if we've detached from it. */
dfd4cc63 482 if (pid != -1 && !WIFSTOPPED (status)
e99b03dc 483 && pid != inferior_ptid.pid ())
771b4502
UW
484 {
485 pid = -1;
486 save_errno = EINTR;
487 }
488
771b4502
UW
489 clear_sigint_trap ();
490 }
491 while (pid == -1 && save_errno == EINTR);
492
493 if (pid == -1)
494 {
b9efddcd 495 warning (_("Child process unexpectedly missing: %s"),
771b4502
UW
496 safe_strerror (save_errno));
497
498 /* Claim it exited with unknown signal. */
499 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
a493e3e2 500 ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
fb66883a 501 return inferior_ptid;
771b4502
UW
502 }
503
504 store_waitstatus (ourstatus, status);
f2907e49 505 return ptid_t (pid);
771b4502
UW
506}
507
508/* Override the fetch_inferior_register routine. */
f6ac5f3d
PA
509void
510spu_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
771b4502
UW
511{
512 int fd;
4179a487 513 ULONGEST addr;
771b4502 514
639a9038
SM
515 /* Since we use functions that rely on inferior_ptid, we need to set and
516 restore it. */
517 scoped_restore save_ptid
222312d3 518 = make_scoped_restore (&inferior_ptid, regcache->ptid ());
639a9038 519
771b4502
UW
520 /* We must be stopped on a spu_run system call. */
521 if (!parse_spufs_run (&fd, &addr))
522 return;
523
524 /* The ID register holds the spufs file handle. */
525 if (regno == -1 || regno == SPU_ID_REGNUM)
526 {
ac7936df 527 struct gdbarch *gdbarch = regcache->arch ();
e17a4113 528 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e362b510 529 gdb_byte buf[4];
e17a4113 530 store_unsigned_integer (buf, 4, byte_order, fd);
73e1c03f 531 regcache->raw_supply (SPU_ID_REGNUM, buf);
771b4502
UW
532 }
533
534 /* The NPC register is found at ADDR. */
535 if (regno == -1 || regno == SPU_PC_REGNUM)
536 {
537 gdb_byte buf[4];
538 if (fetch_ppc_memory (addr, buf, 4) == 0)
73e1c03f 539 regcache->raw_supply (SPU_PC_REGNUM, buf);
771b4502
UW
540 }
541
542 /* The GPRs are found in the "regs" spufs file. */
543 if (regno == -1 || (regno >= 0 && regno < SPU_NUM_GPRS))
544 {
545 gdb_byte buf[16 * SPU_NUM_GPRS];
546 char annex[32];
547 int i;
9b409511 548 ULONGEST len;
771b4502
UW
549
550 xsnprintf (annex, sizeof annex, "%d/regs", fd);
9b409511
YQ
551 if ((spu_proc_xfer_spu (annex, buf, NULL, 0, sizeof buf, &len)
552 == TARGET_XFER_OK)
553 && len == sizeof buf)
771b4502 554 for (i = 0; i < SPU_NUM_GPRS; i++)
73e1c03f 555 regcache->raw_supply (i, buf + i*16);
771b4502
UW
556 }
557}
558
559/* Override the store_inferior_register routine. */
f6ac5f3d
PA
560void
561spu_linux_nat_target::store_registers (struct regcache *regcache, int regno)
771b4502
UW
562{
563 int fd;
4179a487 564 ULONGEST addr;
771b4502 565
639a9038
SM
566 /* Since we use functions that rely on inferior_ptid, we need to set and
567 restore it. */
568 scoped_restore save_ptid
222312d3 569 = make_scoped_restore (&inferior_ptid, regcache->ptid ());
639a9038 570
771b4502
UW
571 /* We must be stopped on a spu_run system call. */
572 if (!parse_spufs_run (&fd, &addr))
573 return;
574
575 /* The NPC register is found at ADDR. */
576 if (regno == -1 || regno == SPU_PC_REGNUM)
577 {
578 gdb_byte buf[4];
34a79281 579 regcache->raw_collect (SPU_PC_REGNUM, buf);
771b4502
UW
580 store_ppc_memory (addr, buf, 4);
581 }
582
583 /* The GPRs are found in the "regs" spufs file. */
584 if (regno == -1 || (regno >= 0 && regno < SPU_NUM_GPRS))
585 {
586 gdb_byte buf[16 * SPU_NUM_GPRS];
587 char annex[32];
588 int i;
9b409511 589 ULONGEST len;
771b4502
UW
590
591 for (i = 0; i < SPU_NUM_GPRS; i++)
34a79281 592 regcache->raw_collect (i, buf + i*16);
771b4502
UW
593
594 xsnprintf (annex, sizeof annex, "%d/regs", fd);
9b409511 595 spu_proc_xfer_spu (annex, NULL, buf, 0, sizeof buf, &len);
771b4502
UW
596 }
597}
598
599/* Override the to_xfer_partial routine. */
f6ac5f3d
PA
600enum target_xfer_status
601spu_linux_nat_target::xfer_partial (enum target_object object, const char *annex,
602 gdb_byte *readbuf, const gdb_byte *writebuf,
603 ULONGEST offset, ULONGEST len,
604 ULONGEST *xfered_len)
771b4502 605{
23d964e7 606 if (object == TARGET_OBJECT_SPU)
9b409511
YQ
607 return spu_proc_xfer_spu (annex, readbuf, writebuf, offset, len,
608 xfered_len);
23d964e7 609
771b4502
UW
610 if (object == TARGET_OBJECT_MEMORY)
611 {
612 int fd;
4179a487 613 ULONGEST addr;
d2ed6730
UW
614 char mem_annex[32], lslr_annex[32];
615 gdb_byte buf[32];
616 ULONGEST lslr;
9b409511 617 enum target_xfer_status ret;
771b4502
UW
618
619 /* We must be stopped on a spu_run system call. */
620 if (!parse_spufs_run (&fd, &addr))
9b409511 621 return TARGET_XFER_EOF;
771b4502
UW
622
623 /* Use the "mem" spufs file to access SPU local store. */
624 xsnprintf (mem_annex, sizeof mem_annex, "%d/mem", fd);
9b409511
YQ
625 ret = spu_proc_xfer_spu (mem_annex, readbuf, writebuf, offset, len,
626 xfered_len);
627 if (ret == TARGET_XFER_OK)
d2ed6730
UW
628 return ret;
629
630 /* SPU local store access wraps the address around at the
631 local store limit. We emulate this here. To avoid needing
632 an extra access to retrieve the LSLR, we only do that after
633 trying the original address first, and getting end-of-file. */
634 xsnprintf (lslr_annex, sizeof lslr_annex, "%d/lslr", fd);
635 memset (buf, 0, sizeof buf);
9b409511
YQ
636 if (spu_proc_xfer_spu (lslr_annex, buf, NULL, 0, sizeof buf, xfered_len)
637 != TARGET_XFER_OK)
d2ed6730
UW
638 return ret;
639
22c90ac1 640 lslr = strtoulst ((const char *) buf, NULL, 16);
d2ed6730 641 return spu_proc_xfer_spu (mem_annex, readbuf, writebuf,
9b409511 642 offset & lslr, len, xfered_len);
771b4502
UW
643 }
644
2ed4b548 645 return TARGET_XFER_E_IO;
771b4502
UW
646}
647
648/* Override the to_can_use_hw_breakpoint routine. */
f6ac5f3d
PA
649int
650spu_linux_nat_target::can_use_hw_breakpoint (enum bptype type,
651 int cnt, int othertype)
771b4502
UW
652{
653 return 0;
654}
655
771b4502
UW
656/* Initialize SPU native target. */
657void
658_initialize_spu_nat (void)
659{
d9f719f1 660 add_inf_child_target (&the_spu_linux_nat_target);
771b4502 661}
This page took 1.400991 seconds and 4 git commands to generate.