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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* Defining this means some system include files define some extra stuff. */
26 #include <sys/param.h>
30 #include <sys/ioctl.h>
33 #include <sys/ptrace.h>
42 /* Get kernel_u_addr using HPUX-style nlist(). */
43 CORE_ADDR kernel_u_addr
;
49 unsigned char n_length
;
53 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
55 /* read the value of the u area from the hp-ux kernel */
56 void _initialize_kernel_u_addr ()
58 #ifndef HPUX_VERSION_5
60 kernel_u_addr
= nl
[0].n_value
;
61 #else /* HPUX version 5. */
62 kernel_u_addr
= (CORE_ADDR
) 0x0097900;
66 #define INFERIOR_AR0(u) \
68 (PT_RUAREA, inferior_pid, \
69 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
73 fetch_inferior_register (regno
, regaddr
)
75 register unsigned int regaddr
;
77 #ifndef HPUX_VERSION_5
78 if (regno
== PS_REGNUM
)
80 union { int i
; short s
[2]; } ps_val
;
83 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
86 supply_register (regno
, (char *)®val
);
89 #endif /* not HPUX_VERSION_5 */
91 char buf
[MAX_REGISTER_RAW_SIZE
];
94 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
96 *(int *) &buf
[i
] = ptrace (PT_RUAREA
, inferior_pid
,
97 (PTRACE_ARG3_TYPE
) regaddr
, 0, 0);
98 regaddr
+= sizeof (int);
100 supply_register (regno
, buf
);
106 store_inferior_register_1 (regno
, regaddr
, val
)
108 unsigned int regaddr
;
112 ptrace (PT_WUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
, val
, 0);
114 /* HP-UX randomly sets errno to non-zero for regno == 25.
115 However, the value is correctly written, so ignore errno. */
120 sprintf (string_buf
, "writing register number %d", regno
);
121 perror_with_name (string_buf
);
128 store_inferior_register (regno
, regaddr
)
130 register unsigned int regaddr
;
132 #ifndef HPUX_VERSION_5
133 if (regno
== PS_REGNUM
)
135 union { int i
; short s
[2]; } ps_val
;
137 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
139 ps_val
.s
[0] = (read_register (regno
));
140 store_inferior_register_1 (regno
, regaddr
, ps_val
.i
);
143 #endif /* not HPUX_VERSION_5 */
145 char buf
[MAX_REGISTER_RAW_SIZE
];
147 extern char registers
[];
149 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
151 store_inferior_register_1
153 (*(int *) ®isters
[(REGISTER_BYTE (regno
)) + i
]));
154 regaddr
+= sizeof (int);
161 fetch_inferior_registers (regno
)
165 register unsigned int ar0_offset
;
167 ar0_offset
= (INFERIOR_AR0 (u
));
170 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
171 fetch_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
172 for (; (regno
< NUM_REGS
); regno
++)
173 fetch_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
176 fetch_inferior_register (regno
,
178 ? REGISTER_ADDR (ar0_offset
, regno
)
179 : FP_REGISTER_ADDR (u
, regno
)));
182 /* Store our register values back into the inferior.
183 If REGNO is -1, do this for all registers.
184 Otherwise, REGNO specifies which register (so we can save time). */
187 store_inferior_registers (regno
)
191 register unsigned int ar0_offset
;
192 extern char registers
[];
194 if (regno
>= FP0_REGNUM
)
196 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
200 ar0_offset
= (INFERIOR_AR0 (u
));
203 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
207 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
208 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
209 for (; (regno
< NUM_REGS
); regno
++)
210 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
215 /* Take the register values out of a core file and store
216 them where `read_register' will find them. */
218 #ifdef HPUX_VERSION_5
219 #define e_PS e_regs[PS]
220 #define e_PC e_regs[PC]
221 #endif /* HPUX_VERSION_5 */
224 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
226 unsigned int core_reg_size
;
228 unsigned int reg_addr
; /* Unused in this version */
232 struct exception_stack
*pes
= (struct exception_stack
*) core_reg_sect
;
238 ((char *) &es
.e_offset
- (char *) &es
.e_regs
[R0
]))
239 error ("Not enough registers in core file");
240 for (regno
= 0; (regno
< PS_REGNUM
); regno
++)
241 supply_register (regno
, (char *) &es
.e_regs
[regno
+ R0
]);
243 supply_register (regno
++, (char *) &val
);
244 supply_register (regno
++, (char *) &es
.e_PC
);
246 } else if (which
== 2) {
248 /* FIXME: This may not work if the float regs and control regs are
250 for (regno
= FP0_REGNUM
, buf
= core_reg_sect
;
252 buf
+= REGISTER_RAW_SIZE (regno
), regno
++)
254 supply_register (regno
, buf
);