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