]>
Commit | Line | Data |
---|---|---|
a332e593 | 1 | /* Target-machine dependent code for Zilog Z8000, for GDB. |
669caa9c | 2 | Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
a332e593 SC |
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 | |
6c9638b4 | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
a332e593 | 19 | |
e4ebb8e5 | 20 | /* |
a332e593 | 21 | Contributed by Steve Chamberlain |
e4ebb8e5 | 22 | [email protected] |
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 | 30 | #include "gdbtypes.h" |
52f8e6a0 | 31 | #include "dis-asm.h" |
669caa9c | 32 | |
a332e593 SC |
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) | |
669caa9c | 40 | struct frame_info *frame; |
a332e593 | 41 | { |
669caa9c | 42 | return read_memory_pointer (frame->frame + (BIG ? 4 : 2)); |
a332e593 SC |
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 | ||
e4ebb8e5 | 54 | /* work out how much local space is on the stack and |
a332e593 SC |
55 | return the pc pointing to the first push */ |
56 | ||
e4ebb8e5 SC |
57 | static CORE_ADDR |
58 | skip_adjust (pc, size) | |
59 | CORE_ADDR pc; | |
60 | int *size; | |
a332e593 SC |
61 | { |
62 | *size = 0; | |
63 | ||
e4ebb8e5 SC |
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 | } | |
a332e593 SC |
71 | |
72 | /* remember any stack adjustment */ | |
e4ebb8e5 SC |
73 | if (IS_SUB_SP (read_memory_short (pc))) |
74 | { | |
75 | *size += read_memory_short (pc + 2); | |
76 | pc += 4; | |
77 | } | |
a332e593 SC |
78 | return pc; |
79 | } | |
80 | ||
a332e593 | 81 | int |
e4ebb8e5 SC |
82 | examine_frame (pc, regs, sp) |
83 | CORE_ADDR pc; | |
84 | struct frame_saved_regs *regs; | |
85 | CORE_ADDR sp; | |
a332e593 | 86 | { |
e4ebb8e5 SC |
87 | int w = read_memory_short (pc); |
88 | int offset = 0; | |
89 | int regno; | |
a332e593 | 90 | |
e4ebb8e5 | 91 | for (regno = 0; regno < NUM_REGS; regno++) |
b2ff9b68 | 92 | regs->regs[regno] = 0; |
a332e593 | 93 | |
e4ebb8e5 | 94 | while (IS_PUSHW (w) || IS_PUSHL (w)) |
e4ebb8e5 | 95 | { |
b2ff9b68 SC |
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); | |
a332e593 | 110 | } |
a332e593 | 111 | |
e4ebb8e5 | 112 | if (IS_MOVE_FP (w)) |
b2ff9b68 SC |
113 | { |
114 | /* We know the fp */ | |
e4ebb8e5 | 115 | |
b2ff9b68 | 116 | } |
e4ebb8e5 | 117 | else if (IS_SUB_SP (w)) |
b2ff9b68 SC |
118 | { |
119 | /* Subtracting a value from the sp, so were in a function | |
e4ebb8e5 SC |
120 | which needs stack space for locals, but has no fp. We fake up |
121 | the values as if we had an fp */ | |
b2ff9b68 SC |
122 | regs->regs[FP_REGNUM] = sp; |
123 | } | |
e4ebb8e5 | 124 | else |
b2ff9b68 SC |
125 | { |
126 | /* This one didn't have an fp, we'll fake it up */ | |
127 | regs->regs[SP_REGNUM] = sp; | |
128 | } | |
e4ebb8e5 SC |
129 | /* stack pointer contains address of next frame */ |
130 | /* regs->regs[fp_regnum()] = fp;*/ | |
a332e593 SC |
131 | regs->regs[SP_REGNUM] = sp; |
132 | return pc; | |
133 | } | |
134 | ||
b2ff9b68 | 135 | CORE_ADDR |
e4ebb8e5 SC |
136 | z8k_skip_prologue (start_pc) |
137 | CORE_ADDR start_pc; | |
a332e593 SC |
138 | { |
139 | struct frame_saved_regs dummy; | |
e4ebb8e5 SC |
140 | |
141 | return examine_frame (start_pc, &dummy, 0); | |
a332e593 SC |
142 | } |
143 | ||
b2ff9b68 | 144 | CORE_ADDR |
e4ebb8e5 SC |
145 | addr_bits_remove (x) |
146 | CORE_ADDR x; | |
a332e593 SC |
147 | { |
148 | return x & PTR_MASK; | |
149 | } | |
150 | ||
669caa9c | 151 | int |
e4ebb8e5 SC |
152 | read_memory_pointer (x) |
153 | CORE_ADDR x; | |
a332e593 | 154 | { |
e4ebb8e5 | 155 | return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2); |
a332e593 SC |
156 | } |
157 | ||
669caa9c | 158 | CORE_ADDR |
a332e593 | 159 | frame_chain (thisframe) |
669caa9c | 160 | struct frame_info *thisframe; |
a332e593 | 161 | { |
e4ebb8e5 SC |
162 | if (thisframe->prev == 0) |
163 | { | |
164 | /* This is the top of the stack, let's get the sp for real */ | |
165 | } | |
669caa9c | 166 | if (!inside_entry_file (thisframe->pc)) |
e4ebb8e5 | 167 | { |
669caa9c | 168 | return read_memory_pointer (thisframe->frame); |
e4ebb8e5 | 169 | } |
a332e593 SC |
170 | return 0; |
171 | } | |
172 | ||
e4ebb8e5 SC |
173 | init_frame_pc () |
174 | { | |
175 | abort (); | |
176 | } | |
a332e593 SC |
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 | ||
b2ff9b68 | 184 | void |
e4ebb8e5 | 185 | get_frame_saved_regs (frame_info, frame_saved_regs) |
a332e593 SC |
186 | struct frame_info *frame_info; |
187 | struct frame_saved_regs *frame_saved_regs; | |
188 | ||
189 | { | |
e4ebb8e5 SC |
190 | CORE_ADDR pc; |
191 | int w; | |
192 | ||
4ed97c9a | 193 | memset (frame_saved_regs, '\0', sizeof (*frame_saved_regs)); |
e4ebb8e5 | 194 | pc = get_pc_function_start (frame_info->pc); |
a332e593 SC |
195 | |
196 | /* wander down the instruction stream */ | |
e4ebb8e5 | 197 | examine_frame (pc, frame_saved_regs, frame_info->frame); |
a332e593 SC |
198 | |
199 | } | |
200 | ||
b2ff9b68 | 201 | void |
e4ebb8e5 SC |
202 | z8k_push_dummy_frame () |
203 | { | |
204 | abort (); | |
a332e593 | 205 | } |
a332e593 | 206 | |
b2ff9b68 | 207 | int |
18b46e7c SS |
208 | gdb_print_insn_z8k (memaddr, info) |
209 | bfd_vma memaddr; | |
210 | disassemble_info *info; | |
a332e593 | 211 | { |
e4ebb8e5 | 212 | if (BIG) |
18b46e7c | 213 | return print_insn_z8001 (memaddr, info); |
e4ebb8e5 | 214 | else |
18b46e7c | 215 | return print_insn_z8002 (memaddr, info); |
a332e593 | 216 | } |
a332e593 SC |
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 | ||
a332e593 | 223 | CORE_ADDR |
e4ebb8e5 SC |
224 | NEXT_PROLOGUE_INSN (addr, lim, pword1) |
225 | CORE_ADDR addr; | |
226 | CORE_ADDR lim; | |
227 | short *pword1; | |
a332e593 | 228 | { |
34df79fc | 229 | char buf[2]; |
e4ebb8e5 SC |
230 | if (addr < lim + 8) |
231 | { | |
34df79fc JK |
232 | read_memory (addr, buf, 2); |
233 | *pword1 = extract_signed_integer (buf, 2); | |
e4ebb8e5 SC |
234 | |
235 | return addr + 2; | |
236 | } | |
a332e593 | 237 | return 0; |
a332e593 SC |
238 | } |
239 | ||
a332e593 SC |
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; | |
e4ebb8e5 | 258 | |
a332e593 SC |
259 | memset (fsrp, 0, sizeof *fsrp); |
260 | ||
e4ebb8e5 SC |
261 | pc = skip_adjust (get_pc_function_start (fip->pc), &locals); |
262 | ||
263 | { | |
669caa9c | 264 | adr = FRAME_FP (fip) - locals; |
e4ebb8e5 SC |
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 | ||
a332e593 SC |
287 | fsrp->regs[PC_REGNUM] = fip->frame + 4; |
288 | fsrp->regs[FP_REGNUM] = fip->frame; | |
289 | ||
290 | } | |
291 | ||
a332e593 | 292 | int |
e4ebb8e5 SC |
293 | saved_pc_after_call () |
294 | { | |
2d8d693a SC |
295 | return addr_bits_remove |
296 | (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE)); | |
297 | } | |
298 | ||
299 | ||
669caa9c SS |
300 | extract_return_value (type, regbuf, valbuf) |
301 | struct type *type; | |
302 | char *regbuf; | |
303 | char *valbuf; | |
2d8d693a SC |
304 | { |
305 | int b; | |
669caa9c | 306 | int len = TYPE_LENGTH (type); |
2d8d693a | 307 | |
669caa9c SS |
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 | } | |
a332e593 SC |
316 | } |
317 | ||
2d8d693a | 318 | void |
669caa9c SS |
319 | write_return_value (type, valbuf) |
320 | struct type *type; | |
321 | char *valbuf; | |
2d8d693a SC |
322 | { |
323 | int reg; | |
324 | int len; | |
669caa9c SS |
325 | |
326 | for (len = 0; len < TYPE_LENGTH (type); len += 2) | |
327 | write_register_bytes (REGISTER_BYTE (len / 2 + 2), valbuf + len, 2); | |
2d8d693a SC |
328 | } |
329 | ||
330 | void | |
669caa9c SS |
331 | store_struct_return (addr, sp) |
332 | CORE_ADDR addr; | |
333 | CORE_ADDR sp; | |
2d8d693a | 334 | { |
669caa9c | 335 | write_register (2, addr); |
2d8d693a SC |
336 | } |
337 | ||
338 | ||
a332e593 | 339 | void |
e4ebb8e5 SC |
340 | print_register_hook (regno) |
341 | int regno; | |
a332e593 | 342 | { |
e4ebb8e5 SC |
343 | if ((regno & 1) == 0 && regno < 16) |
344 | { | |
345 | unsigned short l[2]; | |
a332e593 | 346 | |
e4ebb8e5 SC |
347 | read_relative_register_raw_bytes (regno, (char *) (l + 0)); |
348 | read_relative_register_raw_bytes (regno + 1, (char *) (l + 1)); | |
199b2450 TL |
349 | printf_unfiltered ("\t"); |
350 | printf_unfiltered ("%04x%04x", l[0], l[1]); | |
e4ebb8e5 SC |
351 | } |
352 | ||
353 | if ((regno & 3) == 0 && regno < 16) | |
354 | { | |
355 | unsigned short l[4]; | |
356 | ||
b2ff9b68 SC |
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)); | |
a332e593 | 361 | |
199b2450 TL |
362 | printf_unfiltered ("\t"); |
363 | printf_unfiltered ("%04x%04x%04x%04x", l[0], l[1], l[2], l[3]); | |
a332e593 | 364 | } |
e4ebb8e5 SC |
365 | if (regno == 15) |
366 | { | |
367 | unsigned short rval; | |
368 | int i; | |
a332e593 | 369 | |
e4ebb8e5 SC |
370 | read_relative_register_raw_bytes (regno, (char *) (&rval)); |
371 | ||
199b2450 | 372 | printf_unfiltered ("\n"); |
e4ebb8e5 SC |
373 | for (i = 0; i < 10; i += 2) |
374 | { | |
199b2450 | 375 | printf_unfiltered ("(sp+%d=%04x)", i, read_memory_short (rval + i)); |
e4ebb8e5 SC |
376 | } |
377 | } | |
378 | ||
379 | } | |
a332e593 | 380 | |
b2ff9b68 | 381 | void |
e4ebb8e5 | 382 | z8k_pop_frame () |
a332e593 | 383 | { |
a332e593 SC |
384 | } |
385 | ||
e4ebb8e5 SC |
386 | struct cmd_list_element *setmemorylist; |
387 | ||
b2ff9b68 | 388 | void |
e4ebb8e5 SC |
389 | z8k_set_pointer_size (newsize) |
390 | int newsize; | |
391 | { | |
392 | static int oldsize = 0; | |
a332e593 | 393 | |
e4ebb8e5 SC |
394 | if (oldsize != newsize) |
395 | { | |
199b2450 | 396 | printf_unfiltered ("pointer size set to %d bits\n", newsize); |
e4ebb8e5 SC |
397 | oldsize = newsize; |
398 | if (newsize == 32) | |
399 | { | |
400 | BIG = 1; | |
401 | } | |
402 | else | |
403 | { | |
404 | BIG = 0; | |
405 | } | |
406 | _initialize_gdbtypes (); | |
407 | } | |
408 | } | |
a332e593 | 409 | |
e4ebb8e5 SC |
410 | static void |
411 | segmented_command (args, from_tty) | |
412 | char *args; | |
413 | int from_tty; | |
414 | { | |
2d8d693a | 415 | z8k_set_pointer_size (32); |
e4ebb8e5 SC |
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); | |
e4ebb8e5 SC |
424 | } |
425 | ||
426 | static void | |
427 | set_memory (args, from_tty) | |
428 | char *args; | |
429 | int from_tty; | |
430 | { | |
199b2450 TL |
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); | |
e4ebb8e5 SC |
433 | } |
434 | ||
976bb0be | 435 | void |
e4ebb8e5 SC |
436 | _initialize_z8ktdep () |
437 | { | |
18b46e7c SS |
438 | tm_print_insn = gdb_print_insn_z8k; |
439 | ||
e4ebb8e5 SC |
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 | } |