1 // OBSOLETE /* Definitions to make GDB run on a mips box under Mach 3.0
2 // OBSOLETE Copyright 1992, 1993, 1998, 2000, 2001 Free Software Foundation, Inc.
4 // OBSOLETE This file is part of GDB.
6 // OBSOLETE This program is free software; you can redistribute it and/or modify
7 // OBSOLETE it under the terms of the GNU General Public License as published by
8 // OBSOLETE the Free Software Foundation; either version 2 of the License, or
9 // OBSOLETE (at your option) any later version.
11 // OBSOLETE This program is distributed in the hope that it will be useful,
12 // OBSOLETE but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // OBSOLETE MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // OBSOLETE GNU General Public License for more details.
16 // OBSOLETE You should have received a copy of the GNU General Public License
17 // OBSOLETE along with this program; if not, write to the Free Software
18 // OBSOLETE Foundation, Inc., 59 Temple Place - Suite 330,
19 // OBSOLETE Boston, MA 02111-1307, USA. */
21 // OBSOLETE /* Mach specific routines for little endian mips (e.g. pmax)
22 // OBSOLETE * running Mach 3.0
24 // OBSOLETE * Author: Jukka Virtanen <jtv@hut.fi>
27 // OBSOLETE #include "defs.h"
28 // OBSOLETE #include "inferior.h"
29 // OBSOLETE #include "regcache.h"
31 // OBSOLETE #include <stdio.h>
33 // OBSOLETE #include <mach.h>
34 // OBSOLETE #include <mach/message.h>
35 // OBSOLETE #include <mach/exception.h>
36 // OBSOLETE #include <mach_error.h>
38 // OBSOLETE /* Find offsets to thread states at compile time.
39 // OBSOLETE * If your compiler does not grok this, check the hand coded
40 // OBSOLETE * offsets and use them.
45 // OBSOLETE #define REG_OFFSET(reg) (int)(&((struct mips_thread_state *)0)->reg)
46 // OBSOLETE #define CREG_OFFSET(reg) (int)(&((struct mips_float_state *)0)->reg)
47 // OBSOLETE #define EREG_OFFSET(reg) (int)(&((struct mips_exc_state *)0)->reg)
49 // OBSOLETE /* at reg_offset[i] is the offset to the mips_thread_state
50 // OBSOLETE * location where the gdb registers[i] is stored.
52 // OBSOLETE * -1 means mach does not save it anywhere.
54 // OBSOLETE static int reg_offset[] =
56 // OBSOLETE /* zero at v0 v1 */
57 // OBSOLETE -1, REG_OFFSET (r1), REG_OFFSET (r2), REG_OFFSET (r3),
59 // OBSOLETE /* a0 a1 a2 a3 */
60 // OBSOLETE REG_OFFSET (r4), REG_OFFSET (r5), REG_OFFSET (r6), REG_OFFSET (r7),
62 // OBSOLETE /* t0 t1 t2 t3 */
63 // OBSOLETE REG_OFFSET (r8), REG_OFFSET (r9), REG_OFFSET (r10), REG_OFFSET (r11),
65 // OBSOLETE /* t4 t5 t6 t7 */
66 // OBSOLETE REG_OFFSET (r12), REG_OFFSET (r13), REG_OFFSET (r14), REG_OFFSET (r15),
68 // OBSOLETE /* s0 s1 s2 s3 */
69 // OBSOLETE REG_OFFSET (r16), REG_OFFSET (r17), REG_OFFSET (r18), REG_OFFSET (r19),
71 // OBSOLETE /* s4 s5 s6 s7 */
72 // OBSOLETE REG_OFFSET (r20), REG_OFFSET (r21), REG_OFFSET (r22), REG_OFFSET (r23),
74 // OBSOLETE /* t8 t9 k0 k1 */
75 // OBSOLETE REG_OFFSET (r24), REG_OFFSET (r25), REG_OFFSET (r26), REG_OFFSET (r27),
77 // OBSOLETE /* gp sp s8(30) == fp(72) ra */
78 // OBSOLETE REG_OFFSET (r28), REG_OFFSET (r29), REG_OFFSET (r30), REG_OFFSET (r31),
80 // OBSOLETE /* sr(32) PS_REGNUM */
81 // OBSOLETE EREG_OFFSET (coproc_state),
83 // OBSOLETE /* lo(33) hi(34) */
84 // OBSOLETE REG_OFFSET (mdlo), REG_OFFSET (mdhi),
86 // OBSOLETE /* bad(35) cause(36) pc(37) */
87 // OBSOLETE EREG_OFFSET (address), EREG_OFFSET (cause), REG_OFFSET (pc),
89 // OBSOLETE /* f0(38) f1(39) f2(40) f3(41) */
90 // OBSOLETE CREG_OFFSET (r0), CREG_OFFSET (r1), CREG_OFFSET (r2), CREG_OFFSET (r3),
91 // OBSOLETE CREG_OFFSET (r4), CREG_OFFSET (r5), CREG_OFFSET (r6), CREG_OFFSET (r7),
92 // OBSOLETE CREG_OFFSET (r8), CREG_OFFSET (r9), CREG_OFFSET (r10), CREG_OFFSET (r11),
93 // OBSOLETE CREG_OFFSET (r12), CREG_OFFSET (r13), CREG_OFFSET (r14), CREG_OFFSET (r15),
94 // OBSOLETE CREG_OFFSET (r16), CREG_OFFSET (r17), CREG_OFFSET (r18), CREG_OFFSET (r19),
95 // OBSOLETE CREG_OFFSET (r20), CREG_OFFSET (r21), CREG_OFFSET (r22), CREG_OFFSET (r23),
96 // OBSOLETE CREG_OFFSET (r24), CREG_OFFSET (r25), CREG_OFFSET (r26), CREG_OFFSET (r27),
97 // OBSOLETE CREG_OFFSET (r28), CREG_OFFSET (r29), CREG_OFFSET (r30), CREG_OFFSET (r31),
99 // OBSOLETE /* fsr(70) fir(71) fp(72) == s8(30) */
100 // OBSOLETE CREG_OFFSET (csr), CREG_OFFSET (esr), REG_OFFSET (r30)
103 // OBSOLETE /* If the compiler does not grok the above defines */
104 // OBSOLETE static int reg_offset[] =
106 // OBSOLETE /* mach_thread_state offsets: */
107 // OBSOLETE -1, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
108 // OBSOLETE 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120,
109 // OBSOLETE /*sr, lo, hi,addr,cause,pc */
110 // OBSOLETE 8, 124, 128, 4, 0, 132,
111 // OBSOLETE /* mach_float_state offsets: */
112 // OBSOLETE 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60,
113 // OBSOLETE 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124,
114 // OBSOLETE /*fsr,fir */
115 // OBSOLETE 128, 132,
116 // OBSOLETE /* FP_REGNUM pseudo maps to s8==r30 in mach_thread_state */
121 // OBSOLETE /* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
122 // OBSOLETE * Caller knows that the regs handled in one transaction are of same size.
124 // OBSOLETE #define FETCH_REGS(state, regnum, count) \
125 // OBSOLETE memcpy (&deprecated_registers[REGISTER_BYTE (regnum)], \
126 // OBSOLETE (char *)state+reg_offset[ regnum ], \
127 // OBSOLETE count*REGISTER_SIZE)
129 // OBSOLETE /* Store COUNT contiguous registers to thread STATE starting from REGNUM */
130 // OBSOLETE #define STORE_REGS(state, regnum, count) \
131 // OBSOLETE memcpy ((char *)state+reg_offset[ regnum ], \
132 // OBSOLETE &deprecated_registers[REGISTER_BYTE (regnum)], \
133 // OBSOLETE count*REGISTER_SIZE)
135 // OBSOLETE #define REGS_ALL -1
136 // OBSOLETE #define REGS_NORMAL 1
137 // OBSOLETE #define REGS_EXC 2
138 // OBSOLETE #define REGS_COP1 4
140 // OBSOLETE /* Hardware regs that matches FP_REGNUM */
141 // OBSOLETE #define MACH_FP_REGNUM 30
143 // OBSOLETE /* Fech thread's registers. if regno == -1, fetch all regs */
145 // OBSOLETE fetch_inferior_registers (int regno)
147 // OBSOLETE kern_return_t ret;
149 // OBSOLETE thread_state_data_t state;
150 // OBSOLETE struct mips_exc_state exc_state;
152 // OBSOLETE int stateCnt = MIPS_THREAD_STATE_COUNT;
154 // OBSOLETE int which_regs = 0; /* A bit mask */
156 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
157 // OBSOLETE error ("fetch inferior registers: Invalid thread");
159 // OBSOLETE if (regno < -1 || regno >= NUM_REGS)
160 // OBSOLETE error ("invalid register %d supplied to fetch_inferior_registers", regno);
162 // OBSOLETE if (regno == -1)
163 // OBSOLETE which_regs = REGS_ALL;
164 // OBSOLETE else if (regno == ZERO_REGNUM)
166 // OBSOLETE int zero = 0;
167 // OBSOLETE supply_register (ZERO_REGNUM, &zero);
170 // OBSOLETE else if ((ZERO_REGNUM < regno && regno < PS_REGNUM)
171 // OBSOLETE || regno == FP_REGNUM
172 // OBSOLETE || regno == LO_REGNUM
173 // OBSOLETE || regno == HI_REGNUM
174 // OBSOLETE || regno == PC_REGNUM)
175 // OBSOLETE which_regs = REGS_NORMAL;
176 // OBSOLETE else if (FP0_REGNUM <= regno && regno <= FCRIR_REGNUM)
177 // OBSOLETE which_regs = REGS_COP1 | REGS_EXC;
179 // OBSOLETE which_regs = REGS_EXC;
181 // OBSOLETE /* fetch regs saved to mips_thread_state */
182 // OBSOLETE if (which_regs & REGS_NORMAL)
184 // OBSOLETE ret = thread_get_state (current_thread,
185 // OBSOLETE MIPS_THREAD_STATE,
187 // OBSOLETE &stateCnt);
188 // OBSOLETE CHK ("fetch inferior registers: thread_get_state", ret);
190 // OBSOLETE if (which_regs == REGS_NORMAL)
192 // OBSOLETE /* Fetch also FP_REGNUM if fetching MACH_FP_REGNUM and vice versa */
193 // OBSOLETE if (regno == MACH_FP_REGNUM || regno == FP_REGNUM)
195 // OBSOLETE supply_register (FP_REGNUM,
196 // OBSOLETE (char *) state + reg_offset[MACH_FP_REGNUM]);
197 // OBSOLETE supply_register (MACH_FP_REGNUM,
198 // OBSOLETE (char *) state + reg_offset[MACH_FP_REGNUM]);
201 // OBSOLETE supply_register (regno,
202 // OBSOLETE (char *) state + reg_offset[regno]);
206 // OBSOLETE /* ZERO_REGNUM is always zero */
207 // OBSOLETE *(int *) deprecated_registers = 0;
209 // OBSOLETE /* Copy thread saved regs 1..31 to gdb's reg value array
210 // OBSOLETE * Luckily, they are contiquous
212 // OBSOLETE FETCH_REGS (state, 1, 31);
214 // OBSOLETE /* Copy mdlo and mdhi */
215 // OBSOLETE FETCH_REGS (state, LO_REGNUM, 2);
217 // OBSOLETE /* Copy PC */
218 // OBSOLETE FETCH_REGS (state, PC_REGNUM, 1);
220 // OBSOLETE /* Mach 3.0 saves FP to MACH_FP_REGNUM.
221 // OBSOLETE * For some reason gdb wants to assign a pseudo register for it.
223 // OBSOLETE FETCH_REGS (state, FP_REGNUM, 1);
226 // OBSOLETE /* Read exc state. Also read if need to fetch floats */
227 // OBSOLETE if (which_regs & REGS_EXC)
229 // OBSOLETE stateCnt = MIPS_EXC_STATE_COUNT;
230 // OBSOLETE ret = thread_get_state (current_thread,
231 // OBSOLETE MIPS_EXC_STATE,
232 // OBSOLETE (thread_state_t) & exc_state,
233 // OBSOLETE &stateCnt);
234 // OBSOLETE CHK ("fetch inferior regs (exc): thread_get_state", ret);
236 // OBSOLETE /* We need to fetch exc_state to see if the floating
237 // OBSOLETE * state is valid for the thread.
240 // OBSOLETE /* cproc_state: Which coprocessors the thread uses */
241 // OBSOLETE supply_register (PS_REGNUM,
242 // OBSOLETE (char *) &exc_state + reg_offset[PS_REGNUM]);
244 // OBSOLETE if (which_regs == REGS_EXC || which_regs == REGS_ALL)
246 // OBSOLETE supply_register (BADVADDR_REGNUM,
247 // OBSOLETE (char *) &exc_state + reg_offset[BADVADDR_REGNUM]);
249 // OBSOLETE supply_register (CAUSE_REGNUM,
250 // OBSOLETE (char *) &exc_state + reg_offset[CAUSE_REGNUM]);
251 // OBSOLETE if (which_regs == REGS_EXC)
257 // OBSOLETE if (which_regs & REGS_COP1)
259 // OBSOLETE /* If the thread does not have saved COPROC1, set regs to zero */
261 // OBSOLETE if (!(exc_state.coproc_state & MIPS_STATUS_USE_COP1))
262 // OBSOLETE bzero (&deprecated_registers[REGISTER_BYTE (FP0_REGNUM)],
263 // OBSOLETE sizeof (struct mips_float_state));
266 // OBSOLETE stateCnt = MIPS_FLOAT_STATE_COUNT;
267 // OBSOLETE ret = thread_get_state (current_thread,
268 // OBSOLETE MIPS_FLOAT_STATE,
270 // OBSOLETE &stateCnt);
271 // OBSOLETE CHK ("fetch inferior regs (floats): thread_get_state", ret);
273 // OBSOLETE if (regno != -1)
275 // OBSOLETE supply_register (regno,
276 // OBSOLETE (char *) state + reg_offset[regno]);
280 // OBSOLETE FETCH_REGS (state, FP0_REGNUM, 34);
284 // OBSOLETE /* All registers are valid, if not returned yet */
285 // OBSOLETE deprecated_registers_fetched ();
288 // OBSOLETE /* Store gdb's view of registers to the thread.
289 // OBSOLETE * All registers are always valid when entering here.
290 // OBSOLETE * @@ ahem, maybe that is too strict, we could validate the necessary ones
293 // OBSOLETE * Hmm. It seems that gdb set $reg=value command first reads everything,
294 // OBSOLETE * then sets the reg and then stores everything. -> we must make sure
295 // OBSOLETE * that the immutable registers are not changed by reading them first.
299 // OBSOLETE store_inferior_registers (register int regno)
301 // OBSOLETE thread_state_data_t state;
302 // OBSOLETE kern_return_t ret;
304 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
305 // OBSOLETE error ("store inferior registers: Invalid thread");
307 // OBSOLETE /* Check for read only regs.
308 // OBSOLETE * @@ If some of these is can be changed, fix this
310 // OBSOLETE if (regno == ZERO_REGNUM ||
311 // OBSOLETE regno == PS_REGNUM ||
312 // OBSOLETE regno == BADVADDR_REGNUM ||
313 // OBSOLETE regno == CAUSE_REGNUM ||
314 // OBSOLETE regno == FCRIR_REGNUM)
316 // OBSOLETE message ("You can not alter read-only register `%s'",
317 // OBSOLETE REGISTER_NAME (regno));
318 // OBSOLETE fetch_inferior_registers (regno);
322 // OBSOLETE if (regno == -1)
324 // OBSOLETE /* Don't allow these to change */
326 // OBSOLETE /* ZERO_REGNUM */
327 // OBSOLETE *(int *) deprecated_registers = 0;
329 // OBSOLETE fetch_inferior_registers (PS_REGNUM);
330 // OBSOLETE fetch_inferior_registers (BADVADDR_REGNUM);
331 // OBSOLETE fetch_inferior_registers (CAUSE_REGNUM);
332 // OBSOLETE fetch_inferior_registers (FCRIR_REGNUM);
335 // OBSOLETE if (regno == -1 || (ZERO_REGNUM < regno && regno <= PC_REGNUM))
338 // OBSOLETE /* Mach 3.0 saves thread's FP to MACH_FP_REGNUM.
339 // OBSOLETE * GDB wants assigns a pseudo register FP_REGNUM for frame pointer.
341 // OBSOLETE * @@@ Here I assume (!) that gdb's FP has the value that
342 // OBSOLETE * should go to threads frame pointer. If not true, this
343 // OBSOLETE * fails badly!!!!!
345 // OBSOLETE memcpy (&deprecated_registers[REGISTER_BYTE (MACH_FP_REGNUM)],
346 // OBSOLETE &deprecated_registers[REGISTER_BYTE (FP_REGNUM)],
347 // OBSOLETE REGISTER_RAW_SIZE (FP_REGNUM));
350 // OBSOLETE /* Save gdb's regs 1..31 to thread saved regs 1..31
351 // OBSOLETE * Luckily, they are contiquous
353 // OBSOLETE STORE_REGS (state, 1, 31);
355 // OBSOLETE /* Save mdlo, mdhi */
356 // OBSOLETE STORE_REGS (state, LO_REGNUM, 2);
358 // OBSOLETE /* Save PC */
359 // OBSOLETE STORE_REGS (state, PC_REGNUM, 1);
361 // OBSOLETE ret = thread_set_state (current_thread,
362 // OBSOLETE MIPS_THREAD_STATE,
364 // OBSOLETE MIPS_FLOAT_STATE_COUNT);
365 // OBSOLETE CHK ("store inferior regs : thread_set_state", ret);
368 // OBSOLETE if (regno == -1 || regno >= FP0_REGNUM)
370 // OBSOLETE /* If thread has floating state, save it */
371 // OBSOLETE if (read_register (PS_REGNUM) & MIPS_STATUS_USE_COP1)
373 // OBSOLETE /* Do NOT save FCRIR_REGNUM */
374 // OBSOLETE STORE_REGS (state, FP0_REGNUM, 33);
376 // OBSOLETE ret = thread_set_state (current_thread,
377 // OBSOLETE MIPS_FLOAT_STATE,
379 // OBSOLETE MIPS_FLOAT_STATE_COUNT);
380 // OBSOLETE CHK ("store inferior registers (floats): thread_set_state", ret);
382 // OBSOLETE else if (regno != -1)
384 // OBSOLETE ("Thread does not use floating point unit, floating regs not saved");
This page took 0.045127 seconds and 4 git commands to generate.