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 */
57 _initialize_hp300ux_nat ()
59 #ifndef HPUX_VERSION_5
61 kernel_u_addr
= nl
[0].n_value
;
62 #else /* HPUX version 5. */
63 kernel_u_addr
= (CORE_ADDR
) 0x0097900;
67 #define INFERIOR_AR0(u) \
69 (PT_RUAREA, inferior_pid, \
70 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
74 fetch_inferior_register (regno
, regaddr
)
76 register unsigned int regaddr
;
78 #ifndef HPUX_VERSION_5
79 if (regno
== PS_REGNUM
)
81 union { int i
; short s
[2]; } ps_val
;
84 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
87 supply_register (regno
, (char *)®val
);
90 #endif /* not HPUX_VERSION_5 */
92 char buf
[MAX_REGISTER_RAW_SIZE
];
95 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
97 *(int *) &buf
[i
] = ptrace (PT_RUAREA
, inferior_pid
,
98 (PTRACE_ARG3_TYPE
) regaddr
, 0, 0);
99 regaddr
+= sizeof (int);
101 supply_register (regno
, buf
);
107 store_inferior_register_1 (regno
, regaddr
, val
)
109 unsigned int regaddr
;
113 ptrace (PT_WUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
, val
, 0);
115 /* HP-UX randomly sets errno to non-zero for regno == 25.
116 However, the value is correctly written, so ignore errno. */
121 sprintf (string_buf
, "writing register number %d", regno
);
122 perror_with_name (string_buf
);
129 store_inferior_register (regno
, regaddr
)
131 register unsigned int regaddr
;
133 #ifndef HPUX_VERSION_5
134 if (regno
== PS_REGNUM
)
136 union { int i
; short s
[2]; } ps_val
;
138 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
140 ps_val
.s
[0] = (read_register (regno
));
141 store_inferior_register_1 (regno
, regaddr
, ps_val
.i
);
144 #endif /* not HPUX_VERSION_5 */
146 char buf
[MAX_REGISTER_RAW_SIZE
];
148 extern char registers
[];
150 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
152 store_inferior_register_1
154 (*(int *) ®isters
[(REGISTER_BYTE (regno
)) + i
]));
155 regaddr
+= sizeof (int);
162 fetch_inferior_registers (regno
)
166 register unsigned int ar0_offset
;
168 ar0_offset
= (INFERIOR_AR0 (u
));
171 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
172 fetch_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
173 for (; (regno
< NUM_REGS
); regno
++)
174 fetch_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
177 fetch_inferior_register (regno
,
179 ? REGISTER_ADDR (ar0_offset
, regno
)
180 : FP_REGISTER_ADDR (u
, regno
)));
183 /* Store our register values back into the inferior.
184 If REGNO is -1, do this for all registers.
185 Otherwise, REGNO specifies which register (so we can save time). */
188 store_inferior_registers (regno
)
192 register unsigned int ar0_offset
;
193 extern char registers
[];
195 if (regno
>= FP0_REGNUM
)
197 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
201 ar0_offset
= (INFERIOR_AR0 (u
));
204 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
208 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
209 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
210 for (; (regno
< NUM_REGS
); regno
++)
211 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
218 /* This function is no longer used. The version in coredep.c is used
221 /* Take the register values out of a core file and store
222 them where `read_register' will find them. */
224 #ifdef HPUX_VERSION_5
225 #define e_PS e_regs[PS]
226 #define e_PC e_regs[PC]
227 #endif /* HPUX_VERSION_5 */
230 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
232 unsigned int core_reg_size
;
234 unsigned int reg_addr
; /* Unused in this version */
238 struct exception_stack
*pes
= (struct exception_stack
*) core_reg_sect
;
244 ((char *) &es
.e_offset
- (char *) &es
.e_regs
[R0
]))
245 error ("Not enough registers in core file");
246 for (regno
= 0; (regno
< PS_REGNUM
); regno
++)
247 supply_register (regno
, (char *) &es
.e_regs
[regno
+ R0
]);
249 supply_register (regno
++, (char *) &val
);
250 supply_register (regno
++, (char *) &es
.e_PC
);
252 } else if (which
== 2) {
254 /* FIXME: This may not work if the float regs and control regs are
256 for (regno
= FP0_REGNUM
, buf
= core_reg_sect
;
258 buf
+= REGISTER_RAW_SIZE (regno
), regno
++)
260 supply_register (regno
, buf
);