import gdb-19990422 snapshot
[deliverable/binutils-gdb.git] / gdb / ns32km3-nat.c
CommitLineData
c906108c
SS
1/* Low level interface to ns532 running mach 3.0.
2 Copyright (C) 1992 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "inferior.h"
22
23#include <stdio.h>
24
25#include <mach.h>
26#include <mach/message.h>
27#include <mach/exception.h>
28#include <mach_error.h>
29
30#define private static
31
32\f
33/* Find offsets to thread states at compile time.
34 * If your compiler does not grok this, calculate offsets
35 * offsets yourself and use them (or get a compatible compiler :-)
36 */
37
38#define REG_N_OFFSET(reg) (int)(&((struct ns532_combined_state *)0)->ts.reg)
39#define REG_F_OFFSET(reg) (int)(&((struct ns532_combined_state *)0)->fs.reg)
40
41/* at reg_offset[i] is the offset to the ns532_combined_state
42 * location where the gdb registers[i] is stored.
43 */
44
45static int reg_offset[] =
46{
47 REG_N_OFFSET(r0), REG_N_OFFSET(r1), REG_N_OFFSET(r2), REG_N_OFFSET(r3),
48 REG_N_OFFSET(r4), REG_N_OFFSET(r5), REG_N_OFFSET(r6), REG_N_OFFSET(r7),
49 REG_F_OFFSET(l0a), REG_F_OFFSET(l0b),REG_F_OFFSET(l2a),REG_F_OFFSET(l2b),
50 REG_F_OFFSET(l4a), REG_F_OFFSET(l4b),REG_F_OFFSET(l6a),REG_F_OFFSET(l6b),
51 REG_N_OFFSET(sp), REG_N_OFFSET(fp), REG_N_OFFSET(pc), REG_N_OFFSET(psr),
52 REG_F_OFFSET(fsr),
53 REG_F_OFFSET(l0a), REG_F_OFFSET(l1a),REG_F_OFFSET(l2a),REG_F_OFFSET(l3a),
54 REG_F_OFFSET(l4a), REG_F_OFFSET(l5a),REG_F_OFFSET(l6a),REG_F_OFFSET(l7a),
55};
56
57#define REG_ADDRESS(state,regnum) ((char *)(state)+reg_offset[regnum])
58
59/* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
60 * Caller knows that the regs handled in one transaction are of same size.
61 */
62#define FETCH_REGS(state, regnum, count) \
63 memcpy (&registers[REGISTER_BYTE (regnum)], \
64 (char *)state+reg_offset[ regnum ], \
65 count*REGISTER_SIZE)
66
67/* Store COUNT contiguous registers to thread STATE starting from REGNUM */
68#define STORE_REGS(state, regnum, count) \
69 memcpy ((char *)state+reg_offset[ regnum ], \
70 &registers[REGISTER_BYTE (regnum)], \
71 count*REGISTER_SIZE)
72\f
73/*
74 * Fetch inferiors registers for gdb.
75 * REGNO specifies which (as gdb views it) register, -1 for all.
76 */
77
78void
79fetch_inferior_registers (regno)
80 int regno;
81{
82 kern_return_t ret;
83 thread_state_data_t state;
84 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
85 int index;
86
87 if (! MACH_PORT_VALID (current_thread))
88 error ("fetch inferior registers: Invalid thread");
89
90 if (must_suspend_thread)
91 setup_thread (current_thread, 1);
92
93 ret = thread_get_state (current_thread,
94 NS532_COMBINED_STATE,
95 state,
96 &stateCnt);
97
98 if (ret != KERN_SUCCESS)
99 warning ("fetch_inferior_registers: %s ",
100 mach_error_string (ret));
101#if 0
102 /* It may be more effective to store validate all of them,
103 * since we fetched them all anyway
104 */
105 else if (regno != -1)
106 supply_register (regno, (char *)state+reg_offset[regno]);
107#endif
108 else
109 {
110 for (index = 0; index < NUM_REGS; index++)
111 supply_register (index, (char *)state+reg_offset[index]);
112 }
113
114 if (must_suspend_thread)
115 setup_thread (current_thread, 0);
116}
117\f
118/* Store our register values back into the inferior.
119 * If REGNO is -1, do this for all registers.
120 * Otherwise, REGNO specifies which register
121 *
122 * On mach3 all registers are always saved in one call.
123 */
124void
125store_inferior_registers (regno)
126 int regno;
127{
128 kern_return_t ret;
129 thread_state_data_t state;
130 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
131 register int index;
132
133 if (! MACH_PORT_VALID (current_thread))
134 error ("store inferior registers: Invalid thread");
135
136 if (must_suspend_thread)
137 setup_thread (current_thread, 1);
138
139 /* Fetch the state of the current thread */
140 ret = thread_get_state (current_thread,
141 NS532_COMBINED_STATE,
142 state,
143 &stateCnt);
144
145 if (ret != KERN_SUCCESS)
146 {
147 warning ("store_inferior_registers (get): %s",
148 mach_error_string (ret));
149 if (must_suspend_thread)
150 setup_thread (current_thread, 0);
151 return;
152 }
153
154 /* move gdb's registers to thread's state
155 *
156 * Since we save all registers anyway, save the ones
157 * that gdb thinks are valid (e.g. ignore the regno
158 * parameter)
159 */
160#if 0
161 if (regno != -1)
162 STORE_REGS (state, regno, 1);
163 else
164#endif
165 {
166 for (index = 0; index < NUM_REGS; index++)
167 STORE_REGS (state, index, 1);
168 }
169
170 /* Write gdb's current view of register to the thread
171 */
172 ret = thread_set_state (current_thread,
173 NS532_COMBINED_STATE,
174 state,
175 NS532_COMBINED_STATE_COUNT);
176
177 if (ret != KERN_SUCCESS)
178 warning ("store_inferior_registers (set): %s",
179 mach_error_string (ret));
180
181 if (must_suspend_thread)
182 setup_thread (current_thread, 0);
183}
This page took 0.030463 seconds and 4 git commands to generate.