Replace "exec" with "executable" in messages.
[deliverable/binutils-gdb.git] / gdb / mn10300-tdep.c
CommitLineData
3de76938 1/* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
b5b59a3c 2 Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
ddc2888e
GN
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
3de76938 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ddc2888e
GN
19
20#include "defs.h"
21#include "frame.h"
22#include "inferior.h"
23#include "obstack.h"
24#include "target.h"
25#include "value.h"
26#include "bfd.h"
27#include "gdb_string.h"
28#include "gdbcore.h"
29#include "symfile.h"
30
52e4073c 31char *mn10300_generic_register_names[] = REGISTER_NAMES;
ddc2888e 32
52e4073c
MA
33/* start-sanitize-am33 */
34char *am33_register_names [] =
35{ "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
36 "sp", "pc", "mdr", "psw", "lir", "lar", "",
37 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
38 "ssp", "msp", "usp", "mcrh", "mcrl", "mcvf", "", "", ""};
11ac7952 39int am33_mode;
52e4073c
MA
40/* end-sanitize-am33 */
41
11ac7952
MA
42static CORE_ADDR mn10300_analyze_prologue PARAMS ((struct frame_info *fi,
43 CORE_ADDR pc));
44
45/* Values for frame_info.status */
46
47#define MY_FRAME_IN_SP 0x1
48#define MY_FRAME_IN_FP 0x2
49#define NO_MORE_FRAMES 0x4
50
51
52/* Fix fi->frame if it's bogus at this point. This is a helper
53 function for mn10300_analyze_prologue. */
54
55static void
56fix_frame_pointer (fi, stack_size)
57 struct frame_info *fi;
58 int stack_size;
59{
60 if (fi && fi->next == NULL)
61 {
62 if (fi->status & MY_FRAME_IN_SP)
63 fi->frame = read_sp () - stack_size;
64 else if (fi->status & MY_FRAME_IN_FP)
65 fi->frame = read_register (A3_REGNUM);
66 }
67}
68
52e4073c
MA
69
70/* Set offsets of registers saved by movm instruction.
71 This is a helper function for mn10300_analyze_prologue. */
ddc2888e 72
52e4073c 73static void
11ac7952 74set_movm_offsets (fi, movm_args)
52e4073c 75 struct frame_info *fi;
11ac7952 76 int movm_args;
ddc2888e 77{
11ac7952
MA
78 int offset = 0;
79
80 if (fi == NULL || movm_args == 0)
52e4073c 81 return;
11ac7952
MA
82
83 if (movm_args & 0x10)
84 {
85 fi->fsr.regs[A3_REGNUM] = fi->frame + offset;
86 offset += 4;
87 }
88 if (movm_args & 0x20)
89 {
90 fi->fsr.regs[A2_REGNUM] = fi->frame + offset;
91 offset += 4;
92 }
93 if (movm_args & 0x40)
94 {
95 fi->fsr.regs[D3_REGNUM] = fi->frame + offset;
96 offset += 4;
97 }
98 if (movm_args & 0x80)
99 {
100 fi->fsr.regs[D2_REGNUM] = fi->frame + offset;
101 offset += 4;
102 }
52e4073c 103 /* start-sanitize-am33 */
11ac7952
MA
104 if (am33_mode && movm_args & 0x02)
105 {
106 fi->fsr.regs[E0_REGNUM+5] = fi->frame + offset;
107 fi->fsr.regs[E0_REGNUM+4] = fi->frame + offset + 4;
108 fi->fsr.regs[E0_REGNUM+3] = fi->frame + offset + 8;
109 fi->fsr.regs[E0_REGNUM+2] = fi->frame + offset + 12;
110 }
52e4073c
MA
111 /* end-sanitize-am33 */
112}
ddc2888e 113
3de76938 114
52e4073c
MA
115/* The main purpose of this file is dealing with prologues to extract
116 information about stack frames and saved registers.
3de76938 117
52e4073c 118 For reference here's how prologues look on the mn10300:
3de76938 119
52e4073c
MA
120 With frame pointer:
121 movm [d2,d3,a2,a3],sp
122 mov sp,a3
123 add <size>,sp
124
125 Without frame pointer:
126 movm [d2,d3,a2,a3],sp (if needed)
127 add <size>,sp
128
129 One day we might keep the stack pointer constant, that won't
130 change the code for prologues, but it will make the frame
131 pointerless case much more common. */
132
133/* Analyze the prologue to determine where registers are saved,
134 the end of the prologue, etc etc. Return the end of the prologue
135 scanned.
136
137 We store into FI (if non-null) several tidbits of information:
138
139 * stack_size -- size of this stack frame. Note that if we stop in
140 certain parts of the prologue/epilogue we may claim the size of the
141 current frame is zero. This happens when the current frame has
142 not been allocated yet or has already been deallocated.
143
144 * fsr -- Addresses of registers saved in the stack by this frame.
145
146 * status -- A (relatively) generic status indicator. It's a bitmask
147 with the following bits:
148
149 MY_FRAME_IN_SP: The base of the current frame is actually in
150 the stack pointer. This can happen for frame pointerless
151 functions, or cases where we're stopped in the prologue/epilogue
152 itself. For these cases mn10300_analyze_prologue will need up
153 update fi->frame before returning or analyzing the register
154 save instructions.
155
156 MY_FRAME_IN_FP: The base of the current frame is in the
157 frame pointer register ($a2).
158
159 NO_MORE_FRAMES: Set this if the current frame is "start" or
160 if the first instruction looks like mov <imm>,sp. This tells
161 frame chain to not bother trying to unwind past this frame. */
162
52e4073c
MA
163static CORE_ADDR
164mn10300_analyze_prologue (fi, pc)
165 struct frame_info *fi;
166 CORE_ADDR pc;
ddc2888e 167{
52e4073c
MA
168 CORE_ADDR func_addr, func_end, addr, stop;
169 CORE_ADDR stack_size;
170 int imm_size;
171 unsigned char buf[4];
11ac7952 172 int status, movm_args = 0;
52e4073c
MA
173 char *name;
174
175 /* Use the PC in the frame if it's provided to look up the
176 start of this function. */
177 pc = (fi ? fi->pc : pc);
178
179 /* Find the start of this function. */
180 status = find_pc_partial_function (pc, &name, &func_addr, &func_end);
181
182 /* Do nothing if we couldn't find the start of this function or if we're
183 stopped at the first instruction in the prologue. */
184 if (status == 0)
185 return pc;
186
187 /* If we're in start, then give up. */
188 if (strcmp (name, "start") == 0)
189 {
190 fi->status = NO_MORE_FRAMES;
191 return pc;
192 }
193
194 /* At the start of a function our frame is in the stack pointer. */
195 if (fi)
196 fi->status = MY_FRAME_IN_SP;
3de76938 197
52e4073c
MA
198 /* Get the next two bytes into buf, we need two because rets is a two
199 byte insn and the first isn't enough to uniquely identify it. */
200 status = read_memory_nobpt (pc, buf, 2);
201 if (status != 0)
202 return pc;
3de76938 203
52e4073c
MA
204 /* If we're physically on an "rets" instruction, then our frame has
205 already been deallocated. Note this can also be true for retf
206 and ret if they specify a size of zero.
3de76938 207
52e4073c
MA
208 In this case fi->frame is bogus, we need to fix it. */
209 if (fi && buf[0] == 0xf0 && buf[1] == 0xfc)
210 {
211 if (fi->next == NULL)
212 fi->frame = read_sp ();
213 return fi->pc;
214 }
215
216 /* Similarly if we're stopped on the first insn of a prologue as our
217 frame hasn't been allocated yet. */
218 if (fi && fi->pc == func_addr)
219 {
220 if (fi->next == NULL)
221 fi->frame = read_sp ();
222 return fi->pc;
223 }
3de76938 224
52e4073c
MA
225 /* Figure out where to stop scanning. */
226 stop = fi ? fi->pc : func_end;
3de76938 227
52e4073c
MA
228 /* Don't walk off the end of the function. */
229 stop = stop > func_end ? func_end : stop;
3de76938 230
52e4073c
MA
231 /* Start scanning on the first instruction of this function. */
232 addr = func_addr;
3de76938 233
52e4073c
MA
234 /* Suck in two bytes. */
235 status = read_memory_nobpt (addr, buf, 2);
236 if (status != 0)
3de76938 237 {
11ac7952 238 fix_frame_pointer (fi, 0);
52e4073c 239 return addr;
3de76938
GN
240 }
241
52e4073c
MA
242 /* First see if this insn sets the stack pointer; if so, it's something
243 we won't understand, so quit now. */
244 if (buf[0] == 0xf2 && (buf[1] & 0xf3) == 0xf0)
95efddf2 245 {
52e4073c
MA
246 if (fi)
247 fi->status = NO_MORE_FRAMES;
248 return addr;
249 }
250
251 /* Now look for movm [regs],sp, which saves the callee saved registers.
252
253 At this time we don't know if fi->frame is valid, so we only note
254 that we encountered a movm instruction. Later, we'll set the entries
255 in fsr.regs as needed. */
256 if (buf[0] == 0xcf)
257 {
11ac7952
MA
258 /* Extract the register list for the movm instruction. */
259 status = read_memory_nobpt (addr + 1, buf, 1);
260 movm_args = *buf;
261
52e4073c
MA
262 addr += 2;
263
264 /* Quit now if we're beyond the stop point. */
265 if (addr >= stop)
266 {
267 /* Fix fi->frame since it's bogus at this point. */
268 if (fi && fi->next == NULL)
269 fi->frame = read_sp ();
270
271 /* Note if/where callee saved registers were saved. */
11ac7952 272 set_movm_offsets (fi, movm_args);
52e4073c
MA
273 return addr;
274 }
275
276 /* Get the next two bytes so the prologue scan can continue. */
277 status = read_memory_nobpt (addr, buf, 2);
278 if (status != 0)
279 {
280 /* Fix fi->frame since it's bogus at this point. */
281 if (fi && fi->next == NULL)
282 fi->frame = read_sp ();
283
284 /* Note if/where callee saved registers were saved. */
11ac7952 285 set_movm_offsets (fi, movm_args);
52e4073c
MA
286 return addr;
287 }
288 }
289
290 /* Now see if we set up a frame pointer via "mov sp,a3" */
291 if (buf[0] == 0x3f)
292 {
293 addr += 1;
294
295 /* The frame pointer is now valid. */
296 if (fi)
297 {
298 fi->status |= MY_FRAME_IN_FP;
299 fi->status &= ~MY_FRAME_IN_SP;
300 }
301
302 /* Quit now if we're beyond the stop point. */
303 if (addr >= stop)
304 {
11ac7952
MA
305 /* Fix fi->frame if it's bogus at this point. */
306 fix_frame_pointer (fi, 0);
307
52e4073c 308 /* Note if/where callee saved registers were saved. */
11ac7952 309 set_movm_offsets (fi, movm_args);
52e4073c
MA
310 return addr;
311 }
312
313 /* Get two more bytes so scanning can continue. */
314 status = read_memory_nobpt (addr, buf, 2);
315 if (status != 0)
316 {
11ac7952
MA
317 /* Fix fi->frame if it's bogus at this point. */
318 fix_frame_pointer (fi, 0);
319
52e4073c 320 /* Note if/where callee saved registers were saved. */
11ac7952 321 set_movm_offsets (fi, movm_args);
52e4073c
MA
322 return addr;
323 }
324 }
325
326 /* Next we should allocate the local frame. No more prologue insns
327 are found after allocating the local frame.
328
329 Search for add imm8,sp (0xf8feXX)
330 or add imm16,sp (0xfafeXXXX)
331 or add imm32,sp (0xfcfeXXXXXXXX).
332
333 If none of the above was found, then this prologue has no
334 additional stack. */
335
336 status = read_memory_nobpt (addr, buf, 2);
337 if (status != 0)
338 {
339 /* Fix fi->frame if it's bogus at this point. */
11ac7952 340 fix_frame_pointer (fi, 0);
52e4073c
MA
341
342 /* Note if/where callee saved registers were saved. */
11ac7952 343 set_movm_offsets (fi, movm_args);
52e4073c
MA
344 return addr;
345 }
346
347 imm_size = 0;
348 if (buf[0] == 0xf8 && buf[1] == 0xfe)
349 imm_size = 1;
350 else if (buf[0] == 0xfa && buf[1] == 0xfe)
351 imm_size = 2;
352 else if (buf[0] == 0xfc && buf[1] == 0xfe)
353 imm_size = 4;
354
355 if (imm_size != 0)
356 {
357 /* Suck in imm_size more bytes, they'll hold the size of the
358 current frame. */
359 status = read_memory_nobpt (addr + 2, buf, imm_size);
360 if (status != 0)
361 {
362 /* Fix fi->frame if it's bogus at this point. */
11ac7952 363 fix_frame_pointer (fi, 0);
52e4073c
MA
364
365 /* Note if/where callee saved registers were saved. */
11ac7952 366 set_movm_offsets (fi, movm_args);
52e4073c
MA
367 return addr;
368 }
369
370 /* Note the size of the stack in the frame info structure. */
371 stack_size = extract_signed_integer (buf, imm_size);
372 if (fi)
373 fi->stack_size = stack_size;
374
375 /* We just consumed 2 + imm_size bytes. */
376 addr += 2 + imm_size;
377
378 /* No more prologue insns follow, so begin preparation to return. */
379 /* Fix fi->frame if it's bogus at this point. */
11ac7952 380 fix_frame_pointer (fi, stack_size);
52e4073c
MA
381
382 /* Note if/where callee saved registers were saved. */
11ac7952 383 set_movm_offsets (fi, movm_args);
52e4073c 384 return addr;
95efddf2 385 }
3de76938 386
52e4073c
MA
387 /* We never found an insn which allocates local stack space, regardless
388 this is the end of the prologue. */
389 /* Fix fi->frame if it's bogus at this point. */
11ac7952 390 fix_frame_pointer (fi, 0);
52e4073c
MA
391
392 /* Note if/where callee saved registers were saved. */
11ac7952 393 set_movm_offsets (fi, movm_args);
52e4073c 394 return addr;
ddc2888e 395}
52e4073c
MA
396
397/* Function: frame_chain
398 Figure out and return the caller's frame pointer given current
399 frame_info struct.
ddc2888e 400
52e4073c
MA
401 We don't handle dummy frames yet but we would probably just return the
402 stack pointer that was in use at the time the function call was made? */
3de76938 403
ddc2888e 404CORE_ADDR
52e4073c 405mn10300_frame_chain (fi)
ddc2888e 406 struct frame_info *fi;
ddc2888e 407{
52e4073c 408 struct frame_info dummy_frame;
3de76938 409
52e4073c
MA
410 /* Walk through the prologue to determine the stack size,
411 location of saved registers, end of the prologue, etc. */
412 if (fi->status == 0)
413 mn10300_analyze_prologue (fi, (CORE_ADDR)0);
3de76938 414
52e4073c
MA
415 /* Quit now if mn10300_analyze_prologue set NO_MORE_FRAMES. */
416 if (fi->status & NO_MORE_FRAMES)
417 return 0;
ddc2888e 418
52e4073c
MA
419 /* Now that we've analyzed our prologue, determine the frame
420 pointer for our caller.
3de76938 421
52e4073c
MA
422 If our caller has a frame pointer, then we need to
423 find the entry value of $a3 to our function.
3de76938 424
11ac7952
MA
425 If fsr.regs[A3_REGNUM] is nonzero, then it's at the memory
426 location pointed to by fsr.regs[A3_REGNUM].
3de76938 427
52e4073c 428 Else it's still in $a3.
3de76938 429
52e4073c
MA
430 If our caller does not have a frame pointer, then his
431 frame base is fi->frame + -caller's stack size. */
432
433 /* The easiest way to get that info is to analyze our caller's frame.
3de76938 434
52e4073c
MA
435 So we set up a dummy frame and call mn10300_analyze_prologue to
436 find stuff for us. */
437 dummy_frame.pc = FRAME_SAVED_PC (fi);
438 dummy_frame.frame = fi->frame;
439 memset (dummy_frame.fsr.regs, '\000', sizeof dummy_frame.fsr.regs);
440 dummy_frame.status = 0;
441 dummy_frame.stack_size = 0;
11ac7952 442 mn10300_analyze_prologue (&dummy_frame, 0);
3de76938 443
52e4073c
MA
444 if (dummy_frame.status & MY_FRAME_IN_FP)
445 {
446 /* Our caller has a frame pointer. So find the frame in $a3 or
447 in the stack. */
11ac7952
MA
448 if (fi->fsr.regs[A3_REGNUM])
449 return (read_memory_integer (fi->fsr.regs[A3_REGNUM], REGISTER_SIZE));
3de76938 450 else
11ac7952 451 return read_register (A3_REGNUM);
52e4073c
MA
452 }
453 else
454 {
455 int adjust = 0;
456
11ac7952
MA
457 adjust += (fi->fsr.regs[D2_REGNUM] ? 4 : 0);
458 adjust += (fi->fsr.regs[D3_REGNUM] ? 4 : 0);
459 adjust += (fi->fsr.regs[A2_REGNUM] ? 4 : 0);
460 adjust += (fi->fsr.regs[A3_REGNUM] ? 4 : 0);
b5b59a3c 461 /* start-sanitize-am33 */
11ac7952
MA
462 if (am33_mode)
463 {
464 adjust += (fi->fsr.regs[E0_REGNUM+5] ? 4 : 0);
465 adjust += (fi->fsr.regs[E0_REGNUM+4] ? 4 : 0);
466 adjust += (fi->fsr.regs[E0_REGNUM+3] ? 4 : 0);
467 adjust += (fi->fsr.regs[E0_REGNUM+2] ? 4 : 0);
468 }
b5b59a3c 469 /* end-sanitize-am33 */
52e4073c
MA
470
471 /* Our caller does not have a frame pointer. So his frame starts
5ef103c0
MA
472 at the base of our frame (fi->frame) + register save space
473 + <his size>. */
474 return fi->frame + adjust + -dummy_frame.stack_size;
3de76938 475 }
52e4073c
MA
476}
477
478/* Function: skip_prologue
479 Return the address of the first inst past the prologue of the function. */
3de76938 480
52e4073c
MA
481CORE_ADDR
482mn10300_skip_prologue (pc)
483 CORE_ADDR pc;
484{
485 /* We used to check the debug symbols, but that can lose if
486 we have a null prologue. */
487 return mn10300_analyze_prologue (NULL, pc);
ddc2888e
GN
488}
489
52e4073c 490
ddc2888e
GN
491/* Function: pop_frame
492 This routine gets called when either the user uses the `return'
493 command, or the call dummy breakpoint gets hit. */
494
495void
496mn10300_pop_frame (frame)
497 struct frame_info *frame;
498{
3de76938
GN
499 int regnum;
500
3de76938
GN
501 if (PC_IN_CALL_DUMMY(frame->pc, frame->frame, frame->frame))
502 generic_pop_dummy_frame ();
503 else
504 {
505 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
506
52e4073c 507 /* Restore any saved registers. */
3de76938
GN
508 for (regnum = 0; regnum < NUM_REGS; regnum++)
509 if (frame->fsr.regs[regnum] != 0)
52e4073c
MA
510 {
511 ULONGEST value;
512
513 value = read_memory_unsigned_integer (frame->fsr.regs[regnum],
514 REGISTER_RAW_SIZE (regnum));
515 write_register (regnum, value);
516 }
3de76938 517
52e4073c 518 /* Actually cut back the stack. */
3de76938 519 write_register (SP_REGNUM, FRAME_FP (frame));
52e4073c
MA
520
521 /* Don't we need to set the PC?!? XXX FIXME. */
3de76938
GN
522 }
523
52e4073c 524 /* Throw away any cached frame information. */
3de76938 525 flush_cached_frames ();
ddc2888e
GN
526}
527
3de76938
GN
528/* Function: push_arguments
529 Setup arguments for a call to the target. Arguments go in
52e4073c 530 order on the stack. */
3de76938 531
ddc2888e
GN
532CORE_ADDR
533mn10300_push_arguments (nargs, args, sp, struct_return, struct_addr)
534 int nargs;
535 value_ptr *args;
536 CORE_ADDR sp;
537 unsigned char struct_return;
538 CORE_ADDR struct_addr;
539{
3de76938
GN
540 int argnum = 0;
541 int len = 0;
52e4073c
MA
542 int stack_offset = 0;
543 int regsused = struct_return ? 1 : 0;
3de76938 544
52e4073c
MA
545 /* This should be a nop, but align the stack just in case something
546 went wrong. Stacks are four byte aligned on the mn10300. */
3de76938
GN
547 sp &= ~3;
548
52e4073c
MA
549 /* Now make space on the stack for the args.
550
551 XXX This doesn't appear to handle pass-by-invisible reference
552 arguments. */
3de76938 553 for (argnum = 0; argnum < nargs; argnum++)
52e4073c
MA
554 {
555 int arg_length = (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3;
556
557 while (regsused < 2 && arg_length > 0)
558 {
559 regsused++;
560 arg_length -= 4;
561 }
562 len += arg_length;
563 }
3de76938 564
52e4073c 565 /* Allocate stack space. */
3de76938
GN
566 sp -= len;
567
52e4073c 568 regsused = struct_return ? 1 : 0;
3de76938
GN
569 /* Push all arguments onto the stack. */
570 for (argnum = 0; argnum < nargs; argnum++)
571 {
572 int len;
573 char *val;
574
52e4073c 575 /* XXX Check this. What about UNIONS? */
3de76938
GN
576 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
577 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
578 {
52e4073c 579 /* XXX Wrong, we want a pointer to this argument. */
3de76938
GN
580 len = TYPE_LENGTH (VALUE_TYPE (*args));
581 val = (char *)VALUE_CONTENTS (*args);
582 }
583 else
584 {
585 len = TYPE_LENGTH (VALUE_TYPE (*args));
586 val = (char *)VALUE_CONTENTS (*args);
587 }
588
52e4073c
MA
589 while (regsused < 2 && len > 0)
590 {
591 write_register (regsused, extract_unsigned_integer (val, 4));
592 val += 4;
593 len -= 4;
594 regsused++;
595 }
596
3de76938
GN
597 while (len > 0)
598 {
599 write_memory (sp + stack_offset, val, 4);
3de76938
GN
600 len -= 4;
601 val += 4;
602 stack_offset += 4;
603 }
52e4073c 604
3de76938
GN
605 args++;
606 }
607
52e4073c
MA
608 /* Make space for the flushback area. */
609 sp -= 8;
3de76938 610 return sp;
ddc2888e
GN
611}
612
3de76938
GN
613/* Function: push_return_address (pc)
614 Set up the return address for the inferior function call.
615 Needed for targets where we don't actually execute a JSR/BSR instruction */
616
ddc2888e
GN
617CORE_ADDR
618mn10300_push_return_address (pc, sp)
619 CORE_ADDR pc;
620 CORE_ADDR sp;
621{
52e4073c
MA
622 unsigned char buf[4];
623
624 store_unsigned_integer (buf, 4, CALL_DUMMY_ADDRESS ());
625 write_memory (sp - 4, buf, 4);
626 return sp - 4;
627}
3de76938 628
52e4073c
MA
629/* Function: store_struct_return (addr,sp)
630 Store the structure value return address for an inferior function
631 call. */
632
633CORE_ADDR
634mn10300_store_struct_return (addr, sp)
635 CORE_ADDR addr;
636 CORE_ADDR sp;
637{
638 /* The structure return address is passed as the first argument. */
639 write_register (0, addr);
3de76938 640 return sp;
ddc2888e
GN
641}
642
3de76938
GN
643/* Function: frame_saved_pc
644 Find the caller of this frame. We do this by seeing if RP_REGNUM
645 is saved in the stack anywhere, otherwise we get it from the
646 registers. If the inner frame is a dummy frame, return its PC
647 instead of RP, because that's where "caller" of the dummy-frame
648 will be found. */
649
ddc2888e
GN
650CORE_ADDR
651mn10300_frame_saved_pc (fi)
652 struct frame_info *fi;
653{
52e4073c
MA
654 int adjust = 0;
655
11ac7952
MA
656 adjust += (fi->fsr.regs[D2_REGNUM] ? 4 : 0);
657 adjust += (fi->fsr.regs[D3_REGNUM] ? 4 : 0);
658 adjust += (fi->fsr.regs[A2_REGNUM] ? 4 : 0);
659 adjust += (fi->fsr.regs[A3_REGNUM] ? 4 : 0);
b5b59a3c 660 /* start-sanitize-am33 */
11ac7952
MA
661 if (am33_mode)
662 {
663 adjust += (fi->fsr.regs[E0_REGNUM+5] ? 4 : 0);
664 adjust += (fi->fsr.regs[E0_REGNUM+4] ? 4 : 0);
665 adjust += (fi->fsr.regs[E0_REGNUM+3] ? 4 : 0);
666 adjust += (fi->fsr.regs[E0_REGNUM+2] ? 4 : 0);
667 }
b5b59a3c 668 /* end-sanitize-am33 */
3de76938 669
52e4073c 670 return (read_memory_integer (fi->frame + adjust, REGISTER_SIZE));
ddc2888e
GN
671}
672
673void
674get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
675 char *raw_buffer;
676 int *optimized;
677 CORE_ADDR *addrp;
678 struct frame_info *frame;
679 int regnum;
680 enum lval_type *lval;
681{
682 generic_get_saved_register (raw_buffer, optimized, addrp,
683 frame, regnum, lval);
684}
685
95efddf2
GN
686/* Function: init_extra_frame_info
687 Setup the frame's frame pointer, pc, and frame addresses for saved
52e4073c 688 registers. Most of the work is done in mn10300_analyze_prologue().
3de76938 689
95efddf2
GN
690 Note that when we are called for the last frame (currently active frame),
691 that fi->pc and fi->frame will already be setup. However, fi->frame will
692 be valid only if this routine uses FP. For previous frames, fi-frame will
52e4073c
MA
693 always be correct. mn10300_analyze_prologue will fix fi->frame if
694 it's not valid.
95efddf2
GN
695
696 We can be called with the PC in the call dummy under two circumstances.
697 First, during normal backtracing, second, while figuring out the frame
52e4073c 698 pointer just prior to calling the target function (see run_stack_dummy). */
95efddf2
GN
699
700void
701mn10300_init_extra_frame_info (fi)
702 struct frame_info *fi;
ddc2888e 703{
95efddf2
GN
704 if (fi->next)
705 fi->pc = FRAME_SAVED_PC (fi->next);
3de76938 706
95efddf2 707 memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
52e4073c
MA
708 fi->status = 0;
709 fi->stack_size = 0;
3de76938 710
52e4073c
MA
711 mn10300_analyze_prologue (fi, 0);
712}
3de76938 713
52e4073c
MA
714/* This can be made more generic later. */
715static void
716set_machine_hook (filename)
717 char *filename;
718{
719 int i;
3de76938 720
52e4073c
MA
721 if (bfd_get_mach (exec_bfd) == bfd_mach_mn10300
722 || bfd_get_mach (exec_bfd) == 0)
95efddf2 723 {
52e4073c
MA
724 for (i = 0; i < NUM_REGS; i++)
725 reg_names[i] = mn10300_generic_register_names[i];
726 }
95efddf2 727
52e4073c 728 /* start-sanitize-am33 */
11ac7952 729 am33_mode = 0;
52e4073c
MA
730 if (bfd_get_mach (exec_bfd) == bfd_mach_am33)
731 {
732 for (i = 0; i < NUM_REGS; i++)
733 reg_names[i] = am33_register_names[i];
11ac7952 734 am33_mode = 1;
95efddf2 735 }
52e4073c 736 /* end-sanitize-am33 */
ddc2888e
GN
737}
738
739void
740_initialize_mn10300_tdep ()
741{
95efddf2 742/* printf("_initialize_mn10300_tdep\n"); */
3de76938 743
ddc2888e 744 tm_print_insn = print_insn_mn10300;
52e4073c
MA
745
746 specify_exec_file_hook (set_machine_hook);
ddc2888e 747}
95efddf2 748
This page took 0.126496 seconds and 4 git commands to generate.