updated date
[deliverable/binutils-gdb.git] / gdb / z8k-tdep.c
CommitLineData
a332e593
SC
1/* Target-machine dependent code for Zilog Z8000, for GDB.
2 Copyright (C) 1992 Free Software Foundation, Inc.
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
20/*
21 Contributed by Steve Chamberlain
22 sac@cygnus.com
23 */
24
25
26#include "defs.h"
27#include "frame.h"
28#include "obstack.h"
29#include "symtab.h"
30#include "gdbtypes.h"
31
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
38CORE_ADDR
39frame_saved_pc (frame)
40FRAME 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
55/* work out how much local space is on the stack and
56 return the pc pointing to the first push */
57
58static
59CORE_ADDR
60skip_adjust(pc, size)
61CORE_ADDR pc;
62int *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
84int
85examine_frame(pc, regs, sp)
86CORE_ADDR pc;
87struct frame_saved_regs *regs;
88CORE_ADDR sp;
89{
90 int w = read_memory_short(pc);
91 int offset = 0;
92 int regno;
93
94
95
96 for (regno = 0; regno < NUM_REGS; regno++)
97 regs->regs[regno] = 0;
98
99 while (IS_PUSHW(w) || IS_PUSHL(w))
100 {
101 /* work out which register is being pushed to where */
102 if (IS_PUSHL(w))
103 {
104 regs->regs[w & 0xf] = offset;
105 regs->regs[(w & 0xf) + 1] = offset +2;
106 offset += 4;
107 }
108 else {
109 regs->regs[w & 0xf] = offset;
110 offset += 2;
111 }
112 pc += 2;
113 w = read_memory_short(pc);
114 }
115
116 if (IS_MOVE_FP(w))
117 {
118 /* We know the fp */
119
120 }
121 else if (IS_SUB_SP(w))
122 {
123 /* Subtracting a value from the sp, so were in a function
124 which needs stack space for locals, but has no fp. We fake up
125 the values as if we had an fp */
126 regs->regs[FP_REGNUM] = sp;
127 }
128 else
129 {
130 /* This one didn't have an fp, we'll fake it up */
131 regs->regs[SP_REGNUM] = sp;
132 }
133 /* stack pointer contains address of next frame */
134/* regs->regs[fp_regnum()] = fp;*/
135 regs->regs[SP_REGNUM] = sp;
136 return pc;
137}
138
139CORE_ADDR z8k_skip_prologue(start_pc)
140CORE_ADDR start_pc;
141{
142 struct frame_saved_regs dummy;
143 return examine_frame(start_pc, &dummy, 0);
144}
145
146CORE_ADDR addr_bits_remove(x)
147CORE_ADDR x;
148{
149 return x & PTR_MASK;
150}
151
152read_memory_pointer(x)
153CORE_ADDR x;
154{
155
156return read_memory_integer(ADDR_BITS_REMOVE(x), BIG ? 4 : 2);
157}
158
159FRAME_ADDR
160frame_chain (thisframe)
161 FRAME thisframe;
162{
163 if (thisframe->prev == 0)
164 {
165 /* This is the top of the stack, let's get the sp for real */
166 }
167 if (!inside_entry_file ((thisframe)->pc))
168 {
169return read_memory_pointer ((thisframe)->frame);
170 }
171
172 return 0;
173}
174
175init_frame_pc() { abort(); }
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
183void get_frame_saved_regs(frame_info, frame_saved_regs)
184 struct frame_info *frame_info;
185 struct frame_saved_regs *frame_saved_regs;
186
187{
188CORE_ADDR pc;
189int w;
190bzero(frame_saved_regs, sizeof(*frame_saved_regs));
191pc = get_pc_function_start(frame_info->pc);
192
193/* wander down the instruction stream */
194examine_frame(pc, frame_saved_regs, frame_info->frame);
195
196}
197
198
199extract_return_value(valtype, regbuf, valbuf)
200struct type *valtype;
201char regbuf[REGISTER_BYTES];
202char *valbuf;
203{
204 bcopy(regbuf + REGISTER_BYTE(2), valbuf, TYPE_LENGTH(valtype));
205}
206void z8k_push_dummy_frame() { abort(); }
207
208int print_insn(memaddr, stream)
209CORE_ADDR memaddr;
210FILE *stream;
211{
212 char temp[20];
213 read_memory (memaddr, temp, 20);
214 if (BIG) {
215 return print_insn_z8001(memaddr, temp, stream);
216 }
217 else {
218 return print_insn_z8002(memaddr, temp, stream);
219 }
220}
221
222void
223store_return_value()
224{
225abort();
226}
227void
228store_struct_return() { abort(); }
229
230
231
232/* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
233 is not the address of a valid instruction, the address of the next
234 instruction beyond ADDR otherwise. *PWORD1 receives the first word
235 of the instruction.*/
236
237
238CORE_ADDR
239NEXT_PROLOGUE_INSN(addr, lim, pword1)
240CORE_ADDR addr;
241CORE_ADDR lim;
242short *pword1;
243{
244 if (addr < lim+8)
245 {
246 read_memory (addr, pword1, sizeof(*pword1));
247 SWAP_TARGET_AND_HOST (pword1, sizeof (short));
248 return addr + 2;
249 }
250
251 return 0;
252
253}
254
255
256/* Put here the code to store, into a struct frame_saved_regs,
257 the addresses of the saved registers of frame described by FRAME_INFO.
258 This includes special registers such as pc and fp saved in special
259 ways in the stack frame. sp is even more special:
260 the address we return for it IS the sp for the next frame.
261
262 We cache the result of doing this in the frame_cache_obstack, since
263 it is fairly expensive. */
264
265void
266frame_find_saved_regs (fip, fsrp)
267 struct frame_info *fip;
268 struct frame_saved_regs *fsrp;
269{
270 int locals;
271 CORE_ADDR pc;
272 CORE_ADDR adr;
273 int i;
274
275 memset (fsrp, 0, sizeof *fsrp);
276
277 pc = skip_adjust(get_pc_function_start (fip->pc), &locals);
278
279 {
280 adr = fip->frame - locals;
281 for (i = 0; i < 8; i++)
282 {
283 int word = read_memory_short(pc);
284 pc += 2 ;
285 if (IS_PUSHL(word)) {
286 fsrp->regs[word & 0xf] = adr;
287 fsrp->regs[(word & 0xf) + 1] = adr - 2;
288 adr -= 4;
289 }
290 else if (IS_PUSHW(word)) {
291 fsrp->regs[word & 0xf] = adr;
292 adr -= 2;
293 }
294 else
295 break;
296 }
297
298 }
299
300 fsrp->regs[PC_REGNUM] = fip->frame + 4;
301 fsrp->regs[FP_REGNUM] = fip->frame;
302
303}
304
305void
306addr_bits_set() { abort(); }
307
308int
309saved_pc_after_call()
310{
311 return addr_bits_remove(read_memory_integer(read_register(SP_REGNUM), PTR_SIZE));
312}
313
314void
315print_register_hook(regno)
316int regno;
317{
318
319 if ((regno & 1)==0 && regno < 16)
320 {
321 unsigned short l[2];
322 read_relative_register_raw_bytes(regno, (char *)(l+0));
323 read_relative_register_raw_bytes(regno+1, (char *)(l+1));
324 printf("\t");
325 printf("%04x%04x", l[0],l[1]);
326 }
327
328 if ((regno & 3)== 0 && regno < 16)
329 {
330 unsigned short l[4];
331 read_relative_register_raw_bytes(regno, l+0);
332 read_relative_register_raw_bytes(regno+1, l+1);
333 read_relative_register_raw_bytes(regno+2, l+2);
334 read_relative_register_raw_bytes(regno+3, l+3);
335
336 printf("\t");
337 printf("%04x%04x%04x%04x", l[0],l[1],l[2],l[3]);
338 }
339 if (regno == 15)
340 {
341 unsigned short rval;
342 int i;
343 read_relative_register_raw_bytes(regno, (char *)(&rval));
344
345 printf("\n");
346 for (i = 0; i < 10; i+=2) {
347 printf("(sp+%d=%04x)",i, read_memory_short(rval+i));
348 }
349 }
350
351}
352
353
354void
355register_convert_to_virtual(regnum, from, to)
356unsigned char *from;
357unsigned char *to;
358{
359 to[0] = from[0];
360 to[1] = from[1];
361 to[2] = from[2];
362 to[3] = from[3];
363}
364
365void
366register_convert_to_raw(regnum, to, from)
367char *to;
368char *from;
369{
370 to[0] = from[0];
371 to[1] = from[1];
372 to[2] = from[2];
373 to[3] = from[3];
374}
375
376
377
378void z8k_pop_frame() { }
This page took 0.037797 seconds and 4 git commands to generate.