(Releasing GDB, Coding): Fix typos.
[deliverable/binutils-gdb.git] / gdb / z8k-tdep.c
CommitLineData
c906108c 1/* Target-machine dependent code for Zilog Z8000, for GDB.
cda5a58a
AC
2
3 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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. */
c906108c
SS
22
23/*
c5aa993b
JM
24 Contributed by Steve Chamberlain
25 sac@cygnus.com
c906108c
SS
26 */
27
28#include "defs.h"
29#include "frame.h"
30#include "obstack.h"
31#include "symtab.h"
32#include "gdbcmd.h"
33#include "gdbtypes.h"
34#include "dis-asm.h"
35#include "gdbcore.h"
4e052eda 36#include "regcache.h"
c906108c 37
d4f3574e
SS
38#include "value.h" /* For read_register() */
39
40
41static int read_memory_pointer (CORE_ADDR x);
c906108c
SS
42
43/* Return the saved PC from this frame.
44
45 If the frame has a memory copy of SRP_REGNUM, use that. If not,
46 just use the register SRP_REGNUM itself. */
47
48CORE_ADDR
fba45db2 49z8k_frame_saved_pc (struct frame_info *frame)
c906108c
SS
50{
51 return read_memory_pointer (frame->frame + (BIG ? 4 : 2));
52}
53
54#define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0))
55#define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0))
56#define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa)
57#define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76)
58#define IS_SUB2_SP(x) (x==0x1b87)
59#define IS_MOVK_R5(x) (x==0x7905)
60#define IS_SUB_SP(x) ((x & 0xffff) == 0x020f)
61#define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa))
62
63/* work out how much local space is on the stack and
64 return the pc pointing to the first push */
65
66static CORE_ADDR
fba45db2 67skip_adjust (CORE_ADDR pc, int *size)
c906108c
SS
68{
69 *size = 0;
70
71 if (IS_PUSH_FP (read_memory_short (pc))
72 && IS_MOV_SP_FP (read_memory_short (pc + 2)))
73 {
74 /* This is a function with an explict frame pointer */
75 pc += 4;
76 *size += 2; /* remember the frame pointer */
77 }
78
79 /* remember any stack adjustment */
80 if (IS_SUB_SP (read_memory_short (pc)))
81 {
82 *size += read_memory_short (pc + 2);
83 pc += 4;
84 }
85 return pc;
86}
87
a14ed312 88static CORE_ADDR examine_frame (CORE_ADDR, CORE_ADDR * regs, CORE_ADDR);
c906108c 89static CORE_ADDR
fba45db2 90examine_frame (CORE_ADDR pc, CORE_ADDR *regs, CORE_ADDR sp)
c906108c
SS
91{
92 int w = read_memory_short (pc);
93 int offset = 0;
94 int regno;
95
96 for (regno = 0; regno < NUM_REGS; regno++)
97 regs[regno] = 0;
98
99 while (IS_PUSHW (w) || IS_PUSHL (w))
100 {
101 /* work out which register is being pushed to where */
102 if (IS_PUSHL (w))
103 {
104 regs[w & 0xf] = offset;
105 regs[(w & 0xf) + 1] = offset + 2;
106 offset += 4;
107 }
108 else
109 {
110 regs[w & 0xf] = offset;
111 offset += 2;
112 }
113 pc += 2;
114 w = read_memory_short (pc);
115 }
116
117 if (IS_MOVE_FP (w))
118 {
119 /* We know the fp */
120
121 }
122 else if (IS_SUB_SP (w))
123 {
124 /* Subtracting a value from the sp, so were in a function
c5aa993b
JM
125 which needs stack space for locals, but has no fp. We fake up
126 the values as if we had an fp */
c906108c
SS
127 regs[FP_REGNUM] = sp;
128 }
129 else
130 {
131 /* This one didn't have an fp, we'll fake it up */
132 regs[SP_REGNUM] = sp;
133 }
134 /* stack pointer contains address of next frame */
c5aa993b 135 /* regs[fp_regnum()] = fp; */
c906108c
SS
136 regs[SP_REGNUM] = sp;
137 return pc;
138}
139
140CORE_ADDR
fba45db2 141z8k_skip_prologue (CORE_ADDR start_pc)
c906108c
SS
142{
143 CORE_ADDR dummy[NUM_REGS];
144
145 return examine_frame (start_pc, dummy, 0);
146}
147
148CORE_ADDR
fba45db2 149z8k_addr_bits_remove (CORE_ADDR addr)
c906108c
SS
150{
151 return (addr & PTR_MASK);
152}
153
d4f3574e
SS
154static int
155read_memory_pointer (CORE_ADDR x)
c906108c
SS
156{
157 return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2);
158}
159
160CORE_ADDR
fba45db2 161z8k_frame_chain (struct frame_info *thisframe)
c906108c
SS
162{
163 if (thisframe->prev == 0)
164 {
165 /* This is the top of the stack, let's get the sp for real */
166 }
167 if (!inside_entry_file (thisframe->pc))
168 {
169 return read_memory_pointer (thisframe->frame);
170 }
171 return 0;
172}
173
174void
fba45db2 175init_frame_pc (void)
c906108c 176{
e1e9e218 177 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
178}
179
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. */
185
186void
fba45db2 187z8k_frame_init_saved_regs (struct frame_info *frame_info)
c906108c
SS
188{
189 CORE_ADDR pc;
190 int w;
191
192 frame_saved_regs_zalloc (frame_info);
193 pc = get_pc_function_start (frame_info->pc);
194
195 /* wander down the instruction stream */
196 examine_frame (pc, frame_info->saved_regs, frame_info->frame);
197
198}
199
200void
fba45db2 201z8k_push_dummy_frame (void)
c906108c 202{
e1e9e218 203 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
204}
205
206int
fba45db2 207gdb_print_insn_z8k (bfd_vma memaddr, disassemble_info *info)
c906108c
SS
208{
209 if (BIG)
210 return print_insn_z8001 (memaddr, info);
211 else
212 return print_insn_z8002 (memaddr, info);
213}
214
215/* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
216 is not the address of a valid instruction, the address of the next
217 instruction beyond ADDR otherwise. *PWORD1 receives the first word
c5aa993b 218 of the instruction. */
c906108c
SS
219
220CORE_ADDR
fba45db2 221NEXT_PROLOGUE_INSN (CORE_ADDR addr, CORE_ADDR lim, short *pword1)
c906108c
SS
222{
223 char buf[2];
224 if (addr < lim + 8)
225 {
226 read_memory (addr, buf, 2);
227 *pword1 = extract_signed_integer (buf, 2);
228
229 return addr + 2;
230 }
231 return 0;
232}
233
234#if 0
235/* Put here the code to store, into a struct frame_saved_regs,
236 the addresses of the saved registers of frame described by FRAME_INFO.
237 This includes special registers such as pc and fp saved in special
238 ways in the stack frame. sp is even more special:
239 the address we return for it IS the sp for the next frame.
240
241 We cache the result of doing this in the frame_cache_obstack, since
242 it is fairly expensive. */
243
244void
fba45db2 245frame_find_saved_regs (struct frame_info *fip, struct frame_saved_regs *fsrp)
c906108c
SS
246{
247 int locals;
248 CORE_ADDR pc;
249 CORE_ADDR adr;
250 int i;
251
252 memset (fsrp, 0, sizeof *fsrp);
253
254 pc = skip_adjust (get_pc_function_start (fip->pc), &locals);
255
256 {
257 adr = FRAME_FP (fip) - locals;
258 for (i = 0; i < 8; i++)
259 {
260 int word = read_memory_short (pc);
261
262 pc += 2;
263 if (IS_PUSHL (word))
264 {
265 fsrp->regs[word & 0xf] = adr;
266 fsrp->regs[(word & 0xf) + 1] = adr - 2;
267 adr -= 4;
268 }
269 else if (IS_PUSHW (word))
270 {
271 fsrp->regs[word & 0xf] = adr;
272 adr -= 2;
273 }
274 else
275 break;
276 }
277
278 }
279
280 fsrp->regs[PC_REGNUM] = fip->frame + 4;
281 fsrp->regs[FP_REGNUM] = fip->frame;
282
283}
284#endif
285
286int
d4f3574e 287z8k_saved_pc_after_call (struct frame_info *frame)
c906108c 288{
c5aa993b 289 return ADDR_BITS_REMOVE
c906108c
SS
290 (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE));
291}
292
293
294void
fba45db2 295extract_return_value (struct type *type, char *regbuf, char *valbuf)
c906108c
SS
296{
297 int b;
298 int len = TYPE_LENGTH (type);
299
300 for (b = 0; b < len; b += 2)
301 {
302 int todo = len - b;
303
304 if (todo > 2)
305 todo = 2;
306 memcpy (valbuf + b, regbuf + b, todo);
307 }
308}
309
310void
fba45db2 311write_return_value (struct type *type, char *valbuf)
c906108c
SS
312{
313 int reg;
314 int len;
315
316 for (len = 0; len < TYPE_LENGTH (type); len += 2)
c5aa993b 317 write_register_bytes (REGISTER_BYTE (len / 2 + 2), valbuf + len, 2);
c906108c
SS
318}
319
320void
fba45db2 321store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
c906108c
SS
322{
323 write_register (2, addr);
324}
325
326
327void
fba45db2 328z8k_print_register_hook (int regno)
c906108c
SS
329{
330 if ((regno & 1) == 0 && regno < 16)
331 {
332 unsigned short l[2];
333
cda5a58a
AC
334 frame_register_read (selected_frame, regno, (char *) (l + 0));
335 frame_register_read (selected_frame, regno + 1, (char *) (l + 1));
c906108c
SS
336 printf_unfiltered ("\t");
337 printf_unfiltered ("%04x%04x", l[0], l[1]);
338 }
339
340 if ((regno & 3) == 0 && regno < 16)
341 {
342 unsigned short l[4];
343
cda5a58a
AC
344 frame_register_read (selected_frame, regno, (char *) (l + 0));
345 frame_register_read (selected_frame, regno + 1, (char *) (l + 1));
346 frame_register_read (selected_frame, regno + 2, (char *) (l + 2));
347 frame_register_read (selected_frame, regno + 3, (char *) (l + 3));
c906108c
SS
348
349 printf_unfiltered ("\t");
350 printf_unfiltered ("%04x%04x%04x%04x", l[0], l[1], l[2], l[3]);
351 }
352 if (regno == 15)
353 {
354 unsigned short rval;
355 int i;
356
cda5a58a 357 frame_register_read (selected_frame, regno, (char *) (&rval));
c906108c
SS
358
359 printf_unfiltered ("\n");
360 for (i = 0; i < 10; i += 2)
361 {
d4f3574e
SS
362 printf_unfiltered ("(sp+%d=%04x)", i,
363 (unsigned int)read_memory_short (rval + i));
c906108c
SS
364 }
365 }
366
367}
368
369void
fba45db2 370z8k_pop_frame (void)
c906108c
SS
371{
372}
373
374struct cmd_list_element *setmemorylist;
375
376void
fba45db2 377z8k_set_pointer_size (int newsize)
c906108c
SS
378{
379 static int oldsize = 0;
380
381 if (oldsize != newsize)
382 {
383 printf_unfiltered ("pointer size set to %d bits\n", newsize);
384 oldsize = newsize;
385 if (newsize == 32)
386 {
387 BIG = 1;
388 }
389 else
390 {
391 BIG = 0;
392 }
d4f3574e
SS
393 /* FIXME: This code should be using the GDBARCH framework to
394 handle changed type sizes. If this problem is ever fixed
395 (the direct reference to _initialize_gdbtypes() below
396 eliminated) then Makefile.in should be updated so that
397 z8k-tdep.c is again compiled with -Werror. */
c906108c
SS
398 _initialize_gdbtypes ();
399 }
400}
401
402static void
fba45db2 403segmented_command (char *args, int from_tty)
c906108c
SS
404{
405 z8k_set_pointer_size (32);
406}
407
408static void
fba45db2 409unsegmented_command (char *args, int from_tty)
c906108c
SS
410{
411 z8k_set_pointer_size (16);
412}
413
414static void
fba45db2 415set_memory (char *args, int from_tty)
c906108c
SS
416{
417 printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n");
418 help_list (setmemorylist, "set memory ", -1, gdb_stdout);
419}
420
421void
fba45db2 422_initialize_z8ktdep (void)
c906108c
SS
423{
424 tm_print_insn = gdb_print_insn_z8k;
425
426 add_prefix_cmd ("memory", no_class, set_memory,
427 "set the memory model", &setmemorylist, "set memory ", 0,
428 &setlist);
429 add_cmd ("segmented", class_support, segmented_command,
430 "Set segmented memory model.", &setmemorylist);
431 add_cmd ("unsegmented", class_support, unsegmented_command,
432 "Set unsegmented memory model.", &setmemorylist);
433
434}
This page took 0.227626 seconds and 4 git commands to generate.