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, Boston, MA 02111-1307, USA. */
24 /* Defining this means some system include files define some extra stuff. */
26 #include <sys/param.h>
31 #include <sys/ptrace.h>
39 /* Get kernel_u_addr using HPUX-style nlist(). */
40 CORE_ADDR kernel_u_addr
;
46 unsigned char n_length
;
50 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
52 /* read the value of the u area from the hp-ux kernel */
54 _initialize_hp300ux_nat ()
56 #ifndef HPUX_VERSION_5
58 kernel_u_addr
= nl
[0].n_value
;
59 #else /* HPUX version 5. */
60 kernel_u_addr
= (CORE_ADDR
) 0x0097900;
64 #define INFERIOR_AR0(u) \
66 (PT_RUAREA, inferior_pid, \
67 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
71 fetch_inferior_register (regno
, regaddr
)
73 register unsigned int regaddr
;
75 #ifndef HPUX_VERSION_5
76 if (regno
== PS_REGNUM
)
78 union { int i
; short s
[2]; } ps_val
;
81 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
84 supply_register (regno
, (char *)®val
);
87 #endif /* not HPUX_VERSION_5 */
89 char buf
[MAX_REGISTER_RAW_SIZE
];
92 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
94 *(int *) &buf
[i
] = ptrace (PT_RUAREA
, inferior_pid
,
95 (PTRACE_ARG3_TYPE
) regaddr
, 0, 0);
96 regaddr
+= sizeof (int);
98 supply_register (regno
, buf
);
104 store_inferior_register_1 (regno
, regaddr
, val
)
106 unsigned int regaddr
;
110 ptrace (PT_WUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
, val
, 0);
112 /* HP-UX randomly sets errno to non-zero for regno == 25.
113 However, the value is correctly written, so ignore errno. */
118 sprintf (string_buf
, "writing register number %d", regno
);
119 perror_with_name (string_buf
);
126 store_inferior_register (regno
, regaddr
)
128 register unsigned int regaddr
;
130 #ifndef HPUX_VERSION_5
131 if (regno
== PS_REGNUM
)
133 union { int i
; short s
[2]; } ps_val
;
135 ps_val
.i
= (ptrace (PT_RUAREA
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
137 ps_val
.s
[0] = (read_register (regno
));
138 store_inferior_register_1 (regno
, regaddr
, ps_val
.i
);
141 #endif /* not HPUX_VERSION_5 */
143 char buf
[MAX_REGISTER_RAW_SIZE
];
145 extern char registers
[];
147 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
149 store_inferior_register_1
151 (*(int *) ®isters
[(REGISTER_BYTE (regno
)) + i
]));
152 regaddr
+= sizeof (int);
159 fetch_inferior_registers (regno
)
163 register unsigned int ar0_offset
;
165 ar0_offset
= (INFERIOR_AR0 (u
));
168 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
169 fetch_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
170 for (; (regno
< NUM_REGS
); regno
++)
171 fetch_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
174 fetch_inferior_register (regno
,
176 ? REGISTER_ADDR (ar0_offset
, regno
)
177 : FP_REGISTER_ADDR (u
, regno
)));
180 /* Store our register values back into the inferior.
181 If REGNO is -1, do this for all registers.
182 Otherwise, REGNO specifies which register (so we can save time). */
185 store_inferior_registers (regno
)
189 register unsigned int ar0_offset
;
190 extern char registers
[];
192 if (regno
>= FP0_REGNUM
)
194 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
198 ar0_offset
= (INFERIOR_AR0 (u
));
201 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
205 for (regno
= 0; (regno
< FP0_REGNUM
); regno
++)
206 store_inferior_register (regno
, (REGISTER_ADDR (ar0_offset
, regno
)));
207 for (; (regno
< NUM_REGS
); regno
++)
208 store_inferior_register (regno
, (FP_REGISTER_ADDR (u
, regno
)));
215 /* This function is no longer used. The version in coredep.c is used
218 /* Take the register values out of a core file and store
219 them where `read_register' will find them. */
221 #ifdef HPUX_VERSION_5
222 #define e_PS e_regs[PS]
223 #define e_PC e_regs[PC]
224 #endif /* HPUX_VERSION_5 */
227 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
229 unsigned int core_reg_size
;
231 unsigned int reg_addr
; /* Unused in this version */
235 struct exception_stack
*pes
= (struct exception_stack
*) core_reg_sect
;
241 ((char *) &es
.e_offset
- (char *) &es
.e_regs
[R0
]))
242 error ("Not enough registers in core file");
243 for (regno
= 0; (regno
< PS_REGNUM
); regno
++)
244 supply_register (regno
, (char *) &es
.e_regs
[regno
+ R0
]);
246 supply_register (regno
++, (char *) &val
);
247 supply_register (regno
++, (char *) &es
.e_PC
);
249 } else if (which
== 2) {
251 /* FIXME: This may not work if the float regs and control regs are
253 for (regno
= FP0_REGNUM
, buf
= core_reg_sect
;
255 buf
+= REGISTER_RAW_SIZE (regno
), regno
++)
257 supply_register (regno
, buf
);