29e9f6bafa3cbf5f178d211ed82cb980b49da381
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 Contributed by Steve Chamberlain
35 /* Return the saved PC from this frame.
37 If the frame has a memory copy of SRP_REGNUM, use that. If not,
38 just use the register SRP_REGNUM itself. */
41 frame_saved_pc (frame
)
42 struct frame_info
*frame
;
44 return read_memory_pointer (frame
->frame
+ (BIG
? 4 : 2));
47 #define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0))
48 #define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0))
49 #define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa)
50 #define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76)
51 #define IS_SUB2_SP(x) (x==0x1b87)
52 #define IS_MOVK_R5(x) (x==0x7905)
53 #define IS_SUB_SP(x) ((x & 0xffff) == 0x020f)
54 #define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa))
56 /* work out how much local space is on the stack and
57 return the pc pointing to the first push */
60 skip_adjust (pc
, size
)
66 if (IS_PUSH_FP (read_memory_short (pc
))
67 && IS_MOV_SP_FP (read_memory_short (pc
+ 2)))
69 /* This is a function with an explict frame pointer */
71 *size
+= 2; /* remember the frame pointer */
74 /* remember any stack adjustment */
75 if (IS_SUB_SP (read_memory_short (pc
)))
77 *size
+= read_memory_short (pc
+ 2);
84 examine_frame (pc
, regs
, sp
)
86 struct frame_saved_regs
*regs
;
89 int w
= read_memory_short (pc
);
93 for (regno
= 0; regno
< NUM_REGS
; regno
++)
94 regs
->regs
[regno
] = 0;
96 while (IS_PUSHW (w
) || IS_PUSHL (w
))
98 /* work out which register is being pushed to where */
101 regs
->regs
[w
& 0xf] = offset
;
102 regs
->regs
[(w
& 0xf) + 1] = offset
+ 2;
107 regs
->regs
[w
& 0xf] = offset
;
111 w
= read_memory_short (pc
);
119 else if (IS_SUB_SP (w
))
121 /* Subtracting a value from the sp, so were in a function
122 which needs stack space for locals, but has no fp. We fake up
123 the values as if we had an fp */
124 regs
->regs
[FP_REGNUM
] = sp
;
128 /* This one didn't have an fp, we'll fake it up */
129 regs
->regs
[SP_REGNUM
] = sp
;
131 /* stack pointer contains address of next frame */
132 /* regs->regs[fp_regnum()] = fp;*/
133 regs
->regs
[SP_REGNUM
] = sp
;
138 z8k_skip_prologue (start_pc
)
141 struct frame_saved_regs dummy
;
143 return examine_frame (start_pc
, &dummy
, 0);
147 z8k_addr_bits_remove (addr
)
150 return (addr
& PTR_MASK
);
154 read_memory_pointer (x
)
157 return read_memory_integer (ADDR_BITS_REMOVE (x
), BIG
? 4 : 2);
161 frame_chain (thisframe
)
162 struct frame_info
*thisframe
;
164 if (thisframe
->prev
== 0)
166 /* This is the top of the stack, let's get the sp for real */
168 if (!inside_entry_file (thisframe
->pc
))
170 return read_memory_pointer (thisframe
->frame
);
180 /* Put here the code to store, into a struct frame_saved_regs,
181 the addresses of the saved registers of frame described by FRAME_INFO.
182 This includes special registers such as pc and fp saved in special
183 ways in the stack frame. sp is even more special:
184 the address we return for it IS the sp for the next frame. */
187 get_frame_saved_regs (frame_info
, frame_saved_regs
)
188 struct frame_info
*frame_info
;
189 struct frame_saved_regs
*frame_saved_regs
;
195 memset (frame_saved_regs
, '\0', sizeof (*frame_saved_regs
));
196 pc
= get_pc_function_start (frame_info
->pc
);
198 /* wander down the instruction stream */
199 examine_frame (pc
, frame_saved_regs
, frame_info
->frame
);
204 z8k_push_dummy_frame ()
210 gdb_print_insn_z8k (memaddr
, info
)
212 disassemble_info
*info
;
215 return print_insn_z8001 (memaddr
, info
);
217 return print_insn_z8002 (memaddr
, info
);
220 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
221 is not the address of a valid instruction, the address of the next
222 instruction beyond ADDR otherwise. *PWORD1 receives the first word
223 of the instruction.*/
226 NEXT_PROLOGUE_INSN (addr
, lim
, pword1
)
234 read_memory (addr
, buf
, 2);
235 *pword1
= extract_signed_integer (buf
, 2);
242 /* Put here the code to store, into a struct frame_saved_regs,
243 the addresses of the saved registers of frame described by FRAME_INFO.
244 This includes special registers such as pc and fp saved in special
245 ways in the stack frame. sp is even more special:
246 the address we return for it IS the sp for the next frame.
248 We cache the result of doing this in the frame_cache_obstack, since
249 it is fairly expensive. */
252 frame_find_saved_regs (fip
, fsrp
)
253 struct frame_info
*fip
;
254 struct frame_saved_regs
*fsrp
;
261 memset (fsrp
, 0, sizeof *fsrp
);
263 pc
= skip_adjust (get_pc_function_start (fip
->pc
), &locals
);
266 adr
= FRAME_FP (fip
) - locals
;
267 for (i
= 0; i
< 8; i
++)
269 int word
= read_memory_short (pc
);
274 fsrp
->regs
[word
& 0xf] = adr
;
275 fsrp
->regs
[(word
& 0xf) + 1] = adr
- 2;
278 else if (IS_PUSHW (word
))
280 fsrp
->regs
[word
& 0xf] = adr
;
289 fsrp
->regs
[PC_REGNUM
] = fip
->frame
+ 4;
290 fsrp
->regs
[FP_REGNUM
] = fip
->frame
;
295 saved_pc_after_call ()
297 return ADDR_BITS_REMOVE
298 (read_memory_integer (read_register (SP_REGNUM
), PTR_SIZE
));
302 extract_return_value (type
, regbuf
, valbuf
)
308 int len
= TYPE_LENGTH (type
);
310 for (b
= 0; b
< len
; b
+= 2)
316 memcpy (valbuf
+ b
, regbuf
+ b
, todo
);
321 write_return_value (type
, valbuf
)
328 for (len
= 0; len
< TYPE_LENGTH (type
); len
+= 2)
329 write_register_bytes (REGISTER_BYTE (len
/ 2 + 2), valbuf
+ len
, 2);
333 store_struct_return (addr
, sp
)
337 write_register (2, addr
);
342 print_register_hook (regno
)
345 if ((regno
& 1) == 0 && regno
< 16)
349 read_relative_register_raw_bytes (regno
, (char *) (l
+ 0));
350 read_relative_register_raw_bytes (regno
+ 1, (char *) (l
+ 1));
351 printf_unfiltered ("\t");
352 printf_unfiltered ("%04x%04x", l
[0], l
[1]);
355 if ((regno
& 3) == 0 && regno
< 16)
359 read_relative_register_raw_bytes (regno
, (char *) (l
+ 0));
360 read_relative_register_raw_bytes (regno
+ 1, (char *) (l
+ 1));
361 read_relative_register_raw_bytes (regno
+ 2, (char *) (l
+ 2));
362 read_relative_register_raw_bytes (regno
+ 3, (char *) (l
+ 3));
364 printf_unfiltered ("\t");
365 printf_unfiltered ("%04x%04x%04x%04x", l
[0], l
[1], l
[2], l
[3]);
372 read_relative_register_raw_bytes (regno
, (char *) (&rval
));
374 printf_unfiltered ("\n");
375 for (i
= 0; i
< 10; i
+= 2)
377 printf_unfiltered ("(sp+%d=%04x)", i
, read_memory_short (rval
+ i
));
388 struct cmd_list_element
*setmemorylist
;
391 z8k_set_pointer_size (newsize
)
394 static int oldsize
= 0;
396 if (oldsize
!= newsize
)
398 printf_unfiltered ("pointer size set to %d bits\n", newsize
);
408 _initialize_gdbtypes ();
413 segmented_command (args
, from_tty
)
417 z8k_set_pointer_size (32);
421 unsegmented_command (args
, from_tty
)
425 z8k_set_pointer_size (16);
429 set_memory (args
, from_tty
)
433 printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n");
434 help_list (setmemorylist
, "set memory ", -1, gdb_stdout
);
438 _initialize_z8ktdep ()
440 tm_print_insn
= gdb_print_insn_z8k
;
442 add_prefix_cmd ("memory", no_class
, set_memory
,
443 "set the memory model", &setmemorylist
, "set memory ", 0,
445 add_cmd ("segmented", class_support
, segmented_command
,
446 "Set segmented memory model.", &setmemorylist
);
447 add_cmd ("unsegmented", class_support
, unsegmented_command
,
448 "Set unsegmented memory model.", &setmemorylist
);