1 /* Target-machine dependent code for Zilog Z8000, for GDB.
2 Copyright (C) 1992,1993 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
32 /* Return the saved PC from this frame.
34 If the frame has a memory copy of SRP_REGNUM, use that. If not,
35 just use the register SRP_REGNUM itself. */
38 frame_saved_pc (frame)
41 return (read_memory_pointer (frame->frame + (BIG ? 4 : 2)));
44 #define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0))
45 #define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0))
46 #define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa)
47 #define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76)
48 #define IS_SUB2_SP(x) (x==0x1b87)
49 #define IS_MOVK_R5(x) (x==0x7905)
50 #define IS_SUB_SP(x) ((x & 0xffff) == 0x020f)
51 #define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa))
53 /* work out how much local space is on the stack and
54 return the pc pointing to the first push */
57 skip_adjust (pc, size)
63 if (IS_PUSH_FP (read_memory_short (pc))
64 && IS_MOV_SP_FP (read_memory_short (pc + 2)))
66 /* This is a function with an explict frame pointer */
68 *size += 2; /* remember the frame pointer */
71 /* remember any stack adjustment */
72 if (IS_SUB_SP (read_memory_short (pc)))
74 *size += read_memory_short (pc + 2);
81 examine_frame (pc, regs, sp)
83 struct frame_saved_regs *regs;
86 int w = read_memory_short (pc);
90 for (regno = 0; regno < NUM_REGS; regno++)
91 regs->regs[regno] = 0;
93 while (IS_PUSHW (w) || IS_PUSHL (w))
95 /* work out which register is being pushed to where */
98 regs->regs[w & 0xf] = offset;
99 regs->regs[(w & 0xf) + 1] = offset + 2;
104 regs->regs[w & 0xf] = offset;
108 w = read_memory_short (pc);
116 else if (IS_SUB_SP (w))
118 /* Subtracting a value from the sp, so were in a function
119 which needs stack space for locals, but has no fp. We fake up
120 the values as if we had an fp */
121 regs->regs[FP_REGNUM] = sp;
125 /* This one didn't have an fp, we'll fake it up */
126 regs->regs[SP_REGNUM] = sp;
128 /* stack pointer contains address of next frame */
129 /* regs->regs[fp_regnum()] = fp;*/
130 regs->regs[SP_REGNUM] = sp;
135 z8k_skip_prologue (start_pc)
138 struct frame_saved_regs dummy;
140 return examine_frame (start_pc, &dummy, 0);
150 read_memory_pointer (x)
154 return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2);
158 frame_chain (thisframe)
161 if (thisframe->prev == 0)
163 /* This is the top of the stack, let's get the sp for real */
165 if (!inside_entry_file ((thisframe)->pc))
167 return read_memory_pointer ((thisframe)->frame);
177 /* Put here the code to store, into a struct frame_saved_regs,
178 the addresses of the saved registers of frame described by FRAME_INFO.
179 This includes special registers such as pc and fp saved in special
180 ways in the stack frame. sp is even more special:
181 the address we return for it IS the sp for the next frame. */
184 get_frame_saved_regs (frame_info, frame_saved_regs)
185 struct frame_info *frame_info;
186 struct frame_saved_regs *frame_saved_regs;
192 bzero (frame_saved_regs, sizeof (*frame_saved_regs));
193 pc = get_pc_function_start (frame_info->pc);
195 /* wander down the instruction stream */
196 examine_frame (pc, frame_saved_regs, frame_info->frame);
201 z8k_push_dummy_frame ()
207 print_insn (memaddr, stream)
212 disassemble_info info;
214 GDB_INIT_DISASSEMBLE_INFO(info, stream);
216 read_memory (memaddr, temp, 20);
219 return print_insn_z8001 (memaddr, temp, &info);
223 return print_insn_z8002 (memaddr, temp, &info);
227 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
228 is not the address of a valid instruction, the address of the next
229 instruction beyond ADDR otherwise. *PWORD1 receives the first word
230 of the instruction.*/
233 NEXT_PROLOGUE_INSN (addr, lim, pword1)
240 read_memory (addr, pword1, sizeof (*pword1));
241 SWAP_TARGET_AND_HOST (pword1, sizeof (short));
250 /* Put here the code to store, into a struct frame_saved_regs,
251 the addresses of the saved registers of frame described by FRAME_INFO.
252 This includes special registers such as pc and fp saved in special
253 ways in the stack frame. sp is even more special:
254 the address we return for it IS the sp for the next frame.
256 We cache the result of doing this in the frame_cache_obstack, since
257 it is fairly expensive. */
260 frame_find_saved_regs (fip, fsrp)
261 struct frame_info *fip;
262 struct frame_saved_regs *fsrp;
269 memset (fsrp, 0, sizeof *fsrp);
271 pc = skip_adjust (get_pc_function_start (fip->pc), &locals);
274 adr = fip->frame - locals;
275 for (i = 0; i < 8; i++)
277 int word = read_memory_short (pc);
282 fsrp->regs[word & 0xf] = adr;
283 fsrp->regs[(word & 0xf) + 1] = adr - 2;
286 else if (IS_PUSHW (word))
288 fsrp->regs[word & 0xf] = adr;
297 fsrp->regs[PC_REGNUM] = fip->frame + 4;
298 fsrp->regs[FP_REGNUM] = fip->frame;
309 saved_pc_after_call ()
311 return addr_bits_remove
312 (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE));
316 extract_return_value(type, regbuf, valbuf)
322 int len = TYPE_LENGTH(type);
324 for (b = 0; b < len; b += 2) {
328 memcpy(valbuf + b, regbuf + b, todo);
333 write_return_value(type, valbuf)
339 for (len = 0; len < TYPE_LENGTH(type); len += 2)
341 write_register_bytes(REGISTER_BYTE(len /2 + 2), valbuf + len, 2);
346 store_struct_return(addr, sp)
350 write_register(2, addr);
355 print_register_hook (regno)
358 if ((regno & 1) == 0 && regno < 16)
362 read_relative_register_raw_bytes (regno, (char *) (l + 0));
363 read_relative_register_raw_bytes (regno + 1, (char *) (l + 1));
365 printf ("%04x%04x", l[0], l[1]);
368 if ((regno & 3) == 0 && regno < 16)
372 read_relative_register_raw_bytes (regno, (char *) (l + 0));
373 read_relative_register_raw_bytes (regno + 1, (char *) (l + 1));
374 read_relative_register_raw_bytes (regno + 2, (char *) (l + 2));
375 read_relative_register_raw_bytes (regno + 3, (char *) (l + 3));
378 printf ("%04x%04x%04x%04x", l[0], l[1], l[2], l[3]);
385 read_relative_register_raw_bytes (regno, (char *) (&rval));
388 for (i = 0; i < 10; i += 2)
390 printf ("(sp+%d=%04x)", i, read_memory_short (rval + i));
397 register_convert_to_virtual (regnum, from, to)
408 register_convert_to_raw (regnum, to, from)
423 struct cmd_list_element *setmemorylist;
426 z8k_set_pointer_size (newsize)
429 static int oldsize = 0;
431 if (oldsize != newsize)
433 printf ("pointer size set to %d bits\n", newsize);
443 _initialize_gdbtypes ();
448 segmented_command (args, from_tty)
452 z8k_set_pointer_size (32);
456 unsegmented_command (args, from_tty)
460 z8k_set_pointer_size (16);
465 set_memory (args, from_tty)
469 printf ("\"set memory\" must be followed by the name of a memory subcommand.\n");
470 help_list (setmemorylist, "set memory ", -1, stdout);
473 _initialize_z8ktdep ()
475 add_prefix_cmd ("memory", no_class, set_memory,
476 "set the memory model", &setmemorylist, "set memory ", 0,
478 add_cmd ("segmented", class_support, segmented_command,
479 "Set segmented memory model.", &setmemorylist);
480 add_cmd ("unsegmented", class_support, unsegmented_command,
481 "Set unsegmented memory model.", &setmemorylist);