1 /* Low level interface to ns532 running mach 3.0.
2 Copyright (C) 1992 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. */
26 #include <mach/message.h>
27 #include <mach/exception.h>
28 #include <mach_error.h>
30 #define private static
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 :-)
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)
41 /* at reg_offset[i] is the offset to the ns532_combined_state
42 * location where the gdb registers[i] is stored.
45 static int reg_offset[] =
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),
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 */
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.
60 #define FETCH_REGS(state, regnum, count) \
61 memcpy (®isters[REGISTER_BYTE (regnum)], \
62 (char *)state+reg_offset[ regnum ], \
65 /* Store COUNT contiguous registers to thread STATE starting from REGNUM */
66 #define STORE_REGS(state, regnum, count) \
67 memcpy ((char *)state+reg_offset[ regnum ], \
68 ®isters[REGISTER_BYTE (regnum)], \
72 * Fetch inferiors registers for gdb.
73 * REGNO specifies which (as gdb views it) register, -1 for all.
77 fetch_inferior_registers (regno)
81 thread_state_data_t state;
82 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
85 if (! MACH_PORT_VALID (current_thread))
86 error ("fetch inferior registers: Invalid thread");
88 if (must_suspend_thread)
89 setup_thread (current_thread, 1);
91 ret = thread_get_state (current_thread,
96 if (ret != KERN_SUCCESS)
97 message ("fetch_inferior_registers: %s ",
98 mach_error_string (ret));
100 /* It may be more effective to store validate all of them,
101 * since we fetched them all anyway
103 else if (regno != -1)
104 supply_register (regno, (char *)state+reg_offset[regno]);
108 for (index = 0; index < NUM_REGS; index++)
109 supply_register (index, (char *)state+reg_offset[index]);
112 if (must_suspend_thread)
113 setup_thread (current_thread, 0);
116 /* Store our register values back into the inferior.
117 * If REGNO is -1, do this for all registers.
118 * Otherwise, REGNO specifies which register
120 * On mach3 all registers are always saved in one call.
123 store_inferior_registers (regno)
127 thread_state_data_t state;
128 unsigned int stateCnt = NS532_COMBINED_STATE_COUNT;
131 if (! MACH_PORT_VALID (current_thread))
132 error ("store inferior registers: Invalid thread");
134 if (must_suspend_thread)
135 setup_thread (current_thread, 1);
137 /* Fetch the state of the current thread */
138 ret = thread_get_state (current_thread,
139 NS532_COMBINED_STATE,
143 if (ret != KERN_SUCCESS)
145 message ("store_inferior_registers (get): %s",
146 mach_error_string (ret));
147 if (must_suspend_thread)
148 setup_thread (current_thread, 0);
152 /* move gdb's registers to thread's state
154 * Since we save all registers anyway, save the ones
155 * that gdb thinks are valid (e.g. ignore the regno
160 STORE_REGS (state, regno, 1);
164 for (index = 0; index < NUM_REGS; index++)
165 STORE_REGS (state, index, 1);
168 /* Write gdb's current view of register to the thread
170 ret = thread_set_state (current_thread,
171 NS532_COMBINED_STATE,
173 NS532_COMBINED_STATE_COUNT);
175 if (ret != KERN_SUCCESS)
176 message ("store_inferior_registers (set): %s",
177 mach_error_string (ret));
179 if (must_suspend_thread)
180 setup_thread (current_thread, 0);