* nm-hp300bsd.h (ATTACH_DETACH, PTRACE_ATTACH, PTRACE_DETACH): define.
[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
SC
90 for (regno = 0; regno < NUM_REGS; regno++)
91 regs->regs[regno] = 0;
a332e593 92
e4ebb8e5 93 while (IS_PUSHW (w) || IS_PUSHL (w))
a332e593
SC
94 {
95 /* work out which register is being pushed to where */
e4ebb8e5 96 if (IS_PUSHL (w))
a332e593
SC
97 {
98 regs->regs[w & 0xf] = offset;
e4ebb8e5 99 regs->regs[(w & 0xf) + 1] = offset + 2;
a332e593
SC
100 offset += 4;
101 }
e4ebb8e5
SC
102 else
103 {
a332e593
SC
104 regs->regs[w & 0xf] = offset;
105 offset += 2;
106 }
107 pc += 2;
e4ebb8e5 108 w = read_memory_short (pc);
a332e593
SC
109 }
110
e4ebb8e5
SC
111 if (IS_MOVE_FP (w))
112 {
113 /* We know the fp */
114
115 }
116 else if (IS_SUB_SP (w))
117 {
118 /* Subtracting a value from the sp, so were in a function
119 which needs stack space for locals, but has no fp. We fake up
120 the values as if we had an fp */
121 regs->regs[FP_REGNUM] = sp;
122 }
123 else
124 {
125 /* This one didn't have an fp, we'll fake it up */
126 regs->regs[SP_REGNUM] = sp;
127 }
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
e4ebb8e5
SC
134CORE_ADDR
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
e4ebb8e5
SC
143CORE_ADDR
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
e4ebb8e5
SC
183void
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
e4ebb8e5
SC
200void
201z8k_push_dummy_frame ()
202{
203 abort ();
a332e593 204}
a332e593 205
e4ebb8e5
SC
206int
207print_insn (memaddr, stream)
208 CORE_ADDR memaddr;
209 FILE *stream;
a332e593
SC
210{
211 char temp[20];
a332e593 212
e4ebb8e5
SC
213 read_memory (memaddr, temp, 20);
214 if (BIG)
215 {
216 return print_insn_z8001 (memaddr, temp, stream);
217 }
218 else
219 {
220 return print_insn_z8002 (memaddr, temp, stream);
221 }
a332e593 222}
a332e593
SC
223
224/* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
225 is not the address of a valid instruction, the address of the next
226 instruction beyond ADDR otherwise. *PWORD1 receives the first word
227 of the instruction.*/
228
a332e593 229CORE_ADDR
e4ebb8e5
SC
230NEXT_PROLOGUE_INSN (addr, lim, pword1)
231 CORE_ADDR addr;
232 CORE_ADDR lim;
233 short *pword1;
a332e593 234{
e4ebb8e5
SC
235 if (addr < lim + 8)
236 {
237 read_memory (addr, pword1, sizeof (*pword1));
238 SWAP_TARGET_AND_HOST (pword1, sizeof (short));
239
240 return addr + 2;
241 }
a332e593
SC
242
243 return 0;
244
245}
246
a332e593
SC
247/* Put here the code to store, into a struct frame_saved_regs,
248 the addresses of the saved registers of frame described by FRAME_INFO.
249 This includes special registers such as pc and fp saved in special
250 ways in the stack frame. sp is even more special:
251 the address we return for it IS the sp for the next frame.
252
253 We cache the result of doing this in the frame_cache_obstack, since
254 it is fairly expensive. */
255
256void
257frame_find_saved_regs (fip, fsrp)
258 struct frame_info *fip;
259 struct frame_saved_regs *fsrp;
260{
261 int locals;
262 CORE_ADDR pc;
263 CORE_ADDR adr;
264 int i;
e4ebb8e5 265
a332e593
SC
266 memset (fsrp, 0, sizeof *fsrp);
267
e4ebb8e5
SC
268 pc = skip_adjust (get_pc_function_start (fip->pc), &locals);
269
270 {
271 adr = fip->frame - locals;
272 for (i = 0; i < 8; i++)
273 {
274 int word = read_memory_short (pc);
275
276 pc += 2;
277 if (IS_PUSHL (word))
278 {
279 fsrp->regs[word & 0xf] = adr;
280 fsrp->regs[(word & 0xf) + 1] = adr - 2;
281 adr -= 4;
282 }
283 else if (IS_PUSHW (word))
284 {
285 fsrp->regs[word & 0xf] = adr;
286 adr -= 2;
287 }
288 else
289 break;
290 }
291
292 }
293
a332e593
SC
294 fsrp->regs[PC_REGNUM] = fip->frame + 4;
295 fsrp->regs[FP_REGNUM] = fip->frame;
296
297}
298
299void
e4ebb8e5
SC
300addr_bits_set ()
301{
302 abort ();
303}
a332e593
SC
304
305int
e4ebb8e5
SC
306saved_pc_after_call ()
307{
308 return addr_bits_remove (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE));
a332e593
SC
309}
310
311void
e4ebb8e5
SC
312print_register_hook (regno)
313 int regno;
a332e593
SC
314{
315
e4ebb8e5
SC
316 if ((regno & 1) == 0 && regno < 16)
317 {
318 unsigned short l[2];
a332e593 319
e4ebb8e5
SC
320 read_relative_register_raw_bytes (regno, (char *) (l + 0));
321 read_relative_register_raw_bytes (regno + 1, (char *) (l + 1));
322 printf ("\t");
323 printf ("%04x%04x", l[0], l[1]);
324 }
325
326 if ((regno & 3) == 0 && regno < 16)
327 {
328 unsigned short l[4];
329
330 read_relative_register_raw_bytes (regno, l + 0);
331 read_relative_register_raw_bytes (regno + 1, l + 1);
332 read_relative_register_raw_bytes (regno + 2, l + 2);
333 read_relative_register_raw_bytes (regno + 3, l + 3);
a332e593 334
e4ebb8e5
SC
335 printf ("\t");
336 printf ("%04x%04x%04x%04x", l[0], l[1], l[2], l[3]);
a332e593 337 }
e4ebb8e5
SC
338 if (regno == 15)
339 {
340 unsigned short rval;
341 int i;
a332e593 342
e4ebb8e5
SC
343 read_relative_register_raw_bytes (regno, (char *) (&rval));
344
345 printf ("\n");
346 for (i = 0; i < 10; i += 2)
347 {
348 printf ("(sp+%d=%04x)", i, read_memory_short (rval + i));
349 }
350 }
351
352}
a332e593
SC
353
354void
e4ebb8e5
SC
355register_convert_to_virtual (regnum, from, to)
356 unsigned char *from;
357 unsigned char *to;
a332e593 358{
e4ebb8e5
SC
359 to[0] = from[0];
360 to[1] = from[1];
361 to[2] = from[2];
362 to[3] = from[3];
a332e593
SC
363}
364
365void
e4ebb8e5
SC
366register_convert_to_raw (regnum, to, from)
367 char *to;
368 char *from;
369{
370 to[0] = from[0];
371 to[1] = from[1];
372 to[2] = from[2];
373 to[3] = from[3];
374}
375
376void
377z8k_pop_frame ()
a332e593 378{
a332e593
SC
379}
380
e4ebb8e5
SC
381struct cmd_list_element *setmemorylist;
382
383void
384z8k_set_pointer_size (newsize)
385 int newsize;
386{
387 static int oldsize = 0;
a332e593 388
e4ebb8e5
SC
389 if (oldsize != newsize)
390 {
391 printf ("pointer size set to %d bits\n", newsize);
392 oldsize = newsize;
393 if (newsize == 32)
394 {
395 BIG = 1;
396 }
397 else
398 {
399 BIG = 0;
400 }
401 _initialize_gdbtypes ();
402 }
403}
a332e593 404
e4ebb8e5
SC
405static void
406segmented_command (args, from_tty)
407 char *args;
408 int from_tty;
409{
410 z8k_set_pointer_size (16);
411}
412
413static void
414unsegmented_command (args, from_tty)
415 char *args;
416 int from_tty;
417{
418 z8k_set_pointer_size (16);
419
420}
421
422static void
423set_memory (args, from_tty)
424 char *args;
425 int from_tty;
426{
427 printf ("\"set memory\" must be followed by the name of a memory subcommand.\n");
428 help_list (setmemorylist, "set memory ", -1, stdout);
429}
430
431_initialize_z8ktdep ()
432{
433 add_prefix_cmd ("memory", no_class, set_memory,
434 "set the memory model", &setmemorylist, "set memory ", 0,
435 &setlist);
436 add_cmd ("segmented", class_support, segmented_command,
437 "Set segmented memory model.", &setmemorylist);
438 add_cmd ("unsegmented", class_support, unsegmented_command,
439 "Set unsegmented memory model.", &setmemorylist);
440
441}
This page took 0.044318 seconds and 4 git commands to generate.