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