Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Low level interface to ns532 running mach 3.0. |
b6ba6518 | 2 | Copyright 1992, 1993, 1998, 2000, 2001 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "inferior.h" | |
4e052eda | 23 | #include "regcache.h" |
c906108c SS |
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 | #define private static | |
c906108c | 33 | \f |
c5aa993b | 34 | |
c906108c SS |
35 | /* Find offsets to thread states at compile time. |
36 | * If your compiler does not grok this, calculate offsets | |
37 | * offsets yourself and use them (or get a compatible compiler :-) | |
38 | */ | |
39 | ||
40 | #define REG_N_OFFSET(reg) (int)(&((struct ns532_combined_state *)0)->ts.reg) | |
41 | #define REG_F_OFFSET(reg) (int)(&((struct ns532_combined_state *)0)->fs.reg) | |
42 | ||
43 | /* at reg_offset[i] is the offset to the ns532_combined_state | |
44 | * location where the gdb registers[i] is stored. | |
45 | */ | |
46 | ||
c5aa993b | 47 | static int reg_offset[] = |
c906108c | 48 | { |
c5aa993b JM |
49 | REG_N_OFFSET (r0), REG_N_OFFSET (r1), REG_N_OFFSET (r2), REG_N_OFFSET (r3), |
50 | REG_N_OFFSET (r4), REG_N_OFFSET (r5), REG_N_OFFSET (r6), REG_N_OFFSET (r7), | |
51 | REG_F_OFFSET (l0a), REG_F_OFFSET (l0b), REG_F_OFFSET (l2a), REG_F_OFFSET (l2b), | |
52 | REG_F_OFFSET (l4a), REG_F_OFFSET (l4b), REG_F_OFFSET (l6a), REG_F_OFFSET (l6b), | |
53 | REG_N_OFFSET (sp), REG_N_OFFSET (fp), REG_N_OFFSET (pc), REG_N_OFFSET (psr), | |
54 | REG_F_OFFSET (fsr), | |
55 | REG_F_OFFSET (l0a), REG_F_OFFSET (l1a), REG_F_OFFSET (l2a), REG_F_OFFSET (l3a), | |
56 | REG_F_OFFSET (l4a), REG_F_OFFSET (l5a), REG_F_OFFSET (l6a), REG_F_OFFSET (l7a), | |
c906108c SS |
57 | }; |
58 | ||
59 | #define REG_ADDRESS(state,regnum) ((char *)(state)+reg_offset[regnum]) | |
60 | ||
61 | /* Fetch COUNT contiguous registers from thread STATE starting from REGNUM | |
62 | * Caller knows that the regs handled in one transaction are of same size. | |
63 | */ | |
64 | #define FETCH_REGS(state, regnum, count) \ | |
65 | memcpy (®isters[REGISTER_BYTE (regnum)], \ | |
66 | (char *)state+reg_offset[ regnum ], \ | |
67 | count*REGISTER_SIZE) | |
68 | ||
69 | /* Store COUNT contiguous registers to thread STATE starting from REGNUM */ | |
70 | #define STORE_REGS(state, regnum, count) \ | |
71 | memcpy ((char *)state+reg_offset[ regnum ], \ | |
72 | ®isters[REGISTER_BYTE (regnum)], \ | |
73 | count*REGISTER_SIZE) | |
74 | \f | |
75 | /* | |
76 | * Fetch inferiors registers for gdb. | |
77 | * REGNO specifies which (as gdb views it) register, -1 for all. | |
78 | */ | |
79 | ||
80 | void | |
fba45db2 | 81 | fetch_inferior_registers (int regno) |
c906108c SS |
82 | { |
83 | kern_return_t ret; | |
84 | thread_state_data_t state; | |
85 | unsigned int stateCnt = NS532_COMBINED_STATE_COUNT; | |
86 | int index; | |
c5aa993b JM |
87 | |
88 | if (!MACH_PORT_VALID (current_thread)) | |
c906108c SS |
89 | error ("fetch inferior registers: Invalid thread"); |
90 | ||
91 | if (must_suspend_thread) | |
92 | setup_thread (current_thread, 1); | |
93 | ||
94 | ret = thread_get_state (current_thread, | |
95 | NS532_COMBINED_STATE, | |
96 | state, | |
97 | &stateCnt); | |
98 | ||
99 | if (ret != KERN_SUCCESS) | |
100 | warning ("fetch_inferior_registers: %s ", | |
101 | mach_error_string (ret)); | |
102 | #if 0 | |
103 | /* It may be more effective to store validate all of them, | |
104 | * since we fetched them all anyway | |
105 | */ | |
106 | else if (regno != -1) | |
c5aa993b | 107 | supply_register (regno, (char *) state + reg_offset[regno]); |
c906108c SS |
108 | #endif |
109 | else | |
110 | { | |
c5aa993b JM |
111 | for (index = 0; index < NUM_REGS; index++) |
112 | supply_register (index, (char *) state + reg_offset[index]); | |
c906108c SS |
113 | } |
114 | ||
115 | if (must_suspend_thread) | |
116 | setup_thread (current_thread, 0); | |
117 | } | |
118 | \f | |
119 | /* Store our register values back into the inferior. | |
120 | * If REGNO is -1, do this for all registers. | |
121 | * Otherwise, REGNO specifies which register | |
122 | * | |
123 | * On mach3 all registers are always saved in one call. | |
124 | */ | |
125 | void | |
fba45db2 | 126 | store_inferior_registers (int regno) |
c906108c SS |
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 | ||
c5aa993b | 133 | if (!MACH_PORT_VALID (current_thread)) |
c906108c SS |
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 | ||
c5aa993b | 145 | if (ret != KERN_SUCCESS) |
c906108c SS |
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 | |
c5aa993b | 155 | |
c906108c SS |
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 | { | |
c5aa993b | 166 | for (index = 0; index < NUM_REGS; index++) |
c906108c SS |
167 | STORE_REGS (state, index, 1); |
168 | } | |
c5aa993b | 169 | |
c906108c SS |
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); | |
c5aa993b | 176 | |
c906108c SS |
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 | } |