1 /* Target-machine dependent code for Zilog Z8000, for GDB.
3 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 Contributed by Steve Chamberlain
37 #include "value.h" /* For read_register() */
40 static int read_memory_pointer (CORE_ADDR x);
42 /* Return the saved PC from this frame.
44 If the frame has a memory copy of SRP_REGNUM, use that. If not,
45 just use the register SRP_REGNUM itself. */
48 z8k_frame_saved_pc (struct frame_info *frame)
50 return read_memory_pointer (frame->frame + (BIG ? 4 : 2));
53 #define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0))
54 #define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0))
55 #define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa)
56 #define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76)
57 #define IS_SUB2_SP(x) (x==0x1b87)
58 #define IS_MOVK_R5(x) (x==0x7905)
59 #define IS_SUB_SP(x) ((x & 0xffff) == 0x020f)
60 #define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa))
62 /* work out how much local space is on the stack and
63 return the pc pointing to the first push */
66 skip_adjust (CORE_ADDR pc, int *size)
70 if (IS_PUSH_FP (read_memory_short (pc))
71 && IS_MOV_SP_FP (read_memory_short (pc + 2)))
73 /* This is a function with an explict frame pointer */
75 *size += 2; /* remember the frame pointer */
78 /* remember any stack adjustment */
79 if (IS_SUB_SP (read_memory_short (pc)))
81 *size += read_memory_short (pc + 2);
87 static CORE_ADDR examine_frame (CORE_ADDR, CORE_ADDR * regs, CORE_ADDR);
89 examine_frame (CORE_ADDR pc, CORE_ADDR *regs, CORE_ADDR sp)
91 int w = read_memory_short (pc);
95 for (regno = 0; regno < NUM_REGS; regno++)
98 while (IS_PUSHW (w) || IS_PUSHL (w))
100 /* work out which register is being pushed to where */
103 regs[w & 0xf] = offset;
104 regs[(w & 0xf) + 1] = offset + 2;
109 regs[w & 0xf] = offset;
113 w = read_memory_short (pc);
121 else if (IS_SUB_SP (w))
123 /* Subtracting a value from the sp, so were in a function
124 which needs stack space for locals, but has no fp. We fake up
125 the values as if we had an fp */
126 regs[FP_REGNUM] = sp;
130 /* This one didn't have an fp, we'll fake it up */
131 regs[SP_REGNUM] = sp;
133 /* stack pointer contains address of next frame */
134 /* regs[fp_regnum()] = fp; */
135 regs[SP_REGNUM] = sp;
140 z8k_skip_prologue (CORE_ADDR start_pc)
142 CORE_ADDR dummy[NUM_REGS];
144 return examine_frame (start_pc, dummy, 0);
148 z8k_addr_bits_remove (CORE_ADDR addr)
150 return (addr & PTR_MASK);
154 read_memory_pointer (CORE_ADDR x)
156 return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2);
160 z8k_frame_chain (struct frame_info *thisframe)
162 if (!inside_entry_file (thisframe->pc))
164 return read_memory_pointer (thisframe->frame);
172 internal_error (__FILE__, __LINE__, "failed internal consistency check");
175 /* Put here the code to store, into a struct frame_saved_regs,
176 the addresses of the saved registers of frame described by FRAME_INFO.
177 This includes special registers such as pc and fp saved in special
178 ways in the stack frame. sp is even more special:
179 the address we return for it IS the sp for the next frame. */
182 z8k_frame_init_saved_regs (struct frame_info *frame_info)
187 frame_saved_regs_zalloc (frame_info);
188 pc = get_pc_function_start (frame_info->pc);
190 /* wander down the instruction stream */
191 examine_frame (pc, frame_info->saved_regs, frame_info->frame);
196 z8k_push_dummy_frame (void)
198 internal_error (__FILE__, __LINE__, "failed internal consistency check");
202 gdb_print_insn_z8k (bfd_vma memaddr, disassemble_info *info)
205 return print_insn_z8001 (memaddr, info);
207 return print_insn_z8002 (memaddr, info);
210 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
211 is not the address of a valid instruction, the address of the next
212 instruction beyond ADDR otherwise. *PWORD1 receives the first word
213 of the instruction. */
216 NEXT_PROLOGUE_INSN (CORE_ADDR addr, CORE_ADDR lim, short *pword1)
221 read_memory (addr, buf, 2);
222 *pword1 = extract_signed_integer (buf, 2);
230 /* Put here the code to store, into a struct frame_saved_regs,
231 the addresses of the saved registers of frame described by FRAME_INFO.
232 This includes special registers such as pc and fp saved in special
233 ways in the stack frame. sp is even more special:
234 the address we return for it IS the sp for the next frame.
236 We cache the result of doing this in the frame_cache_obstack, since
237 it is fairly expensive. */
240 frame_find_saved_regs (struct frame_info *fip, struct frame_saved_regs *fsrp)
247 memset (fsrp, 0, sizeof *fsrp);
249 pc = skip_adjust (get_pc_function_start (fip->pc), &locals);
252 adr = get_frame_base (fip) - locals;
253 for (i = 0; i < 8; i++)
255 int word = read_memory_short (pc);
260 fsrp->regs[word & 0xf] = adr;
261 fsrp->regs[(word & 0xf) + 1] = adr - 2;
264 else if (IS_PUSHW (word))
266 fsrp->regs[word & 0xf] = adr;
275 fsrp->regs[PC_REGNUM] = fip->frame + 4;
276 fsrp->regs[FP_REGNUM] = fip->frame;
282 z8k_saved_pc_after_call (struct frame_info *frame)
284 return ADDR_BITS_REMOVE
285 (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE));
290 extract_return_value (struct type *type, char *regbuf, char *valbuf)
293 int len = TYPE_LENGTH (type);
295 for (b = 0; b < len; b += 2)
301 memcpy (valbuf + b, regbuf + b, todo);
306 write_return_value (struct type *type, char *valbuf)
311 for (len = 0; len < TYPE_LENGTH (type); len += 2)
312 deprecated_write_register_bytes (REGISTER_BYTE (len / 2 + 2),
317 store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
319 write_register (2, addr);
324 z8k_print_register_hook (int regno)
326 if ((regno & 1) == 0 && regno < 16)
330 frame_register_read (deprecated_selected_frame, regno, l + 0);
331 frame_register_read (deprecated_selected_frame, regno + 1, l + 2);
332 printf_unfiltered ("\t");
333 printf_unfiltered ("0x%02x%02x%02x%02x", l[0], l[1], l[2], l[3]);
336 if ((regno & 3) == 0 && regno < 16)
340 frame_register_read (deprecated_selected_frame, regno, l + 0);
341 frame_register_read (deprecated_selected_frame, regno + 1, l + 2);
342 frame_register_read (deprecated_selected_frame, regno + 2, l + 4);
343 frame_register_read (deprecated_selected_frame, regno + 3, l + 6);
345 printf_unfiltered ("\t");
346 printf_unfiltered ("0x%02x%02x%02x%02x%02x%02x%02x%02x",
347 l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]);
354 frame_register_read (deprecated_selected_frame, regno, (char *) (&rval));
356 printf_unfiltered ("\n");
357 for (i = 0; i < 10; i += 2)
359 printf_unfiltered ("(sp+%d=%04x)", i,
360 (unsigned int)read_memory_short (rval + i));
366 z8k_print_registers_info (struct gdbarch *gdbarch,
367 struct ui_file *file,
368 struct frame_info *frame,
369 int regnum, int print_all)
372 const int numregs = NUM_REGS + NUM_PSEUDO_REGS;
373 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
374 char *virtual_buffer = alloca (MAX_REGISTER_VIRTUAL_SIZE);
376 for (i = 0; i < numregs; i++)
378 /* Decide between printing all regs, non-float / vector regs, or
384 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
386 if (TYPE_VECTOR (REGISTER_VIRTUAL_TYPE (i)))
396 /* If the register name is empty, it is undefined for this
397 processor, so don't display anything. */
398 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
401 fputs_filtered (REGISTER_NAME (i), file);
402 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), file);
404 /* Get the data in raw format. */
405 if (! frame_register_read (frame, i, raw_buffer))
407 fprintf_filtered (file, "*value not available*\n");
411 /* FIXME: cagney/2002-08-03: This code shouldn't be necessary.
412 The function frame_register_read() should have returned the
413 pre-cooked register so no conversion is necessary. */
414 /* Convert raw data to virtual format if necessary. */
415 if (REGISTER_CONVERTIBLE (i))
417 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
418 raw_buffer, virtual_buffer);
422 memcpy (virtual_buffer, raw_buffer,
423 REGISTER_VIRTUAL_SIZE (i));
426 /* If virtual format is floating, print it that way, and in raw
428 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
432 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
433 file, 0, 1, 0, Val_pretty_default);
435 fprintf_filtered (file, "\t(raw 0x");
436 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
439 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
442 idx = REGISTER_RAW_SIZE (i) - 1 - j;
443 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[idx]);
445 fprintf_filtered (file, ")");
449 /* Print the register in hex. */
450 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
451 file, 'x', 1, 0, Val_pretty_default);
452 /* If not a vector register, print it also according to its
454 if (TYPE_VECTOR (REGISTER_VIRTUAL_TYPE (i)) == 0)
456 fprintf_filtered (file, "\t");
457 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
458 file, 0, 1, 0, Val_pretty_default);
462 /* Some z8k specific info. */
463 z8k_print_register_hook (i);
465 fprintf_filtered (file, "\n");
470 z8k_do_registers_info (int regnum, int all)
472 z8k_print_registers_info (current_gdbarch, gdb_stdout,
473 deprecated_selected_frame, regnum, all);
481 struct cmd_list_element *setmemorylist;
484 z8k_set_pointer_size (int newsize)
486 static int oldsize = 0;
488 if (oldsize != newsize)
490 printf_unfiltered ("pointer size set to %d bits\n", newsize);
500 /* FIXME: This code should be using the GDBARCH framework to
501 handle changed type sizes. If this problem is ever fixed
502 (the direct reference to _initialize_gdbtypes() below
503 eliminated) then Makefile.in should be updated so that
504 z8k-tdep.c is again compiled with -Werror. */
505 _initialize_gdbtypes ();
510 segmented_command (char *args, int from_tty)
512 z8k_set_pointer_size (32);
516 unsegmented_command (char *args, int from_tty)
518 z8k_set_pointer_size (16);
522 set_memory (char *args, int from_tty)
524 printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n");
525 help_list (setmemorylist, "set memory ", -1, gdb_stdout);
529 _initialize_z8ktdep (void)
531 tm_print_insn = gdb_print_insn_z8k;
533 add_prefix_cmd ("memory", no_class, set_memory,
534 "set the memory model", &setmemorylist, "set memory ", 0,
536 add_cmd ("segmented", class_support, segmented_command,
537 "Set segmented memory model.", &setmemorylist);
538 add_cmd ("unsegmented", class_support, unsegmented_command,
539 "Set unsegmented memory model.", &setmemorylist);