1 /* Low level DECstation interface to ptrace, for GDB when running native.
2 Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <sys/ptrace.h>
26 #include <setjmp.h> /* For JB_XXX. */
28 /* Size of elements in jmpbuf */
30 #define JB_ELEMENT_SIZE 4
32 /* Map gdb internal register number to ptrace ``address''.
33 These ``addresses'' are defined in DECstation <sys/ptrace.h> */
35 #define REGISTER_PTRACE_ADDR(regno) \
36 (regno < 32 ? GPR_BASE + regno \
37 : regno == PC_REGNUM ? PC \
38 : regno == CAUSE_REGNUM ? CAUSE \
39 : regno == HI_REGNUM ? MMHI \
40 : regno == LO_REGNUM ? MMLO \
41 : regno == FCRCS_REGNUM ? FPC_CSR \
42 : regno == FCRIR_REGNUM ? FPC_EIR \
43 : regno >= FP0_REGNUM ? FPR_BASE + (regno - FP0_REGNUM) \
46 static const char zerobuf[MAX_REGISTER_RAW_SIZE];
48 /* Get all registers from the inferior */
51 fetch_inferior_registers (regno)
54 register unsigned int regaddr;
55 char buf[MAX_REGISTER_RAW_SIZE];
60 for (regno = 1; regno < NUM_REGS; regno++)
62 regaddr = REGISTER_PTRACE_ADDR (regno);
63 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
65 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid,
66 (PTRACE_ARG3_TYPE) regaddr, 0);
67 regaddr += sizeof (int);
69 supply_register (regno, buf);
72 supply_register (ZERO_REGNUM, zerobuf);
73 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
74 supply_register (FP_REGNUM, zerobuf);
77 /* Store our register values back into the inferior.
78 If REGNO is -1, do this for all registers.
79 Otherwise, REGNO specifies which register (so we can save time). */
82 store_inferior_registers (regno)
85 register unsigned int regaddr;
93 regaddr = REGISTER_PTRACE_ADDR (regno);
95 ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
96 read_register (regno));
99 sprintf (buf, "writing register number %d", regno);
100 perror_with_name (buf);
105 for (regno = 0; regno < NUM_REGS; regno++)
107 if (regno == ZERO_REGNUM || regno == PS_REGNUM
108 || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
109 || regno == FCRIR_REGNUM || regno == FP_REGNUM
110 || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
112 regaddr = register_addr (regno, 1);
114 ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
115 read_register (regno));
118 sprintf (buf, "writing all regs, number %d", regno);
119 perror_with_name (buf);
126 /* Figure out where the longjmp will land.
127 We expect the first arg to be a pointer to the jmp_buf structure from which
128 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
129 This routine returns true on success. */
132 get_longjmp_target(pc)
137 jb_addr = read_register(A0_REGNUM);
139 if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc,
143 SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));