* ieee-float.c: Moved to ../libiberty.
[deliverable/binutils-gdb.git] / gdb / z8k-tdep.c
CommitLineData
a332e593 1/* Target-machine dependent code for Zilog Z8000, for GDB.
e4ebb8e5 2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
a332e593
SC
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
e4ebb8e5 20/*
a332e593 21 Contributed by Steve Chamberlain
e4ebb8e5 22 sac@cygnus.com
a332e593
SC
23 */
24
a332e593
SC
25#include "defs.h"
26#include "frame.h"
27#include "obstack.h"
28#include "symtab.h"
e4ebb8e5 29#include "gdbcmd.h"
a332e593
SC
30#include "gdbtypes.h"
31
a332e593
SC
32/* Return the saved PC from this frame.
33
34 If the frame has a memory copy of SRP_REGNUM, use that. If not,
35 just use the register SRP_REGNUM itself. */
36
37CORE_ADDR
38frame_saved_pc (frame)
e4ebb8e5 39 FRAME frame;
a332e593 40{
e4ebb8e5 41 return (read_memory_pointer (frame->frame + (BIG ? 4 : 2)));
a332e593
SC
42}
43
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))
52
e4ebb8e5 53/* work out how much local space is on the stack and
a332e593
SC
54 return the pc pointing to the first push */
55
e4ebb8e5
SC
56static CORE_ADDR
57skip_adjust (pc, size)
58 CORE_ADDR pc;
59 int *size;
a332e593
SC
60{
61 *size = 0;
62
e4ebb8e5
SC
63 if (IS_PUSH_FP (read_memory_short (pc))
64 && IS_MOV_SP_FP (read_memory_short (pc + 2)))
65 {
66 /* This is a function with an explict frame pointer */
67 pc += 4;
68 *size += 2; /* remember the frame pointer */
69 }
a332e593
SC
70
71 /* remember any stack adjustment */
e4ebb8e5
SC
72 if (IS_SUB_SP (read_memory_short (pc)))
73 {
74 *size += read_memory_short (pc + 2);
75 pc += 4;
76 }
a332e593
SC
77 return pc;
78}
79
a332e593 80int
e4ebb8e5
SC
81examine_frame (pc, regs, sp)
82 CORE_ADDR pc;
83 struct frame_saved_regs *regs;
84 CORE_ADDR sp;
a332e593 85{
e4ebb8e5
SC
86 int w = read_memory_short (pc);
87 int offset = 0;
88 int regno;
a332e593 89
e4ebb8e5 90 for (regno = 0; regno < NUM_REGS; regno++)
b2ff9b68 91 regs->regs[regno] = 0;
a332e593 92
e4ebb8e5 93 while (IS_PUSHW (w) || IS_PUSHL (w))
e4ebb8e5 94 {
b2ff9b68
SC
95 /* work out which register is being pushed to where */
96 if (IS_PUSHL (w))
97 {
98 regs->regs[w & 0xf] = offset;
99 regs->regs[(w & 0xf) + 1] = offset + 2;
100 offset += 4;
101 }
102 else
103 {
104 regs->regs[w & 0xf] = offset;
105 offset += 2;
106 }
107 pc += 2;
108 w = read_memory_short (pc);
a332e593 109 }
a332e593 110
e4ebb8e5 111 if (IS_MOVE_FP (w))
b2ff9b68
SC
112 {
113 /* We know the fp */
e4ebb8e5 114
b2ff9b68 115 }
e4ebb8e5 116 else if (IS_SUB_SP (w))
b2ff9b68
SC
117 {
118 /* Subtracting a value from the sp, so were in a function
e4ebb8e5
SC
119 which needs stack space for locals, but has no fp. We fake up
120 the values as if we had an fp */
b2ff9b68
SC
121 regs->regs[FP_REGNUM] = sp;
122 }
e4ebb8e5 123 else
b2ff9b68
SC
124 {
125 /* This one didn't have an fp, we'll fake it up */
126 regs->regs[SP_REGNUM] = sp;
127 }
e4ebb8e5
SC
128 /* stack pointer contains address of next frame */
129 /* regs->regs[fp_regnum()] = fp;*/
a332e593
SC
130 regs->regs[SP_REGNUM] = sp;
131 return pc;
132}
133
b2ff9b68 134CORE_ADDR
e4ebb8e5
SC
135z8k_skip_prologue (start_pc)
136 CORE_ADDR start_pc;
a332e593
SC
137{
138 struct frame_saved_regs dummy;
e4ebb8e5
SC
139
140 return examine_frame (start_pc, &dummy, 0);
a332e593
SC
141}
142
b2ff9b68 143CORE_ADDR
e4ebb8e5
SC
144addr_bits_remove (x)
145 CORE_ADDR x;
a332e593
SC
146{
147 return x & PTR_MASK;
148}
149
e4ebb8e5
SC
150read_memory_pointer (x)
151 CORE_ADDR x;
a332e593
SC
152{
153
e4ebb8e5 154 return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2);
a332e593
SC
155}
156
157FRAME_ADDR
158frame_chain (thisframe)
159 FRAME thisframe;
160{
e4ebb8e5
SC
161 if (thisframe->prev == 0)
162 {
163 /* This is the top of the stack, let's get the sp for real */
164 }
a332e593 165 if (!inside_entry_file ((thisframe)->pc))
e4ebb8e5
SC
166 {
167 return read_memory_pointer ((thisframe)->frame);
168 }
a332e593
SC
169 return 0;
170}
171
e4ebb8e5
SC
172init_frame_pc ()
173{
174 abort ();
175}
a332e593
SC
176
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. */
182
b2ff9b68 183void
e4ebb8e5 184get_frame_saved_regs (frame_info, frame_saved_regs)
a332e593
SC
185 struct frame_info *frame_info;
186 struct frame_saved_regs *frame_saved_regs;
187
188{
e4ebb8e5
SC
189 CORE_ADDR pc;
190 int w;
191
192 bzero (frame_saved_regs, sizeof (*frame_saved_regs));
193 pc = get_pc_function_start (frame_info->pc);
a332e593
SC
194
195/* wander down the instruction stream */
e4ebb8e5 196 examine_frame (pc, frame_saved_regs, frame_info->frame);
a332e593
SC
197
198}
199
b2ff9b68 200void
e4ebb8e5
SC
201z8k_push_dummy_frame ()
202{
203 abort ();
a332e593 204}
a332e593 205
b2ff9b68 206int
e4ebb8e5
SC
207print_insn (memaddr, stream)
208 CORE_ADDR memaddr;
209 FILE *stream;
a332e593
SC
210{
211 char temp[20];
00cea52f
PB
212 disassemble_info info;
213
214 GDB_INIT_DISASSEMBLE_INFO(info, stream);
a332e593 215
e4ebb8e5
SC
216 read_memory (memaddr, temp, 20);
217 if (BIG)
218 {
00cea52f 219 return print_insn_z8001 (memaddr, temp, &info);
e4ebb8e5
SC
220 }
221 else
222 {
00cea52f 223 return print_insn_z8002 (memaddr, temp, &info);
e4ebb8e5 224 }
a332e593 225}
a332e593
SC
226
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.*/
231
a332e593 232CORE_ADDR
e4ebb8e5
SC
233NEXT_PROLOGUE_INSN (addr, lim, pword1)
234 CORE_ADDR addr;
235 CORE_ADDR lim;
236 short *pword1;
a332e593 237{
e4ebb8e5
SC
238 if (addr < lim + 8)
239 {
240 read_memory (addr, pword1, sizeof (*pword1));
241 SWAP_TARGET_AND_HOST (pword1, sizeof (short));
242
243 return addr + 2;
244 }
a332e593
SC
245
246 return 0;
247
248}
249
a332e593
SC
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.
255
256 We cache the result of doing this in the frame_cache_obstack, since
257 it is fairly expensive. */
258
259void
260frame_find_saved_regs (fip, fsrp)
261 struct frame_info *fip;
262 struct frame_saved_regs *fsrp;
263{
264 int locals;
265 CORE_ADDR pc;
266 CORE_ADDR adr;
267 int i;
e4ebb8e5 268
a332e593
SC
269 memset (fsrp, 0, sizeof *fsrp);
270
e4ebb8e5
SC
271 pc = skip_adjust (get_pc_function_start (fip->pc), &locals);
272
273 {
274 adr = fip->frame - locals;
275 for (i = 0; i < 8; i++)
276 {
277 int word = read_memory_short (pc);
278
279 pc += 2;
280 if (IS_PUSHL (word))
281 {
282 fsrp->regs[word & 0xf] = adr;
283 fsrp->regs[(word & 0xf) + 1] = adr - 2;
284 adr -= 4;
285 }
286 else if (IS_PUSHW (word))
287 {
288 fsrp->regs[word & 0xf] = adr;
289 adr -= 2;
290 }
291 else
292 break;
293 }
294
295 }
296
a332e593
SC
297 fsrp->regs[PC_REGNUM] = fip->frame + 4;
298 fsrp->regs[FP_REGNUM] = fip->frame;
299
300}
301
302void
e4ebb8e5
SC
303addr_bits_set ()
304{
305 abort ();
306}
a332e593
SC
307
308int
e4ebb8e5
SC
309saved_pc_after_call ()
310{
2d8d693a
SC
311 return addr_bits_remove
312 (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE));
313}
314
315
316extract_return_value(type, regbuf, valbuf)
317struct type *type;
318char *regbuf;
319char *valbuf;
320{
321 int b;
322 int len = TYPE_LENGTH(type);
323
324 for (b = 0; b < len; b += 2) {
325 int todo = len - b;
326 if (todo > 2)
327 todo = 2;
328 memcpy(valbuf + b, regbuf + b, todo);
329 }
a332e593
SC
330}
331
2d8d693a
SC
332void
333write_return_value(type, valbuf)
334struct type *type;
335char *valbuf;
336{
337 int reg;
338 int len;
339 for (len = 0; len < TYPE_LENGTH(type); len += 2)
340 {
341 write_register_bytes(REGISTER_BYTE(len /2 + 2), valbuf + len, 2);
342 }
343}
344
345void
346store_struct_return(addr, sp)
347CORE_ADDR addr;
348CORE_ADDR sp;
349{
350 write_register(2, addr);
351}
352
353
a332e593 354void
e4ebb8e5
SC
355print_register_hook (regno)
356 int regno;
a332e593 357{
e4ebb8e5
SC
358 if ((regno & 1) == 0 && regno < 16)
359 {
360 unsigned short l[2];
a332e593 361
e4ebb8e5
SC
362 read_relative_register_raw_bytes (regno, (char *) (l + 0));
363 read_relative_register_raw_bytes (regno + 1, (char *) (l + 1));
364 printf ("\t");
365 printf ("%04x%04x", l[0], l[1]);
366 }
367
368 if ((regno & 3) == 0 && regno < 16)
369 {
370 unsigned short l[4];
371
b2ff9b68
SC
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));
a332e593 376
e4ebb8e5
SC
377 printf ("\t");
378 printf ("%04x%04x%04x%04x", l[0], l[1], l[2], l[3]);
a332e593 379 }
e4ebb8e5
SC
380 if (regno == 15)
381 {
382 unsigned short rval;
383 int i;
a332e593 384
e4ebb8e5
SC
385 read_relative_register_raw_bytes (regno, (char *) (&rval));
386
387 printf ("\n");
388 for (i = 0; i < 10; i += 2)
389 {
390 printf ("(sp+%d=%04x)", i, read_memory_short (rval + i));
391 }
392 }
393
394}
a332e593
SC
395
396void
e4ebb8e5
SC
397register_convert_to_virtual (regnum, from, to)
398 unsigned char *from;
399 unsigned char *to;
a332e593 400{
e4ebb8e5
SC
401 to[0] = from[0];
402 to[1] = from[1];
403 to[2] = from[2];
404 to[3] = from[3];
a332e593
SC
405}
406
407void
e4ebb8e5
SC
408register_convert_to_raw (regnum, to, from)
409 char *to;
410 char *from;
411{
412 to[0] = from[0];
413 to[1] = from[1];
414 to[2] = from[2];
415 to[3] = from[3];
416}
417
b2ff9b68 418void
e4ebb8e5 419z8k_pop_frame ()
a332e593 420{
a332e593
SC
421}
422
e4ebb8e5
SC
423struct cmd_list_element *setmemorylist;
424
b2ff9b68 425void
e4ebb8e5
SC
426z8k_set_pointer_size (newsize)
427 int newsize;
428{
429 static int oldsize = 0;
a332e593 430
e4ebb8e5
SC
431 if (oldsize != newsize)
432 {
433 printf ("pointer size set to %d bits\n", newsize);
434 oldsize = newsize;
435 if (newsize == 32)
436 {
437 BIG = 1;
438 }
439 else
440 {
441 BIG = 0;
442 }
443 _initialize_gdbtypes ();
444 }
445}
a332e593 446
e4ebb8e5
SC
447static void
448segmented_command (args, from_tty)
449 char *args;
450 int from_tty;
451{
2d8d693a 452 z8k_set_pointer_size (32);
e4ebb8e5
SC
453}
454
455static void
456unsegmented_command (args, from_tty)
457 char *args;
458 int from_tty;
459{
460 z8k_set_pointer_size (16);
461
462}
463
464static void
465set_memory (args, from_tty)
466 char *args;
467 int from_tty;
468{
469 printf ("\"set memory\" must be followed by the name of a memory subcommand.\n");
470 help_list (setmemorylist, "set memory ", -1, stdout);
471}
472
473_initialize_z8ktdep ()
474{
475 add_prefix_cmd ("memory", no_class, set_memory,
476 "set the memory model", &setmemorylist, "set memory ", 0,
477 &setlist);
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);
482
483}
This page took 0.050723 seconds and 4 git commands to generate.