* config/i386/go32.mh: Define CC.
[deliverable/binutils-gdb.git] / gdb / ns32km3-nat.c
CommitLineData
c2d751d5
JK
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., 675 Mass Ave, Cambridge, MA 02139, 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(l1a),REG_F_OFFSET(l2a),REG_F_OFFSET(l3a),
50 REG_F_OFFSET(l4a), REG_F_OFFSET(l5a),REG_F_OFFSET(l6a),REG_F_OFFSET(l7a),
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(l2a),REG_F_OFFSET(l4a),REG_F_OFFSET(l6a)
54 /* @@@ 532 has more double length floating point regs, not accessed currently */
55};
56
57/* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
58 * Caller knows that the regs handled in one transaction are of same size.
59 */
60#define FETCH_REGS(state, regnum, count) \
a6e0dae9
JK
61 memcpy (&registers[REGISTER_BYTE (regnum)], \
62 (char *)state+reg_offset[ regnum ], \
f4f0d174 63 count*REGISTER_SIZE)
c2d751d5
JK
64
65/* Store COUNT contiguous registers to thread STATE starting from REGNUM */
66#define STORE_REGS(state, regnum, count) \
a6e0dae9
JK
67 memcpy ((char *)state+reg_offset[ regnum ], \
68 &registers[REGISTER_BYTE (regnum)], \
f4f0d174 69 count*REGISTER_SIZE)
c2d751d5
JK
70\f
71/* 4.4 bfd support function */
72/* jtv@hut.fi: UNIMPLEMENTED!!!!! */
73
74void
75fetch_core_registers (core_regs, core_reg_size, which)
76 char *core_regs;
77 unsigned int core_reg_size;
78 int which;
79{
80 error ("Unimplemented routine fetch_core_registers called");
81}
82\f
83/*
84 * Fetch inferiors registers for gdb.
85 * REGNO specifies which (as gdb views it) register, -1 for all.
86 */
87
88void
89fetch_inferior_registers (regno)
90 int regno;
91{
92 kern_return_t ret;
93 thread_state_data_t state;
94 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
95 int index;
96
97 if (! MACH_PORT_VALID (current_thread))
98 error ("fetch inferior registers: Invalid thread");
99
100 if (must_suspend_thread)
101 setup_thread (current_thread, 1);
102
103 ret = thread_get_state (current_thread,
104 NS532_COMBINED_STATE,
105 state,
106 &stateCnt);
107
108 if (ret != KERN_SUCCESS)
109 message ("fetch_inferior_registers: %s ",
110 mach_error_string (ret));
111#if 0
112 /* It may be more effective to store validate all of them,
113 * since we fetched them all anyway
114 */
115 else if (regno != -1)
116 supply_register (regno, (char *)state+reg_offset[regno]);
117#endif
118 else
119 {
120 for (index = 0; index < NUM_REGS; index++)
121 supply_register (index, (char *)state+reg_offset[index]);
122 }
123
124 if (must_suspend_thread)
125 setup_thread (current_thread, 0);
126}
127\f
128/* Store our register values back into the inferior.
129 * If REGNO is -1, do this for all registers.
130 * Otherwise, REGNO specifies which register
131 *
132 * On mach3 all registers are always saved in one call.
133 */
134void
135store_inferior_registers (regno)
136 int regno;
137{
138 kern_return_t ret;
139 thread_state_data_t state;
140 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
141 register int index;
142
143 if (! MACH_PORT_VALID (current_thread))
144 error ("store inferior registers: Invalid thread");
145
146 if (must_suspend_thread)
147 setup_thread (current_thread, 1);
148
149 /* Fetch the state of the current thread */
150 ret = thread_get_state (current_thread,
151 NS532_COMBINED_STATE,
152 state,
153 &stateCnt);
154
155 if (ret != KERN_SUCCESS)
156 {
157 message ("store_inferior_registers (get): %s",
158 mach_error_string (ret));
159 if (must_suspend_thread)
160 setup_thread (current_thread, 0);
161 return;
162 }
163
164 /* move gdb's registers to thread's state
165 *
166 * Since we save all registers anyway, save the ones
167 * that gdb thinks are valid (e.g. ignore the regno
168 * parameter)
169 */
170#if 0
171 if (regno != -1)
172 STORE_REGS (state, regno, 1);
173 else
174#endif
175 {
176 for (index = 0; index < NUM_REGS; index++)
177 STORE_REGS (state, index, 1);
178 }
179
180 /* Write gdb's current view of register to the thread
181 */
182 ret = thread_set_state (current_thread,
183 NS532_COMBINED_STATE,
184 state,
185 NS532_COMBINED_STATE_COUNT);
186
187 if (ret != KERN_SUCCESS)
188 message ("store_inferior_registers (set): %s",
189 mach_error_string (ret));
190
191 if (must_suspend_thread)
192 setup_thread (current_thread, 0);
193}
This page took 0.065318 seconds and 4 git commands to generate.