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