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