]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-machine dependent code for Zilog Z8000, for GDB. |
cda5a58a AC |
2 | |
3 | Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, | |
4 | 2002 Free Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | /* | |
c5aa993b JM |
24 | Contributed by Steve Chamberlain |
25 | [email protected] | |
c906108c SS |
26 | */ |
27 | ||
28 | #include "defs.h" | |
29 | #include "frame.h" | |
30 | #include "obstack.h" | |
31 | #include "symtab.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "gdbtypes.h" | |
34 | #include "dis-asm.h" | |
35 | #include "gdbcore.h" | |
4e052eda | 36 | #include "regcache.h" |
c906108c | 37 | |
d4f3574e SS |
38 | #include "value.h" /* For read_register() */ |
39 | ||
40 | ||
41 | static int read_memory_pointer (CORE_ADDR x); | |
c906108c SS |
42 | |
43 | /* Return the saved PC from this frame. | |
44 | ||
45 | If the frame has a memory copy of SRP_REGNUM, use that. If not, | |
46 | just use the register SRP_REGNUM itself. */ | |
47 | ||
48 | CORE_ADDR | |
fba45db2 | 49 | z8k_frame_saved_pc (struct frame_info *frame) |
c906108c SS |
50 | { |
51 | return read_memory_pointer (frame->frame + (BIG ? 4 : 2)); | |
52 | } | |
53 | ||
54 | #define IS_PUSHL(x) (BIG ? ((x & 0xfff0) == 0x91e0):((x & 0xfff0) == 0x91F0)) | |
55 | #define IS_PUSHW(x) (BIG ? ((x & 0xfff0) == 0x93e0):((x & 0xfff0)==0x93f0)) | |
56 | #define IS_MOVE_FP(x) (BIG ? x == 0xa1ea : x == 0xa1fa) | |
57 | #define IS_MOV_SP_FP(x) (BIG ? x == 0x94ea : x == 0x0d76) | |
58 | #define IS_SUB2_SP(x) (x==0x1b87) | |
59 | #define IS_MOVK_R5(x) (x==0x7905) | |
60 | #define IS_SUB_SP(x) ((x & 0xffff) == 0x020f) | |
61 | #define IS_PUSH_FP(x) (BIG ? (x == 0x93ea) : (x == 0x93fa)) | |
62 | ||
63 | /* work out how much local space is on the stack and | |
64 | return the pc pointing to the first push */ | |
65 | ||
66 | static CORE_ADDR | |
fba45db2 | 67 | skip_adjust (CORE_ADDR pc, int *size) |
c906108c SS |
68 | { |
69 | *size = 0; | |
70 | ||
71 | if (IS_PUSH_FP (read_memory_short (pc)) | |
72 | && IS_MOV_SP_FP (read_memory_short (pc + 2))) | |
73 | { | |
74 | /* This is a function with an explict frame pointer */ | |
75 | pc += 4; | |
76 | *size += 2; /* remember the frame pointer */ | |
77 | } | |
78 | ||
79 | /* remember any stack adjustment */ | |
80 | if (IS_SUB_SP (read_memory_short (pc))) | |
81 | { | |
82 | *size += read_memory_short (pc + 2); | |
83 | pc += 4; | |
84 | } | |
85 | return pc; | |
86 | } | |
87 | ||
a14ed312 | 88 | static CORE_ADDR examine_frame (CORE_ADDR, CORE_ADDR * regs, CORE_ADDR); |
c906108c | 89 | static CORE_ADDR |
fba45db2 | 90 | examine_frame (CORE_ADDR pc, CORE_ADDR *regs, CORE_ADDR sp) |
c906108c SS |
91 | { |
92 | int w = read_memory_short (pc); | |
93 | int offset = 0; | |
94 | int regno; | |
95 | ||
96 | for (regno = 0; regno < NUM_REGS; regno++) | |
97 | 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[w & 0xf] = offset; | |
105 | regs[(w & 0xf) + 1] = offset + 2; | |
106 | offset += 4; | |
107 | } | |
108 | else | |
109 | { | |
110 | regs[w & 0xf] = offset; | |
111 | offset += 2; | |
112 | } | |
113 | pc += 2; | |
114 | w = read_memory_short (pc); | |
115 | } | |
116 | ||
117 | if (IS_MOVE_FP (w)) | |
118 | { | |
119 | /* We know the fp */ | |
120 | ||
121 | } | |
122 | else if (IS_SUB_SP (w)) | |
123 | { | |
124 | /* Subtracting a value from the sp, so were in a function | |
c5aa993b JM |
125 | which needs stack space for locals, but has no fp. We fake up |
126 | the values as if we had an fp */ | |
c906108c SS |
127 | regs[FP_REGNUM] = sp; |
128 | } | |
129 | else | |
130 | { | |
131 | /* This one didn't have an fp, we'll fake it up */ | |
132 | regs[SP_REGNUM] = sp; | |
133 | } | |
134 | /* stack pointer contains address of next frame */ | |
c5aa993b | 135 | /* regs[fp_regnum()] = fp; */ |
c906108c SS |
136 | regs[SP_REGNUM] = sp; |
137 | return pc; | |
138 | } | |
139 | ||
140 | CORE_ADDR | |
fba45db2 | 141 | z8k_skip_prologue (CORE_ADDR start_pc) |
c906108c SS |
142 | { |
143 | CORE_ADDR dummy[NUM_REGS]; | |
144 | ||
145 | return examine_frame (start_pc, dummy, 0); | |
146 | } | |
147 | ||
148 | CORE_ADDR | |
fba45db2 | 149 | z8k_addr_bits_remove (CORE_ADDR addr) |
c906108c SS |
150 | { |
151 | return (addr & PTR_MASK); | |
152 | } | |
153 | ||
d4f3574e SS |
154 | static int |
155 | read_memory_pointer (CORE_ADDR x) | |
c906108c SS |
156 | { |
157 | return read_memory_integer (ADDR_BITS_REMOVE (x), BIG ? 4 : 2); | |
158 | } | |
159 | ||
160 | CORE_ADDR | |
fba45db2 | 161 | z8k_frame_chain (struct frame_info *thisframe) |
c906108c | 162 | { |
c906108c SS |
163 | if (!inside_entry_file (thisframe->pc)) |
164 | { | |
165 | return read_memory_pointer (thisframe->frame); | |
166 | } | |
167 | return 0; | |
168 | } | |
169 | ||
170 | void | |
fba45db2 | 171 | init_frame_pc (void) |
c906108c | 172 | { |
e1e9e218 | 173 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
174 | } |
175 | ||
176 | /* Put here the code to store, into a struct frame_saved_regs, | |
177 | the addresses of the saved registers of frame described by FRAME_INFO. | |
178 | This includes special registers such as pc and fp saved in special | |
179 | ways in the stack frame. sp is even more special: | |
180 | the address we return for it IS the sp for the next frame. */ | |
181 | ||
182 | void | |
fba45db2 | 183 | z8k_frame_init_saved_regs (struct frame_info *frame_info) |
c906108c SS |
184 | { |
185 | CORE_ADDR pc; | |
186 | int w; | |
187 | ||
188 | frame_saved_regs_zalloc (frame_info); | |
189 | pc = get_pc_function_start (frame_info->pc); | |
190 | ||
191 | /* wander down the instruction stream */ | |
192 | examine_frame (pc, frame_info->saved_regs, frame_info->frame); | |
193 | ||
194 | } | |
195 | ||
196 | void | |
fba45db2 | 197 | z8k_push_dummy_frame (void) |
c906108c | 198 | { |
e1e9e218 | 199 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
200 | } |
201 | ||
202 | int | |
fba45db2 | 203 | gdb_print_insn_z8k (bfd_vma memaddr, disassemble_info *info) |
c906108c SS |
204 | { |
205 | if (BIG) | |
206 | return print_insn_z8001 (memaddr, info); | |
207 | else | |
208 | return print_insn_z8002 (memaddr, info); | |
209 | } | |
210 | ||
211 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or | |
212 | is not the address of a valid instruction, the address of the next | |
213 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
c5aa993b | 214 | of the instruction. */ |
c906108c SS |
215 | |
216 | CORE_ADDR | |
fba45db2 | 217 | NEXT_PROLOGUE_INSN (CORE_ADDR addr, CORE_ADDR lim, short *pword1) |
c906108c SS |
218 | { |
219 | char buf[2]; | |
220 | if (addr < lim + 8) | |
221 | { | |
222 | read_memory (addr, buf, 2); | |
223 | *pword1 = extract_signed_integer (buf, 2); | |
224 | ||
225 | return addr + 2; | |
226 | } | |
227 | return 0; | |
228 | } | |
229 | ||
230 | #if 0 | |
231 | /* Put here the code to store, into a struct frame_saved_regs, | |
232 | the addresses of the saved registers of frame described by FRAME_INFO. | |
233 | This includes special registers such as pc and fp saved in special | |
234 | ways in the stack frame. sp is even more special: | |
235 | the address we return for it IS the sp for the next frame. | |
236 | ||
237 | We cache the result of doing this in the frame_cache_obstack, since | |
238 | it is fairly expensive. */ | |
239 | ||
240 | void | |
fba45db2 | 241 | frame_find_saved_regs (struct frame_info *fip, struct frame_saved_regs *fsrp) |
c906108c SS |
242 | { |
243 | int locals; | |
244 | CORE_ADDR pc; | |
245 | CORE_ADDR adr; | |
246 | int i; | |
247 | ||
248 | memset (fsrp, 0, sizeof *fsrp); | |
249 | ||
250 | pc = skip_adjust (get_pc_function_start (fip->pc), &locals); | |
251 | ||
252 | { | |
253 | adr = FRAME_FP (fip) - locals; | |
254 | for (i = 0; i < 8; i++) | |
255 | { | |
256 | int word = read_memory_short (pc); | |
257 | ||
258 | pc += 2; | |
259 | if (IS_PUSHL (word)) | |
260 | { | |
261 | fsrp->regs[word & 0xf] = adr; | |
262 | fsrp->regs[(word & 0xf) + 1] = adr - 2; | |
263 | adr -= 4; | |
264 | } | |
265 | else if (IS_PUSHW (word)) | |
266 | { | |
267 | fsrp->regs[word & 0xf] = adr; | |
268 | adr -= 2; | |
269 | } | |
270 | else | |
271 | break; | |
272 | } | |
273 | ||
274 | } | |
275 | ||
276 | fsrp->regs[PC_REGNUM] = fip->frame + 4; | |
277 | fsrp->regs[FP_REGNUM] = fip->frame; | |
278 | ||
279 | } | |
280 | #endif | |
281 | ||
282 | int | |
d4f3574e | 283 | z8k_saved_pc_after_call (struct frame_info *frame) |
c906108c | 284 | { |
c5aa993b | 285 | return ADDR_BITS_REMOVE |
c906108c SS |
286 | (read_memory_integer (read_register (SP_REGNUM), PTR_SIZE)); |
287 | } | |
288 | ||
289 | ||
290 | void | |
fba45db2 | 291 | extract_return_value (struct type *type, char *regbuf, char *valbuf) |
c906108c SS |
292 | { |
293 | int b; | |
294 | int len = TYPE_LENGTH (type); | |
295 | ||
296 | for (b = 0; b < len; b += 2) | |
297 | { | |
298 | int todo = len - b; | |
299 | ||
300 | if (todo > 2) | |
301 | todo = 2; | |
302 | memcpy (valbuf + b, regbuf + b, todo); | |
303 | } | |
304 | } | |
305 | ||
306 | void | |
fba45db2 | 307 | write_return_value (struct type *type, char *valbuf) |
c906108c SS |
308 | { |
309 | int reg; | |
310 | int len; | |
311 | ||
312 | for (len = 0; len < TYPE_LENGTH (type); len += 2) | |
c5aa993b | 313 | write_register_bytes (REGISTER_BYTE (len / 2 + 2), valbuf + len, 2); |
c906108c SS |
314 | } |
315 | ||
316 | void | |
fba45db2 | 317 | store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
c906108c SS |
318 | { |
319 | write_register (2, addr); | |
320 | } | |
321 | ||
322 | ||
323 | void | |
fba45db2 | 324 | z8k_print_register_hook (int regno) |
c906108c SS |
325 | { |
326 | if ((regno & 1) == 0 && regno < 16) | |
327 | { | |
df94e18a | 328 | unsigned char l[4]; |
c906108c | 329 | |
df94e18a AC |
330 | frame_register_read (selected_frame, regno, l + 0); |
331 | frame_register_read (selected_frame, regno + 1, l + 2); | |
c906108c | 332 | printf_unfiltered ("\t"); |
df94e18a | 333 | printf_unfiltered ("0x%02x%02x%02x%02x", l[0], l[1], l[2], l[3]); |
c906108c SS |
334 | } |
335 | ||
336 | if ((regno & 3) == 0 && regno < 16) | |
337 | { | |
df94e18a | 338 | unsigned char l[8]; |
c906108c | 339 | |
df94e18a AC |
340 | frame_register_read (selected_frame, regno, l + 0); |
341 | frame_register_read (selected_frame, regno + 1, l + 2); | |
342 | frame_register_read (selected_frame, regno + 2, l + 4); | |
343 | frame_register_read (selected_frame, regno + 3, l + 6); | |
c906108c SS |
344 | |
345 | printf_unfiltered ("\t"); | |
df94e18a AC |
346 | printf_unfiltered ("0x%02x%02x%02x%02x%02x%02x%02x%02x", |
347 | l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]); | |
c906108c SS |
348 | } |
349 | if (regno == 15) | |
350 | { | |
351 | unsigned short rval; | |
352 | int i; | |
353 | ||
cda5a58a | 354 | frame_register_read (selected_frame, regno, (char *) (&rval)); |
c906108c SS |
355 | |
356 | printf_unfiltered ("\n"); | |
357 | for (i = 0; i < 10; i += 2) | |
358 | { | |
d4f3574e SS |
359 | printf_unfiltered ("(sp+%d=%04x)", i, |
360 | (unsigned int)read_memory_short (rval + i)); | |
c906108c SS |
361 | } |
362 | } | |
363 | ||
364 | } | |
365 | ||
366 | void | |
fba45db2 | 367 | z8k_pop_frame (void) |
c906108c SS |
368 | { |
369 | } | |
370 | ||
371 | struct cmd_list_element *setmemorylist; | |
372 | ||
373 | void | |
fba45db2 | 374 | z8k_set_pointer_size (int newsize) |
c906108c SS |
375 | { |
376 | static int oldsize = 0; | |
377 | ||
378 | if (oldsize != newsize) | |
379 | { | |
380 | printf_unfiltered ("pointer size set to %d bits\n", newsize); | |
381 | oldsize = newsize; | |
382 | if (newsize == 32) | |
383 | { | |
384 | BIG = 1; | |
385 | } | |
386 | else | |
387 | { | |
388 | BIG = 0; | |
389 | } | |
d4f3574e SS |
390 | /* FIXME: This code should be using the GDBARCH framework to |
391 | handle changed type sizes. If this problem is ever fixed | |
392 | (the direct reference to _initialize_gdbtypes() below | |
393 | eliminated) then Makefile.in should be updated so that | |
394 | z8k-tdep.c is again compiled with -Werror. */ | |
c906108c SS |
395 | _initialize_gdbtypes (); |
396 | } | |
397 | } | |
398 | ||
399 | static void | |
fba45db2 | 400 | segmented_command (char *args, int from_tty) |
c906108c SS |
401 | { |
402 | z8k_set_pointer_size (32); | |
403 | } | |
404 | ||
405 | static void | |
fba45db2 | 406 | unsegmented_command (char *args, int from_tty) |
c906108c SS |
407 | { |
408 | z8k_set_pointer_size (16); | |
409 | } | |
410 | ||
411 | static void | |
fba45db2 | 412 | set_memory (char *args, int from_tty) |
c906108c SS |
413 | { |
414 | printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n"); | |
415 | help_list (setmemorylist, "set memory ", -1, gdb_stdout); | |
416 | } | |
417 | ||
418 | void | |
fba45db2 | 419 | _initialize_z8ktdep (void) |
c906108c SS |
420 | { |
421 | tm_print_insn = gdb_print_insn_z8k; | |
422 | ||
423 | add_prefix_cmd ("memory", no_class, set_memory, | |
424 | "set the memory model", &setmemorylist, "set memory ", 0, | |
425 | &setlist); | |
426 | add_cmd ("segmented", class_support, segmented_command, | |
427 | "Set segmented memory model.", &setmemorylist); | |
428 | add_cmd ("unsegmented", class_support, unsegmented_command, | |
429 | "Set unsegmented memory model.", &setmemorylist); | |
430 | ||
431 | } |