2000-03-21 J.T. Conklin <jtc@redback.com>
[platform/upstream/binutils.git] / gdb / hppam3-nat.c
1 /* Low level interface to HP800 running mach 4.0.
2    Copyright (C) 1995 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
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.
10
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.
15
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.  */
20
21 #include "defs.h"
22 #include "inferior.h"
23 #include "floatformat.h"
24
25 #include <stdio.h>
26
27 #include <mach.h>
28 #include <mach/message.h>
29 #include <mach/exception.h>
30 #include <mach_error.h>
31
32 #include <target.h>
33
34 /*
35  * Fetch inferiors registers for gdb.
36  * REGNO specifies which (as gdb views it) register, -1 for all.
37  */
38
39 void
40 fetch_inferior_registers (regno)
41      int regno;
42 {
43   kern_return_t ret;
44   thread_state_data_t state;
45   unsigned int stateCnt = TRACE_FLAVOR_SIZE;
46   int index;
47
48   if (!MACH_PORT_VALID (current_thread))
49     error ("fetch inferior registers: Invalid thread");
50
51   if (must_suspend_thread)
52     setup_thread (current_thread, 1);
53
54   ret = thread_get_state (current_thread,
55                           TRACE_FLAVOR,
56                           state,
57                           &stateCnt);
58
59   if (ret != KERN_SUCCESS)
60     warning ("fetch_inferior_registers: %s ",
61              mach_error_string (ret));
62   else
63     {
64       for (index = 0; index < NUM_REGS; index++)
65         supply_register (index, (void *) &state[index]);
66     }
67
68   if (must_suspend_thread)
69     setup_thread (current_thread, 0);
70 }
71 \f
72 /* Store our register values back into the inferior.
73  * If REGNO is -1, do this for all registers.
74  * Otherwise, REGNO specifies which register
75  *
76  * On mach3 all registers are always saved in one call.
77  */
78 void
79 store_inferior_registers (regno)
80      int regno;
81 {
82   kern_return_t ret;
83   thread_state_data_t state;
84   unsigned int stateCnt = TRACE_FLAVOR_SIZE;
85   register int index;
86
87   if (!MACH_PORT_VALID (current_thread))
88     error ("store inferior registers: Invalid thread");
89
90   if (must_suspend_thread)
91     setup_thread (current_thread, 1);
92
93   /* Fetch the state of the current thread */
94   ret = thread_get_state (current_thread,
95                           TRACE_FLAVOR,
96                           state,
97                           &stateCnt);
98
99   if (ret != KERN_SUCCESS)
100     {
101       warning ("store_inferior_registers (get): %s",
102                mach_error_string (ret));
103       if (must_suspend_thread)
104         setup_thread (current_thread, 0);
105       return;
106     }
107
108
109   /* move gdb's registers to thread's state
110
111    * Since we save all registers anyway, save the ones
112    * that gdb thinks are valid (e.g. ignore the regno
113    * parameter)
114    */
115   if (regno > 0 && regno < NUM_REGS)
116     {
117       memcpy (&state[regno], &registers[REGISTER_BYTE (regno)],
118               REGISTER_RAW_SIZE (regno));
119     }
120   else
121     {
122       for (index = 0; index < NUM_REGS; index++)
123         memcpy (&state[index], &registers[REGISTER_BYTE (index)],
124                 REGISTER_RAW_SIZE (index));
125 /*      state[index] = registers[REGISTER_BYTE (index)]; */
126
127     }
128
129   /* Write gdb's current view of register to the thread
130    */
131   ret = thread_set_state (current_thread,
132                           TRACE_FLAVOR,
133                           state,
134                           TRACE_FLAVOR_SIZE);
135
136   if (ret != KERN_SUCCESS)
137     warning ("store_inferior_registers (set): %s",
138              mach_error_string (ret));
139
140   if (must_suspend_thread)
141     setup_thread (current_thread, 0);
142 }