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