1 /* Target-machine dependent code for Zilog Z8000, for GDB.
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 Contributed by Steve Chamberlain
33 /* Return the saved PC from this frame.
35 If the frame has a memory copy of SRP_REGNUM, use that. If not,
36 just use the register SRP_REGNUM itself. */
39 frame_saved_pc (frame
)
40 struct frame_info
*frame
;
42 return read_memory_pointer (frame
->frame
+ (BIG
? 4 : 2));
45 #define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0))
46 #define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0))
47 #define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa)
48 #define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76)
49 #define IS_SUB2_SP(x) (x==0x1b87)
50 #define IS_MOVK_R5(x) (x==0x7905)
51 #define IS_SUB_SP(x) ((x & 0xffff) == 0x020f)
52 #define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa))
54 /* work out how much local space is on the stack and
55 return the pc pointing to the first push */
58 skip_adjust (pc
, size
)
64 if (IS_PUSH_FP (read_memory_short (pc
))
65 && IS_MOV_SP_FP (read_memory_short (pc
+ 2)))
67 /* This is a function with an explict frame pointer */
69 *size
+= 2; /* remember the frame pointer */
72 /* remember any stack adjustment */
73 if (IS_SUB_SP (read_memory_short (pc
)))
75 *size
+= read_memory_short (pc
+ 2);
82 examine_frame (pc
, regs
, sp
)
84 struct frame_saved_regs
*regs
;
87 int w
= read_memory_short (pc
);
91 for (regno
= 0; regno
< NUM_REGS
; regno
++)
92 regs
->regs
[regno
] = 0;
94 while (IS_PUSHW (w
) || IS_PUSHL (w
))
96 /* work out which register is being pushed to where */
99 regs
->regs
[w
& 0xf] = offset
;
100 regs
->regs
[(w
& 0xf) + 1] = offset
+ 2;
105 regs
->regs
[w
& 0xf] = offset
;
109 w
= read_memory_short (pc
);
117 else if (IS_SUB_SP (w
))
119 /* Subtracting a value from the sp, so were in a function
120 which needs stack space for locals, but has no fp. We fake up
121 the values as if we had an fp */
122 regs
->regs
[FP_REGNUM
] = sp
;
126 /* This one didn't have an fp, we'll fake it up */
127 regs
->regs
[SP_REGNUM
] = sp
;
129 /* stack pointer contains address of next frame */
130 /* regs->regs[fp_regnum()] = fp;*/
131 regs
->regs
[SP_REGNUM
] = sp
;
136 z8k_skip_prologue (start_pc
)
139 struct frame_saved_regs dummy
;
141 return examine_frame (start_pc
, &dummy
, 0);
152 read_memory_pointer (x
)
155 return read_memory_integer (ADDR_BITS_REMOVE (x
), BIG
? 4 : 2);
159 frame_chain (thisframe
)
160 struct frame_info
*thisframe
;
162 if (thisframe
->prev
== 0)
164 /* This is the top of the stack, let's get the sp for real */
166 if (!inside_entry_file (thisframe
->pc
))
168 return read_memory_pointer (thisframe
->frame
);
178 /* Put here the code to store, into a struct frame_saved_regs,
179 the addresses of the saved registers of frame described by FRAME_INFO.
180 This includes special registers such as pc and fp saved in special
181 ways in the stack frame. sp is even more special:
182 the address we return for it IS the sp for the next frame. */
185 get_frame_saved_regs (frame_info
, frame_saved_regs
)
186 struct frame_info
*frame_info
;
187 struct frame_saved_regs
*frame_saved_regs
;
193 memset (frame_saved_regs
, '\0', sizeof (*frame_saved_regs
));
194 pc
= get_pc_function_start (frame_info
->pc
);
196 /* wander down the instruction stream */
197 examine_frame (pc
, frame_saved_regs
, frame_info
->frame
);
202 z8k_push_dummy_frame ()
208 print_insn (memaddr
, stream
)
212 disassemble_info info
;
214 GDB_INIT_DISASSEMBLE_INFO (info
, stream
);
218 return print_insn_z8001 ((bfd_vma
) memaddr
, &info
);
222 return print_insn_z8002 ((bfd_vma
) memaddr
, &info
);
226 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
227 is not the address of a valid instruction, the address of the next
228 instruction beyond ADDR otherwise. *PWORD1 receives the first word
229 of the instruction.*/
232 NEXT_PROLOGUE_INSN (addr
, lim
, pword1
)
240 read_memory (addr
, buf
, 2);
241 *pword1
= extract_signed_integer (buf
, 2);
248 /* Put here the code to store, into a struct frame_saved_regs,
249 the addresses of the saved registers of frame described by FRAME_INFO.
250 This includes special registers such as pc and fp saved in special
251 ways in the stack frame. sp is even more special:
252 the address we return for it IS the sp for the next frame.
254 We cache the result of doing this in the frame_cache_obstack, since
255 it is fairly expensive. */
258 frame_find_saved_regs (fip
, fsrp
)
259 struct frame_info
*fip
;
260 struct frame_saved_regs
*fsrp
;
267 memset (fsrp
, 0, sizeof *fsrp
);
269 pc
= skip_adjust (get_pc_function_start (fip
->pc
), &locals
);
272 adr
= FRAME_FP (fip
) - locals
;
273 for (i
= 0; i
< 8; i
++)
275 int word
= read_memory_short (pc
);
280 fsrp
->regs
[word
& 0xf] = adr
;
281 fsrp
->regs
[(word
& 0xf) + 1] = adr
- 2;
284 else if (IS_PUSHW (word
))
286 fsrp
->regs
[word
& 0xf] = adr
;
295 fsrp
->regs
[PC_REGNUM
] = fip
->frame
+ 4;
296 fsrp
->regs
[FP_REGNUM
] = fip
->frame
;
301 saved_pc_after_call ()
303 return addr_bits_remove
304 (read_memory_integer (read_register (SP_REGNUM
), PTR_SIZE
));
308 extract_return_value (type
, regbuf
, valbuf
)
314 int len
= TYPE_LENGTH (type
);
316 for (b
= 0; b
< len
; b
+= 2)
322 memcpy (valbuf
+ b
, regbuf
+ b
, todo
);
327 write_return_value (type
, valbuf
)
334 for (len
= 0; len
< TYPE_LENGTH (type
); len
+= 2)
335 write_register_bytes (REGISTER_BYTE (len
/ 2 + 2), valbuf
+ len
, 2);
339 store_struct_return (addr
, sp
)
343 write_register (2, addr
);
348 print_register_hook (regno
)
351 if ((regno
& 1) == 0 && regno
< 16)
355 read_relative_register_raw_bytes (regno
, (char *) (l
+ 0));
356 read_relative_register_raw_bytes (regno
+ 1, (char *) (l
+ 1));
357 printf_unfiltered ("\t");
358 printf_unfiltered ("%04x%04x", l
[0], l
[1]);
361 if ((regno
& 3) == 0 && regno
< 16)
365 read_relative_register_raw_bytes (regno
, (char *) (l
+ 0));
366 read_relative_register_raw_bytes (regno
+ 1, (char *) (l
+ 1));
367 read_relative_register_raw_bytes (regno
+ 2, (char *) (l
+ 2));
368 read_relative_register_raw_bytes (regno
+ 3, (char *) (l
+ 3));
370 printf_unfiltered ("\t");
371 printf_unfiltered ("%04x%04x%04x%04x", l
[0], l
[1], l
[2], l
[3]);
378 read_relative_register_raw_bytes (regno
, (char *) (&rval
));
380 printf_unfiltered ("\n");
381 for (i
= 0; i
< 10; i
+= 2)
383 printf_unfiltered ("(sp+%d=%04x)", i
, read_memory_short (rval
+ i
));
394 struct cmd_list_element
*setmemorylist
;
397 z8k_set_pointer_size (newsize
)
400 static int oldsize
= 0;
402 if (oldsize
!= newsize
)
404 printf_unfiltered ("pointer size set to %d bits\n", newsize
);
414 _initialize_gdbtypes ();
419 segmented_command (args
, from_tty
)
423 z8k_set_pointer_size (32);
427 unsegmented_command (args
, from_tty
)
431 z8k_set_pointer_size (16);
435 set_memory (args
, from_tty
)
439 printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n");
440 help_list (setmemorylist
, "set memory ", -1, gdb_stdout
);
444 _initialize_z8ktdep ()
446 add_prefix_cmd ("memory", no_class
, set_memory
,
447 "set the memory model", &setmemorylist
, "set memory ", 0,
449 add_cmd ("segmented", class_support
, segmented_command
,
450 "Set segmented memory model.", &setmemorylist
);
451 add_cmd ("unsegmented", class_support
, unsegmented_command
,
452 "Set unsegmented memory model.", &setmemorylist
);
This page took 0.03821 seconds and 4 git commands to generate.