i386: Check vector length for scatter/gather prefetch instructions
[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"
0747795c 29#include "common/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
374 xfree ((char *)nbfd->filename);
375 nbfd->filename = xstrdup (buf);
376 }
377 }
378
771b4502
UW
379 return nbfd;
380}
381
382/* INFERIOR_FD is a file handle passed by the inferior to the
383 spu_run system call. Assuming the SPE context was allocated
384 by the libspe library, try to retrieve the main SPE executable
385 file from its copy within the target process. */
386static void
387spu_symbol_file_add_from_memory (int inferior_fd)
388{
4179a487 389 ULONGEST addr;
771b4502 390
22c90ac1 391 gdb_byte id[128];
771b4502 392 char annex[32];
9b409511
YQ
393 ULONGEST len;
394 enum target_xfer_status status;
771b4502
UW
395
396 /* Read object ID. */
397 xsnprintf (annex, sizeof annex, "%d/object-id", inferior_fd);
9b409511
YQ
398 status = spu_proc_xfer_spu (annex, id, NULL, 0, sizeof id, &len);
399 if (status != TARGET_XFER_OK || len >= sizeof id)
771b4502
UW
400 return;
401 id[len] = 0;
22c90ac1 402 addr = strtoulst ((const char *) id, NULL, 16);
b9efddcd 403 if (!addr)
771b4502
UW
404 return;
405
406 /* Open BFD representing SPE executable and read its symbols. */
192b62ce
TT
407 gdb_bfd_ref_ptr nbfd (spu_bfd_open (addr));
408 if (nbfd != NULL)
8ac244b4 409 {
192b62ce 410 symbol_file_add_from_bfd (nbfd.get (), bfd_get_filename (nbfd),
d64ad97c 411 SYMFILE_VERBOSE | SYMFILE_MAINLINE,
8ac244b4 412 NULL, 0, NULL);
8ac244b4 413 }
771b4502
UW
414}
415
416
417/* Override the post_startup_inferior routine to continue running
418 the inferior until the first spu_run system call. */
f6ac5f3d
PA
419void
420spu_linux_nat_target::post_startup_inferior (ptid_t ptid)
771b4502
UW
421{
422 int fd;
4179a487 423 ULONGEST addr;
771b4502 424
e38504b3 425 int tid = ptid.lwp ();
771b4502 426 if (tid == 0)
e99b03dc 427 tid = ptid.pid ();
771b4502
UW
428
429 while (!parse_spufs_run (&fd, &addr))
430 {
431 ptrace (PT_SYSCALL, tid, (PTRACE_TYPE_ARG3) 0, 0);
432 waitpid (tid, NULL, __WALL | __WNOTHREAD);
433 }
434}
435
436/* Override the post_attach routine to try load the SPE executable
437 file image from its copy inside the target process. */
f6ac5f3d
PA
438void
439spu_linux_nat_target::post_attach (int pid)
771b4502
UW
440{
441 int fd;
4179a487 442 ULONGEST addr;
771b4502
UW
443
444 /* Like child_post_startup_inferior, if we happened to attach to
445 the inferior while it wasn't currently in spu_run, continue
446 running it until we get back there. */
447 while (!parse_spufs_run (&fd, &addr))
448 {
449 ptrace (PT_SYSCALL, pid, (PTRACE_TYPE_ARG3) 0, 0);
450 waitpid (pid, NULL, __WALL | __WNOTHREAD);
451 }
452
453 /* If the user has not provided an executable file, try to extract
454 the image from inside the target process. */
455 if (!get_exec_file (0))
456 spu_symbol_file_add_from_memory (fd);
457}
458
459/* Wait for child PTID to do something. Return id of the child,
460 minus_one_ptid in case of error; store status into *OURSTATUS. */
f6ac5f3d 461ptid_t
2be4d7f0
UW
462spu_linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
463 int options)
771b4502
UW
464{
465 int save_errno;
466 int status;
467 pid_t pid;
468
469 do
470 {
471 set_sigint_trap (); /* Causes SIGINT to be passed on to the
472 attached process. */
771b4502 473
e99b03dc 474 pid = waitpid (ptid.pid (), &status, 0);
771b4502
UW
475 if (pid == -1 && errno == ECHILD)
476 /* Try again with __WCLONE to check cloned processes. */
e99b03dc 477 pid = waitpid (ptid.pid (), &status, __WCLONE);
771b4502
UW
478
479 save_errno = errno;
480
481 /* Make sure we don't report an event for the exit of the
482 original program, if we've detached from it. */
dfd4cc63 483 if (pid != -1 && !WIFSTOPPED (status)
e99b03dc 484 && pid != inferior_ptid.pid ())
771b4502
UW
485 {
486 pid = -1;
487 save_errno = EINTR;
488 }
489
771b4502
UW
490 clear_sigint_trap ();
491 }
492 while (pid == -1 && save_errno == EINTR);
493
494 if (pid == -1)
495 {
b9efddcd 496 warning (_("Child process unexpectedly missing: %s"),
771b4502
UW
497 safe_strerror (save_errno));
498
499 /* Claim it exited with unknown signal. */
500 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
a493e3e2 501 ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
fb66883a 502 return inferior_ptid;
771b4502
UW
503 }
504
505 store_waitstatus (ourstatus, status);
f2907e49 506 return ptid_t (pid);
771b4502
UW
507}
508
509/* Override the fetch_inferior_register routine. */
f6ac5f3d
PA
510void
511spu_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
771b4502
UW
512{
513 int fd;
4179a487 514 ULONGEST addr;
771b4502 515
639a9038
SM
516 /* Since we use functions that rely on inferior_ptid, we need to set and
517 restore it. */
518 scoped_restore save_ptid
222312d3 519 = make_scoped_restore (&inferior_ptid, regcache->ptid ());
639a9038 520
771b4502
UW
521 /* We must be stopped on a spu_run system call. */
522 if (!parse_spufs_run (&fd, &addr))
523 return;
524
525 /* The ID register holds the spufs file handle. */
526 if (regno == -1 || regno == SPU_ID_REGNUM)
527 {
ac7936df 528 struct gdbarch *gdbarch = regcache->arch ();
e17a4113 529 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e362b510 530 gdb_byte buf[4];
e17a4113 531 store_unsigned_integer (buf, 4, byte_order, fd);
73e1c03f 532 regcache->raw_supply (SPU_ID_REGNUM, buf);
771b4502
UW
533 }
534
535 /* The NPC register is found at ADDR. */
536 if (regno == -1 || regno == SPU_PC_REGNUM)
537 {
538 gdb_byte buf[4];
539 if (fetch_ppc_memory (addr, buf, 4) == 0)
73e1c03f 540 regcache->raw_supply (SPU_PC_REGNUM, buf);
771b4502
UW
541 }
542
543 /* The GPRs are found in the "regs" spufs file. */
544 if (regno == -1 || (regno >= 0 && regno < SPU_NUM_GPRS))
545 {
546 gdb_byte buf[16 * SPU_NUM_GPRS];
547 char annex[32];
548 int i;
9b409511 549 ULONGEST len;
771b4502
UW
550
551 xsnprintf (annex, sizeof annex, "%d/regs", fd);
9b409511
YQ
552 if ((spu_proc_xfer_spu (annex, buf, NULL, 0, sizeof buf, &len)
553 == TARGET_XFER_OK)
554 && len == sizeof buf)
771b4502 555 for (i = 0; i < SPU_NUM_GPRS; i++)
73e1c03f 556 regcache->raw_supply (i, buf + i*16);
771b4502
UW
557 }
558}
559
560/* Override the store_inferior_register routine. */
f6ac5f3d
PA
561void
562spu_linux_nat_target::store_registers (struct regcache *regcache, int regno)
771b4502
UW
563{
564 int fd;
4179a487 565 ULONGEST addr;
771b4502 566
639a9038
SM
567 /* Since we use functions that rely on inferior_ptid, we need to set and
568 restore it. */
569 scoped_restore save_ptid
222312d3 570 = make_scoped_restore (&inferior_ptid, regcache->ptid ());
639a9038 571
771b4502
UW
572 /* We must be stopped on a spu_run system call. */
573 if (!parse_spufs_run (&fd, &addr))
574 return;
575
576 /* The NPC register is found at ADDR. */
577 if (regno == -1 || regno == SPU_PC_REGNUM)
578 {
579 gdb_byte buf[4];
34a79281 580 regcache->raw_collect (SPU_PC_REGNUM, buf);
771b4502
UW
581 store_ppc_memory (addr, buf, 4);
582 }
583
584 /* The GPRs are found in the "regs" spufs file. */
585 if (regno == -1 || (regno >= 0 && regno < SPU_NUM_GPRS))
586 {
587 gdb_byte buf[16 * SPU_NUM_GPRS];
588 char annex[32];
589 int i;
9b409511 590 ULONGEST len;
771b4502
UW
591
592 for (i = 0; i < SPU_NUM_GPRS; i++)
34a79281 593 regcache->raw_collect (i, buf + i*16);
771b4502
UW
594
595 xsnprintf (annex, sizeof annex, "%d/regs", fd);
9b409511 596 spu_proc_xfer_spu (annex, NULL, buf, 0, sizeof buf, &len);
771b4502
UW
597 }
598}
599
600/* Override the to_xfer_partial routine. */
f6ac5f3d
PA
601enum target_xfer_status
602spu_linux_nat_target::xfer_partial (enum target_object object, const char *annex,
603 gdb_byte *readbuf, const gdb_byte *writebuf,
604 ULONGEST offset, ULONGEST len,
605 ULONGEST *xfered_len)
771b4502 606{
23d964e7 607 if (object == TARGET_OBJECT_SPU)
9b409511
YQ
608 return spu_proc_xfer_spu (annex, readbuf, writebuf, offset, len,
609 xfered_len);
23d964e7 610
771b4502
UW
611 if (object == TARGET_OBJECT_MEMORY)
612 {
613 int fd;
4179a487 614 ULONGEST addr;
d2ed6730
UW
615 char mem_annex[32], lslr_annex[32];
616 gdb_byte buf[32];
617 ULONGEST lslr;
9b409511 618 enum target_xfer_status ret;
771b4502
UW
619
620 /* We must be stopped on a spu_run system call. */
621 if (!parse_spufs_run (&fd, &addr))
9b409511 622 return TARGET_XFER_EOF;
771b4502
UW
623
624 /* Use the "mem" spufs file to access SPU local store. */
625 xsnprintf (mem_annex, sizeof mem_annex, "%d/mem", fd);
9b409511
YQ
626 ret = spu_proc_xfer_spu (mem_annex, readbuf, writebuf, offset, len,
627 xfered_len);
628 if (ret == TARGET_XFER_OK)
d2ed6730
UW
629 return ret;
630
631 /* SPU local store access wraps the address around at the
632 local store limit. We emulate this here. To avoid needing
633 an extra access to retrieve the LSLR, we only do that after
634 trying the original address first, and getting end-of-file. */
635 xsnprintf (lslr_annex, sizeof lslr_annex, "%d/lslr", fd);
636 memset (buf, 0, sizeof buf);
9b409511
YQ
637 if (spu_proc_xfer_spu (lslr_annex, buf, NULL, 0, sizeof buf, xfered_len)
638 != TARGET_XFER_OK)
d2ed6730
UW
639 return ret;
640
22c90ac1 641 lslr = strtoulst ((const char *) buf, NULL, 16);
d2ed6730 642 return spu_proc_xfer_spu (mem_annex, readbuf, writebuf,
9b409511 643 offset & lslr, len, xfered_len);
771b4502
UW
644 }
645
2ed4b548 646 return TARGET_XFER_E_IO;
771b4502
UW
647}
648
649/* Override the to_can_use_hw_breakpoint routine. */
f6ac5f3d
PA
650int
651spu_linux_nat_target::can_use_hw_breakpoint (enum bptype type,
652 int cnt, int othertype)
771b4502
UW
653{
654 return 0;
655}
656
771b4502
UW
657/* Initialize SPU native target. */
658void
659_initialize_spu_nat (void)
660{
d9f719f1 661 add_inf_child_target (&the_spu_linux_nat_target);
771b4502 662}
This page took 1.608772 seconds and 4 git commands to generate.