1 /* HP/UX native interface for HP 300's, for GDB when running under Unix.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
25 /* Defining this means some system include files define some extra stuff. */
27 #include <sys/param.h>
32 #include <sys/ptrace.h>
38 static void fetch_inferior_register (int, unsigned int);
40 static void store_inferior_register_1 (int, unsigned int, int);
42 static void store_inferior_register (int, unsigned int);
44 /* Get kernel_u_addr using HPUX-style nlist(). */
45 CORE_ADDR kernel_u_addr
;
52 unsigned char n_length
;
56 static struct hpnlist nl
[] =
61 /* read the value of the u area from the hp-ux kernel */
63 _initialize_hp300ux_nat (void)
65 #ifndef HPUX_VERSION_5
67 kernel_u_addr
= nl
[0].n_value
;
68 #else /* HPUX version 5. */
69 kernel_u_addr
= (CORE_ADDR
) 0x0097900;
73 #define INFERIOR_AR0(u) \
75 (PT_RUAREA, inferior_pid, \
76 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
80 fetch_inferior_register (register int regno
, register unsigned int regaddr
)
82 #ifndef HPUX_VERSION_5
83 if (regno
== PS_REGNUM
)
93 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
96 supply_register (regno
, (char *) ®val
);
99 #endif /* not HPUX_VERSION_5 */
101 char buf
[MAX_REGISTER_RAW_SIZE
];
104 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
106 *(int *) &buf
[i
] = ptrace (PT_RUAREA
, inferior_pid
,
107 (PTRACE_ARG3_TYPE
) regaddr
, 0, 0);
108 regaddr
+= sizeof (int);
110 supply_register (regno
, buf
);
116 store_inferior_register_1 (int regno
, unsigned int regaddr
, int val
)
119 ptrace (PT_WUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
, val
, 0);
121 /* HP-UX randomly sets errno to non-zero for regno == 25.
122 However, the value is correctly written, so ignore errno. */
127 sprintf (string_buf
, "writing register number %d", regno
);
128 perror_with_name (string_buf
);
135 store_inferior_register (register int regno
, register unsigned int regaddr
)
137 #ifndef HPUX_VERSION_5
138 if (regno
== PS_REGNUM
)
147 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
149 ps_val
.s
[0] = (read_register (regno
));
150 store_inferior_register_1 (regno
, regaddr
, ps_val
.i
);
153 #endif /* not HPUX_VERSION_5 */
157 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
159 store_inferior_register_1
161 (*(int *) ®isters
[(REGISTER_BYTE (regno
)) + i
]));
162 regaddr
+= sizeof (int);
169 fetch_inferior_registers (int regno
)
172 register unsigned int ar0_offset
;
174 ar0_offset
= (INFERIOR_AR0 (u
));
177 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
178 fetch_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
179 for (; (regno
< NUM_REGS
); regno
++)
180 fetch_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
183 fetch_inferior_register (regno
,
185 ? REGISTER_ADDR (ar0_offset
, regno
)
186 : FP_REGISTER_ADDR (u
, regno
)));
189 /* Store our register values back into the inferior.
190 If REGNO is -1, do this for all registers.
191 Otherwise, REGNO specifies which register (so we can save time). */
194 store_inferior_registers (register int regno
)
197 register unsigned int ar0_offset
;
199 if (regno
>= FP0_REGNUM
)
201 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
205 ar0_offset
= (INFERIOR_AR0 (u
));
208 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
212 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
213 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
214 for (; (regno
< NUM_REGS
); regno
++)
215 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));