1 /* ARC target-dependent stuff.
2 Copyright (C) 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "floatformat.h"
28 static void codestream_read
PARAMS ((unsigned int *, int));
29 static void codestream_seek
PARAMS ((int));
30 static unsigned int codestream_fill
PARAMS ((int));
32 #define CODESTREAM_BUFSIZ 16
33 static CORE_ADDR codestream_next_addr
;
34 static CORE_ADDR codestream_addr
;
35 static unsigned int codestream_buf
[CODESTREAM_BUFSIZ
];
36 static int codestream_off
;
37 static int codestream_cnt
;
39 #define codestream_tell() (codestream_addr + codestream_off)
40 #define codestream_peek() (codestream_cnt == 0 ? \
41 codestream_fill(1): codestream_buf[codestream_off])
42 #define codestream_get() (codestream_cnt-- == 0 ? \
43 codestream_fill(0) : codestream_buf[codestream_off++])
44 #define OPMASK 0xf8000000
47 codestream_fill (peek_flag
)
50 codestream_addr
= codestream_next_addr
;
51 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
53 codestream_cnt
= CODESTREAM_BUFSIZ
;
54 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
57 return (codestream_peek());
59 return (codestream_get());
63 codestream_seek (place
)
66 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
67 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
70 while (codestream_tell() != place
)
75 codestream_read (buf
, count
)
82 for (i
= 0; i
< count
; i
++)
83 *p
++ = codestream_get ();
87 * find & return amound a local space allocated, and advance codestream to
88 * first register push (if any)
89 * if entry sequence doesn't make sense, return -1, and leave
90 * codestream pointer random
94 arc_get_frame_setup (pc
)
100 insn
= codestream_get ();
102 if (insn
& OPMASK
== 0x10000000) /* st fp,[sp] */
104 insn
= codestream_get ();
105 if (insn
& OPMASK
!= 0x10000000) /* st blink,[sp,4] */
107 if (insn
& OPMASK
!= 0x60000000) /* for leaf, no st blink */
110 else if (codestream_get () & OPMASK
!= 0x60000000) /* mov fp,sp */
113 /* check for stack adjustment sub sp,nnn,sp */
114 insn
= codestream_peek ();
115 if (insn
& OPMASK
== 0x50000000)
117 n
= (insn
& 0x000001ff );
120 /* this sequence is used to get the address of the return
121 * buffer for a function that returns a structure
123 insn
= codestream_peek ();
124 if (insn
& OPMASK
== 0x60000000)
137 /* return pc of first real instruction */
146 if (arc_get_frame_setup (pc
) < 0)
149 /* skip over register saves */
150 for (i
= 0; i
< 10; i
++)
152 insn
= codestream_peek ();
153 if (insn
& OPMASK
!= 0x10000000) /* break if not st inst */
158 codestream_seek (pos
);
159 return (codestream_tell ());
162 /* Return number of args passed to a frame.
163 Can return -1, meaning no way to tell. */
166 struct frame_info
*fi
;
171 /* This loses because not only might the compiler not be popping the
172 args right after the function call, it might be popping args from both
173 this call and a previous one, and we would say there are more args
174 than there really are. Is it true for ARC */
178 struct frame_info
*pfi
;
182 FRAMELESS_FUNCTION_INVOCATION (fi
, frameless
);
184 /* In the absence of a frame pointer, GDB doesn't get correct values
185 for nameless arguments. Return -1, so it doesn't print any
186 nameless arguments. */
189 pfi
= get_prev_frame_info (fi
);
192 /* Note: this can happen if we are looking at the frame for
193 main, because FRAME_CHAIN_VALID won't let us go into
194 start. If we have debugging symbols, that's not really
195 a big deal; it just means it will only show as many arguments
196 to main as are declared. */
202 op
= read_memory_integer (retpc
, 1);
216 * parse the first few instructions of the function to see
217 * what registers were stored.
219 * The startup sequence can be at the start of the function.
220 * 'st fp,[sp], st blink,[sp+4], mov fp,sp'
222 * Local space is allocated just below by sub sp,nnn,sp
223 * Next, the registers used by this function are stored.
227 frame_find_saved_regs (fip
, fsrp
)
228 struct frame_info
*fip
;
229 struct frame_saved_regs
*fsrp
;
233 CORE_ADDR dummy_bottom
;
235 int i
, regnum
, offset
;
237 memset (fsrp
, 0, sizeof *fsrp
);
239 /* if frame is the end of a dummy, compute where the
242 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
244 /* check if the PC is in the stack, in a dummy frame */
245 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
247 /* all regs were saved by push_call_dummy () */
249 for (i
= 0; i
< NUM_REGS
; i
++)
251 adr
-= REGISTER_RAW_SIZE (i
);
257 locals
= arc_get_frame_setup (get_pc_function_start (fip
->pc
));
261 adr
= fip
->frame
- locals
;
262 for (i
= 0; i
< 10; i
++)
264 insn
= codestream_get ();
265 if (insn
& 0xffff8000 != 0x100d8000)
267 regnum
= (insn
& 0x00007c00) >> 9;
268 offset
= (insn
<< 23) >> 23;
269 fsrp
->regs
[regnum
] = adr
+ offset
;
273 fsrp
->regs
[PC_REGNUM
] = fip
->frame
+ 4;
274 fsrp
->regs
[FP_REGNUM
] = fip
->frame
;
280 CORE_ADDR sp
= read_register (SP_REGNUM
);
282 char regbuf
[MAX_REGISTER_RAW_SIZE
];
284 read_register_gen (PC_REGNUM
, regbuf
);
285 write_memory (sp
+4, regbuf
, REGISTER_SIZE
);
286 read_register_gen (FP_REGNUM
, regbuf
);
287 write_memory (sp
, regbuf
, REGISTER_SIZE
);
288 write_register (FP_REGNUM
, sp
);
289 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
291 read_register_gen (regnum
, regbuf
);
292 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
294 sp
+= (2*REGISTER_SIZE
);
295 write_register (SP_REGNUM
, sp
);
301 struct frame_info
*frame
= get_current_frame ();
304 struct frame_saved_regs fsr
;
305 char regbuf
[MAX_REGISTER_RAW_SIZE
];
307 fp
= FRAME_FP (frame
);
308 get_frame_saved_regs (frame
, &fsr
);
309 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
312 adr
= fsr
.regs
[regnum
];
315 read_memory (adr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
316 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
317 REGISTER_RAW_SIZE (regnum
));
320 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
321 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
322 write_register (SP_REGNUM
, fp
+ 8);
323 flush_cached_frames ();
326 #ifdef GET_LONGJMP_TARGET
327 /* Figure out where the longjmp will land. Slurp the args out of the stack.
328 We expect the first arg to be a pointer to the jmp_buf structure from which
329 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
330 This routine returns true on success. */
333 get_longjmp_target(pc
)
336 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
337 CORE_ADDR sp
, jb_addr
;
339 sp
= read_register (SP_REGNUM
);
341 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack */
343 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
346 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
348 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
349 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
352 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
356 #endif /* GET_LONGJMP_TARGET */
359 _initialize_arc_tdep ()
361 tm_print_insn
= arc_get_disassembler (bfd_mach_arc_host
);