* configure.tgt (hppa*-*-bsd*, hppa*-*-osf*, m68*-*-sunos4*,
[deliverable/binutils-gdb.git] / gdb / ptx4-nat.c
CommitLineData
c906108c
SS
1/* Native-dependent code for ptx 4.0
2 Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
c5aa993b
JM
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
c906108c
SS
20
21#include "defs.h"
22#include "inferior.h"
23#include "gdbcore.h"
24#include <sys/procfs.h>
25#include <sys/ptrace.h>
26#include <sys/param.h>
27#include <fcntl.h>
28
c60c0f5f
MS
29/* Prototypes for supply_gregset etc. */
30#include "gregset.h"
31
c906108c 32/* Given a pointer to a general register set in /proc format (gregset_t *),
c5aa993b
JM
33 unpack the register contents and supply them as gdb's idea of the current
34 register values. */
c906108c
SS
35
36void
fba45db2 37supply_gregset (gregset_t *gregsetp)
c906108c 38{
c5aa993b
JM
39 supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]);
40 supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]);
41 supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]);
42 supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]);
43 supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]);
44 supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]);
45 supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]);
46 supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]);
47 supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]);
48 supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]);
c906108c
SS
49}
50
51void
fba45db2 52fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
53{
54 int regi;
c906108c 55
c5aa993b 56 for (regi = 0; regi < NUM_REGS; regi++)
c906108c
SS
57 {
58 if ((regno == -1) || (regno == regi))
59 {
c5aa993b 60 (*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)];
c906108c
SS
61 }
62 }
63}
64
c906108c 65/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
66 (fpregset_t *), unpack the register contents and supply them as gdb's
67 idea of the current floating point register values. */
c906108c 68
c5aa993b 69void
fba45db2 70supply_fpregset (fpregset_t *fpregsetp)
c906108c 71{
c5aa993b
JM
72 supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set);
73 supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs);
c906108c
SS
74}
75
76/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
77 (fpregset_t *), update the register specified by REGNO from gdb's idea
78 of the current floating point register set. If REGNO is -1, update
79 them all. */
c906108c
SS
80
81void
fba45db2 82fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c
SS
83{
84 int regi;
85 char *to;
86 char *from;
c906108c
SS
87
88 /* FIXME: see m68k-tdep.c for an example, for the m68k. */
89}
90
c906108c
SS
91/*
92 * This doesn't quite do the same thing as the procfs.c version, but give
93 * it the same name so we don't have to put an ifdef in solib.c.
94 */
95/* this could use elf_interpreter() from elfread.c */
96int
d0849a9a 97proc_iterate_over_mappings (int (*func) (int, CORE_ADDR))
c906108c 98{
c5aa993b
JM
99 vaddr_t curseg, memptr;
100 pt_vseg_t pv;
101 int rv, cmperr;
102 sec_ptr interp_sec;
103 char *interp_content;
104 int interp_fd, funcstat;
105 unsigned int size;
106 char buf1[NBPG], buf2[NBPG];
107
108 /*
109 * The following is really vile. We can get the name of the
110 * shared library from the exec_bfd, and we can get a list of
111 * each virtual memory segment, but there is no simple way to
112 * find the mapped segment from the shared library (ala
113 * procfs's PIOCOPENMEM). As a pretty nasty kludge, we
114 * compare the virtual memory segment to the contents of the
115 * .interp file. If they match, we assume that we've got the
116 * right one.
117 */
118
119 /*
120 * TODO: for attach, use XPT_OPENT to get the executable, in
121 * case we're attached without knowning the executable's
122 * filename.
123 */
c906108c
SS
124
125#ifdef VERBOSE_DEBUG
c5aa993b 126 printf ("proc_iter\n");
c906108c 127#endif
c5aa993b
JM
128 interp_sec = bfd_get_section_by_name (exec_bfd, ".interp");
129 if (!interp_sec)
130 {
131 return 0;
132 }
c906108c 133
c5aa993b
JM
134 size = bfd_section_size (exec_bfd, interp_sec);
135 interp_content = alloca (size);
136 if (0 == bfd_get_section_contents (exec_bfd, interp_sec,
137 interp_content, (file_ptr) 0, size))
138 {
139 return 0;
140 }
c906108c
SS
141
142#ifdef VERBOSE_DEBUG
c5aa993b 143 printf ("proc_iter: \"%s\"\n", interp_content);
c906108c 144#endif
c5aa993b
JM
145 interp_fd = open (interp_content, O_RDONLY, 0);
146 if (-1 == interp_fd)
147 {
148 return 0;
149 }
c906108c 150
c5aa993b
JM
151 curseg = 0;
152 while (1)
153 {
154 rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg);
c906108c 155#ifdef VERBOSE_DEBUG
c5aa993b 156 printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno);
c906108c 157#endif
c5aa993b
JM
158 if (-1 == rv)
159 break;
160 if (0 == rv)
161 break;
c906108c 162#ifdef VERBOSE_DEBUG
c5aa993b
JM
163 printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n",
164 pv.pv_start, pv.pv_size, pv.pv_prot);
c906108c 165#endif
c5aa993b
JM
166 curseg = pv.pv_start + pv.pv_size;
167
168 rv = lseek (interp_fd, 0, SEEK_SET);
169 if (-1 == rv)
170 {
171 perror ("lseek");
172 close (interp_fd);
173 return 0;
174 }
175 for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size;
176 memptr += NBPG)
177 {
c906108c 178#ifdef VERBOSE_DEBUG
c5aa993b 179 printf ("memptr 0x%x\n", memptr);
c906108c 180#endif
c5aa993b
JM
181 rv = read (interp_fd, buf1, NBPG);
182 if (-1 == rv)
183 {
184 perror ("read");
185 close (interp_fd);
186 return 0;
187 }
188 rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2,
189 memptr);
190 if (-1 == rv)
191 {
192 perror ("ptrace");
193 close (interp_fd);
194 return 0;
195 }
196 cmperr = memcmp (buf1, buf2, NBPG);
197 if (cmperr)
198 break;
199 }
200 if (0 == cmperr)
201 {
202 /* this is it */
203 funcstat = (*func) (interp_fd, pv.pv_start);
204 break;
c906108c 205 }
c5aa993b
JM
206 }
207 close (interp_fd);
208 return 0;
c906108c 209}
This page took 0.089522 seconds and 4 git commands to generate.