OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [hp300ux-nat.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* HP/UX native interface for HP 300's, for GDB when running under Unix.
2
   Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1996, 1999, 2000,
3
   2001 Free Software Foundation, Inc.
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
#include "frame.h"
24
#include "inferior.h"
25
#include "regcache.h"
26
 
27
/* Defining this means some system include files define some extra stuff.  */
28
#define WOPR
29
#include <sys/param.h>
30
#include <signal.h>
31
#include <sys/user.h>
32
#include <fcntl.h>
33
 
34
#include <sys/ptrace.h>
35
#include <sys/reg.h>
36
#include <sys/trap.h>
37
 
38
#include <sys/file.h>
39
 
40
static void fetch_inferior_register (int, unsigned int);
41
 
42
static void store_inferior_register_1 (int, unsigned int, int);
43
 
44
static void store_inferior_register (int, unsigned int);
45
 
46
/* Get kernel_u_addr using HPUX-style nlist().  */
47
CORE_ADDR kernel_u_addr;
48
 
49
struct hpnlist
50
  {
51
    char *n_name;
52
    long n_value;
53
    unsigned char n_type;
54
    unsigned char n_length;
55
    short n_almod;
56
    short n_unused;
57
  };
58
static struct hpnlist nl[] =
59
{
60
  {"_u", -1,},
61
  {(char *) 0,}};
62
 
63
/* read the value of the u area from the hp-ux kernel */
64
void
65
_initialize_hp300ux_nat (void)
66
{
67
#ifndef HPUX_VERSION_5
68
  nlist ("/hp-ux", nl);
69
  kernel_u_addr = nl[0].n_value;
70
#else /* HPUX version 5.  */
71
  kernel_u_addr = (CORE_ADDR) 0x0097900;
72
#endif
73
}
74
 
75
#define INFERIOR_AR0(u)                                                 \
76
  ((ptrace                                                              \
77
    (PT_RUAREA, PIDGET (inferior_ptid),                                 \
78
     (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
79
   - kernel_u_addr)
80
 
81
static void
82
fetch_inferior_register (register int regno, register unsigned int regaddr)
83
{
84
#ifndef HPUX_VERSION_5
85
  if (regno == PS_REGNUM)
86
    {
87
      union
88
        {
89
          int i;
90
          short s[2];
91
        }
92
      ps_val;
93
      int regval;
94
 
95
      ps_val.i = (ptrace (PT_RUAREA, PIDGET (inferior_ptid),
96
                          (PTRACE_ARG3_TYPE) regaddr, 0, 0));
97
      regval = ps_val.s[0];
98
      supply_register (regno, (char *) &regval);
99
    }
100
  else
101
#endif /* not HPUX_VERSION_5 */
102
    {
103
      char buf[MAX_REGISTER_RAW_SIZE];
104
      register int i;
105
 
106
      for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
107
        {
108
          *(int *) &buf[i] = ptrace (PT_RUAREA, PIDGET (inferior_ptid),
109
                                     (PTRACE_ARG3_TYPE) regaddr, 0, 0);
110
          regaddr += sizeof (int);
111
        }
112
      supply_register (regno, buf);
113
    }
114
  return;
115
}
116
 
117
static void
118
store_inferior_register_1 (int regno, unsigned int regaddr, int val)
119
{
120
  errno = 0;
121
  ptrace (PT_WUAREA, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) regaddr,
122
          val, 0);
123
#if 0
124
  /* HP-UX randomly sets errno to non-zero for regno == 25.
125
     However, the value is correctly written, so ignore errno. */
126
  if (errno != 0)
127
    {
128
      char string_buf[64];
129
 
130
      sprintf (string_buf, "writing register number %d", regno);
131
      perror_with_name (string_buf);
132
    }
133
#endif
134
  return;
135
}
136
 
137
static void
138
store_inferior_register (register int regno, register unsigned int regaddr)
139
{
140
#ifndef HPUX_VERSION_5
141
  if (regno == PS_REGNUM)
142
    {
143
      union
144
        {
145
          int i;
146
          short s[2];
147
        }
148
      ps_val;
149
 
150
      ps_val.i = (ptrace (PT_RUAREA, PIDGET (inferior_ptid),
151
                          (PTRACE_ARG3_TYPE) regaddr, 0, 0));
152
      ps_val.s[0] = (read_register (regno));
153
      store_inferior_register_1 (regno, regaddr, ps_val.i);
154
    }
155
  else
156
#endif /* not HPUX_VERSION_5 */
157
    {
158
      register int i;
159
 
160
      for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
161
        {
162
          store_inferior_register_1
163
            (regno, regaddr,
164
             (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
165
          regaddr += sizeof (int);
166
        }
167
    }
168
  return;
169
}
170
 
171
void
172
fetch_inferior_registers (int regno)
173
{
174
  struct user u;
175
  register unsigned int ar0_offset;
176
 
177
  ar0_offset = (INFERIOR_AR0 (u));
178
  if (regno == -1)
179
    {
180
      for (regno = 0; (regno < FP0_REGNUM); regno++)
181
        fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
182
      for (; (regno < NUM_REGS); regno++)
183
        fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
184
    }
185
  else
186
    fetch_inferior_register (regno,
187
                             (regno < FP0_REGNUM
188
                              ? REGISTER_ADDR (ar0_offset, regno)
189
                              : FP_REGISTER_ADDR (u, regno)));
190
}
191
 
192
/* Store our register values back into the inferior.
193
   If REGNO is -1, do this for all registers.
194
   Otherwise, REGNO specifies which register (so we can save time).  */
195
 
196
void
197
store_inferior_registers (register int regno)
198
{
199
  struct user u;
200
  register unsigned int ar0_offset;
201
 
202
  if (regno >= FP0_REGNUM)
203
    {
204
      store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
205
      return;
206
    }
207
 
208
  ar0_offset = (INFERIOR_AR0 (u));
209
  if (regno >= 0)
210
    {
211
      store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
212
      return;
213
    }
214
 
215
  for (regno = 0; (regno < FP0_REGNUM); regno++)
216
    store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
217
  for (; (regno < NUM_REGS); regno++)
218
    store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
219
  return;
220
}
221
 
222
int
223
getpagesize (void)
224
{
225
  return 4096;
226
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.