OLD | NEW |
1 /* Low level interface to SPUs, for the remote server for GDB. | 1 /* Low level interface to SPUs, for the remote server for GDB. |
2 Copyright (C) 2006-2012 Free Software Foundation, Inc. | 2 Copyright (C) 2006-2013 Free Software Foundation, Inc. |
3 | 3 |
4 Contributed by Ulrich Weigand <uweigand@de.ibm.com>. | 4 Contributed by Ulrich Weigand <uweigand@de.ibm.com>. |
5 | 5 |
6 This file is part of GDB. | 6 This file is part of GDB. |
7 | 7 |
8 This program is free software; you can redistribute it and/or modify | 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 | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
11 (at your option) any later version. | 11 (at your option) any later version. |
12 | 12 |
13 This program is distributed in the hope that it will be useful, | 13 This program is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 GNU General Public License for more details. | 16 GNU General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
20 | 20 |
21 #include "server.h" | 21 #include "server.h" |
22 | 22 |
23 #include <sys/wait.h> | 23 #include "gdb_wait.h" |
24 #include <stdio.h> | 24 #include <stdio.h> |
25 #include <sys/ptrace.h> | 25 #include <sys/ptrace.h> |
26 #include <fcntl.h> | 26 #include <fcntl.h> |
27 #include <string.h> | 27 #include <string.h> |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include <errno.h> | 30 #include <errno.h> |
31 #include <sys/syscall.h> | 31 #include <sys/syscall.h> |
| 32 #include "filestuff.h" |
| 33 #include "hostio.h" |
32 | 34 |
33 /* Some older glibc versions do not define this. */ | 35 /* Some older glibc versions do not define this. */ |
34 #ifndef __WNOTHREAD | 36 #ifndef __WNOTHREAD |
35 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other | 37 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other |
36 threads in this group */ | 38 threads in this group */ |
37 #endif | 39 #endif |
38 | 40 |
39 #define PTRACE_TYPE_RET long | 41 #define PTRACE_TYPE_RET long |
40 #define PTRACE_TYPE_ARG3 long | 42 #define PTRACE_TYPE_ARG3 long |
41 | 43 |
42 /* Number of registers. */ | 44 /* Number of registers. */ |
43 #define SPU_NUM_REGS 130 | 45 #define SPU_NUM_REGS 130 |
44 #define SPU_NUM_CORE_REGS 128 | 46 #define SPU_NUM_CORE_REGS 128 |
45 | 47 |
46 /* Special registers. */ | 48 /* Special registers. */ |
47 #define SPU_ID_REGNUM 128 | 49 #define SPU_ID_REGNUM 128 |
48 #define SPU_PC_REGNUM 129 | 50 #define SPU_PC_REGNUM 129 |
49 | 51 |
50 /* PPU side system calls. */ | 52 /* PPU side system calls. */ |
51 #define INSTR_SC 0x44000002 | 53 #define INSTR_SC 0x44000002 |
52 #define NR_spu_run 0x0116 | 54 #define NR_spu_run 0x0116 |
53 | 55 |
54 /* Get current thread ID (Linux task ID). */ | |
55 #define current_ptid ((struct inferior_list_entry *)current_inferior)->id | |
56 | |
57 /* These are used in remote-utils.c. */ | 56 /* These are used in remote-utils.c. */ |
58 int using_threads = 0; | 57 int using_threads = 0; |
59 | 58 |
60 /* Defined in auto-generated file reg-spu.c. */ | 59 /* Defined in auto-generated file reg-spu.c. */ |
61 void init_registers_spu (void); | 60 void init_registers_spu (void); |
62 | 61 extern const struct target_desc *tdesc_spu; |
63 | 62 |
64 /* Fetch PPU register REGNO. */ | 63 /* Fetch PPU register REGNO. */ |
65 static CORE_ADDR | 64 static CORE_ADDR |
66 fetch_ppc_register (int regno) | 65 fetch_ppc_register (int regno) |
67 { | 66 { |
68 PTRACE_TYPE_RET res; | 67 PTRACE_TYPE_RET res; |
69 | 68 |
70 int tid = ptid_get_lwp (current_ptid); | 69 int tid = ptid_get_lwp (current_ptid); |
71 | 70 |
72 #ifndef __powerpc64__ | 71 #ifndef __powerpc64__ |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 261 } |
263 | 262 |
264 | 263 |
265 /* Start an inferior process and returns its pid. | 264 /* Start an inferior process and returns its pid. |
266 ALLARGS is a vector of program-name and args. */ | 265 ALLARGS is a vector of program-name and args. */ |
267 static int | 266 static int |
268 spu_create_inferior (char *program, char **allargs) | 267 spu_create_inferior (char *program, char **allargs) |
269 { | 268 { |
270 int pid; | 269 int pid; |
271 ptid_t ptid; | 270 ptid_t ptid; |
| 271 struct process_info *proc; |
272 | 272 |
273 pid = fork (); | 273 pid = fork (); |
274 if (pid < 0) | 274 if (pid < 0) |
275 perror_with_name ("fork"); | 275 perror_with_name ("fork"); |
276 | 276 |
277 if (pid == 0) | 277 if (pid == 0) |
278 { | 278 { |
| 279 close_most_fds (); |
279 ptrace (PTRACE_TRACEME, 0, 0, 0); | 280 ptrace (PTRACE_TRACEME, 0, 0, 0); |
280 | 281 |
281 setpgid (0, 0); | 282 setpgid (0, 0); |
282 | 283 |
283 execv (program, allargs); | 284 execv (program, allargs); |
284 if (errno == ENOENT) | 285 if (errno == ENOENT) |
285 execvp (program, allargs); | 286 execvp (program, allargs); |
286 | 287 |
287 fprintf (stderr, "Cannot exec %s: %s.\n", program, | 288 fprintf (stderr, "Cannot exec %s: %s.\n", program, |
288 strerror (errno)); | 289 strerror (errno)); |
289 fflush (stderr); | 290 fflush (stderr); |
290 _exit (0177); | 291 _exit (0177); |
291 } | 292 } |
292 | 293 |
293 add_process (pid, 0); | 294 proc = add_process (pid, 0); |
| 295 proc->tdesc = tdesc_spu; |
294 | 296 |
295 ptid = ptid_build (pid, pid, 0); | 297 ptid = ptid_build (pid, pid, 0); |
296 add_thread (ptid, NULL); | 298 add_thread (ptid, NULL); |
297 return pid; | 299 return pid; |
298 } | 300 } |
299 | 301 |
300 /* Attach to an inferior process. */ | 302 /* Attach to an inferior process. */ |
301 int | 303 int |
302 spu_attach (unsigned long pid) | 304 spu_attach (unsigned long pid) |
303 { | 305 { |
304 ptid_t ptid; | 306 ptid_t ptid; |
| 307 struct process_info *proc; |
305 | 308 |
306 if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0) | 309 if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0) |
307 { | 310 { |
308 fprintf (stderr, "Cannot attach to process %ld: %s (%d)\n", pid, | 311 fprintf (stderr, "Cannot attach to process %ld: %s (%d)\n", pid, |
309 strerror (errno), errno); | 312 strerror (errno), errno); |
310 fflush (stderr); | 313 fflush (stderr); |
311 _exit (0177); | 314 _exit (0177); |
312 } | 315 } |
313 | 316 |
314 add_process (pid, 1); | 317 proc = add_process (pid, 1); |
| 318 proc->tdesc = tdesc_spu; |
315 ptid = ptid_build (pid, pid, 0); | 319 ptid = ptid_build (pid, pid, 0); |
316 add_thread (ptid, NULL); | 320 add_thread (ptid, NULL); |
317 return 0; | 321 return 0; |
318 } | 322 } |
319 | 323 |
320 /* Kill the inferior process. */ | 324 /* Kill the inferior process. */ |
321 static int | 325 static int |
322 spu_kill (int pid) | 326 spu_kill (int pid) |
323 { | 327 { |
324 int status, ret; | 328 int status, ret; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 671 |
668 void | 672 void |
669 initialize_low (void) | 673 initialize_low (void) |
670 { | 674 { |
671 static const unsigned char breakpoint[] = { 0x00, 0x00, 0x3f, 0xff }; | 675 static const unsigned char breakpoint[] = { 0x00, 0x00, 0x3f, 0xff }; |
672 | 676 |
673 set_target_ops (&spu_target_ops); | 677 set_target_ops (&spu_target_ops); |
674 set_breakpoint_data (breakpoint, sizeof breakpoint); | 678 set_breakpoint_data (breakpoint, sizeof breakpoint); |
675 init_registers_spu (); | 679 init_registers_spu (); |
676 } | 680 } |
OLD | NEW |