mn10300-tdep.c revision 1.6 1 1.1 christos /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2 1.1 christos
3 1.6 christos Copyright (C) 1996-2016 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "defs.h"
21 1.1 christos #include "arch-utils.h"
22 1.1 christos #include "dis-asm.h"
23 1.1 christos #include "gdbtypes.h"
24 1.1 christos #include "regcache.h"
25 1.1 christos #include "gdbcore.h" /* For write_memory_unsigned_integer. */
26 1.1 christos #include "value.h"
27 1.1 christos #include "frame.h"
28 1.1 christos #include "frame-unwind.h"
29 1.1 christos #include "frame-base.h"
30 1.1 christos #include "symtab.h"
31 1.1 christos #include "dwarf2-frame.h"
32 1.1 christos #include "osabi.h"
33 1.1 christos #include "infcall.h"
34 1.1 christos #include "prologue-value.h"
35 1.1 christos #include "target.h"
36 1.1 christos
37 1.1 christos #include "mn10300-tdep.h"
38 1.1 christos
39 1.1 christos
40 1.1 christos /* The am33-2 has 64 registers. */
41 1.1 christos #define MN10300_MAX_NUM_REGS 64
42 1.1 christos
43 1.1 christos /* This structure holds the results of a prologue analysis. */
44 1.1 christos struct mn10300_prologue
45 1.1 christos {
46 1.1 christos /* The architecture for which we generated this prologue info. */
47 1.1 christos struct gdbarch *gdbarch;
48 1.1 christos
49 1.1 christos /* The offset from the frame base to the stack pointer --- always
50 1.1 christos zero or negative.
51 1.1 christos
52 1.1 christos Calling this a "size" is a bit misleading, but given that the
53 1.1 christos stack grows downwards, using offsets for everything keeps one
54 1.1 christos from going completely sign-crazy: you never change anything's
55 1.1 christos sign for an ADD instruction; always change the second operand's
56 1.1 christos sign for a SUB instruction; and everything takes care of
57 1.1 christos itself. */
58 1.1 christos int frame_size;
59 1.1 christos
60 1.1 christos /* Non-zero if this function has initialized the frame pointer from
61 1.1 christos the stack pointer, zero otherwise. */
62 1.1 christos int has_frame_ptr;
63 1.1 christos
64 1.1 christos /* If has_frame_ptr is non-zero, this is the offset from the frame
65 1.1 christos base to where the frame pointer points. This is always zero or
66 1.1 christos negative. */
67 1.1 christos int frame_ptr_offset;
68 1.1 christos
69 1.1 christos /* The address of the first instruction at which the frame has been
70 1.1 christos set up and the arguments are where the debug info says they are
71 1.1 christos --- as best as we can tell. */
72 1.1 christos CORE_ADDR prologue_end;
73 1.1 christos
74 1.1 christos /* reg_offset[R] is the offset from the CFA at which register R is
75 1.1 christos saved, or 1 if register R has not been saved. (Real values are
76 1.1 christos always zero or negative.) */
77 1.1 christos int reg_offset[MN10300_MAX_NUM_REGS];
78 1.1 christos };
79 1.1 christos
80 1.1 christos
81 1.1 christos /* Compute the alignment required by a type. */
82 1.1 christos
83 1.1 christos static int
84 1.1 christos mn10300_type_align (struct type *type)
85 1.1 christos {
86 1.1 christos int i, align = 1;
87 1.1 christos
88 1.1 christos switch (TYPE_CODE (type))
89 1.1 christos {
90 1.1 christos case TYPE_CODE_INT:
91 1.1 christos case TYPE_CODE_ENUM:
92 1.1 christos case TYPE_CODE_SET:
93 1.1 christos case TYPE_CODE_RANGE:
94 1.1 christos case TYPE_CODE_CHAR:
95 1.1 christos case TYPE_CODE_BOOL:
96 1.1 christos case TYPE_CODE_FLT:
97 1.1 christos case TYPE_CODE_PTR:
98 1.1 christos case TYPE_CODE_REF:
99 1.1 christos return TYPE_LENGTH (type);
100 1.1 christos
101 1.1 christos case TYPE_CODE_COMPLEX:
102 1.1 christos return TYPE_LENGTH (type) / 2;
103 1.1 christos
104 1.1 christos case TYPE_CODE_STRUCT:
105 1.1 christos case TYPE_CODE_UNION:
106 1.1 christos for (i = 0; i < TYPE_NFIELDS (type); i++)
107 1.1 christos {
108 1.1 christos int falign = mn10300_type_align (TYPE_FIELD_TYPE (type, i));
109 1.1 christos while (align < falign)
110 1.1 christos align <<= 1;
111 1.1 christos }
112 1.1 christos return align;
113 1.1 christos
114 1.1 christos case TYPE_CODE_ARRAY:
115 1.1 christos /* HACK! Structures containing arrays, even small ones, are not
116 1.1 christos elligible for returning in registers. */
117 1.1 christos return 256;
118 1.1 christos
119 1.1 christos case TYPE_CODE_TYPEDEF:
120 1.1 christos return mn10300_type_align (check_typedef (type));
121 1.1 christos
122 1.1 christos default:
123 1.1 christos internal_error (__FILE__, __LINE__, _("bad switch"));
124 1.1 christos }
125 1.1 christos }
126 1.1 christos
127 1.1 christos /* Should call_function allocate stack space for a struct return? */
128 1.1 christos static int
129 1.1 christos mn10300_use_struct_convention (struct type *type)
130 1.1 christos {
131 1.1 christos /* Structures bigger than a pair of words can't be returned in
132 1.1 christos registers. */
133 1.1 christos if (TYPE_LENGTH (type) > 8)
134 1.1 christos return 1;
135 1.1 christos
136 1.1 christos switch (TYPE_CODE (type))
137 1.1 christos {
138 1.1 christos case TYPE_CODE_STRUCT:
139 1.1 christos case TYPE_CODE_UNION:
140 1.1 christos /* Structures with a single field are handled as the field
141 1.1 christos itself. */
142 1.1 christos if (TYPE_NFIELDS (type) == 1)
143 1.1 christos return mn10300_use_struct_convention (TYPE_FIELD_TYPE (type, 0));
144 1.1 christos
145 1.1 christos /* Structures with word or double-word size are passed in memory, as
146 1.1 christos long as they require at least word alignment. */
147 1.1 christos if (mn10300_type_align (type) >= 4)
148 1.1 christos return 0;
149 1.1 christos
150 1.1 christos return 1;
151 1.1 christos
152 1.1 christos /* Arrays are addressable, so they're never returned in
153 1.1 christos registers. This condition can only hold when the array is
154 1.1 christos the only field of a struct or union. */
155 1.1 christos case TYPE_CODE_ARRAY:
156 1.1 christos return 1;
157 1.1 christos
158 1.1 christos case TYPE_CODE_TYPEDEF:
159 1.1 christos return mn10300_use_struct_convention (check_typedef (type));
160 1.1 christos
161 1.1 christos default:
162 1.1 christos return 0;
163 1.1 christos }
164 1.1 christos }
165 1.1 christos
166 1.1 christos static void
167 1.1 christos mn10300_store_return_value (struct gdbarch *gdbarch, struct type *type,
168 1.1 christos struct regcache *regcache, const gdb_byte *valbuf)
169 1.1 christos {
170 1.1 christos int len = TYPE_LENGTH (type);
171 1.1 christos int reg, regsz;
172 1.1 christos
173 1.1 christos if (TYPE_CODE (type) == TYPE_CODE_PTR)
174 1.1 christos reg = 4;
175 1.1 christos else
176 1.1 christos reg = 0;
177 1.1 christos
178 1.1 christos regsz = register_size (gdbarch, reg);
179 1.1 christos
180 1.1 christos if (len <= regsz)
181 1.1 christos regcache_raw_write_part (regcache, reg, 0, len, valbuf);
182 1.1 christos else if (len <= 2 * regsz)
183 1.1 christos {
184 1.1 christos regcache_raw_write (regcache, reg, valbuf);
185 1.1 christos gdb_assert (regsz == register_size (gdbarch, reg + 1));
186 1.1 christos regcache_raw_write_part (regcache, reg+1, 0,
187 1.1 christos len - regsz, valbuf + regsz);
188 1.1 christos }
189 1.1 christos else
190 1.1 christos internal_error (__FILE__, __LINE__,
191 1.1 christos _("Cannot store return value %d bytes long."), len);
192 1.1 christos }
193 1.1 christos
194 1.1 christos static void
195 1.1 christos mn10300_extract_return_value (struct gdbarch *gdbarch, struct type *type,
196 1.1 christos struct regcache *regcache, void *valbuf)
197 1.1 christos {
198 1.1 christos gdb_byte buf[MAX_REGISTER_SIZE];
199 1.1 christos int len = TYPE_LENGTH (type);
200 1.1 christos int reg, regsz;
201 1.1 christos
202 1.1 christos if (TYPE_CODE (type) == TYPE_CODE_PTR)
203 1.1 christos reg = 4;
204 1.1 christos else
205 1.1 christos reg = 0;
206 1.1 christos
207 1.1 christos regsz = register_size (gdbarch, reg);
208 1.1 christos if (len <= regsz)
209 1.1 christos {
210 1.1 christos regcache_raw_read (regcache, reg, buf);
211 1.1 christos memcpy (valbuf, buf, len);
212 1.1 christos }
213 1.1 christos else if (len <= 2 * regsz)
214 1.1 christos {
215 1.1 christos regcache_raw_read (regcache, reg, buf);
216 1.1 christos memcpy (valbuf, buf, regsz);
217 1.1 christos gdb_assert (regsz == register_size (gdbarch, reg + 1));
218 1.1 christos regcache_raw_read (regcache, reg + 1, buf);
219 1.1 christos memcpy ((char *) valbuf + regsz, buf, len - regsz);
220 1.1 christos }
221 1.1 christos else
222 1.1 christos internal_error (__FILE__, __LINE__,
223 1.1 christos _("Cannot extract return value %d bytes long."), len);
224 1.1 christos }
225 1.1 christos
226 1.1 christos /* Determine, for architecture GDBARCH, how a return value of TYPE
227 1.1 christos should be returned. If it is supposed to be returned in registers,
228 1.1 christos and READBUF is non-zero, read the appropriate value from REGCACHE,
229 1.1 christos and copy it into READBUF. If WRITEBUF is non-zero, write the value
230 1.1 christos from WRITEBUF into REGCACHE. */
231 1.1 christos
232 1.1 christos static enum return_value_convention
233 1.1 christos mn10300_return_value (struct gdbarch *gdbarch, struct value *function,
234 1.1 christos struct type *type, struct regcache *regcache,
235 1.1 christos gdb_byte *readbuf, const gdb_byte *writebuf)
236 1.1 christos {
237 1.1 christos if (mn10300_use_struct_convention (type))
238 1.1 christos return RETURN_VALUE_STRUCT_CONVENTION;
239 1.1 christos
240 1.1 christos if (readbuf)
241 1.1 christos mn10300_extract_return_value (gdbarch, type, regcache, readbuf);
242 1.1 christos if (writebuf)
243 1.1 christos mn10300_store_return_value (gdbarch, type, regcache, writebuf);
244 1.1 christos
245 1.1 christos return RETURN_VALUE_REGISTER_CONVENTION;
246 1.1 christos }
247 1.1 christos
248 1.1 christos static char *
249 1.1 christos register_name (int reg, char **regs, long sizeof_regs)
250 1.1 christos {
251 1.1 christos if (reg < 0 || reg >= sizeof_regs / sizeof (regs[0]))
252 1.1 christos return NULL;
253 1.1 christos else
254 1.1 christos return regs[reg];
255 1.1 christos }
256 1.1 christos
257 1.1 christos static const char *
258 1.1 christos mn10300_generic_register_name (struct gdbarch *gdbarch, int reg)
259 1.1 christos {
260 1.1 christos static char *regs[] =
261 1.1 christos { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
262 1.1 christos "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
263 1.1 christos "", "", "", "", "", "", "", "",
264 1.1 christos "", "", "", "", "", "", "", "fp"
265 1.1 christos };
266 1.1 christos return register_name (reg, regs, sizeof regs);
267 1.1 christos }
268 1.1 christos
269 1.1 christos
270 1.1 christos static const char *
271 1.1 christos am33_register_name (struct gdbarch *gdbarch, int reg)
272 1.1 christos {
273 1.1 christos static char *regs[] =
274 1.1 christos { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
275 1.1 christos "sp", "pc", "mdr", "psw", "lir", "lar", "",
276 1.1 christos "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
277 1.1 christos "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""
278 1.1 christos };
279 1.1 christos return register_name (reg, regs, sizeof regs);
280 1.1 christos }
281 1.1 christos
282 1.1 christos static const char *
283 1.1 christos am33_2_register_name (struct gdbarch *gdbarch, int reg)
284 1.1 christos {
285 1.1 christos static char *regs[] =
286 1.1 christos {
287 1.1 christos "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
288 1.1 christos "sp", "pc", "mdr", "psw", "lir", "lar", "mdrq", "r0",
289 1.1 christos "r1", "r2", "r3", "r4", "r5", "r6", "r7", "ssp",
290 1.1 christos "msp", "usp", "mcrh", "mcrl", "mcvf", "fpcr", "", "",
291 1.1 christos "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
292 1.1 christos "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15",
293 1.1 christos "fs16", "fs17", "fs18", "fs19", "fs20", "fs21", "fs22", "fs23",
294 1.1 christos "fs24", "fs25", "fs26", "fs27", "fs28", "fs29", "fs30", "fs31"
295 1.1 christos };
296 1.1 christos return register_name (reg, regs, sizeof regs);
297 1.1 christos }
298 1.1 christos
299 1.1 christos static struct type *
300 1.1 christos mn10300_register_type (struct gdbarch *gdbarch, int reg)
301 1.1 christos {
302 1.1 christos return builtin_type (gdbarch)->builtin_int;
303 1.1 christos }
304 1.1 christos
305 1.1 christos static CORE_ADDR
306 1.1 christos mn10300_read_pc (struct regcache *regcache)
307 1.1 christos {
308 1.1 christos ULONGEST val;
309 1.1 christos regcache_cooked_read_unsigned (regcache, E_PC_REGNUM, &val);
310 1.1 christos return val;
311 1.1 christos }
312 1.1 christos
313 1.1 christos static void
314 1.1 christos mn10300_write_pc (struct regcache *regcache, CORE_ADDR val)
315 1.1 christos {
316 1.1 christos regcache_cooked_write_unsigned (regcache, E_PC_REGNUM, val);
317 1.1 christos }
318 1.1 christos
319 1.1 christos /* The breakpoint instruction must be the same size as the smallest
320 1.1 christos instruction in the instruction set.
321 1.1 christos
322 1.1 christos The Matsushita mn10x00 processors have single byte instructions
323 1.1 christos so we need a single byte breakpoint. Matsushita hasn't defined
324 1.1 christos one, so we defined it ourselves. */
325 1.1 christos
326 1.1 christos static const unsigned char *
327 1.1 christos mn10300_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
328 1.1 christos int *bp_size)
329 1.1 christos {
330 1.1 christos static gdb_byte breakpoint[] = {0xff};
331 1.1 christos *bp_size = 1;
332 1.1 christos return breakpoint;
333 1.1 christos }
334 1.1 christos
335 1.1 christos /* Model the semantics of pushing a register onto the stack. This
336 1.1 christos is a helper function for mn10300_analyze_prologue, below. */
337 1.1 christos static void
338 1.1 christos push_reg (pv_t *regs, struct pv_area *stack, int regnum)
339 1.1 christos {
340 1.1 christos regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], -4);
341 1.1 christos pv_area_store (stack, regs[E_SP_REGNUM], 4, regs[regnum]);
342 1.1 christos }
343 1.1 christos
344 1.1 christos /* Translate an "r" register number extracted from an instruction encoding
345 1.1 christos into a GDB register number. Adapted from a simulator function
346 1.1 christos of the same name; see am33.igen. */
347 1.1 christos static int
348 1.1 christos translate_rreg (int rreg)
349 1.1 christos {
350 1.1 christos /* The higher register numbers actually correspond to the
351 1.1 christos basic machine's address and data registers. */
352 1.1 christos if (rreg > 7 && rreg < 12)
353 1.1 christos return E_A0_REGNUM + rreg - 8;
354 1.1 christos else if (rreg > 11 && rreg < 16)
355 1.1 christos return E_D0_REGNUM + rreg - 12;
356 1.1 christos else
357 1.1 christos return E_E0_REGNUM + rreg;
358 1.1 christos }
359 1.1 christos
360 1.1 christos /* Find saved registers in a 'struct pv_area'; we pass this to pv_area_scan.
361 1.1 christos
362 1.1 christos If VALUE is a saved register, ADDR says it was saved at a constant
363 1.1 christos offset from the frame base, and SIZE indicates that the whole
364 1.1 christos register was saved, record its offset in RESULT_UNTYPED. */
365 1.1 christos static void
366 1.1 christos check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
367 1.1 christos {
368 1.1 christos struct mn10300_prologue *result = (struct mn10300_prologue *) result_untyped;
369 1.1 christos
370 1.1 christos if (value.kind == pvk_register
371 1.1 christos && value.k == 0
372 1.1 christos && pv_is_register (addr, E_SP_REGNUM)
373 1.1 christos && size == register_size (result->gdbarch, value.reg))
374 1.1 christos result->reg_offset[value.reg] = addr.k;
375 1.1 christos }
376 1.1 christos
377 1.1 christos /* Analyze the prologue to determine where registers are saved,
378 1.1 christos the end of the prologue, etc. The result of this analysis is
379 1.1 christos returned in RESULT. See struct mn10300_prologue above for more
380 1.1 christos information. */
381 1.1 christos static void
382 1.1 christos mn10300_analyze_prologue (struct gdbarch *gdbarch,
383 1.1 christos CORE_ADDR start_pc, CORE_ADDR limit_pc,
384 1.1 christos struct mn10300_prologue *result)
385 1.1 christos {
386 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
387 1.1 christos CORE_ADDR pc;
388 1.1 christos int rn;
389 1.1 christos pv_t regs[MN10300_MAX_NUM_REGS];
390 1.1 christos struct pv_area *stack;
391 1.1 christos struct cleanup *back_to;
392 1.1 christos CORE_ADDR after_last_frame_setup_insn = start_pc;
393 1.1 christos int am33_mode = AM33_MODE (gdbarch);
394 1.1 christos
395 1.1 christos memset (result, 0, sizeof (*result));
396 1.1 christos result->gdbarch = gdbarch;
397 1.1 christos
398 1.1 christos for (rn = 0; rn < MN10300_MAX_NUM_REGS; rn++)
399 1.1 christos {
400 1.1 christos regs[rn] = pv_register (rn, 0);
401 1.1 christos result->reg_offset[rn] = 1;
402 1.1 christos }
403 1.1 christos stack = make_pv_area (E_SP_REGNUM, gdbarch_addr_bit (gdbarch));
404 1.1 christos back_to = make_cleanup_free_pv_area (stack);
405 1.1 christos
406 1.1 christos /* The typical call instruction will have saved the return address on the
407 1.1 christos stack. Space for the return address has already been preallocated in
408 1.1 christos the caller's frame. It's possible, such as when using -mrelax with gcc
409 1.1 christos that other registers were saved as well. If this happens, we really
410 1.1 christos have no chance of deciphering the frame. DWARF info can save the day
411 1.1 christos when this happens. */
412 1.1 christos pv_area_store (stack, regs[E_SP_REGNUM], 4, regs[E_PC_REGNUM]);
413 1.1 christos
414 1.1 christos pc = start_pc;
415 1.1 christos while (pc < limit_pc)
416 1.1 christos {
417 1.1 christos int status;
418 1.1 christos gdb_byte instr[2];
419 1.1 christos
420 1.1 christos /* Instructions can be as small as one byte; however, we usually
421 1.1 christos need at least two bytes to do the decoding, so fetch that many
422 1.1 christos to begin with. */
423 1.1 christos status = target_read_memory (pc, instr, 2);
424 1.1 christos if (status != 0)
425 1.1 christos break;
426 1.1 christos
427 1.1 christos /* movm [regs], sp */
428 1.1 christos if (instr[0] == 0xcf)
429 1.1 christos {
430 1.1 christos gdb_byte save_mask;
431 1.1 christos
432 1.1 christos save_mask = instr[1];
433 1.1 christos
434 1.1 christos if ((save_mask & movm_exreg0_bit) && am33_mode)
435 1.1 christos {
436 1.1 christos push_reg (regs, stack, E_E2_REGNUM);
437 1.1 christos push_reg (regs, stack, E_E3_REGNUM);
438 1.1 christos }
439 1.1 christos if ((save_mask & movm_exreg1_bit) && am33_mode)
440 1.1 christos {
441 1.1 christos push_reg (regs, stack, E_E4_REGNUM);
442 1.1 christos push_reg (regs, stack, E_E5_REGNUM);
443 1.1 christos push_reg (regs, stack, E_E6_REGNUM);
444 1.1 christos push_reg (regs, stack, E_E7_REGNUM);
445 1.1 christos }
446 1.1 christos if ((save_mask & movm_exother_bit) && am33_mode)
447 1.1 christos {
448 1.1 christos push_reg (regs, stack, E_E0_REGNUM);
449 1.1 christos push_reg (regs, stack, E_E1_REGNUM);
450 1.1 christos push_reg (regs, stack, E_MDRQ_REGNUM);
451 1.1 christos push_reg (regs, stack, E_MCRH_REGNUM);
452 1.1 christos push_reg (regs, stack, E_MCRL_REGNUM);
453 1.1 christos push_reg (regs, stack, E_MCVF_REGNUM);
454 1.1 christos }
455 1.1 christos if (save_mask & movm_d2_bit)
456 1.1 christos push_reg (regs, stack, E_D2_REGNUM);
457 1.1 christos if (save_mask & movm_d3_bit)
458 1.1 christos push_reg (regs, stack, E_D3_REGNUM);
459 1.1 christos if (save_mask & movm_a2_bit)
460 1.1 christos push_reg (regs, stack, E_A2_REGNUM);
461 1.1 christos if (save_mask & movm_a3_bit)
462 1.1 christos push_reg (regs, stack, E_A3_REGNUM);
463 1.1 christos if (save_mask & movm_other_bit)
464 1.1 christos {
465 1.1 christos push_reg (regs, stack, E_D0_REGNUM);
466 1.1 christos push_reg (regs, stack, E_D1_REGNUM);
467 1.1 christos push_reg (regs, stack, E_A0_REGNUM);
468 1.1 christos push_reg (regs, stack, E_A1_REGNUM);
469 1.1 christos push_reg (regs, stack, E_MDR_REGNUM);
470 1.1 christos push_reg (regs, stack, E_LIR_REGNUM);
471 1.1 christos push_reg (regs, stack, E_LAR_REGNUM);
472 1.1 christos /* The `other' bit leaves a blank area of four bytes at
473 1.1 christos the beginning of its block of saved registers, making
474 1.1 christos it 32 bytes long in total. */
475 1.1 christos regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], -4);
476 1.1 christos }
477 1.1 christos
478 1.1 christos pc += 2;
479 1.1 christos after_last_frame_setup_insn = pc;
480 1.1 christos }
481 1.1 christos /* mov sp, aN */
482 1.1 christos else if ((instr[0] & 0xfc) == 0x3c)
483 1.1 christos {
484 1.1 christos int aN = instr[0] & 0x03;
485 1.1 christos
486 1.1 christos regs[E_A0_REGNUM + aN] = regs[E_SP_REGNUM];
487 1.1 christos
488 1.1 christos pc += 1;
489 1.1 christos if (aN == 3)
490 1.1 christos after_last_frame_setup_insn = pc;
491 1.1 christos }
492 1.1 christos /* mov aM, aN */
493 1.1 christos else if ((instr[0] & 0xf0) == 0x90
494 1.1 christos && (instr[0] & 0x03) != ((instr[0] & 0x0c) >> 2))
495 1.1 christos {
496 1.1 christos int aN = instr[0] & 0x03;
497 1.1 christos int aM = (instr[0] & 0x0c) >> 2;
498 1.1 christos
499 1.1 christos regs[E_A0_REGNUM + aN] = regs[E_A0_REGNUM + aM];
500 1.1 christos
501 1.1 christos pc += 1;
502 1.1 christos }
503 1.1 christos /* mov dM, dN */
504 1.1 christos else if ((instr[0] & 0xf0) == 0x80
505 1.1 christos && (instr[0] & 0x03) != ((instr[0] & 0x0c) >> 2))
506 1.1 christos {
507 1.1 christos int dN = instr[0] & 0x03;
508 1.1 christos int dM = (instr[0] & 0x0c) >> 2;
509 1.1 christos
510 1.1 christos regs[E_D0_REGNUM + dN] = regs[E_D0_REGNUM + dM];
511 1.1 christos
512 1.1 christos pc += 1;
513 1.1 christos }
514 1.1 christos /* mov aM, dN */
515 1.1 christos else if (instr[0] == 0xf1 && (instr[1] & 0xf0) == 0xd0)
516 1.1 christos {
517 1.1 christos int dN = instr[1] & 0x03;
518 1.1 christos int aM = (instr[1] & 0x0c) >> 2;
519 1.1 christos
520 1.1 christos regs[E_D0_REGNUM + dN] = regs[E_A0_REGNUM + aM];
521 1.1 christos
522 1.1 christos pc += 2;
523 1.1 christos }
524 1.1 christos /* mov dM, aN */
525 1.1 christos else if (instr[0] == 0xf1 && (instr[1] & 0xf0) == 0xe0)
526 1.1 christos {
527 1.1 christos int aN = instr[1] & 0x03;
528 1.1 christos int dM = (instr[1] & 0x0c) >> 2;
529 1.1 christos
530 1.1 christos regs[E_A0_REGNUM + aN] = regs[E_D0_REGNUM + dM];
531 1.1 christos
532 1.1 christos pc += 2;
533 1.1 christos }
534 1.1 christos /* add imm8, SP */
535 1.1 christos else if (instr[0] == 0xf8 && instr[1] == 0xfe)
536 1.1 christos {
537 1.1 christos gdb_byte buf[1];
538 1.1 christos LONGEST imm8;
539 1.1 christos
540 1.1 christos
541 1.1 christos status = target_read_memory (pc + 2, buf, 1);
542 1.1 christos if (status != 0)
543 1.1 christos break;
544 1.1 christos
545 1.1 christos imm8 = extract_signed_integer (buf, 1, byte_order);
546 1.1 christos regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm8);
547 1.1 christos
548 1.1 christos pc += 3;
549 1.1 christos /* Stack pointer adjustments are frame related. */
550 1.1 christos after_last_frame_setup_insn = pc;
551 1.1 christos }
552 1.1 christos /* add imm16, SP */
553 1.1 christos else if (instr[0] == 0xfa && instr[1] == 0xfe)
554 1.1 christos {
555 1.1 christos gdb_byte buf[2];
556 1.1 christos LONGEST imm16;
557 1.1 christos
558 1.1 christos status = target_read_memory (pc + 2, buf, 2);
559 1.1 christos if (status != 0)
560 1.1 christos break;
561 1.1 christos
562 1.1 christos imm16 = extract_signed_integer (buf, 2, byte_order);
563 1.1 christos regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm16);
564 1.1 christos
565 1.1 christos pc += 4;
566 1.1 christos /* Stack pointer adjustments are frame related. */
567 1.1 christos after_last_frame_setup_insn = pc;
568 1.1 christos }
569 1.1 christos /* add imm32, SP */
570 1.1 christos else if (instr[0] == 0xfc && instr[1] == 0xfe)
571 1.1 christos {
572 1.1 christos gdb_byte buf[4];
573 1.1 christos LONGEST imm32;
574 1.1 christos
575 1.1 christos status = target_read_memory (pc + 2, buf, 4);
576 1.1 christos if (status != 0)
577 1.1 christos break;
578 1.1 christos
579 1.1 christos
580 1.1 christos imm32 = extract_signed_integer (buf, 4, byte_order);
581 1.1 christos regs[E_SP_REGNUM] = pv_add_constant (regs[E_SP_REGNUM], imm32);
582 1.1 christos
583 1.1 christos pc += 6;
584 1.1 christos /* Stack pointer adjustments are frame related. */
585 1.1 christos after_last_frame_setup_insn = pc;
586 1.1 christos }
587 1.1 christos /* add imm8, aN */
588 1.1 christos else if ((instr[0] & 0xfc) == 0x20)
589 1.1 christos {
590 1.1 christos int aN;
591 1.1 christos LONGEST imm8;
592 1.1 christos
593 1.1 christos aN = instr[0] & 0x03;
594 1.1 christos imm8 = extract_signed_integer (&instr[1], 1, byte_order);
595 1.1 christos
596 1.1 christos regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
597 1.1 christos imm8);
598 1.1 christos
599 1.1 christos pc += 2;
600 1.1 christos }
601 1.1 christos /* add imm16, aN */
602 1.1 christos else if (instr[0] == 0xfa && (instr[1] & 0xfc) == 0xd0)
603 1.1 christos {
604 1.1 christos int aN;
605 1.1 christos LONGEST imm16;
606 1.1 christos gdb_byte buf[2];
607 1.1 christos
608 1.1 christos aN = instr[1] & 0x03;
609 1.1 christos
610 1.1 christos status = target_read_memory (pc + 2, buf, 2);
611 1.1 christos if (status != 0)
612 1.1 christos break;
613 1.1 christos
614 1.1 christos
615 1.1 christos imm16 = extract_signed_integer (buf, 2, byte_order);
616 1.1 christos
617 1.1 christos regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
618 1.1 christos imm16);
619 1.1 christos
620 1.1 christos pc += 4;
621 1.1 christos }
622 1.1 christos /* add imm32, aN */
623 1.1 christos else if (instr[0] == 0xfc && (instr[1] & 0xfc) == 0xd0)
624 1.1 christos {
625 1.1 christos int aN;
626 1.1 christos LONGEST imm32;
627 1.1 christos gdb_byte buf[4];
628 1.1 christos
629 1.1 christos aN = instr[1] & 0x03;
630 1.1 christos
631 1.1 christos status = target_read_memory (pc + 2, buf, 4);
632 1.1 christos if (status != 0)
633 1.1 christos break;
634 1.1 christos
635 1.1 christos imm32 = extract_signed_integer (buf, 2, byte_order);
636 1.1 christos
637 1.1 christos regs[E_A0_REGNUM + aN] = pv_add_constant (regs[E_A0_REGNUM + aN],
638 1.1 christos imm32);
639 1.1 christos pc += 6;
640 1.1 christos }
641 1.1 christos /* fmov fsM, (rN) */
642 1.1 christos else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x30)
643 1.1 christos {
644 1.1 christos int fsM, sM, Y, rN;
645 1.1 christos gdb_byte buf[1];
646 1.1 christos
647 1.1 christos Y = (instr[1] & 0x02) >> 1;
648 1.1 christos
649 1.1 christos status = target_read_memory (pc + 2, buf, 1);
650 1.1 christos if (status != 0)
651 1.1 christos break;
652 1.1 christos
653 1.1 christos sM = (buf[0] & 0xf0) >> 4;
654 1.1 christos rN = buf[0] & 0x0f;
655 1.1 christos fsM = (Y << 4) | sM;
656 1.1 christos
657 1.1 christos pv_area_store (stack, regs[translate_rreg (rN)], 4,
658 1.1 christos regs[E_FS0_REGNUM + fsM]);
659 1.1 christos
660 1.1 christos pc += 3;
661 1.1 christos }
662 1.1 christos /* fmov fsM, (sp) */
663 1.1 christos else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x34)
664 1.1 christos {
665 1.1 christos int fsM, sM, Y;
666 1.1 christos gdb_byte buf[1];
667 1.1 christos
668 1.1 christos Y = (instr[1] & 0x02) >> 1;
669 1.1 christos
670 1.1 christos status = target_read_memory (pc + 2, buf, 1);
671 1.1 christos if (status != 0)
672 1.1 christos break;
673 1.1 christos
674 1.1 christos sM = (buf[0] & 0xf0) >> 4;
675 1.1 christos fsM = (Y << 4) | sM;
676 1.1 christos
677 1.1 christos pv_area_store (stack, regs[E_SP_REGNUM], 4,
678 1.1 christos regs[E_FS0_REGNUM + fsM]);
679 1.1 christos
680 1.1 christos pc += 3;
681 1.1 christos }
682 1.1 christos /* fmov fsM, (rN, rI) */
683 1.1 christos else if (instr[0] == 0xfb && instr[1] == 0x37)
684 1.1 christos {
685 1.1 christos int fsM, sM, Z, rN, rI;
686 1.1 christos gdb_byte buf[2];
687 1.1 christos
688 1.1 christos
689 1.1 christos status = target_read_memory (pc + 2, buf, 2);
690 1.1 christos if (status != 0)
691 1.1 christos break;
692 1.1 christos
693 1.1 christos rI = (buf[0] & 0xf0) >> 4;
694 1.1 christos rN = buf[0] & 0x0f;
695 1.1 christos sM = (buf[1] & 0xf0) >> 4;
696 1.1 christos Z = (buf[1] & 0x02) >> 1;
697 1.1 christos fsM = (Z << 4) | sM;
698 1.1 christos
699 1.1 christos pv_area_store (stack,
700 1.1 christos pv_add (regs[translate_rreg (rN)],
701 1.1 christos regs[translate_rreg (rI)]),
702 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
703 1.1 christos
704 1.1 christos pc += 4;
705 1.1 christos }
706 1.1 christos /* fmov fsM, (d8, rN) */
707 1.1 christos else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x30)
708 1.1 christos {
709 1.1 christos int fsM, sM, Y, rN;
710 1.1 christos LONGEST d8;
711 1.1 christos gdb_byte buf[2];
712 1.1 christos
713 1.1 christos Y = (instr[1] & 0x02) >> 1;
714 1.1 christos
715 1.1 christos status = target_read_memory (pc + 2, buf, 2);
716 1.1 christos if (status != 0)
717 1.1 christos break;
718 1.1 christos
719 1.1 christos sM = (buf[0] & 0xf0) >> 4;
720 1.1 christos rN = buf[0] & 0x0f;
721 1.1 christos fsM = (Y << 4) | sM;
722 1.1 christos d8 = extract_signed_integer (&buf[1], 1, byte_order);
723 1.1 christos
724 1.1 christos pv_area_store (stack,
725 1.1 christos pv_add_constant (regs[translate_rreg (rN)], d8),
726 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
727 1.1 christos
728 1.1 christos pc += 4;
729 1.1 christos }
730 1.1 christos /* fmov fsM, (d24, rN) */
731 1.1 christos else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x30)
732 1.1 christos {
733 1.1 christos int fsM, sM, Y, rN;
734 1.1 christos LONGEST d24;
735 1.1 christos gdb_byte buf[4];
736 1.1 christos
737 1.1 christos Y = (instr[1] & 0x02) >> 1;
738 1.1 christos
739 1.1 christos status = target_read_memory (pc + 2, buf, 4);
740 1.1 christos if (status != 0)
741 1.1 christos break;
742 1.1 christos
743 1.1 christos sM = (buf[0] & 0xf0) >> 4;
744 1.1 christos rN = buf[0] & 0x0f;
745 1.1 christos fsM = (Y << 4) | sM;
746 1.1 christos d24 = extract_signed_integer (&buf[1], 3, byte_order);
747 1.1 christos
748 1.1 christos pv_area_store (stack,
749 1.1 christos pv_add_constant (regs[translate_rreg (rN)], d24),
750 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
751 1.1 christos
752 1.1 christos pc += 6;
753 1.1 christos }
754 1.1 christos /* fmov fsM, (d32, rN) */
755 1.1 christos else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x30)
756 1.1 christos {
757 1.1 christos int fsM, sM, Y, rN;
758 1.1 christos LONGEST d32;
759 1.1 christos gdb_byte buf[5];
760 1.1 christos
761 1.1 christos Y = (instr[1] & 0x02) >> 1;
762 1.1 christos
763 1.1 christos status = target_read_memory (pc + 2, buf, 5);
764 1.1 christos if (status != 0)
765 1.1 christos break;
766 1.1 christos
767 1.1 christos sM = (buf[0] & 0xf0) >> 4;
768 1.1 christos rN = buf[0] & 0x0f;
769 1.1 christos fsM = (Y << 4) | sM;
770 1.1 christos d32 = extract_signed_integer (&buf[1], 4, byte_order);
771 1.1 christos
772 1.1 christos pv_area_store (stack,
773 1.1 christos pv_add_constant (regs[translate_rreg (rN)], d32),
774 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
775 1.1 christos
776 1.1 christos pc += 7;
777 1.1 christos }
778 1.1 christos /* fmov fsM, (d8, SP) */
779 1.1 christos else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x34)
780 1.1 christos {
781 1.1 christos int fsM, sM, Y;
782 1.1 christos LONGEST d8;
783 1.1 christos gdb_byte buf[2];
784 1.1 christos
785 1.1 christos Y = (instr[1] & 0x02) >> 1;
786 1.1 christos
787 1.1 christos status = target_read_memory (pc + 2, buf, 2);
788 1.1 christos if (status != 0)
789 1.1 christos break;
790 1.1 christos
791 1.1 christos sM = (buf[0] & 0xf0) >> 4;
792 1.1 christos fsM = (Y << 4) | sM;
793 1.1 christos d8 = extract_signed_integer (&buf[1], 1, byte_order);
794 1.1 christos
795 1.1 christos pv_area_store (stack,
796 1.1 christos pv_add_constant (regs[E_SP_REGNUM], d8),
797 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
798 1.1 christos
799 1.1 christos pc += 4;
800 1.1 christos }
801 1.1 christos /* fmov fsM, (d24, SP) */
802 1.1 christos else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x34)
803 1.1 christos {
804 1.1 christos int fsM, sM, Y;
805 1.1 christos LONGEST d24;
806 1.1 christos gdb_byte buf[4];
807 1.1 christos
808 1.1 christos Y = (instr[1] & 0x02) >> 1;
809 1.1 christos
810 1.1 christos status = target_read_memory (pc + 2, buf, 4);
811 1.1 christos if (status != 0)
812 1.1 christos break;
813 1.1 christos
814 1.1 christos sM = (buf[0] & 0xf0) >> 4;
815 1.1 christos fsM = (Y << 4) | sM;
816 1.1 christos d24 = extract_signed_integer (&buf[1], 3, byte_order);
817 1.1 christos
818 1.1 christos pv_area_store (stack,
819 1.1 christos pv_add_constant (regs[E_SP_REGNUM], d24),
820 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
821 1.1 christos
822 1.1 christos pc += 6;
823 1.1 christos }
824 1.1 christos /* fmov fsM, (d32, SP) */
825 1.1 christos else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x34)
826 1.1 christos {
827 1.1 christos int fsM, sM, Y;
828 1.1 christos LONGEST d32;
829 1.1 christos gdb_byte buf[5];
830 1.1 christos
831 1.1 christos Y = (instr[1] & 0x02) >> 1;
832 1.1 christos
833 1.1 christos status = target_read_memory (pc + 2, buf, 5);
834 1.1 christos if (status != 0)
835 1.1 christos break;
836 1.1 christos
837 1.1 christos sM = (buf[0] & 0xf0) >> 4;
838 1.1 christos fsM = (Y << 4) | sM;
839 1.1 christos d32 = extract_signed_integer (&buf[1], 4, byte_order);
840 1.1 christos
841 1.1 christos pv_area_store (stack,
842 1.1 christos pv_add_constant (regs[E_SP_REGNUM], d32),
843 1.1 christos 4, regs[E_FS0_REGNUM + fsM]);
844 1.1 christos
845 1.1 christos pc += 7;
846 1.1 christos }
847 1.1 christos /* fmov fsM, (rN+) */
848 1.1 christos else if (instr[0] == 0xf9 && (instr[1] & 0xfd) == 0x31)
849 1.1 christos {
850 1.1 christos int fsM, sM, Y, rN, rN_regnum;
851 1.1 christos gdb_byte buf[1];
852 1.1 christos
853 1.1 christos Y = (instr[1] & 0x02) >> 1;
854 1.1 christos
855 1.1 christos status = target_read_memory (pc + 2, buf, 1);
856 1.1 christos if (status != 0)
857 1.1 christos break;
858 1.1 christos
859 1.1 christos sM = (buf[0] & 0xf0) >> 4;
860 1.1 christos rN = buf[0] & 0x0f;
861 1.1 christos fsM = (Y << 4) | sM;
862 1.1 christos
863 1.1 christos rN_regnum = translate_rreg (rN);
864 1.1 christos
865 1.1 christos pv_area_store (stack, regs[rN_regnum], 4,
866 1.1 christos regs[E_FS0_REGNUM + fsM]);
867 1.1 christos regs[rN_regnum] = pv_add_constant (regs[rN_regnum], 4);
868 1.1 christos
869 1.1 christos pc += 3;
870 1.1 christos }
871 1.1 christos /* fmov fsM, (rN+, imm8) */
872 1.1 christos else if (instr[0] == 0xfb && (instr[1] & 0xfd) == 0x31)
873 1.1 christos {
874 1.1 christos int fsM, sM, Y, rN, rN_regnum;
875 1.1 christos LONGEST imm8;
876 1.1 christos gdb_byte buf[2];
877 1.1 christos
878 1.1 christos Y = (instr[1] & 0x02) >> 1;
879 1.1 christos
880 1.1 christos status = target_read_memory (pc + 2, buf, 2);
881 1.1 christos if (status != 0)
882 1.1 christos break;
883 1.1 christos
884 1.1 christos sM = (buf[0] & 0xf0) >> 4;
885 1.1 christos rN = buf[0] & 0x0f;
886 1.1 christos fsM = (Y << 4) | sM;
887 1.1 christos imm8 = extract_signed_integer (&buf[1], 1, byte_order);
888 1.1 christos
889 1.1 christos rN_regnum = translate_rreg (rN);
890 1.1 christos
891 1.1 christos pv_area_store (stack, regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
892 1.1 christos regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm8);
893 1.1 christos
894 1.1 christos pc += 4;
895 1.1 christos }
896 1.1 christos /* fmov fsM, (rN+, imm24) */
897 1.1 christos else if (instr[0] == 0xfd && (instr[1] & 0xfd) == 0x31)
898 1.1 christos {
899 1.1 christos int fsM, sM, Y, rN, rN_regnum;
900 1.1 christos LONGEST imm24;
901 1.1 christos gdb_byte buf[4];
902 1.1 christos
903 1.1 christos Y = (instr[1] & 0x02) >> 1;
904 1.1 christos
905 1.1 christos status = target_read_memory (pc + 2, buf, 4);
906 1.1 christos if (status != 0)
907 1.1 christos break;
908 1.1 christos
909 1.1 christos sM = (buf[0] & 0xf0) >> 4;
910 1.1 christos rN = buf[0] & 0x0f;
911 1.1 christos fsM = (Y << 4) | sM;
912 1.1 christos imm24 = extract_signed_integer (&buf[1], 3, byte_order);
913 1.1 christos
914 1.1 christos rN_regnum = translate_rreg (rN);
915 1.1 christos
916 1.1 christos pv_area_store (stack, regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
917 1.1 christos regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm24);
918 1.1 christos
919 1.1 christos pc += 6;
920 1.1 christos }
921 1.1 christos /* fmov fsM, (rN+, imm32) */
922 1.1 christos else if (instr[0] == 0xfe && (instr[1] & 0xfd) == 0x31)
923 1.1 christos {
924 1.1 christos int fsM, sM, Y, rN, rN_regnum;
925 1.1 christos LONGEST imm32;
926 1.1 christos gdb_byte buf[5];
927 1.1 christos
928 1.1 christos Y = (instr[1] & 0x02) >> 1;
929 1.1 christos
930 1.1 christos status = target_read_memory (pc + 2, buf, 5);
931 1.1 christos if (status != 0)
932 1.1 christos break;
933 1.1 christos
934 1.1 christos sM = (buf[0] & 0xf0) >> 4;
935 1.1 christos rN = buf[0] & 0x0f;
936 1.1 christos fsM = (Y << 4) | sM;
937 1.1 christos imm32 = extract_signed_integer (&buf[1], 4, byte_order);
938 1.1 christos
939 1.1 christos rN_regnum = translate_rreg (rN);
940 1.1 christos
941 1.1 christos pv_area_store (stack, regs[rN_regnum], 4, regs[E_FS0_REGNUM + fsM]);
942 1.1 christos regs[rN_regnum] = pv_add_constant (regs[rN_regnum], imm32);
943 1.1 christos
944 1.1 christos pc += 7;
945 1.1 christos }
946 1.1 christos /* mov imm8, aN */
947 1.1 christos else if ((instr[0] & 0xf0) == 0x90)
948 1.1 christos {
949 1.1 christos int aN = instr[0] & 0x03;
950 1.1 christos LONGEST imm8;
951 1.1 christos
952 1.1 christos imm8 = extract_signed_integer (&instr[1], 1, byte_order);
953 1.1 christos
954 1.1 christos regs[E_A0_REGNUM + aN] = pv_constant (imm8);
955 1.1 christos pc += 2;
956 1.1 christos }
957 1.1 christos /* mov imm16, aN */
958 1.1 christos else if ((instr[0] & 0xfc) == 0x24)
959 1.1 christos {
960 1.1 christos int aN = instr[0] & 0x03;
961 1.1 christos gdb_byte buf[2];
962 1.1 christos LONGEST imm16;
963 1.1 christos
964 1.1 christos status = target_read_memory (pc + 1, buf, 2);
965 1.1 christos if (status != 0)
966 1.1 christos break;
967 1.1 christos
968 1.1 christos imm16 = extract_signed_integer (buf, 2, byte_order);
969 1.1 christos regs[E_A0_REGNUM + aN] = pv_constant (imm16);
970 1.1 christos pc += 3;
971 1.1 christos }
972 1.1 christos /* mov imm32, aN */
973 1.1 christos else if (instr[0] == 0xfc && ((instr[1] & 0xfc) == 0xdc))
974 1.1 christos {
975 1.1 christos int aN = instr[1] & 0x03;
976 1.1 christos gdb_byte buf[4];
977 1.1 christos LONGEST imm32;
978 1.1 christos
979 1.1 christos status = target_read_memory (pc + 2, buf, 4);
980 1.1 christos if (status != 0)
981 1.1 christos break;
982 1.1 christos
983 1.1 christos imm32 = extract_signed_integer (buf, 4, byte_order);
984 1.1 christos regs[E_A0_REGNUM + aN] = pv_constant (imm32);
985 1.1 christos pc += 6;
986 1.1 christos }
987 1.1 christos /* mov imm8, dN */
988 1.1 christos else if ((instr[0] & 0xf0) == 0x80)
989 1.1 christos {
990 1.1 christos int dN = instr[0] & 0x03;
991 1.1 christos LONGEST imm8;
992 1.1 christos
993 1.1 christos imm8 = extract_signed_integer (&instr[1], 1, byte_order);
994 1.1 christos
995 1.1 christos regs[E_D0_REGNUM + dN] = pv_constant (imm8);
996 1.1 christos pc += 2;
997 1.1 christos }
998 1.1 christos /* mov imm16, dN */
999 1.1 christos else if ((instr[0] & 0xfc) == 0x2c)
1000 1.1 christos {
1001 1.1 christos int dN = instr[0] & 0x03;
1002 1.1 christos gdb_byte buf[2];
1003 1.1 christos LONGEST imm16;
1004 1.1 christos
1005 1.1 christos status = target_read_memory (pc + 1, buf, 2);
1006 1.1 christos if (status != 0)
1007 1.1 christos break;
1008 1.1 christos
1009 1.1 christos imm16 = extract_signed_integer (buf, 2, byte_order);
1010 1.1 christos regs[E_D0_REGNUM + dN] = pv_constant (imm16);
1011 1.1 christos pc += 3;
1012 1.1 christos }
1013 1.1 christos /* mov imm32, dN */
1014 1.1 christos else if (instr[0] == 0xfc && ((instr[1] & 0xfc) == 0xcc))
1015 1.1 christos {
1016 1.1 christos int dN = instr[1] & 0x03;
1017 1.1 christos gdb_byte buf[4];
1018 1.1 christos LONGEST imm32;
1019 1.1 christos
1020 1.1 christos status = target_read_memory (pc + 2, buf, 4);
1021 1.1 christos if (status != 0)
1022 1.1 christos break;
1023 1.1 christos
1024 1.1 christos imm32 = extract_signed_integer (buf, 4, byte_order);
1025 1.1 christos regs[E_D0_REGNUM + dN] = pv_constant (imm32);
1026 1.1 christos pc += 6;
1027 1.1 christos }
1028 1.1 christos else
1029 1.1 christos {
1030 1.1 christos /* We've hit some instruction that we don't recognize. Hopefully,
1031 1.1 christos we have enough to do prologue analysis. */
1032 1.1 christos break;
1033 1.1 christos }
1034 1.1 christos }
1035 1.1 christos
1036 1.1 christos /* Is the frame size (offset, really) a known constant? */
1037 1.1 christos if (pv_is_register (regs[E_SP_REGNUM], E_SP_REGNUM))
1038 1.1 christos result->frame_size = regs[E_SP_REGNUM].k;
1039 1.1 christos
1040 1.1 christos /* Was the frame pointer initialized? */
1041 1.1 christos if (pv_is_register (regs[E_A3_REGNUM], E_SP_REGNUM))
1042 1.1 christos {
1043 1.1 christos result->has_frame_ptr = 1;
1044 1.1 christos result->frame_ptr_offset = regs[E_A3_REGNUM].k;
1045 1.1 christos }
1046 1.1 christos
1047 1.1 christos /* Record where all the registers were saved. */
1048 1.1 christos pv_area_scan (stack, check_for_saved, (void *) result);
1049 1.1 christos
1050 1.1 christos result->prologue_end = after_last_frame_setup_insn;
1051 1.1 christos
1052 1.1 christos do_cleanups (back_to);
1053 1.1 christos }
1054 1.1 christos
1055 1.1 christos /* Function: skip_prologue
1056 1.1 christos Return the address of the first inst past the prologue of the function. */
1057 1.1 christos
1058 1.1 christos static CORE_ADDR
1059 1.1 christos mn10300_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1060 1.1 christos {
1061 1.1 christos const char *name;
1062 1.1 christos CORE_ADDR func_addr, func_end;
1063 1.1 christos struct mn10300_prologue p;
1064 1.1 christos
1065 1.1 christos /* Try to find the extent of the function that contains PC. */
1066 1.1 christos if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
1067 1.1 christos return pc;
1068 1.1 christos
1069 1.1 christos mn10300_analyze_prologue (gdbarch, pc, func_end, &p);
1070 1.1 christos return p.prologue_end;
1071 1.1 christos }
1072 1.1 christos
1073 1.1 christos /* Wrapper for mn10300_analyze_prologue: find the function start;
1074 1.1 christos use the current frame PC as the limit, then
1075 1.1 christos invoke mn10300_analyze_prologue and return its result. */
1076 1.1 christos static struct mn10300_prologue *
1077 1.1 christos mn10300_analyze_frame_prologue (struct frame_info *this_frame,
1078 1.1 christos void **this_prologue_cache)
1079 1.1 christos {
1080 1.1 christos if (!*this_prologue_cache)
1081 1.1 christos {
1082 1.1 christos CORE_ADDR func_start, stop_addr;
1083 1.1 christos
1084 1.1 christos *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct mn10300_prologue);
1085 1.1 christos
1086 1.1 christos func_start = get_frame_func (this_frame);
1087 1.1 christos stop_addr = get_frame_pc (this_frame);
1088 1.1 christos
1089 1.1 christos /* If we couldn't find any function containing the PC, then
1090 1.1 christos just initialize the prologue cache, but don't do anything. */
1091 1.1 christos if (!func_start)
1092 1.1 christos stop_addr = func_start;
1093 1.1 christos
1094 1.1 christos mn10300_analyze_prologue (get_frame_arch (this_frame),
1095 1.6 christos func_start, stop_addr,
1096 1.6 christos ((struct mn10300_prologue *)
1097 1.6 christos *this_prologue_cache));
1098 1.1 christos }
1099 1.1 christos
1100 1.6 christos return (struct mn10300_prologue *) *this_prologue_cache;
1101 1.1 christos }
1102 1.1 christos
1103 1.1 christos /* Given the next frame and a prologue cache, return this frame's
1104 1.1 christos base. */
1105 1.1 christos static CORE_ADDR
1106 1.1 christos mn10300_frame_base (struct frame_info *this_frame, void **this_prologue_cache)
1107 1.1 christos {
1108 1.1 christos struct mn10300_prologue *p
1109 1.1 christos = mn10300_analyze_frame_prologue (this_frame, this_prologue_cache);
1110 1.1 christos
1111 1.1 christos /* In functions that use alloca, the distance between the stack
1112 1.1 christos pointer and the frame base varies dynamically, so we can't use
1113 1.1 christos the SP plus static information like prologue analysis to find the
1114 1.1 christos frame base. However, such functions must have a frame pointer,
1115 1.1 christos to be able to restore the SP on exit. So whenever we do have a
1116 1.1 christos frame pointer, use that to find the base. */
1117 1.1 christos if (p->has_frame_ptr)
1118 1.1 christos {
1119 1.1 christos CORE_ADDR fp = get_frame_register_unsigned (this_frame, E_A3_REGNUM);
1120 1.1 christos return fp - p->frame_ptr_offset;
1121 1.1 christos }
1122 1.1 christos else
1123 1.1 christos {
1124 1.1 christos CORE_ADDR sp = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
1125 1.1 christos return sp - p->frame_size;
1126 1.1 christos }
1127 1.1 christos }
1128 1.1 christos
1129 1.1 christos /* Here is a dummy implementation. */
1130 1.1 christos static struct frame_id
1131 1.1 christos mn10300_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1132 1.1 christos {
1133 1.1 christos CORE_ADDR sp = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
1134 1.1 christos CORE_ADDR pc = get_frame_register_unsigned (this_frame, E_PC_REGNUM);
1135 1.1 christos return frame_id_build (sp, pc);
1136 1.1 christos }
1137 1.1 christos
1138 1.1 christos static void
1139 1.1 christos mn10300_frame_this_id (struct frame_info *this_frame,
1140 1.1 christos void **this_prologue_cache,
1141 1.1 christos struct frame_id *this_id)
1142 1.1 christos {
1143 1.1 christos *this_id = frame_id_build (mn10300_frame_base (this_frame,
1144 1.1 christos this_prologue_cache),
1145 1.1 christos get_frame_func (this_frame));
1146 1.1 christos
1147 1.1 christos }
1148 1.1 christos
1149 1.1 christos static struct value *
1150 1.1 christos mn10300_frame_prev_register (struct frame_info *this_frame,
1151 1.1 christos void **this_prologue_cache, int regnum)
1152 1.1 christos {
1153 1.1 christos struct mn10300_prologue *p
1154 1.1 christos = mn10300_analyze_frame_prologue (this_frame, this_prologue_cache);
1155 1.1 christos CORE_ADDR frame_base = mn10300_frame_base (this_frame, this_prologue_cache);
1156 1.1 christos
1157 1.1 christos if (regnum == E_SP_REGNUM)
1158 1.1 christos return frame_unwind_got_constant (this_frame, regnum, frame_base);
1159 1.1 christos
1160 1.1 christos /* If prologue analysis says we saved this register somewhere,
1161 1.1 christos return a description of the stack slot holding it. */
1162 1.1 christos if (p->reg_offset[regnum] != 1)
1163 1.1 christos return frame_unwind_got_memory (this_frame, regnum,
1164 1.1 christos frame_base + p->reg_offset[regnum]);
1165 1.1 christos
1166 1.1 christos /* Otherwise, presume we haven't changed the value of this
1167 1.1 christos register, and get it from the next frame. */
1168 1.1 christos return frame_unwind_got_register (this_frame, regnum, regnum);
1169 1.1 christos }
1170 1.1 christos
1171 1.1 christos static const struct frame_unwind mn10300_frame_unwind = {
1172 1.1 christos NORMAL_FRAME,
1173 1.1 christos default_frame_unwind_stop_reason,
1174 1.1 christos mn10300_frame_this_id,
1175 1.1 christos mn10300_frame_prev_register,
1176 1.1 christos NULL,
1177 1.1 christos default_frame_sniffer
1178 1.1 christos };
1179 1.1 christos
1180 1.1 christos static CORE_ADDR
1181 1.1 christos mn10300_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
1182 1.1 christos {
1183 1.1 christos ULONGEST pc;
1184 1.1 christos
1185 1.1 christos pc = frame_unwind_register_unsigned (this_frame, E_PC_REGNUM);
1186 1.1 christos return pc;
1187 1.1 christos }
1188 1.1 christos
1189 1.1 christos static CORE_ADDR
1190 1.1 christos mn10300_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
1191 1.1 christos {
1192 1.1 christos ULONGEST sp;
1193 1.1 christos
1194 1.1 christos sp = frame_unwind_register_unsigned (this_frame, E_SP_REGNUM);
1195 1.1 christos return sp;
1196 1.1 christos }
1197 1.1 christos
1198 1.1 christos static void
1199 1.1 christos mn10300_frame_unwind_init (struct gdbarch *gdbarch)
1200 1.1 christos {
1201 1.1 christos dwarf2_append_unwinders (gdbarch);
1202 1.1 christos frame_unwind_append_unwinder (gdbarch, &mn10300_frame_unwind);
1203 1.1 christos set_gdbarch_dummy_id (gdbarch, mn10300_dummy_id);
1204 1.1 christos set_gdbarch_unwind_pc (gdbarch, mn10300_unwind_pc);
1205 1.1 christos set_gdbarch_unwind_sp (gdbarch, mn10300_unwind_sp);
1206 1.1 christos }
1207 1.1 christos
1208 1.1 christos /* Function: push_dummy_call
1209 1.1 christos *
1210 1.1 christos * Set up machine state for a target call, including
1211 1.1 christos * function arguments, stack, return address, etc.
1212 1.1 christos *
1213 1.1 christos */
1214 1.1 christos
1215 1.1 christos static CORE_ADDR
1216 1.1 christos mn10300_push_dummy_call (struct gdbarch *gdbarch,
1217 1.1 christos struct value *target_func,
1218 1.1 christos struct regcache *regcache,
1219 1.1 christos CORE_ADDR bp_addr,
1220 1.1 christos int nargs, struct value **args,
1221 1.1 christos CORE_ADDR sp,
1222 1.1 christos int struct_return,
1223 1.1 christos CORE_ADDR struct_addr)
1224 1.1 christos {
1225 1.1 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1226 1.1 christos const int push_size = register_size (gdbarch, E_PC_REGNUM);
1227 1.1 christos int regs_used;
1228 1.1 christos int len, arg_len;
1229 1.1 christos int stack_offset = 0;
1230 1.1 christos int argnum;
1231 1.1 christos const gdb_byte *val;
1232 1.1 christos gdb_byte valbuf[MAX_REGISTER_SIZE];
1233 1.1 christos
1234 1.1 christos /* This should be a nop, but align the stack just in case something
1235 1.1 christos went wrong. Stacks are four byte aligned on the mn10300. */
1236 1.1 christos sp &= ~3;
1237 1.1 christos
1238 1.1 christos /* Now make space on the stack for the args.
1239 1.1 christos
1240 1.1 christos XXX This doesn't appear to handle pass-by-invisible reference
1241 1.1 christos arguments. */
1242 1.1 christos regs_used = struct_return ? 1 : 0;
1243 1.1 christos for (len = 0, argnum = 0; argnum < nargs; argnum++)
1244 1.1 christos {
1245 1.1 christos arg_len = (TYPE_LENGTH (value_type (args[argnum])) + 3) & ~3;
1246 1.1 christos while (regs_used < 2 && arg_len > 0)
1247 1.1 christos {
1248 1.1 christos regs_used++;
1249 1.1 christos arg_len -= push_size;
1250 1.1 christos }
1251 1.1 christos len += arg_len;
1252 1.1 christos }
1253 1.1 christos
1254 1.1 christos /* Allocate stack space. */
1255 1.1 christos sp -= len;
1256 1.1 christos
1257 1.1 christos if (struct_return)
1258 1.1 christos {
1259 1.1 christos regs_used = 1;
1260 1.1 christos regcache_cooked_write_unsigned (regcache, E_D0_REGNUM, struct_addr);
1261 1.1 christos }
1262 1.1 christos else
1263 1.1 christos regs_used = 0;
1264 1.1 christos
1265 1.1 christos /* Push all arguments onto the stack. */
1266 1.1 christos for (argnum = 0; argnum < nargs; argnum++)
1267 1.1 christos {
1268 1.1 christos /* FIXME what about structs? Unions? */
1269 1.1 christos if (TYPE_CODE (value_type (*args)) == TYPE_CODE_STRUCT
1270 1.1 christos && TYPE_LENGTH (value_type (*args)) > 8)
1271 1.1 christos {
1272 1.1 christos /* Change to pointer-to-type. */
1273 1.1 christos arg_len = push_size;
1274 1.1 christos store_unsigned_integer (valbuf, push_size, byte_order,
1275 1.1 christos value_address (*args));
1276 1.1 christos val = &valbuf[0];
1277 1.1 christos }
1278 1.1 christos else
1279 1.1 christos {
1280 1.1 christos arg_len = TYPE_LENGTH (value_type (*args));
1281 1.1 christos val = value_contents (*args);
1282 1.1 christos }
1283 1.1 christos
1284 1.1 christos while (regs_used < 2 && arg_len > 0)
1285 1.1 christos {
1286 1.1 christos regcache_cooked_write_unsigned (regcache, regs_used,
1287 1.1 christos extract_unsigned_integer (val, push_size, byte_order));
1288 1.1 christos val += push_size;
1289 1.1 christos arg_len -= push_size;
1290 1.1 christos regs_used++;
1291 1.1 christos }
1292 1.1 christos
1293 1.1 christos while (arg_len > 0)
1294 1.1 christos {
1295 1.1 christos write_memory (sp + stack_offset, val, push_size);
1296 1.1 christos arg_len -= push_size;
1297 1.1 christos val += push_size;
1298 1.1 christos stack_offset += push_size;
1299 1.1 christos }
1300 1.1 christos
1301 1.1 christos args++;
1302 1.1 christos }
1303 1.1 christos
1304 1.1 christos /* Make space for the flushback area. */
1305 1.1 christos sp -= 8;
1306 1.1 christos
1307 1.1 christos /* Push the return address that contains the magic breakpoint. */
1308 1.1 christos sp -= 4;
1309 1.1 christos write_memory_unsigned_integer (sp, push_size, byte_order, bp_addr);
1310 1.1 christos
1311 1.1 christos /* The CPU also writes the return address always into the
1312 1.1 christos MDR register on "call". */
1313 1.1 christos regcache_cooked_write_unsigned (regcache, E_MDR_REGNUM, bp_addr);
1314 1.1 christos
1315 1.1 christos /* Update $sp. */
1316 1.1 christos regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp);
1317 1.1 christos
1318 1.1 christos /* On the mn10300, it's possible to move some of the stack adjustment
1319 1.1 christos and saving of the caller-save registers out of the prologue and
1320 1.1 christos into the call sites. (When using gcc, this optimization can
1321 1.1 christos occur when using the -mrelax switch.) If this occurs, the dwarf2
1322 1.1 christos info will reflect this fact. We can test to see if this is the
1323 1.1 christos case by creating a new frame using the current stack pointer and
1324 1.1 christos the address of the function that we're about to call. We then
1325 1.1 christos unwind SP and see if it's different than the SP of our newly
1326 1.1 christos created frame. If the SP values are the same, the caller is not
1327 1.1 christos expected to allocate any additional stack. On the other hand, if
1328 1.1 christos the SP values are different, the difference determines the
1329 1.1 christos additional stack that must be allocated.
1330 1.1 christos
1331 1.1 christos Note that we don't update the return value though because that's
1332 1.1 christos the value of the stack just after pushing the arguments, but prior
1333 1.1 christos to performing the call. This value is needed in order to
1334 1.1 christos construct the frame ID of the dummy call. */
1335 1.1 christos {
1336 1.1 christos CORE_ADDR func_addr = find_function_addr (target_func, NULL);
1337 1.1 christos CORE_ADDR unwound_sp
1338 1.1 christos = mn10300_unwind_sp (gdbarch, create_new_frame (sp, func_addr));
1339 1.1 christos if (sp != unwound_sp)
1340 1.1 christos regcache_cooked_write_unsigned (regcache, E_SP_REGNUM,
1341 1.1 christos sp - (unwound_sp - sp));
1342 1.1 christos }
1343 1.1 christos
1344 1.1 christos return sp;
1345 1.1 christos }
1346 1.1 christos
1347 1.1 christos /* If DWARF2 is a register number appearing in Dwarf2 debug info, then
1348 1.1 christos mn10300_dwarf2_reg_to_regnum (DWARF2) is the corresponding GDB
1349 1.1 christos register number. Why don't Dwarf2 and GDB use the same numbering?
1350 1.1 christos Who knows? But since people have object files lying around with
1351 1.1 christos the existing Dwarf2 numbering, and other people have written stubs
1352 1.1 christos to work with the existing GDB, neither of them can change. So we
1353 1.1 christos just have to cope. */
1354 1.1 christos static int
1355 1.1 christos mn10300_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int dwarf2)
1356 1.1 christos {
1357 1.1 christos /* This table is supposed to be shaped like the gdbarch_register_name
1358 1.1 christos initializer in gcc/config/mn10300/mn10300.h. Registers which
1359 1.1 christos appear in GCC's numbering, but have no counterpart in GDB's
1360 1.1 christos world, are marked with a -1. */
1361 1.1 christos static int dwarf2_to_gdb[] = {
1362 1.3 christos E_D0_REGNUM, E_D1_REGNUM, E_D2_REGNUM, E_D3_REGNUM,
1363 1.3 christos E_A0_REGNUM, E_A1_REGNUM, E_A2_REGNUM, E_A3_REGNUM,
1364 1.3 christos -1, E_SP_REGNUM,
1365 1.3 christos
1366 1.3 christos E_E0_REGNUM, E_E1_REGNUM, E_E2_REGNUM, E_E3_REGNUM,
1367 1.3 christos E_E4_REGNUM, E_E5_REGNUM, E_E6_REGNUM, E_E7_REGNUM,
1368 1.3 christos
1369 1.3 christos E_FS0_REGNUM + 0, E_FS0_REGNUM + 1, E_FS0_REGNUM + 2, E_FS0_REGNUM + 3,
1370 1.3 christos E_FS0_REGNUM + 4, E_FS0_REGNUM + 5, E_FS0_REGNUM + 6, E_FS0_REGNUM + 7,
1371 1.3 christos
1372 1.3 christos E_FS0_REGNUM + 8, E_FS0_REGNUM + 9, E_FS0_REGNUM + 10, E_FS0_REGNUM + 11,
1373 1.3 christos E_FS0_REGNUM + 12, E_FS0_REGNUM + 13, E_FS0_REGNUM + 14, E_FS0_REGNUM + 15,
1374 1.3 christos
1375 1.3 christos E_FS0_REGNUM + 16, E_FS0_REGNUM + 17, E_FS0_REGNUM + 18, E_FS0_REGNUM + 19,
1376 1.3 christos E_FS0_REGNUM + 20, E_FS0_REGNUM + 21, E_FS0_REGNUM + 22, E_FS0_REGNUM + 23,
1377 1.3 christos
1378 1.3 christos E_FS0_REGNUM + 24, E_FS0_REGNUM + 25, E_FS0_REGNUM + 26, E_FS0_REGNUM + 27,
1379 1.3 christos E_FS0_REGNUM + 28, E_FS0_REGNUM + 29, E_FS0_REGNUM + 30, E_FS0_REGNUM + 31,
1380 1.3 christos
1381 1.3 christos E_MDR_REGNUM, E_PSW_REGNUM, E_PC_REGNUM
1382 1.1 christos };
1383 1.1 christos
1384 1.1 christos if (dwarf2 < 0
1385 1.1 christos || dwarf2 >= ARRAY_SIZE (dwarf2_to_gdb))
1386 1.6 christos return -1;
1387 1.1 christos
1388 1.1 christos return dwarf2_to_gdb[dwarf2];
1389 1.1 christos }
1390 1.1 christos
1391 1.1 christos static struct gdbarch *
1392 1.1 christos mn10300_gdbarch_init (struct gdbarch_info info,
1393 1.1 christos struct gdbarch_list *arches)
1394 1.1 christos {
1395 1.1 christos struct gdbarch *gdbarch;
1396 1.1 christos struct gdbarch_tdep *tdep;
1397 1.1 christos int num_regs;
1398 1.1 christos
1399 1.1 christos arches = gdbarch_list_lookup_by_info (arches, &info);
1400 1.1 christos if (arches != NULL)
1401 1.1 christos return arches->gdbarch;
1402 1.1 christos
1403 1.6 christos tdep = XNEW (struct gdbarch_tdep);
1404 1.1 christos gdbarch = gdbarch_alloc (&info, tdep);
1405 1.1 christos
1406 1.1 christos switch (info.bfd_arch_info->mach)
1407 1.1 christos {
1408 1.1 christos case 0:
1409 1.1 christos case bfd_mach_mn10300:
1410 1.1 christos set_gdbarch_register_name (gdbarch, mn10300_generic_register_name);
1411 1.1 christos tdep->am33_mode = 0;
1412 1.1 christos num_regs = 32;
1413 1.1 christos break;
1414 1.1 christos case bfd_mach_am33:
1415 1.1 christos set_gdbarch_register_name (gdbarch, am33_register_name);
1416 1.1 christos tdep->am33_mode = 1;
1417 1.1 christos num_regs = 32;
1418 1.1 christos break;
1419 1.1 christos case bfd_mach_am33_2:
1420 1.1 christos set_gdbarch_register_name (gdbarch, am33_2_register_name);
1421 1.1 christos tdep->am33_mode = 2;
1422 1.1 christos num_regs = 64;
1423 1.1 christos set_gdbarch_fp0_regnum (gdbarch, 32);
1424 1.1 christos break;
1425 1.1 christos default:
1426 1.1 christos internal_error (__FILE__, __LINE__,
1427 1.1 christos _("mn10300_gdbarch_init: Unknown mn10300 variant"));
1428 1.1 christos break;
1429 1.1 christos }
1430 1.1 christos
1431 1.1 christos /* By default, chars are unsigned. */
1432 1.1 christos set_gdbarch_char_signed (gdbarch, 0);
1433 1.1 christos
1434 1.1 christos /* Registers. */
1435 1.1 christos set_gdbarch_num_regs (gdbarch, num_regs);
1436 1.1 christos set_gdbarch_register_type (gdbarch, mn10300_register_type);
1437 1.1 christos set_gdbarch_skip_prologue (gdbarch, mn10300_skip_prologue);
1438 1.1 christos set_gdbarch_read_pc (gdbarch, mn10300_read_pc);
1439 1.1 christos set_gdbarch_write_pc (gdbarch, mn10300_write_pc);
1440 1.1 christos set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1441 1.1 christos set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
1442 1.1 christos set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mn10300_dwarf2_reg_to_regnum);
1443 1.1 christos
1444 1.1 christos /* Stack unwinding. */
1445 1.1 christos set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1446 1.1 christos /* Breakpoints. */
1447 1.1 christos set_gdbarch_breakpoint_from_pc (gdbarch, mn10300_breakpoint_from_pc);
1448 1.1 christos /* decr_pc_after_break? */
1449 1.1 christos /* Disassembly. */
1450 1.1 christos set_gdbarch_print_insn (gdbarch, print_insn_mn10300);
1451 1.1 christos
1452 1.1 christos /* Stage 2 */
1453 1.1 christos set_gdbarch_return_value (gdbarch, mn10300_return_value);
1454 1.1 christos
1455 1.1 christos /* Stage 3 -- get target calls working. */
1456 1.1 christos set_gdbarch_push_dummy_call (gdbarch, mn10300_push_dummy_call);
1457 1.1 christos /* set_gdbarch_return_value (store, extract) */
1458 1.1 christos
1459 1.1 christos
1460 1.1 christos mn10300_frame_unwind_init (gdbarch);
1461 1.1 christos
1462 1.1 christos /* Hook in ABI-specific overrides, if they have been registered. */
1463 1.1 christos gdbarch_init_osabi (info, gdbarch);
1464 1.1 christos
1465 1.1 christos return gdbarch;
1466 1.1 christos }
1467 1.1 christos
1468 1.1 christos /* Dump out the mn10300 specific architecture information. */
1469 1.1 christos
1470 1.1 christos static void
1471 1.1 christos mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
1472 1.1 christos {
1473 1.1 christos struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1474 1.1 christos fprintf_unfiltered (file, "mn10300_dump_tdep: am33_mode = %d\n",
1475 1.1 christos tdep->am33_mode);
1476 1.1 christos }
1477 1.1 christos
1478 1.1 christos /* Provide a prototype to silence -Wmissing-prototypes. */
1479 1.1 christos extern initialize_file_ftype _initialize_mn10300_tdep;
1480 1.1 christos
1481 1.1 christos void
1482 1.1 christos _initialize_mn10300_tdep (void)
1483 1.1 christos {
1484 1.1 christos gdbarch_register (bfd_arch_mn10300, mn10300_gdbarch_init, mn10300_dump_tdep);
1485 1.1 christos }
1486 1.1 christos
1487