merge from gcc
[deliverable/binutils-gdb.git] / gdb / hppam3-nat.c
1 /* Low level interface to HP800 running mach 4.0 for GDB, the GNU
2 debugger.
3
4 Copyright 1995, 2000, 2001, 2003 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "inferior.h"
25 #include "floatformat.h"
26 #include "regcache.h"
27
28 #include <stdio.h>
29
30 #include <mach.h>
31 #include <mach/message.h>
32 #include <mach/exception.h>
33 #include <mach_error.h>
34
35 #include <target.h>
36
37 /*
38 * Fetch inferiors registers for gdb.
39 * REGNO specifies which (as gdb views it) register, -1 for all.
40 */
41
42 void
43 fetch_inferior_registers (int regno)
44 {
45 kern_return_t ret;
46 thread_state_data_t state;
47 unsigned int stateCnt = TRACE_FLAVOR_SIZE;
48 int index;
49
50 if (!MACH_PORT_VALID (current_thread))
51 error ("fetch inferior registers: Invalid thread");
52
53 if (must_suspend_thread)
54 setup_thread (current_thread, 1);
55
56 ret = thread_get_state (current_thread,
57 TRACE_FLAVOR,
58 state,
59 &stateCnt);
60
61 if (ret != KERN_SUCCESS)
62 warning ("fetch_inferior_registers: %s ",
63 mach_error_string (ret));
64 else
65 {
66 for (index = 0; index < NUM_REGS; index++)
67 supply_register (index, (void *) &state[index]);
68 }
69
70 if (must_suspend_thread)
71 setup_thread (current_thread, 0);
72 }
73 \f
74 /* Store our register values back into the inferior.
75 * If REGNO is -1, do this for all registers.
76 * Otherwise, REGNO specifies which register
77 *
78 * On mach3 all registers are always saved in one call.
79 */
80 void
81 store_inferior_registers (int regno)
82 {
83 kern_return_t ret;
84 thread_state_data_t state;
85 unsigned int stateCnt = TRACE_FLAVOR_SIZE;
86 int index;
87
88 if (!MACH_PORT_VALID (current_thread))
89 error ("store inferior registers: Invalid thread");
90
91 if (must_suspend_thread)
92 setup_thread (current_thread, 1);
93
94 /* Fetch the state of the current thread */
95 ret = thread_get_state (current_thread,
96 TRACE_FLAVOR,
97 state,
98 &stateCnt);
99
100 if (ret != KERN_SUCCESS)
101 {
102 warning ("store_inferior_registers (get): %s",
103 mach_error_string (ret));
104 if (must_suspend_thread)
105 setup_thread (current_thread, 0);
106 return;
107 }
108
109
110 /* move gdb's registers to thread's state
111
112 * Since we save all registers anyway, save the ones
113 * that gdb thinks are valid (e.g. ignore the regno
114 * parameter)
115 */
116 if (regno > 0 && regno < NUM_REGS)
117 {
118 memcpy (&state[regno], &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
119 DEPRECATED_REGISTER_RAW_SIZE (regno));
120 }
121 else
122 {
123 for (index = 0; index < NUM_REGS; index++)
124 memcpy (&state[index], &deprecated_registers[DEPRECATED_REGISTER_BYTE (index)],
125 DEPRECATED_REGISTER_RAW_SIZE (index));
126 /* state[index] = deprecated_registers[DEPRECATED_REGISTER_BYTE (index)]; */
127
128 }
129
130 /* Write gdb's current view of register to the thread
131 */
132 ret = thread_set_state (current_thread,
133 TRACE_FLAVOR,
134 state,
135 TRACE_FLAVOR_SIZE);
136
137 if (ret != KERN_SUCCESS)
138 warning ("store_inferior_registers (set): %s",
139 mach_error_string (ret));
140
141 if (must_suspend_thread)
142 setup_thread (current_thread, 0);
143 }
This page took 0.055212 seconds and 4 git commands to generate.