]>
Commit | Line | Data |
---|---|---|
78073dd8 AC |
1 | /* Target-dependent code for Motorola 68HC11 |
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | |
3 | Contributed by Stephane Carrez, [email protected] | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #if 0 | |
22 | /* FIXME: This is from tm-m68hc1.h */ | |
23 | ||
24 | #define GDB_TARGET_IS_M6811 | |
25 | ||
26 | /* Define the bit, byte, and word ordering of the machine. */ | |
27 | ||
28 | #define TARGET_BYTE_ORDER BIG_ENDIAN | |
29 | ||
30 | /* Offset from address of function to start of its code. | |
31 | Zero on most machines. */ | |
32 | ||
33 | #define FUNCTION_START_OFFSET 0 | |
34 | ||
35 | #ifdef __STDC__ /* Forward decls for prototypes */ | |
36 | struct frame_info; | |
37 | struct frame_saved_regs; | |
38 | struct type; | |
39 | struct value; | |
40 | #endif | |
41 | ||
42 | /* Advance PC across any function entry prologue instructions | |
43 | to reach some "real" code. */ | |
44 | ||
45 | extern CORE_ADDR m68hc11_skip_prologue (); | |
46 | #define SKIP_PROLOGUE(ip) \ | |
47 | m68hc11_skip_prologue (ip) | |
48 | ||
49 | ||
50 | /* Stack grows downward. */ | |
51 | ||
52 | #define INNER_THAN(lhs,rhs) ((lhs) < (rhs)) | |
53 | ||
54 | /* For a breakpoint, use "test". This is also the breakpoint | |
55 | instruction on the 68HC12. */ | |
56 | #define BREAKPOINT {0x0} | |
57 | ||
58 | /* If your kernel resets the pc after the trap happens you may need to | |
59 | define this before including this file. */ | |
60 | #define DECR_PC_AFTER_BREAK 0 | |
61 | ||
62 | extern char *m68hc11_register_names[]; | |
63 | #define REGISTER_NAME(i) m68hc11_register_names[i] | |
64 | ||
65 | #define REGISTER_SIZE 2 | |
66 | ||
67 | /* Register numbers of various important registers. | |
68 | Note that some of these values are "real" register numbers, | |
69 | and correspond to the general registers of the machine, | |
70 | and some are "phony" register numbers which are too large | |
71 | to be actual register numbers as far as the user is concerned | |
72 | but do serve to get the desired values when passed to read_register. */ | |
73 | ||
74 | #define X_REGNUM 0 | |
75 | #define D_REGNUM 1 | |
76 | #define Y_REGNUM 2 | |
77 | #define SP_REGNUM 3 | |
78 | #define PC_REGNUM 4 | |
79 | #define A_REGNUM 5 | |
80 | #define B_REGNUM 6 | |
81 | #define PSW_REGNUM 7 | |
82 | #define Z_REGNUM 8 | |
83 | #define FP_REGNUM 9 | |
84 | #define TMP_REGNUM 10 | |
85 | #define ZS_REGNUM 11 | |
86 | #define XY_REGNUM 12 | |
87 | #define ZD1_REGNUM 13 | |
88 | #define ZD32_REGNUM (ZD1_REGNUM+31) | |
89 | ||
90 | #define NUM_REGS (ZD32_REGNUM+1) | |
91 | ||
92 | #include "opcode/m68hc11.h" | |
93 | ||
94 | /* Say how much memory is needed to store a copy of the register set */ | |
95 | #define REGISTER_BYTES ((NUM_REGS)*2) | |
96 | ||
97 | /* Index within `registers' of the first byte of the space for | |
98 | register N. */ | |
99 | ||
100 | #define REGISTER_BYTE(N) ((N) * 2) | |
101 | ||
102 | /* Number of bytes of storage in the actual machine representation | |
103 | for register N. */ | |
104 | ||
105 | #define REGISTER_RAW_SIZE(N) (2) | |
106 | ||
107 | /* Number of bytes of storage in the program's representation | |
108 | for register N. */ | |
109 | ||
110 | #define REGISTER_VIRTUAL_SIZE(N) (2) | |
111 | ||
112 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
113 | ||
114 | #define MAX_REGISTER_RAW_SIZE 8 | |
115 | ||
116 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
117 | ||
118 | #define MAX_REGISTER_VIRTUAL_SIZE 8 | |
119 | ||
120 | /* Return the GDB type object for the "standard" data type | |
121 | of data in register N. */ | |
122 | ||
123 | #define REGISTER_VIRTUAL_TYPE(N) builtin_type_uint16 | |
124 | ||
125 | /* Store the address of the place in which to copy the structure the | |
126 | subroutine will return. This is called from call_function. | |
127 | ||
128 | We store structs through a pointer passed in D */ | |
129 | ||
130 | #define STORE_STRUCT_RETURN(ADDR, SP) \ | |
131 | { write_register (D_REGNUM, (ADDR)); } | |
132 | ||
133 | ||
134 | /* Write into appropriate registers a function return value | |
135 | of type TYPE, given in virtual format. | |
136 | ||
137 | Things always get returned in D/X */ | |
138 | ||
139 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
140 | write_register_bytes (REGISTER_BYTE (D_REGNUM), VALBUF, TYPE_LENGTH (TYPE)) | |
141 | ||
142 | ||
143 | /* Extract from an array REGBUF containing the (raw) register state | |
144 | the address in which a function should return its structure value, | |
145 | as a CORE_ADDR (or an expression that can be used as one). */ | |
146 | ||
147 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(CORE_ADDR *)(REGBUF)) | |
148 | \f | |
149 | ||
150 | /* Define other aspects of the stack frame. | |
151 | we keep a copy of the worked out return pc lying around, since it | |
152 | is a useful bit of info */ | |
153 | ||
154 | #define EXTRA_FRAME_INFO \ | |
155 | int frame_reg; \ | |
156 | CORE_ADDR return_pc; \ | |
157 | CORE_ADDR dummy; \ | |
158 | int frameless; \ | |
159 | int size; | |
160 | ||
161 | /* There's a mess in stack frame creation. See comments in blockframe.c | |
162 | near reference to INIT_FRAME_PC_FIRST. */ | |
163 | ||
164 | #define INIT_FRAME_PC(fromleaf, prev) /* nada */ | |
165 | ||
166 | #define INIT_FRAME_PC_FIRST(fromleaf, prev) \ | |
167 | (prev)->pc = ((fromleaf) ? SAVED_PC_AFTER_CALL ((prev)->next) : \ | |
168 | (prev)->next ? FRAME_SAVED_PC ((prev)->next) : read_pc ()); | |
169 | ||
170 | #define INIT_EXTRA_FRAME_INFO(fromleaf, fi) \ | |
171 | m68hc11_init_extra_frame_info (fromleaf, fi) | |
172 | ||
173 | extern void m68hc11_init_extra_frame_info (int fromleaf, | |
174 | struct frame_info * fi); | |
175 | ||
176 | /* A macro that tells us whether the function invocation represented | |
177 | by FI does not have a frame on the stack associated with it. If it | |
178 | does not, FRAMELESS is set to 1, else 0. */ | |
179 | ||
180 | #define FRAMELESS_FUNCTION_INVOCATION(FI) \ | |
181 | frameless_look_for_prologue (FI) | |
182 | ||
183 | #define FRAME_CHAIN(FRAME) m68hc11_frame_chain (FRAME) | |
184 | #define FRAME_CHAIN_VALID(chain,frame) \ | |
185 | ((chain) != 0 && (frame) != 0) | |
186 | #define FRAME_SAVED_PC(FRAME) ((FRAME)->return_pc) | |
187 | #define FRAME_ARGS_ADDRESS(fi) (fi)->frame | |
188 | #define FRAME_LOCALS_ADDRESS(fi) (fi)->frame | |
189 | ||
190 | #define SAVED_PC_AFTER_CALL(frame) m68hc11_saved_pc_after_call (frame) | |
191 | ||
192 | /* Set VAL to the number of args passed to frame described by FI. | |
193 | Can set VAL to -1, meaning no way to tell. */ | |
194 | /* We can't tell how many args there are */ | |
195 | ||
196 | #define FRAME_NUM_ARGS(fi) (-1) | |
197 | ||
198 | /* Return number of bytes at start of arglist that are not really args. */ | |
199 | ||
200 | #define FRAME_ARGS_SKIP 0 | |
201 | ||
202 | ||
203 | /* Put here the code to store, into a struct frame_saved_regs, | |
204 | the addresses of the saved registers of frame described by FRAME_INFO. | |
205 | This includes special registers such as pc and fp saved in special | |
206 | ways in the stack frame. sp is even more special: | |
207 | the address we return for it IS the sp for the next frame. */ | |
208 | ||
209 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ | |
210 | m68hc11_frame_find_saved_regs (frame_info, &(frame_saved_regs)) | |
211 | ||
212 | extern void m68hc11_frame_find_saved_regs (struct frame_info *, | |
213 | struct frame_saved_regs *); | |
214 | ||
215 | #define CALL_DUMMY { 0 } | |
216 | #define PUSH_DUMMY_FRAME | |
217 | #define CALL_DUMMY_START_OFFSET 0 | |
218 | #define CALL_DUMMY_BREAKPOINT_OFFSET (0) | |
219 | ||
220 | extern CORE_ADDR m68hc11_call_dummy_address (void); | |
221 | #define CALL_DUMMY_ADDRESS() m68hc11_call_dummy_address () | |
222 | ||
223 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
224 | sp = m68hc11_fix_call_dummy (dummyname, pc, fun, nargs, args, type, gcc_p) | |
225 | ||
226 | extern CORE_ADDR m68hc11_fix_call_dummy (char *, CORE_ADDR, CORE_ADDR, | |
227 | int, struct value **, | |
228 | struct type *, int); | |
229 | #define PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr) \ | |
230 | sp = m68hc11_push_arguments ((nargs), (args), (sp), \ | |
231 | (struct_return), (struct_addr)) | |
232 | extern CORE_ADDR m68hc11_push_arguments (int, struct value **, | |
233 | CORE_ADDR, int, CORE_ADDR); | |
234 | ||
235 | ||
236 | /* Extract from an array REGBUF containing the (raw) register state | |
237 | a function return value of type TYPE, and copy that, in virtual format, | |
238 | into VALBUF. */ | |
239 | ||
240 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
241 | m68hc11_extract_return_value(TYPE, REGBUF, VALBUF) | |
242 | extern void m68hc11_extract_return_value (struct type *, char *, char *); | |
243 | ||
244 | ||
245 | /* Discard from the stack the innermost frame, | |
246 | restoring all saved registers. */ | |
247 | #define POP_FRAME m68hc11_pop_frame(); | |
248 | extern void m68hc11_pop_frame (void); | |
249 | ||
250 | ||
251 | /* Number of bits in the appropriate type. */ | |
252 | ||
253 | #define TARGET_INT_BIT (2 * TARGET_CHAR_BIT) | |
254 | #define TARGET_PTR_BIT (2 * TARGET_CHAR_BIT) | |
255 | #define TARGET_DOUBLE_BIT (4 * TARGET_CHAR_BIT) | |
256 | #define TARGET_LONG_DOUBLE_BIT (8 * TARGET_CHAR_BIT) | |
257 | ||
258 | #endif | |
259 | ||
260 | #include "defs.h" | |
261 | #include "frame.h" | |
262 | #include "obstack.h" | |
263 | #include "symtab.h" | |
264 | #include "gdbtypes.h" | |
265 | #include "gdbcmd.h" | |
266 | #include "gdbcore.h" | |
267 | #include "gdb_string.h" | |
268 | #include "value.h" | |
269 | #include "inferior.h" | |
270 | #include "dis-asm.h" | |
271 | #include "symfile.h" | |
272 | #include "objfiles.h" | |
273 | ||
274 | /* NOTE: This port is not finished. Several operations are not implemented | |
275 | and will raise an error. Most of these functions concern the calling | |
276 | of a function by GDB itself (command 'call') and retrieving data pushed | |
277 | on the stack. */ | |
278 | ||
279 | void m68hc11_frame_find_saved_regs (struct frame_info *fi, | |
280 | struct frame_saved_regs *fsr); | |
281 | static void m68hc11_pop_dummy_frame (struct frame_info *fi); | |
282 | ||
283 | /* Table of registers for 68HC11. This includes the hard registers | |
284 | and the pseudo hard registers used by GCC. */ | |
285 | char* | |
286 | m68hc11_register_names[] = | |
287 | { | |
288 | "x", "d", "y", "sp", "pc", "a", "b", | |
289 | "ccr", "z", "frame","tmp", "zs", "xy", | |
290 | "ZD1", "ZD2", "ZD3", "ZD4", "ZD5", "ZD6", "ZD7", | |
291 | "ZD8", "ZD9", "ZD10", "ZD11", "ZD12", "ZD13", "ZD14", | |
292 | "ZD15", "ZD16", "ZD17", "ZD18", "ZD19", "ZD20", "ZD21", | |
293 | "ZD22", "ZD23", "ZD24", "ZD25", "ZD26", "ZD27", "ZD28", | |
294 | "ZD29", "ZD30", "ZD31", "ZD32" | |
295 | }; | |
296 | ||
297 | static int reg_last = 32 * 2 + 6; | |
298 | static int frame_index = 6; | |
299 | ||
300 | /* Raise an error for operations which are not yet provided. */ | |
301 | static void | |
302 | m68hc11_not_yet (const char *operation) | |
303 | { | |
304 | error ("Operation '%s' is not yet implemented\n", operation); | |
305 | } | |
306 | ||
307 | /* Immediately after a function call, return the saved pc before the frame | |
308 | is setup. For sun3's, we check for the common case of being inside of a | |
309 | system call, and if so, we know that Sun pushes the call # on the stack | |
310 | prior to doing the trap. */ | |
311 | ||
312 | CORE_ADDR | |
313 | m68hc11_saved_pc_after_call (struct frame_info *frame) | |
314 | { | |
315 | unsigned addr = frame->frame + 1 + 2; | |
316 | ||
317 | addr = read_register (SP_REGNUM) + 1; | |
318 | addr &= 0x0ffff; | |
319 | return read_memory_integer (addr, 2) & 0x0FFFF; | |
320 | } | |
321 | ||
322 | /* Discard from the stack the innermost frame, restoring all saved | |
323 | registers. */ | |
324 | ||
325 | void | |
326 | m68hc11_pop_frame () | |
327 | { | |
328 | m68hc11_not_yet ("m68hc11_pop_frame"); | |
329 | } | |
330 | ||
331 | /* Analyze the function prologue to find some information | |
332 | about the function: | |
333 | - the PC of the first line (for m68hc11_skip_prologue) | |
334 | - the offset of the previous frame saved address (from current frame) | |
335 | - the soft registers which are pushed. */ | |
336 | static void | |
337 | m68hc11_guess_from_prologue (CORE_ADDR pc, CORE_ADDR* first_line, | |
338 | int* frame_offset, int* pushed_regs) | |
339 | { | |
340 | CORE_ADDR func_end; | |
341 | unsigned char op0, op1, op2; | |
342 | int add_sp_mode; | |
343 | int sp_adjust; | |
344 | int size; | |
345 | int found_frame_point; | |
346 | int found_load; | |
347 | CORE_ADDR first_pc; | |
348 | int reg_saved; | |
349 | ||
350 | first_pc = get_pc_function_start (pc); | |
351 | size = 0; | |
352 | ||
353 | if (first_pc == 0) | |
354 | { | |
355 | *frame_offset = 0; | |
356 | *pushed_regs = 0; | |
357 | *first_line = pc; | |
358 | return; | |
359 | } | |
360 | ||
361 | #define OP_PAGE2 (0x18) | |
362 | #define OP_LDX (0xde) | |
363 | #define OP_LDY (0xde) | |
364 | #define OP_PSHX (0x3c) | |
365 | #define OP_PSHY (0x3c) | |
366 | #define OP_STS (0x9f) | |
367 | #define OP_TSX (0x30) | |
368 | #define OP_TSY (0x30) | |
369 | #define OP_XGDX (0x8f) | |
370 | #define OP_XGDY (0x8f) | |
371 | #define OP_ADDD (0xc3) | |
372 | #define OP_TXS (0x35) | |
373 | #define OP_TYS (0x35) | |
374 | ||
375 | /* The 68hc11 stack is as follows: | |
376 | ||
377 | ||
378 | | | | |
379 | +-----------+ | |
380 | | | | |
381 | | args | | |
382 | | | | |
383 | +-----------+ | |
384 | | PC-return | | |
385 | +-----------+ | |
386 | | Old frame | | |
387 | +-----------+ | |
388 | | | | |
389 | | Locals | | |
390 | | | | |
391 | +-----------+ <--- current frame | |
392 | | | | |
393 | ||
394 | With most processors (like 68K) the previous frame can be computed | |
395 | easily because it is always at a fixed offset (see link/unlink). | |
396 | That is, locals are accessed with negative offsets, arguments are | |
397 | accessed with positive ones. Since 68hc11 only supports offsets | |
398 | in the range [0..255], the frame is defined at the bottom of | |
399 | locals (see picture). | |
400 | ||
401 | The purpose of the analysis made here is to find out the size | |
402 | of locals in this function. An alternative to this is to use | |
403 | DWARF2 info. This would be better but I don't know how to | |
404 | access dwarf2 debug from this function. | |
405 | ||
406 | Walk from the function entry point to the point where we save | |
407 | the frame. While walking instructions, compute the size of bytes | |
408 | which are pushed. This gives us the index to access the previous | |
409 | frame. | |
410 | ||
411 | We limit the search to 128 bytes so that the algorithm is bounded | |
412 | in case of random and wrong code. We also stop and abort if | |
413 | we find an instruction which is not supposed to appear in the | |
414 | prologue (as generated by gcc 2.95, 2.96). | |
415 | */ | |
416 | pc = first_pc; | |
417 | func_end = pc + 128; | |
418 | add_sp_mode = 0; | |
419 | found_frame_point = 0; | |
420 | while (pc + 2 < func_end) | |
421 | { | |
422 | op0 = read_memory_unsigned_integer (pc, 1); | |
423 | op1 = read_memory_unsigned_integer (pc + 1, 1); | |
424 | op2 = read_memory_unsigned_integer (pc + 2, 1); | |
425 | ||
426 | /* ldx *frame */ | |
427 | if (op0 == OP_LDX && op1 == frame_index) | |
428 | { | |
429 | pc += 2; | |
430 | } | |
431 | ||
432 | /* ldy *frame */ | |
433 | else if (op0 == OP_PAGE2 && op1 == OP_LDY && op2 == frame_index) | |
434 | { | |
435 | pc += 3; | |
436 | } | |
437 | ||
438 | /* pshx */ | |
439 | else if (op0 == OP_PSHX) | |
440 | { | |
441 | pc += 1; | |
442 | size += 2; | |
443 | } | |
444 | ||
445 | /* pshy */ | |
446 | else if (op0 == OP_PAGE2 && op1 == OP_PSHX) | |
447 | { | |
448 | pc += 2; | |
449 | size += 2; | |
450 | } | |
451 | ||
452 | /* sts *frame */ | |
453 | else if (op0 == OP_STS && op1 == frame_index) | |
454 | { | |
455 | found_frame_point = 1; | |
456 | pc += 2; | |
457 | break; | |
458 | } | |
459 | else if (op0 == OP_TSX && op1 == OP_XGDX) | |
460 | { | |
461 | add_sp_mode = 1; | |
462 | pc += 2; | |
463 | } | |
464 | else if (op0 == OP_PAGE2 && op1 == OP_TSY && op2 == OP_PAGE2) | |
465 | { | |
466 | op0 = read_memory_unsigned_integer (pc + 3, 1); | |
467 | if (op0 != OP_XGDY) | |
468 | break; | |
469 | ||
470 | add_sp_mode = 2; | |
471 | pc += 4; | |
472 | } | |
473 | else if (add_sp_mode && op0 == OP_ADDD) | |
474 | { | |
475 | sp_adjust = read_memory_unsigned_integer (pc + 1, 2); | |
476 | if (sp_adjust & 0x8000) | |
477 | sp_adjust |= 0xffff0000L; | |
478 | ||
479 | sp_adjust = -sp_adjust; | |
480 | add_sp_mode |= 4; | |
481 | pc += 3; | |
482 | } | |
483 | else if (add_sp_mode == (1 | 4) && op0 == OP_XGDX | |
484 | && op1 == OP_TXS) | |
485 | { | |
486 | size += sp_adjust; | |
487 | pc += 2; | |
488 | add_sp_mode = 0; | |
489 | } | |
490 | else if (add_sp_mode == (2 | 4) && op0 == OP_PAGE2 | |
491 | && op1 == OP_XGDY && op2 == OP_PAGE2) | |
492 | { | |
493 | op0 = read_memory_unsigned_integer (pc + 3, 1); | |
494 | if (op0 != OP_TYS) | |
495 | break; | |
496 | ||
497 | size += sp_adjust; | |
498 | pc += 4; | |
499 | add_sp_mode = 0; | |
500 | } | |
501 | else | |
502 | { | |
503 | break; | |
504 | } | |
505 | } | |
506 | ||
507 | if (found_frame_point == 0) | |
508 | { | |
509 | *frame_offset = 0; | |
510 | } | |
511 | else | |
512 | { | |
513 | *frame_offset = size; | |
514 | } | |
515 | ||
516 | /* Now, look forward to see how many registers are pushed on the stack. | |
517 | We look only for soft registers so there must be a first LDX *REG | |
518 | before a PSHX. */ | |
519 | reg_saved = 0; | |
520 | found_load = 0; | |
521 | while (pc + 2 < func_end) | |
522 | { | |
523 | op0 = read_memory_unsigned_integer (pc, 1); | |
524 | op1 = read_memory_unsigned_integer (pc + 1, 1); | |
525 | op2 = read_memory_unsigned_integer (pc + 2, 1); | |
526 | if (op0 == OP_LDX && op1 > frame_index && op1 <= reg_last) | |
527 | { | |
528 | found_load = 1; | |
529 | pc += 2; | |
530 | } | |
531 | else if (op0 == OP_PAGE2 && op1 == OP_LDY | |
532 | && op2 > frame_index && op2 < reg_last) | |
533 | { | |
534 | found_load = 1; | |
535 | pc += 3; | |
536 | } | |
537 | else if (op0 == OP_PSHX) | |
538 | { | |
539 | /* If there was no load, this is a push for a function call. */ | |
540 | if (found_load == 0) | |
541 | break; | |
542 | ||
543 | reg_saved += 2; | |
544 | pc += 1; | |
545 | found_load = 0; | |
546 | } | |
547 | else if (op0 == OP_PAGE2 && op1 == OP_PSHY) | |
548 | { | |
549 | if (found_load == 0) | |
550 | break; | |
551 | ||
552 | reg_saved += 2; | |
553 | pc += 2; | |
554 | found_load = 0; | |
555 | } | |
556 | else | |
557 | { | |
558 | break; | |
559 | } | |
560 | } | |
561 | *pushed_regs = reg_saved; | |
562 | *first_line = pc; | |
563 | } | |
564 | ||
565 | ||
566 | CORE_ADDR | |
567 | m68hc11_skip_prologue (CORE_ADDR pc) | |
568 | { | |
569 | CORE_ADDR func_addr, func_end; | |
570 | struct symtab_and_line sal; | |
571 | int frame_offset; | |
572 | int pushed_args; | |
573 | ||
574 | /* If we have line debugging information, then the end of the. */ | |
575 | /* prologue should be the first assembly instruction of the | |
576 | first source line. */ | |
577 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
578 | { | |
579 | sal = find_pc_line (func_addr, 0); | |
580 | if (sal.end && sal.end < func_end) | |
581 | return sal.end; | |
582 | } | |
583 | ||
584 | m68hc11_guess_from_prologue (pc, &pc, &frame_offset, &pushed_args); | |
585 | return pc; | |
586 | } | |
587 | ||
588 | /* Given a GDB frame, determine the address of the calling function's frame. | |
589 | This will be used to create a new GDB frame struct, and then | |
590 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
591 | */ | |
592 | ||
593 | CORE_ADDR | |
594 | m68hc11_frame_chain (struct frame_info *frame) | |
595 | { | |
596 | unsigned addr; | |
597 | ||
598 | if (frame->return_pc == 0 || inside_entry_file(frame->return_pc)) | |
599 | return (CORE_ADDR)0; | |
600 | ||
601 | if (frame->frame == 0) | |
602 | { | |
603 | return (CORE_ADDR) 0; | |
604 | } | |
605 | ||
606 | addr = frame->frame + frame->size + 1 - 2; | |
607 | addr = read_memory_unsigned_integer (addr, 2) & 0x0FFFF; | |
608 | if (addr == 0) | |
609 | { | |
610 | return (CORE_ADDR)0; | |
611 | } | |
612 | ||
613 | return addr; | |
614 | } | |
615 | ||
616 | /* Put here the code to store, into a struct frame_saved_regs, the | |
617 | addresses of the saved registers of frame described by FRAME_INFO. | |
618 | This includes special registers such as pc and fp saved in special | |
619 | ways in the stack frame. sp is even more special: the address we | |
620 | return for it IS the sp for the next frame. */ | |
621 | void | |
622 | m68hc11_frame_find_saved_regs (struct frame_info *fi, | |
623 | struct frame_saved_regs *fsr) | |
624 | { | |
625 | CORE_ADDR pc; | |
626 | int saved; | |
627 | ||
628 | pc = fi->pc; | |
629 | memset (fsr, 0, sizeof (*fsr)); | |
630 | m68hc11_guess_from_prologue (pc, &pc, &fi->size, &saved); | |
631 | } | |
632 | ||
633 | void | |
634 | m68hc11_init_extra_frame_info (int fromleaf, struct frame_info *fi) | |
635 | { | |
636 | unsigned addr; | |
637 | struct frame_saved_regs dummy; | |
638 | ||
639 | m68hc11_frame_find_saved_regs (fi, &dummy); | |
640 | ||
641 | if (fromleaf) | |
642 | { | |
643 | fi->return_pc = m68hc11_saved_pc_after_call (fi); | |
644 | } | |
645 | else | |
646 | { | |
647 | addr = fi->frame + fi->size + 1; | |
648 | fi->return_pc = read_memory_unsigned_integer (addr, 2) & 0x0ffff; | |
649 | ||
650 | #if 0 | |
651 | printf ("Pc@0x%04x, FR 0x%04x, size %d, read ret @0x%04x -> 0x%04x\n", | |
652 | fi->pc, | |
653 | fi->frame, fi->size, | |
654 | addr & 0x0ffff, | |
655 | fi->return_pc); | |
656 | #endif | |
657 | } | |
658 | } | |
659 | ||
660 | /* Same as 'info reg' but prints the registers in a different way. */ | |
661 | static void | |
662 | show_regs (char *args, int from_tty) | |
663 | { | |
664 | int ccr = read_register (PSW_REGNUM); | |
665 | int i; | |
666 | ||
667 | printf_filtered ("PC=%04x SP=%04x FP=%04x CCR=%02x %c%c%c%c%c%c%c%c\n", | |
668 | read_register (PC_REGNUM), | |
669 | read_register (SP_REGNUM), | |
670 | read_register (FP_REGNUM), | |
671 | ccr, | |
672 | ccr & M6811_S_BIT ? 'S' : '-', | |
673 | ccr & M6811_X_BIT ? 'X' : '-', | |
674 | ccr & M6811_H_BIT ? 'H' : '-', | |
675 | ccr & M6811_I_BIT ? 'I' : '-', | |
676 | ccr & M6811_N_BIT ? 'N' : '-', | |
677 | ccr & M6811_Z_BIT ? 'Z' : '-', | |
678 | ccr & M6811_V_BIT ? 'V' : '-', | |
679 | ccr & M6811_C_BIT ? 'C' : '-'); | |
680 | ||
681 | printf_filtered ("D=%04x IX=%04x IY=%04x\n", | |
682 | read_register (D_REGNUM), | |
683 | read_register (X_REGNUM), | |
684 | read_register (Y_REGNUM)); | |
685 | for (i = ZD1_REGNUM; i <= ZD32_REGNUM; i++) | |
686 | { | |
687 | printf_filtered ("ZD%d=%04x", | |
688 | i - ZD1_REGNUM + 1, | |
689 | read_register (i)); | |
690 | if (((i - ZD1_REGNUM) % 8) == 7) | |
691 | printf_filtered ("\n"); | |
692 | else | |
693 | printf_filtered (" "); | |
694 | } | |
695 | } | |
696 | ||
697 | CORE_ADDR | |
698 | m68hc11_fix_call_dummy (char *dummyname, | |
699 | CORE_ADDR start_sp, | |
700 | CORE_ADDR fun, | |
701 | int nargs, | |
702 | value_ptr *args, | |
703 | struct type *type, | |
704 | int gcc_p) | |
705 | { | |
706 | m68hc11_not_yet ("m68hc11_fix_call_dummy"); | |
707 | return 0; | |
708 | } | |
709 | ||
710 | static void | |
711 | m68hc11_pop_dummy_frame (struct frame_info *fi) | |
712 | { | |
713 | m68hc11_not_yet ("m68hc11_pop_dummy_frame"); | |
714 | } | |
715 | ||
716 | ||
717 | CORE_ADDR | |
718 | m68hc11_push_arguments (int nargs, | |
719 | value_ptr *args, | |
720 | CORE_ADDR sp, | |
721 | int struct_return, | |
722 | CORE_ADDR struct_addr) | |
723 | { | |
724 | m68hc11_not_yet ("m68hc11_push_arguments"); | |
725 | return 0; | |
726 | } | |
727 | ||
728 | ||
729 | CORE_ADDR | |
730 | m68hc11_call_dummy_address () | |
731 | { | |
732 | m68hc11_not_yet ("m68hc11_call_dummy_address"); | |
733 | return 0; | |
734 | } | |
735 | ||
736 | /* Given a return value in `regbuf' with a type `valtype', | |
737 | extract and copy its value into `valbuf'. */ | |
738 | ||
739 | void | |
740 | m68hc11_extract_return_value (struct type *valtype, | |
741 | char *regbuf, | |
742 | char *valbuf) | |
743 | { | |
744 | m68hc11_not_yet ("m68hc11_extract_return_value"); | |
745 | } | |
746 | ||
747 | void | |
748 | _initialize_m68hc11_tdep () | |
749 | { | |
750 | tm_print_insn = print_insn_m68hc11; | |
751 | ||
752 | add_com ("regs", class_vars, show_regs, "Print all registers"); | |
753 | } | |
754 |