Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / bfin-tdep.c
CommitLineData
91021223
MF
1/* Target-dependent code for Analog Devices Blackfin processor, for GDB.
2
42a4f53d 3 Copyright (C) 2005-2019 Free Software Foundation, Inc.
91021223
MF
4
5 Contributed by Analog Devices, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#include "defs.h"
d55e5aa6
TT
23
24/* Local non-gdb includes. */
91021223 25#include "arch-utils.h"
d55e5aa6 26#include "bfin-tdep.h"
91021223 27#include "dis-asm.h"
91021223 28#include "dwarf2-frame.h"
91021223
MF
29#include "elf-bfd.h"
30#include "elf/bfin.h"
d55e5aa6
TT
31#include "frame-base.h"
32#include "frame-unwind.h"
33#include "frame.h"
34#include "gdb/sim-bfin.h"
35#include "gdbcore.h"
91021223 36#include "infcall.h"
d55e5aa6
TT
37#include "inferior.h"
38#include "osabi.h"
39#include "regcache.h"
40#include "sim-regno.h"
41#include "symtab.h"
42#include "trad-frame.h"
91021223 43#include "xml-syscall.h"
91021223
MF
44
45/* Macros used by prologue functions. */
46#define P_LINKAGE 0xE800
47#define P_MINUS_SP1 0x0140
48#define P_MINUS_SP2 0x05C0
49#define P_MINUS_SP3 0x0540
50#define P_MINUS_SP4 0x04C0
51#define P_SP_PLUS 0x6C06
52#define P_P2_LOW 0xE10A
53#define P_P2_HIGH 0XE14A
54#define P_SP_EQ_SP_PLUS_P2 0X5BB2
55#define P_SP_EQ_P2_PLUS_SP 0x5B96
56#define P_MINUS_MINUS_SP_EQ_RETS 0x0167
57
58/* Macros used for program flow control. */
59/* 16 bit instruction, max */
60#define P_16_BIT_INSR_MAX 0xBFFF
61/* 32 bit instruction, min */
62#define P_32_BIT_INSR_MIN 0xC000
63/* 32 bit instruction, max */
64#define P_32_BIT_INSR_MAX 0xE801
65/* jump (preg), 16-bit, min */
66#define P_JUMP_PREG_MIN 0x0050
67/* jump (preg), 16-bit, max */
68#define P_JUMP_PREG_MAX 0x0057
69/* jump (pc+preg), 16-bit, min */
70#define P_JUMP_PC_PLUS_PREG_MIN 0x0080
71/* jump (pc+preg), 16-bit, max */
72#define P_JUMP_PC_PLUS_PREG_MAX 0x0087
73/* jump.s pcrel13m2, 16-bit, min */
74#define P_JUMP_S_MIN 0x2000
75/* jump.s pcrel13m2, 16-bit, max */
76#define P_JUMP_S_MAX 0x2FFF
77/* jump.l pcrel25m2, 32-bit, min */
78#define P_JUMP_L_MIN 0xE200
79/* jump.l pcrel25m2, 32-bit, max */
80#define P_JUMP_L_MAX 0xE2FF
81/* conditional jump pcrel11m2, 16-bit, min */
82#define P_IF_CC_JUMP_MIN 0x1800
83/* conditional jump pcrel11m2, 16-bit, max */
84#define P_IF_CC_JUMP_MAX 0x1BFF
85/* conditional jump(bp) pcrel11m2, 16-bit, min */
86#define P_IF_CC_JUMP_BP_MIN 0x1C00
87/* conditional jump(bp) pcrel11m2, 16-bit, max */
88#define P_IF_CC_JUMP_BP_MAX 0x1FFF
89/* conditional !jump pcrel11m2, 16-bit, min */
90#define P_IF_NOT_CC_JUMP_MIN 0x1000
91/* conditional !jump pcrel11m2, 16-bit, max */
92#define P_IF_NOT_CC_JUMP_MAX 0x13FF
93/* conditional jump(bp) pcrel11m2, 16-bit, min */
94#define P_IF_NOT_CC_JUMP_BP_MIN 0x1400
95/* conditional jump(bp) pcrel11m2, 16-bit, max */
96#define P_IF_NOT_CC_JUMP_BP_MAX 0x17FF
97/* call (preg), 16-bit, min */
98#define P_CALL_PREG_MIN 0x0060
99/* call (preg), 16-bit, max */
100#define P_CALL_PREG_MAX 0x0067
101/* call (pc+preg), 16-bit, min */
102#define P_CALL_PC_PLUS_PREG_MIN 0x0070
103/* call (pc+preg), 16-bit, max */
104#define P_CALL_PC_PLUS_PREG_MAX 0x0077
105/* call pcrel25m2, 32-bit, min */
106#define P_CALL_MIN 0xE300
107/* call pcrel25m2, 32-bit, max */
108#define P_CALL_MAX 0xE3FF
109/* RTS */
110#define P_RTS 0x0010
111/* MNOP */
112#define P_MNOP 0xC803
113/* EXCPT, 16-bit, min */
114#define P_EXCPT_MIN 0x00A0
115/* EXCPT, 16-bit, max */
116#define P_EXCPT_MAX 0x00AF
117/* multi instruction mask 1, 16-bit */
118#define P_BIT_MULTI_INS_1 0xC000
119/* multi instruction mask 2, 16-bit */
120#define P_BIT_MULTI_INS_2 0x0800
121
122/* The maximum bytes we search to skip the prologue. */
123#define UPPER_LIMIT 40
124
125/* ASTAT bits */
126#define ASTAT_CC_POS 5
127#define ASTAT_CC (1 << ASTAT_CC_POS)
128
129/* Initial value: Register names used in BFIN's ISA documentation. */
130
131static const char * const bfin_register_name_strings[] =
132{
133 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
134 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
135 "i0", "i1", "i2", "i3", "m0", "m1", "m2", "m3",
136 "b0", "b1", "b2", "b3", "l0", "l1", "l2", "l3",
137 "a0x", "a0w", "a1x", "a1w", "astat", "rets",
138 "lc0", "lt0", "lb0", "lc1", "lt1", "lb1", "cycles", "cycles2",
139 "usp", "seqstat", "syscfg", "reti", "retx", "retn", "rete",
140 "pc", "cc",
141};
142
143#define NUM_BFIN_REGNAMES ARRAY_SIZE (bfin_register_name_strings)
144
145
146/* In this diagram successive memory locations increase downwards or the
147 stack grows upwards with negative indices. (PUSH analogy for stack.)
148
149 The top frame is the "frame" of the current function being executed.
150
151 +--------------+ SP -
152 | local vars | ^
153 +--------------+ |
154 | save regs | |
155 +--------------+ FP |
156 | old FP -|-- top
157 +--------------+ | frame
158 | RETS | | |
159 +--------------+ | |
160 | param 1 | | |
161 | param 2 | | |
162 | ... | | V
163 +--------------+ | -
164 | local vars | | ^
165 +--------------+ | |
166 | save regs | | |
167 +--------------+<- |
168 | old FP -|-- next
169 +--------------+ | frame
170 | RETS | | |
171 +--------------+ | |
172 | param 1 | | |
173 | param 2 | | |
174 | ... | | V
175 +--------------+ | -
176 | local vars | | ^
177 +--------------+ | |
178 | save regs | | |
179 +--------------+<- next frame
180 | old FP | |
181 +--------------+ |
182 | RETS | V
183 +--------------+ -
184
185 The frame chain is formed as following:
186
187 FP has the topmost frame.
188 FP + 4 has the previous FP and so on. */
189
190
191/* Map from DWARF2 register number to GDB register number. */
192
193static const int map_gcc_gdb[] =
194{
195 BFIN_R0_REGNUM,
196 BFIN_R1_REGNUM,
197 BFIN_R2_REGNUM,
198 BFIN_R3_REGNUM,
199 BFIN_R4_REGNUM,
200 BFIN_R5_REGNUM,
201 BFIN_R6_REGNUM,
202 BFIN_R7_REGNUM,
203 BFIN_P0_REGNUM,
204 BFIN_P1_REGNUM,
205 BFIN_P2_REGNUM,
206 BFIN_P3_REGNUM,
207 BFIN_P4_REGNUM,
208 BFIN_P5_REGNUM,
209 BFIN_SP_REGNUM,
210 BFIN_FP_REGNUM,
211 BFIN_I0_REGNUM,
212 BFIN_I1_REGNUM,
213 BFIN_I2_REGNUM,
214 BFIN_I3_REGNUM,
215 BFIN_B0_REGNUM,
216 BFIN_B1_REGNUM,
217 BFIN_B2_REGNUM,
218 BFIN_B3_REGNUM,
219 BFIN_L0_REGNUM,
220 BFIN_L1_REGNUM,
221 BFIN_L2_REGNUM,
222 BFIN_L3_REGNUM,
223 BFIN_M0_REGNUM,
224 BFIN_M1_REGNUM,
225 BFIN_M2_REGNUM,
226 BFIN_M3_REGNUM,
227 BFIN_A0_DOT_X_REGNUM,
228 BFIN_A1_DOT_X_REGNUM,
229 BFIN_CC_REGNUM,
230 BFIN_RETS_REGNUM,
231 BFIN_RETI_REGNUM,
232 BFIN_RETX_REGNUM,
233 BFIN_RETN_REGNUM,
234 BFIN_RETE_REGNUM,
235 BFIN_ASTAT_REGNUM,
236 BFIN_SEQSTAT_REGNUM,
237 BFIN_USP_REGNUM,
238 BFIN_LT0_REGNUM,
239 BFIN_LT1_REGNUM,
240 BFIN_LC0_REGNUM,
241 BFIN_LC1_REGNUM,
242 BFIN_LB0_REGNUM,
243 BFIN_LB1_REGNUM
244};
245
ba2f91bb
AH
246/* Big enough to hold the size of the largest register in bytes. */
247#define BFIN_MAX_REGISTER_SIZE 4
91021223
MF
248
249struct bfin_frame_cache
250{
251 /* Base address. */
252 CORE_ADDR base;
253 CORE_ADDR sp_offset;
254 CORE_ADDR pc;
255 int frameless_pc_value;
256
257 /* Saved registers. */
258 CORE_ADDR saved_regs[BFIN_NUM_REGS];
259 CORE_ADDR saved_sp;
260
261 /* Stack space reserved for local variables. */
262 long locals;
263};
264
265/* Allocate and initialize a frame cache. */
266
267static struct bfin_frame_cache *
268bfin_alloc_frame_cache (void)
269{
270 struct bfin_frame_cache *cache;
271 int i;
272
273 cache = FRAME_OBSTACK_ZALLOC (struct bfin_frame_cache);
274
275 /* Base address. */
276 cache->base = 0;
277 cache->sp_offset = -4;
278 cache->pc = 0;
279 cache->frameless_pc_value = 0;
280
281 /* Saved registers. We initialize these to -1 since zero is a valid
282 offset (that's where fp is supposed to be stored). */
283 for (i = 0; i < BFIN_NUM_REGS; i++)
284 cache->saved_regs[i] = -1;
285
286 /* Frameless until proven otherwise. */
287 cache->locals = -1;
288
289 return cache;
290}
291
292static struct bfin_frame_cache *
293bfin_frame_cache (struct frame_info *this_frame, void **this_cache)
294{
295 struct bfin_frame_cache *cache;
296 int i;
297
298 if (*this_cache)
9a3c8263 299 return (struct bfin_frame_cache *) *this_cache;
91021223
MF
300
301 cache = bfin_alloc_frame_cache ();
302 *this_cache = cache;
303
304 cache->base = get_frame_register_unsigned (this_frame, BFIN_FP_REGNUM);
305 if (cache->base == 0)
306 return cache;
307
308 /* For normal frames, PC is stored at [FP + 4]. */
309 cache->saved_regs[BFIN_PC_REGNUM] = 4;
310 cache->saved_regs[BFIN_FP_REGNUM] = 0;
311
312 /* Adjust all the saved registers such that they contain addresses
313 instead of offsets. */
314 for (i = 0; i < BFIN_NUM_REGS; i++)
315 if (cache->saved_regs[i] != -1)
316 cache->saved_regs[i] += cache->base;
317
318 cache->pc = get_frame_func (this_frame) ;
319 if (cache->pc == 0 || cache->pc == get_frame_pc (this_frame))
320 {
321 /* Either there is no prologue (frameless function) or we are at
322 the start of a function. In short we do not have a frame.
323 PC is stored in rets register. FP points to previous frame. */
324
325 cache->saved_regs[BFIN_PC_REGNUM] =
326 get_frame_register_unsigned (this_frame, BFIN_RETS_REGNUM);
327 cache->frameless_pc_value = 1;
328 cache->base = get_frame_register_unsigned (this_frame, BFIN_FP_REGNUM);
329 cache->saved_regs[BFIN_FP_REGNUM] = cache->base;
330 cache->saved_sp = cache->base;
331 }
332 else
333 {
334 cache->frameless_pc_value = 0;
335
336 /* Now that we have the base address for the stack frame we can
337 calculate the value of SP in the calling frame. */
338 cache->saved_sp = cache->base + 8;
339 }
340
341 return cache;
342}
343
344static void
345bfin_frame_this_id (struct frame_info *this_frame,
346 void **this_cache,
347 struct frame_id *this_id)
348{
349 struct bfin_frame_cache *cache = bfin_frame_cache (this_frame, this_cache);
350
351 /* This marks the outermost frame. */
352 if (cache->base == 0)
353 return;
354
355 /* See the end of bfin_push_dummy_call. */
356 *this_id = frame_id_build (cache->base + 8, cache->pc);
357}
358
359static struct value *
360bfin_frame_prev_register (struct frame_info *this_frame,
361 void **this_cache,
362 int regnum)
363{
364 struct gdbarch *gdbarch = get_frame_arch (this_frame);
365 struct bfin_frame_cache *cache = bfin_frame_cache (this_frame, this_cache);
366
367 if (regnum == gdbarch_sp_regnum (gdbarch) && cache->saved_sp)
368 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
369
370 if (regnum < BFIN_NUM_REGS && cache->saved_regs[regnum] != -1)
371 return frame_unwind_got_memory (this_frame, regnum,
372 cache->saved_regs[regnum]);
373
374 return frame_unwind_got_register (this_frame, regnum, regnum);
375}
376
377static const struct frame_unwind bfin_frame_unwind =
378{
379 NORMAL_FRAME,
8fbca658 380 default_frame_unwind_stop_reason,
91021223
MF
381 bfin_frame_this_id,
382 bfin_frame_prev_register,
383 NULL,
384 default_frame_sniffer
385};
386
387/* Check for "[--SP] = <reg>;" insns. These are appear in function
388 prologues to save misc registers onto the stack. */
389
390static int
391is_minus_minus_sp (int op)
392{
393 op &= 0xFFC0;
394
395 if ((op == P_MINUS_SP1) || (op == P_MINUS_SP2)
396 || (op == P_MINUS_SP3) || (op == P_MINUS_SP4))
397 return 1;
398
399 return 0;
400}
401
402/* Skip all the insns that appear in generated function prologues. */
403
404static CORE_ADDR
405bfin_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
406{
407 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
408 int op = read_memory_unsigned_integer (pc, 2, byte_order);
409 CORE_ADDR orig_pc = pc;
410 int done = 0;
411
412 /* The new gcc prologue generates the register saves BEFORE the link
413 or RETS saving instruction.
414 So, our job is to stop either at those instructions or some upper
415 limit saying there is no frame! */
416
417 while (!done)
418 {
419 if (is_minus_minus_sp (op))
420 {
421 while (is_minus_minus_sp (op))
422 {
423 pc += 2;
424 op = read_memory_unsigned_integer (pc, 2, byte_order);
425 }
426
427 if (op == P_LINKAGE)
428 pc += 4;
429
430 done = 1;
431 }
432 else if (op == P_LINKAGE)
433 {
434 pc += 4;
435 done = 1;
436 }
437 else if (op == P_MINUS_MINUS_SP_EQ_RETS)
438 {
439 pc += 2;
440 done = 1;
441 }
442 else if (op == P_RTS)
443 {
444 done = 1;
445 }
446 else if ((op >= P_JUMP_PREG_MIN && op <= P_JUMP_PREG_MAX)
447 || (op >= P_JUMP_PC_PLUS_PREG_MIN
448 && op <= P_JUMP_PC_PLUS_PREG_MAX)
449 || (op == P_JUMP_S_MIN && op <= P_JUMP_S_MAX))
450 {
451 done = 1;
452 }
453 else if (pc - orig_pc >= UPPER_LIMIT)
454 {
455 warning (_("Function Prologue not recognised; "
456 "pc will point to ENTRY_POINT of the function"));
457 pc = orig_pc + 2;
458 done = 1;
459 }
460 else
461 {
462 pc += 2; /* Not a terminating instruction go on. */
463 op = read_memory_unsigned_integer (pc, 2, byte_order);
464 }
465 }
466
467 /* TODO:
468 Dwarf2 uses entry point value AFTER some register initializations.
469 We should perhaps skip such asssignments as well (R6 = R1, ...). */
470
471 return pc;
472}
473
474/* Return the GDB type object for the "standard" data type of data in
475 register N. This should be void pointer for P0-P5, SP, FP;
476 void pointer to function for PC; int otherwise. */
477
478static struct type *
479bfin_register_type (struct gdbarch *gdbarch, int regnum)
480{
481 if ((regnum >= BFIN_P0_REGNUM && regnum <= BFIN_FP_REGNUM)
482 || regnum == BFIN_USP_REGNUM)
483 return builtin_type (gdbarch)->builtin_data_ptr;
484
2ce7ff1d
MF
485 if (regnum == BFIN_PC_REGNUM || regnum == BFIN_RETS_REGNUM
486 || regnum == BFIN_RETI_REGNUM || regnum == BFIN_RETX_REGNUM
487 || regnum == BFIN_RETN_REGNUM || regnum == BFIN_RETE_REGNUM
488 || regnum == BFIN_LT0_REGNUM || regnum == BFIN_LB0_REGNUM
489 || regnum == BFIN_LT1_REGNUM || regnum == BFIN_LB1_REGNUM)
91021223
MF
490 return builtin_type (gdbarch)->builtin_func_ptr;
491
492 return builtin_type (gdbarch)->builtin_int32;
493}
494
495static CORE_ADDR
496bfin_push_dummy_call (struct gdbarch *gdbarch,
497 struct value *function,
498 struct regcache *regcache,
499 CORE_ADDR bp_addr,
500 int nargs,
501 struct value **args,
502 CORE_ADDR sp,
cf84fa6b 503 function_call_return_method return_method,
91021223
MF
504 CORE_ADDR struct_addr)
505{
506 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
91021223
MF
507 int i;
508 long reg_r0, reg_r1, reg_r2;
509 int total_len = 0;
91021223
MF
510
511 for (i = nargs - 1; i >= 0; i--)
512 {
513 struct type *value_type = value_enclosing_type (args[i]);
91021223 514
744a8059 515 total_len += (TYPE_LENGTH (value_type) + 3) & ~3;
91021223
MF
516 }
517
518 /* At least twelve bytes of stack space must be allocated for the function's
519 arguments, even for functions that have less than 12 bytes of argument
520 data. */
521
522 if (total_len < 12)
523 sp -= 12 - total_len;
524
525 /* Push arguments in reverse order. */
526
527 for (i = nargs - 1; i >= 0; i--)
528 {
529 struct type *value_type = value_enclosing_type (args[i]);
530 struct type *arg_type = check_typedef (value_type);
996d693a 531 int container_len = (TYPE_LENGTH (arg_type) + 3) & ~3;
91021223
MF
532
533 sp -= container_len;
0d1993c0 534 write_memory (sp, value_contents (args[i]), container_len);
91021223
MF
535 }
536
537 /* Initialize R0, R1, and R2 to the first 3 words of parameters. */
538
539 reg_r0 = read_memory_integer (sp, 4, byte_order);
540 regcache_cooked_write_unsigned (regcache, BFIN_R0_REGNUM, reg_r0);
541 reg_r1 = read_memory_integer (sp + 4, 4, byte_order);
542 regcache_cooked_write_unsigned (regcache, BFIN_R1_REGNUM, reg_r1);
543 reg_r2 = read_memory_integer (sp + 8, 4, byte_order);
544 regcache_cooked_write_unsigned (regcache, BFIN_R2_REGNUM, reg_r2);
545
546 /* Store struct value address. */
547
cf84fa6b 548 if (return_method == return_method_struct)
91021223
MF
549 regcache_cooked_write_unsigned (regcache, BFIN_P0_REGNUM, struct_addr);
550
551 /* Set the dummy return value to bp_addr.
552 A dummy breakpoint will be setup to execute the call. */
553
554 regcache_cooked_write_unsigned (regcache, BFIN_RETS_REGNUM, bp_addr);
555
556 /* Finally, update the stack pointer. */
557
558 regcache_cooked_write_unsigned (regcache, BFIN_SP_REGNUM, sp);
559
560 return sp;
561}
562
563/* Convert DWARF2 register number REG to the appropriate register number
564 used by GDB. */
565
566static int
567bfin_reg_to_regnum (struct gdbarch *gdbarch, int reg)
568{
0fde2c53
DE
569 if (reg < 0 || reg >= ARRAY_SIZE (map_gcc_gdb))
570 return -1;
91021223
MF
571
572 return map_gcc_gdb[reg];
573}
574
cd6c3b4f
YQ
575/* Implement the breakpoint_kind_from_pc gdbarch method. */
576
d19280ad
YQ
577static int
578bfin_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
91021223
MF
579{
580 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
581 unsigned short iw;
91021223
MF
582
583 iw = read_memory_unsigned_integer (*pcptr, 2, byte_order);
584
585 if ((iw & 0xf000) >= 0xc000)
586 /* 32-bit instruction. */
d19280ad 587 return 4;
91021223 588 else
d19280ad
YQ
589 return 2;
590}
591
cd6c3b4f
YQ
592/* Implement the sw_breakpoint_from_kind gdbarch method. */
593
d19280ad
YQ
594static const gdb_byte *
595bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
596{
597 static unsigned char bfin_breakpoint[] = {0xa1, 0x00, 0x00, 0x00};
598 static unsigned char bfin_sim_breakpoint[] = {0x25, 0x00, 0x00, 0x00};
599
600 *size = kind;
91021223
MF
601
602 if (strcmp (target_shortname, "sim") == 0)
603 return bfin_sim_breakpoint;
604 else
605 return bfin_breakpoint;
606}
607
608static void
609bfin_extract_return_value (struct type *type,
610 struct regcache *regs,
611 gdb_byte *dst)
612{
ac7936df 613 struct gdbarch *gdbarch = regs->arch ();
91021223
MF
614 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
615 bfd_byte *valbuf = dst;
616 int len = TYPE_LENGTH (type);
617 ULONGEST tmp;
618 int regno = BFIN_R0_REGNUM;
619
bad43aa5 620 gdb_assert (len <= 8);
91021223
MF
621
622 while (len > 0)
623 {
624 regcache_cooked_read_unsigned (regs, regno++, &tmp);
1364323a 625 store_unsigned_integer (valbuf, (len > 4 ? 4 : len), byte_order, tmp);
91021223
MF
626 len -= 4;
627 valbuf += 4;
628 }
629}
630
631/* Write into appropriate registers a function return value of type
632 TYPE, given in virtual format. */
633
634static void
635bfin_store_return_value (struct type *type,
636 struct regcache *regs,
637 const gdb_byte *src)
638{
639 const bfd_byte *valbuf = src;
640
641 /* Integral values greater than one word are stored in consecutive
642 registers starting with R0. This will always be a multiple of
643 the register size. */
644
645 int len = TYPE_LENGTH (type);
646 int regno = BFIN_R0_REGNUM;
647
bad43aa5 648 gdb_assert (len <= 8);
91021223
MF
649
650 while (len > 0)
651 {
b66f5587 652 regs->cooked_write (regno++, valbuf);
91021223
MF
653 len -= 4;
654 valbuf += 4;
655 }
656}
657
658/* Determine, for architecture GDBARCH, how a return value of TYPE
659 should be returned. If it is supposed to be returned in registers,
660 and READBUF is nonzero, read the appropriate value from REGCACHE,
661 and copy it into READBUF. If WRITEBUF is nonzero, write the value
662 from WRITEBUF into REGCACHE. */
663
664static enum return_value_convention
665bfin_return_value (struct gdbarch *gdbarch,
6a3a010b 666 struct value *function,
91021223
MF
667 struct type *type,
668 struct regcache *regcache,
669 gdb_byte *readbuf,
670 const gdb_byte *writebuf)
671{
672 if (TYPE_LENGTH (type) > 8)
673 return RETURN_VALUE_STRUCT_CONVENTION;
674
675 if (readbuf)
676 bfin_extract_return_value (type, regcache, readbuf);
677
678 if (writebuf)
679 bfin_store_return_value (type, regcache, writebuf);
680
681 return RETURN_VALUE_REGISTER_CONVENTION;
682}
683
684/* Return the BFIN register name corresponding to register I. */
685
686static const char *
687bfin_register_name (struct gdbarch *gdbarch, int i)
688{
689 return bfin_register_name_strings[i];
690}
691
05d1431c 692static enum register_status
849d0ba8 693bfin_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
91021223
MF
694 int regnum, gdb_byte *buffer)
695{
ba2f91bb 696 gdb_byte buf[BFIN_MAX_REGISTER_SIZE];
05d1431c 697 enum register_status status;
91021223
MF
698
699 if (regnum != BFIN_CC_REGNUM)
700 internal_error (__FILE__, __LINE__,
701 _("invalid register number %d"), regnum);
702
703 /* Extract the CC bit from the ASTAT register. */
03f50fc8 704 status = regcache->raw_read (BFIN_ASTAT_REGNUM, buf);
05d1431c
PA
705 if (status == REG_VALID)
706 {
707 buffer[1] = buffer[2] = buffer[3] = 0;
708 buffer[0] = !!(buf[0] & ASTAT_CC);
709 }
710 return status;
91021223
MF
711}
712
713static void
714bfin_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
715 int regnum, const gdb_byte *buffer)
716{
ba2f91bb 717 gdb_byte buf[BFIN_MAX_REGISTER_SIZE];
91021223
MF
718
719 if (regnum != BFIN_CC_REGNUM)
720 internal_error (__FILE__, __LINE__,
721 _("invalid register number %d"), regnum);
722
723 /* Overlay the CC bit in the ASTAT register. */
0b883586 724 regcache->raw_read (BFIN_ASTAT_REGNUM, buf);
91021223 725 buf[0] = (buf[0] & ~ASTAT_CC) | ((buffer[0] & 1) << ASTAT_CC_POS);
10eaee5f 726 regcache->raw_write (BFIN_ASTAT_REGNUM, buf);
91021223
MF
727}
728
729static CORE_ADDR
730bfin_frame_base_address (struct frame_info *this_frame, void **this_cache)
731{
732 struct bfin_frame_cache *cache = bfin_frame_cache (this_frame, this_cache);
733
734 return cache->base;
735}
736
737static CORE_ADDR
738bfin_frame_local_address (struct frame_info *this_frame, void **this_cache)
739{
740 struct bfin_frame_cache *cache = bfin_frame_cache (this_frame, this_cache);
741
742 return cache->base - 4;
743}
744
745static CORE_ADDR
746bfin_frame_args_address (struct frame_info *this_frame, void **this_cache)
747{
748 struct bfin_frame_cache *cache = bfin_frame_cache (this_frame, this_cache);
749
750 return cache->base + 8;
751}
752
753static const struct frame_base bfin_frame_base =
754{
755 &bfin_frame_unwind,
756 bfin_frame_base_address,
757 bfin_frame_local_address,
758 bfin_frame_args_address
759};
760
91021223
MF
761static CORE_ADDR
762bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
763{
764 return (address & ~0x3);
765}
766
767enum bfin_abi
768bfin_abi (struct gdbarch *gdbarch)
769{
770 return gdbarch_tdep (gdbarch)->bfin_abi;
771}
772
773/* Initialize the current architecture based on INFO. If possible,
774 re-use an architecture from ARCHES, which is a list of
775 architectures already created during this debugging session.
776
777 Called e.g. at program startup, when reading a core file, and when
778 reading a binary file. */
779
780static struct gdbarch *
781bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
782{
783 struct gdbarch_tdep *tdep;
784 struct gdbarch *gdbarch;
91021223
MF
785 enum bfin_abi abi;
786
91021223
MF
787 abi = BFIN_ABI_FLAT;
788
789 /* If there is already a candidate, use it. */
790
791 for (arches = gdbarch_list_lookup_by_info (arches, &info);
792 arches != NULL;
793 arches = gdbarch_list_lookup_by_info (arches->next, &info))
794 {
795 if (gdbarch_tdep (arches->gdbarch)->bfin_abi != abi)
796 continue;
797 return arches->gdbarch;
798 }
799
cdd238da 800 tdep = XCNEW (struct gdbarch_tdep);
91021223
MF
801 gdbarch = gdbarch_alloc (&info, tdep);
802
803 tdep->bfin_abi = abi;
804
805 set_gdbarch_num_regs (gdbarch, BFIN_NUM_REGS);
806 set_gdbarch_pseudo_register_read (gdbarch, bfin_pseudo_register_read);
807 set_gdbarch_pseudo_register_write (gdbarch, bfin_pseudo_register_write);
808 set_gdbarch_num_pseudo_regs (gdbarch, BFIN_NUM_PSEUDO_REGS);
809 set_gdbarch_sp_regnum (gdbarch, BFIN_SP_REGNUM);
810 set_gdbarch_pc_regnum (gdbarch, BFIN_PC_REGNUM);
811 set_gdbarch_ps_regnum (gdbarch, BFIN_ASTAT_REGNUM);
812 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, bfin_reg_to_regnum);
813 set_gdbarch_register_name (gdbarch, bfin_register_name);
814 set_gdbarch_register_type (gdbarch, bfin_register_type);
91021223
MF
815 set_gdbarch_push_dummy_call (gdbarch, bfin_push_dummy_call);
816 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
817 set_gdbarch_return_value (gdbarch, bfin_return_value);
818 set_gdbarch_skip_prologue (gdbarch, bfin_skip_prologue);
819 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
04180708
YQ
820 set_gdbarch_breakpoint_kind_from_pc (gdbarch, bfin_breakpoint_kind_from_pc);
821 set_gdbarch_sw_breakpoint_from_kind (gdbarch, bfin_sw_breakpoint_from_kind);
91021223
MF
822 set_gdbarch_decr_pc_after_break (gdbarch, 2);
823 set_gdbarch_frame_args_skip (gdbarch, 8);
91021223 824 set_gdbarch_frame_align (gdbarch, bfin_frame_align);
91021223
MF
825
826 /* Hook in ABI-specific overrides, if they have been registered. */
827 gdbarch_init_osabi (info, gdbarch);
828
829 dwarf2_append_unwinders (gdbarch);
830
831 frame_base_set_default (gdbarch, &bfin_frame_base);
832
833 frame_unwind_append_unwinder (gdbarch, &bfin_frame_unwind);
834
835 return gdbarch;
836}
837
91021223
MF
838void
839_initialize_bfin_tdep (void)
840{
841 register_gdbarch_init (bfd_arch_bfin, bfin_gdbarch_init);
842}
This page took 0.641705 seconds and 4 git commands to generate.