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