OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [scarts_32-tdep.c] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
/* SCARTS (32-bit) target-dependent code for GDB, the GNU debugger.
2
   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
3
   Contributed by Martin Walter <mwalter@opencores.org>
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
 
20
 
21
#include <inttypes.h>
22
#include "demangle.h"
23
#include "defs.h"
24
#include "dis-asm.h"
25
#include "dwarf2-frame.h"
26
#include "gdb_string.h"
27
#include "gdbtypes.h"
28
#include "frame.h"
29
#include "frame-base.h"
30
#include "frame-unwind.h"
31
#include "gdbcmd.h"
32
#include "gdbcore.h"
33
#include "inferior.h"
34
#include "language.h"
35
#include "objfiles.h"
36
#include "regcache.h"
37
#include "reggroups.h"
38
#include "safe-ctype.h"
39
#include "symfile.h"
40
#include "symtab.h"
41
#include "target.h"
42
#include "trad-frame.h"
43
#include "value.h"
44
#include "arch-utils.h"
45
#include "block.h"
46
#include "scarts_32-tdep.h"
47
 
48
struct scarts_32_frame_cache
49
{
50
  CORE_ADDR base;
51
  struct trad_frame_saved_reg *saved_regs;
52
};
53
 
54
static enum return_value_convention scarts_32_return_value (struct gdbarch  *gdbarch,
55
                                                          struct type     *type,
56
                                                          struct regcache *regcache,
57
                                                          gdb_byte        *readbuf,
58
                                                          const gdb_byte  *writebuf);
59
 
60
static const gdb_byte *scarts_32_breakpoint_from_pc (struct gdbarch *gdbarch,
61
                                                   CORE_ADDR      *bp_addr,
62
                                                   int            *bp_size);
63
 
64
static int scarts_32_print_insn (bfd_vma vma,
65
                               disassemble_info *info);
66
 
67
static void scarts_32_pseudo_register_read (struct gdbarch  *gdbarch,
68
                                          struct regcache *regcache,
69
                                          int              regnum,
70
                                          gdb_byte        *buf);
71
 
72
static void scarts_32_pseudo_register_write (struct gdbarch  *gdbarch,
73
                                           struct regcache *regcache,
74
                                           int              regnum,
75
                                           const gdb_byte  *buf);
76
 
77
static const char *scarts_32_register_name (struct gdbarch *gdbarch,
78
                                          int             regnum);
79
 
80
static struct type *scarts_32_register_type (struct gdbarch *arch,
81
                                           int             regnum);
82
 
83
static void scarts_32_registers_info (struct gdbarch    *gdbarch,
84
                                    struct ui_file    *file,
85
                                    struct frame_info *frame,
86
                                    int                regnum,
87
                                    int                all);
88
 
89
static int scarts_32_register_reggroup_p (struct gdbarch  *gdbarch,
90
                                        int              regnum,
91
                                        struct reggroup *group);
92
 
93
static CORE_ADDR scarts_32_scan_prologue (CORE_ADDR                  start_pc,
94
                                        CORE_ADDR                  end_pc,
95
                                        struct frame_info         *next_frame,
96
                                        struct scarts_32_frame_cache *this_cache);
97
 
98
static CORE_ADDR scarts_32_skip_prologue (struct gdbarch *gdbarch,
99
                                        CORE_ADDR       pc);
100
 
101
static CORE_ADDR scarts_32_frame_align (struct gdbarch *gdbarch,
102
                                      CORE_ADDR       sp);
103
 
104
static CORE_ADDR scarts_32_addr_bits_remove (CORE_ADDR addr);
105
 
106
static CORE_ADDR scarts_32_unwind_pc (struct gdbarch    *gdbarch,
107
                                    struct frame_info *next_frame);
108
 
109
static CORE_ADDR scarts_32_unwind_sp (struct gdbarch    *gdbarch,
110
                                    struct frame_info *next_frame);
111
 
112
static CORE_ADDR scarts_32_push_dummy_call (struct gdbarch  *gdbarch,
113
                                          struct value    *function,
114
                                          struct regcache *regcache,
115
                                          CORE_ADDR        bp_addr,
116
                                          int              nargs,
117
                                          struct value   **args,
118
                                          CORE_ADDR        sp,
119
                                          int              struct_return,
120
                                          CORE_ADDR        struct_addr);
121
 
122
static struct frame_id scarts_32_unwind_dummy_id (struct gdbarch    *gdbarch,
123
                                                struct frame_info *next_frame);
124
 
125
static unsigned long int scarts_32_fetch_insn (struct frame_info *next_frame,
126
                                             CORE_ADDR          addr);
127
 
128
static int scarts_32_frame_size (struct frame_info *next_frame,
129
                               CORE_ADDR          start_addr,
130
                               CORE_ADDR          end_addr);
131
 
132
static struct trad_frame_cache *scarts_32_frame_unwind_cache (struct frame_info  *next_frame,
133
                                                            void              **this_prologue_cache);
134
 
135
static void scarts_32_frame_this_id (struct frame_info *next_frame,
136
                                   void             **this_prologue_cache,
137
                                   struct frame_id   *this_id);
138
 
139
static void scarts_32_frame_prev_register (struct frame_info  *next_frame,
140
                                         void              **this_prologue_cache,
141
                                         int                 regnum,
142
                                         int                *optimizedp,
143
                                         enum lval_type     *lvalp,
144
                                         CORE_ADDR          *addrp,
145
                                         int                *realregp,
146
                                         gdb_byte           *bufferp);
147
 
148
static CORE_ADDR scarts_32_frame_base_address (struct frame_info *next_frame,
149
                                             void             **this_prologue_cache);
150
 
151
static const struct frame_unwind *scarts_32_frame_sniffer (struct frame_info *next_frame);
152
 
153
static struct gdbarch *scarts_32_gdbarch_init (struct gdbarch_info  info,
154
                                             struct gdbarch_list *arches);
155
 
156
static void scarts_32_dump_tdep (struct gdbarch *gdbarch,
157
                               struct ui_file *file);
158
 
159
 
160
/*----------------------------------------------------------------------------*/
161
/*!Determine the return convention used for a given type
162
 *
163
 * Optionally, fetch or set the return value via "readbuf" or "writebuf"
164
 * respectively using "regcache" for the register values.
165
 *
166
 * Throughout use read_memory(), not target_read_memory(), since the address
167
 * may be invalid and we want an error reported (read_memory() is
168
 * target_read_memory() with error reporting).
169
 *
170
 * @param[in]  gdbarch   The GDB architecture being used
171
 * @param[in]  type      The type of the entity to be returned
172
 * @param[in]  regcache  The register cache
173
 * @param[in]  readbuf   Buffer into which the return value should be written
174
 * @param[out] writebuf  Buffer from which the return value should be written
175
 *
176
 * @return  The type of return value */
177
/*---------------------------------------------------------------------------*/
178
 
179
static enum return_value_convention
180
scarts_32_return_value (struct gdbarch  *gdbarch,
181
                      struct type     *type,
182
                      struct regcache *regcache,
183
                      gdb_byte        *readbuf,
184
                      const gdb_byte  *writebuf)
185
{
186
  unsigned int rv_size;
187
  ULONGEST     tmp;
188
 
189
  rv_size = TYPE_LENGTH (type);
190
 
191
  if (readbuf)
192
  {
193
    regcache_cooked_read_unsigned (regcache, 0, &tmp);
194
    store_unsigned_integer (readbuf, rv_size, tmp);
195
  }
196
 
197
  if (writebuf)
198
  {
199
    regcache_cooked_write_unsigned (regcache, 0, unpack_long (type, writebuf));
200
  }
201
 
202
  return RETURN_VALUE_REGISTER_CONVENTION;
203
}
204
 
205
 
206
/*---------------------------------------------------------------------------*/
207
/* !Determine the instruction to use for a breakpoint.
208
 *
209
 * Given the address at which to insert a breakpoint (bp_addr), what will that
210
 * breakpoint be?
211
 *
212
 * We use the ILLOP instruction to stop program execution of the simulator.
213
 *
214
 * @param[in]  gdbarch  The GDB architecture being used
215
 * @param[in]  bp_addr  The breakpoint address in question
216
 * @param[out] bp_size  The size of instruction selected
217
 *
218
 * @return  The chosen breakpoint instruction */
219
/*---------------------------------------------------------------------------*/
220
 
221
static const gdb_byte *
222
scarts_32_breakpoint_from_pc (struct gdbarch *gdbarch,
223
                            CORE_ADDR      *bp_addr,
224
                            int            *bp_size)
225
{
226
  static const gdb_byte breakpoint[] = SCARTS_ILLOP_INSN_STRUCT;
227
 
228
  *bp_addr += SCARTS_CODEMEM_LMA;
229
  *bp_size  = SCARTS_INSN_SIZE;
230
  return breakpoint;
231
}
232
 
233
 
234
static int
235
scarts_32_print_insn (bfd_vma memaddr, disassemble_info *info)
236
{
237
  memaddr += SCARTS_CODEMEM_LMA;
238
  return print_insn_scarts_32 (memaddr, info);
239
}
240
 
241
 
242
/*----------------------------------------------------------------------------*/
243
/*!Read a pseudo register
244
 *
245
 * Since we have no pseudo registers this is a null function for now.
246
 *
247
 * @param[in]  gdbarch   The GDB architecture to consider
248
 * @param[in]  regcache  The cached register values as an array
249
 * @param[in]  regnum    The register to read
250
 * @param[out] buf       A buffer to put the result in */
251
/*---------------------------------------------------------------------------*/
252
 
253
static void
254
scarts_32_pseudo_register_read (struct gdbarch  *gdbarch,
255
                              struct regcache *regcache,
256
                              int              regnum,
257
                              gdb_byte        *buf)
258
{
259
  return;
260
}
261
 
262
 
263
/*----------------------------------------------------------------------------*/
264
/*!Write a pseudo register
265
 *
266
 * Since we have no pseudo registers this is a null function for now.
267
 *
268
 * @param[in] gdbarch   The GDB architecture to consider
269
 * @param[in] regcache  The cached register values as an array
270
 * @param[in] regnum    The register to read
271
 * @param[in] buf       A buffer with the value to write */
272
/*---------------------------------------------------------------------------*/
273
 
274
static void
275
scarts_32_pseudo_register_write (struct gdbarch  *gdbarch,
276
                               struct regcache *regcache,
277
                               int              regnum,
278
                               const gdb_byte  *buf)
279
{
280
  return;
281
}
282
 
283
 
284
/*----------------------------------------------------------------------------*/
285
/*!Return the register name for the SCARTS architecture
286
 *
287
 * This version converted to ANSI C, made static and incorporates the static
288
 * table of register names (this is the only place it is referenced).
289
 *
290
 * @param[in] gdbarch  The GDB architecture being used
291
 * @param[in] regnum   The register number
292
 *
293
 * @return  The textual name of the register */
294
/*---------------------------------------------------------------------------*/
295
 
296
static const char *
297
scarts_32_register_name (struct gdbarch *gdbarch,
298
                       int             regnum)
299
{
300
  static char *scarts_32_gdb_reg_names[SCARTS_TOTAL_NUM_REGS] =
301
  {
302
      /* General Purpose Registers */
303
      "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
304
      "r8",  "r9",  "r10", "r11", "r12", "r13", "RTS", "RTE",
305
 
306
      /* Special Purpose Registers */
307
      "FPW (PC)", "FPX", "FPY (FP)", "FPZ (SP)",
308
  };
309
 
310
  return scarts_32_gdb_reg_names[regnum];
311
}
312
 
313
 
314
/*----------------------------------------------------------------------------*/
315
/*!Identify the type of a register
316
 *
317
 * @todo I don't fully understand exactly what this does, but I think this
318
 * makes sense!
319
 *
320
 * @param[in] arch     The GDB architecture to consider
321
 * @param[in] regnum   The register to identify
322
 *
323
 * @return  The type of the register */
324
/*---------------------------------------------------------------------------*/
325
 
326
static struct type *
327
scarts_32_register_type (struct gdbarch *arch,
328
                       int             regnum)
329
{
330
  if (regnum >= 0 && regnum < SCARTS_NUM_GP_REGS)
331
  {
332
    switch (regnum)
333
    {
334
      case SCARTS_RTS_REGNUM:
335
      case SCARTS_RTE_REGNUM:
336
        return builtin_type_void_func_ptr;
337
      default:
338
        return builtin_type_uint32;
339
    }
340
  }
341
  else if (regnum >= SCARTS_NUM_GP_REGS && regnum < SCARTS_TOTAL_NUM_REGS)
342
  {
343
    switch (regnum)
344
    {
345
      case SCARTS_PC_REGNUM:
346
        return builtin_type_void_func_ptr;
347
      default:
348
        return builtin_type_void_data_ptr;
349
    }
350
  }
351
 
352
  return builtin_type_uint32;
353
}
354
 
355
 
356
/*----------------------------------------------------------------------------*/
357
/*!Handle the "info register" command
358
 *
359
 * Print the identified register, unless it is -1, in which case print all
360
 * the registers. If all is 1 means all registers, otherwise only the core
361
 * GPRs.
362
 *
363
 * @param[in] gdbarch  The GDB architecture being used
364
 * @param[in] file     File handle for use with any custom I/O
365
 * @param[in] frame    Frame info for use with custom output
366
 * @param[in] regnum   Register of interest, or -1 if all registers
367
 * @param[in] all      1 if all means all, 0 if all means just GPRs
368
 *
369
 * @return  The aligned stack frame address */
370
/*---------------------------------------------------------------------------*/
371
 
372
static void
373
scarts_32_registers_info (struct gdbarch    *gdbarch,
374
                        struct ui_file    *file,
375
                        struct frame_info *frame,
376
                        int                regnum,
377
                        int                all)
378
{
379
  if (regnum == -1)
380
  {
381
    unsigned int n = all ? SCARTS_NUM_REGS : SCARTS_NUM_GP_REGS;
382
 
383
    for (regnum = 0; regnum < n; regnum++)
384
    {
385
      if (*(scarts_32_register_name (gdbarch, regnum)) != '\0')
386
      {
387
        scarts_32_registers_info (gdbarch, file, frame, regnum, all);
388
      }
389
    }
390
  }
391
  else
392
  {
393
    if (*(scarts_32_register_name (gdbarch, regnum)) == '\0')
394
    {
395
      error ("Invalid register number");
396
    }
397
    else
398
    {
399
      default_print_registers_info (gdbarch, file, frame, regnum, all);
400
    }
401
  }
402
}
403
 
404
 
405
/*----------------------------------------------------------------------------*/
406
/*!Identify if a register belongs to a specified group
407
 *
408
 * Return true if the specified register is a member of the specified
409
 * register group.
410
 *
411
 * These are the groups of registers that can be displayed via "info reg".
412
 *
413
 * @param[in] gdbarch  The GDB architecture to consider
414
 * @param[in] regnum   The register to consider
415
 * @param[in] group    The group to consider
416
 *
417
 * @return  True (1) if regnum is a member of group */
418
/*---------------------------------------------------------------------------*/
419
 
420
static int
421
scarts_32_register_reggroup_p (struct gdbarch  *gdbarch,
422
                             int              regnum,
423
                             struct reggroup *group)
424
{
425
  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
426
 
427
  if (group == all_reggroup)
428
    return (regnum >= 0 && regnum < SCARTS_TOTAL_NUM_REGS && (scarts_32_register_name (gdbarch, regnum)[0] != '\0'));
429
 
430
  /* Registers displayed via 'info registers'. */
431
  if (group == general_reggroup)
432
    return (regnum >= 0 && regnum < tdep->num_gp_regs);
433
 
434
  /* Registers displayed via 'info float' or 'info vector'. */
435
  else if (group == float_reggroup || group == vector_reggroup)
436
    return 0;
437
 
438
  return default_register_reggroup_p (gdbarch, regnum, group);
439
}
440
 
441
 
442
/*----------------------------------------------------------------------------*/
443
/*!Skip a function prolog
444
 *
445
 * If the input address, PC, is in a function prologue, return the address of
446
 * the end of the prologue, otherwise return the input  address.
447
 *
448
 * @param[in] gdbarch  The GDB architecture being used
449
 * @param[in] pc       Current program counter
450
 *
451
 * @return  The address of the end of the prolog if the PC is in a function
452
 * prologue, otherwise the input  address. */
453
/*--------------------------------------------------------------------------*/
454
 
455
static CORE_ADDR
456
scarts_32_skip_prologue (struct gdbarch *gdbarch,
457
                       CORE_ADDR       pc)
458
{
459
  CORE_ADDR start_addr, end_addr;
460
 
461
  /* Determine the end of the prologue from the line number information held
462
   * for debugging purposes in the symbol table (symbol-and-line information,
463
   * SAL). */
464
  if (find_pc_partial_function (pc, NULL, &start_addr, &end_addr))
465
  {
466
    CORE_ADDR pc_after_prologue = skip_prologue_using_sal (start_addr);
467
 
468
    /* Return the PC or the PC after the prologue, whichever is greater. */
469
    if (pc_after_prologue != 0)
470
      return max (pc, pc_after_prologue);
471
  }
472
 
473
  return pc;
474
}
475
 
476
 
477
/*----------------------------------------------------------------------------*/
478
/*!Align the stack frame
479
 *
480
 * SCARTS uses a falling stack frame, so this aligns down to the
481
 * nearest SCARTS_STACK_ALIGN bytes.
482
 *
483
 * @param[in] gdbarch  The GDB architecture being used
484
 * @param[in] sp       Current stack pointer
485
 *
486
 * @return  The aligned stack frame address */
487
/*---------------------------------------------------------------------------*/
488
 
489
static CORE_ADDR
490
scarts_32_frame_align (struct gdbarch *gdbarch,
491
                     CORE_ADDR       sp)
492
{
493
  return align_down (sp, SCARTS_STACK_ALIGN);
494
}
495
 
496
 
497
static CORE_ADDR
498
scarts_32_addr_bits_remove (CORE_ADDR addr)
499
{
500
  return (addr >= SCARTS_CODEMEM_LMA) ? addr - SCARTS_CODEMEM_LMA : addr;
501
}
502
 
503
/*----------------------------------------------------------------------------*/
504
/*!Unwind the program counter from a stack frame
505
 *
506
 * This just uses the built in frame unwinder
507
 *
508
 * @param[in] gdbarch     The GDB architecture being used
509
 * @param[in] next_frame  Frame info for the NEXT frame
510
 *
511
 * @return  The program counter for THIS frame */
512
/*---------------------------------------------------------------------------*/
513
 
514
static CORE_ADDR
515
scarts_32_unwind_pc (struct gdbarch    *gdbarch,
516
                   struct frame_info *next_frame)
517
{
518
  return frame_unwind_register_unsigned (next_frame, SCARTS_PC_REGNUM);
519
}
520
 
521
 
522
/*----------------------------------------------------------------------------*/
523
/*!Unwind the stack pointer from a stack frame
524
 *
525
 * This just uses the built in frame unwinder
526
 *
527
 * @param[in] gdbarch     The GDB architecture being used
528
 * @param[in] next_frame  Frame info for the NEXT frame
529
 *
530
 * @return  The stack pointer for THIS frame */
531
/*---------------------------------------------------------------------------*/
532
 
533
static CORE_ADDR
534
scarts_32_unwind_sp (struct gdbarch    *gdbarch,
535
                   struct frame_info *next_frame)
536
{
537
  return frame_unwind_register_unsigned (next_frame, SCARTS_SP_REGNUM);
538
}
539
 
540
/*----------------------------------------------------------------------------*/
541
/*!Create a dummy stack frame
542
 
543
   The arguments are placed in registers and/or pushed on the stack as per the
544
   SCARTS ABI.
545
 
546
   @param[in] gdbarch        The architecture to use
547
   @param[in] function       Pointer to the function that will be called
548
   @param[in] regcache       The register cache to use
549
   @param[in] bp_addr        Breakpoint address
550
   @param[in] nargs          Number of ags to push
551
   @param[in] args           The arguments
552
   @param[in] sp             The stack pointer
553
   @param[in] struct_return  True (1) if this returns a structure
554
   @param[in] struct_addr    Address for returning structures
555
 
556
   @return  The updated stack pointer */
557
/*---------------------------------------------------------------------------*/
558
 
559
static CORE_ADDR scarts_32_push_dummy_call (struct gdbarch  *gdbarch,
560
                                          struct value    *function,
561
                                          struct regcache *regcache,
562
                                          CORE_ADDR        bp_addr,
563
                                          int              nargs,
564
                                          struct value   **args,
565
                                          CORE_ADDR        sp,
566
                                          int              struct_return,
567
                                          CORE_ADDR        struct_addr)
568
{
569
   return 0;
570
}
571
 
572
 
573
/*----------------------------------------------------------------------------*/
574
/*!Unwind a dummy stack frame
575
 
576
   @param[in] gdbarch     The architecture to use
577
   @param[in] next_frame  Information about the next frame
578
 
579
   @return  Frame ID of the preceding frame */
580
/*---------------------------------------------------------------------------*/
581
 
582
static struct frame_id scarts_32_unwind_dummy_id (struct gdbarch    *gdbarch,
583
                                                struct frame_info *next_frame)
584
{
585
  return frame_id_build (0, 0);
586
}
587
 
588
 
589
/*----------------------------------------------------------------------------*/
590
/*!Initialize a prologue (unwind) cache
591
 
592
   Build up the information (saved registers etc) for the given frame if it
593
   does not already exist.
594
 
595
   @param[in]     next_frame           The NEXT frame (i.e. inner from here,
596
                                       the one THIS frame called)
597
   @param[in,out] this_prologue_cache  The prologue cache. If not supplied, we
598
                                       build it.
599
 
600
   @return  The prolog cache (duplicates the return through the argument) */
601
/*---------------------------------------------------------------------------*/
602
 
603
static struct trad_frame_cache *
604
scarts_32_frame_unwind_cache (struct frame_info  *next_frame,
605
                            void              **this_prologue_cache)
606
{
607
  struct trad_frame_cache *info;
608
 
609
  if (*this_prologue_cache != NULL)
610
    return *this_prologue_cache;
611
 
612
  info = trad_frame_cache_zalloc (next_frame);
613
  *this_prologue_cache = info;
614
 
615
  return info;
616
}
617
 
618
 
619
/*----------------------------------------------------------------------------*/
620
/*!Find the frame ID of this frame
621
 *
622
 * Given a GDB frame (called by THIS frame), determine the address of oru
623
 * frame and from this create a new GDB frame struct. The info required is
624
 * obtained from the prologue cache for THIS frame.
625
 *
626
 * @param[in] next_frame           The NEXT frame (i.e. inner from here, the
627
 *                                 one THIS frame called)
628
 * @param[in] this_prologue_cache  Any cached prologue for THIS function.
629
 * @param[out]this_id              Frame ID of our own frame.
630
 *
631
 * @return  Frame ID for THIS frame */
632
/*---------------------------------------------------------------------------*/
633
 
634
static void
635
scarts_32_frame_this_id (struct frame_info *next_frame,
636
                       void             **this_prologue_cache,
637
                       struct frame_id   *this_id)
638
{
639
  struct trad_frame_cache *info = scarts_32_frame_unwind_cache (next_frame, this_prologue_cache);
640
  trad_frame_get_id (info, this_id);
641
}
642
 
643
 
644
/*----------------------------------------------------------------------------*/
645
/*!Get a register from THIS frame
646
 *
647
 * Given a pointer to the NEXT frame, return the details of a register in the
648
 * PREVIOUS frame.
649
 *
650
 * @param[in] next_frame            The NEXT frame (i.e. inner from here, the
651
 *                                  one THIS frame called).
652
 * @param[in]  this_prologue_cache  Any cached prologue associated with THIS
653
 *                                  frame, which may therefore tell us about
654
 *                                  registers in the PREVIOUS frame.
655
 * @param[in]  regnum               The register of interest in the PREVIOUS
656
 *                                  frame.
657
 * @param[out] optimizedp           True (1) if the register has been
658
 *                                  optimized out.
659
 * @param[out] lvalp                What sort of l-value (if any) does the
660
 *                                  register represent.
661
 * @param[out] addrp                Address in THIS frame where the register's
662
 *                                  value may be found (-1 if not available).
663
 * @param[out] realregp             Register in this frame where the
664
 *                                  register's value may be found (-1 if not
665
 *                                  available).
666
 * @param[out] bufferp              If non-NULL, buffer where the value held
667
 *                                  in the register may be put */
668
/*--------------------------------------------------------------------------*/
669
 
670
static void
671
scarts_32_frame_prev_register (struct frame_info  *next_frame,
672
                             void              **this_prologue_cache,
673
                             int                 regnum,
674
                             int                *optimizedp,
675
                             enum lval_type     *lvalp,
676
                             CORE_ADDR          *addrp,
677
                             int                *realregp,
678
                             gdb_byte           *bufferp)
679
{
680
  struct trad_frame_cache *info = scarts_32_frame_unwind_cache (next_frame, this_prologue_cache);
681
  trad_frame_get_register (info, next_frame, regnum, optimizedp, lvalp, addrp, realregp, bufferp);
682
}
683
 
684
 
685
/*----------------------------------------------------------------------------*/
686
/*!Return the base address of the frame
687
 *
688
 * The commenting in the GDB source code could mean our stack pointer or our
689
 * frame pointer, since we have a falling stack, but index within the frame
690
 * using negative offsets from the FP.
691
 *
692
 * This seems to be the function used to determine the value of $fp, but the
693
 * value required seems to be the stack pointer, so we return that, even if
694
 * the value of $fp will be wrong.
695
 *
696
 * @param[in] next_frame            The NEXT frame (i.e. inner from here, the
697
 *                                  one THIS frame called).
698
 * @param[in]  this_prologue_cache  Any cached prologue for THIS function.
699
 *
700
 * @return  The frame base address */
701
/*---------------------------------------------------------------------------*/
702
 
703
static CORE_ADDR
704
scarts_32_frame_base_address (struct frame_info *next_frame,
705
                            void             **this_prologue_cache)
706
{
707
  return frame_unwind_register_unsigned (next_frame, SCARTS_SP_REGNUM);
708
}
709
 
710
 
711
static CORE_ADDR
712
scarts_32_frame_locals_address (struct frame_info *next_frame,
713
                              void             **this_prologue_cache)
714
{
715
  return frame_unwind_register_unsigned (next_frame, SCARTS_FP_REGNUM);
716
}
717
 
718
 
719
static CORE_ADDR
720
scarts_32_frame_args_address (struct frame_info *next_frame,
721
                            void             **this_prologue_cache)
722
{
723
  return scarts_32_frame_base_address (next_frame, this_prologue_cache);
724
}
725
 
726
 
727
/*----------------------------------------------------------------------------*/
728
/*!The SCARTS registered frame sniffer
729
 *
730
 * This function just identifies our family of frame sniffing functions.
731
 *
732
 * @param[in] next_frame  The "next" (i.e. inner, newer from here, the one
733
 *                        THIS frame called) frame.
734
 *
735
 * @return  A pointer to a struct identifying the sniffing functions */
736
/*---------------------------------------------------------------------------*/
737
 
738
static const struct frame_unwind *
739
scarts_32_frame_sniffer (struct frame_info *next_frame)
740
{
741
  static const struct frame_unwind scarts_32_frame_unwind =
742
  {
743
    .type          = NORMAL_FRAME,
744
    .this_id       = scarts_32_frame_this_id,
745
    .prev_register = scarts_32_frame_prev_register,
746
    .unwind_data   = NULL,
747
    .sniffer       = NULL,
748
    .prev_pc       = NULL,
749
    .dealloc_cache = NULL
750
  };
751
 
752
  return &scarts_32_frame_unwind;
753
}
754
 
755
static struct gdbarch *
756
scarts_32_gdbarch_init (struct gdbarch_info  info,
757
                      struct gdbarch_list *arches)
758
{
759
  static struct frame_base     scarts_32_frame_base;
760
  struct        gdbarch       *gdbarch;
761
  struct        gdbarch_tdep  *tdep;
762
  const struct  bfd_arch_info *binfo;
763
 
764
  binfo                   = info.bfd_arch_info;
765
  tdep                    = xmalloc (sizeof *tdep);
766
  tdep->num_gp_regs       = SCARTS_NUM_GP_REGS;
767
  tdep->num_sp_regs       = SCARTS_NUM_SP_REGS;
768
  tdep->num_pseudo_regs   = SCARTS_NUM_PSEUDO_REGS;
769
  tdep->pc_regnum         = SCARTS_PC_REGNUM;
770
  tdep->fp_regnum         = SCARTS_FP_REGNUM;
771
  tdep->sp_regnum         = SCARTS_SP_REGNUM;
772
  tdep->bytes_per_word    = binfo->bits_per_word / binfo->bits_per_byte;
773
  tdep->bytes_per_address = binfo->bits_per_address / binfo->bits_per_byte;
774
  gdbarch                 = gdbarch_alloc (&info, tdep);
775
 
776
  /* Target data types. */
777
  set_gdbarch_short_bit             (gdbarch, 16);
778
  set_gdbarch_int_bit               (gdbarch, 32);
779
  set_gdbarch_long_bit              (gdbarch, 32);
780
  set_gdbarch_long_long_bit         (gdbarch, 64);
781
  set_gdbarch_float_bit             (gdbarch, 32);
782
  set_gdbarch_float_format          (gdbarch, floatformats_ieee_single);
783
  set_gdbarch_double_bit            (gdbarch, 64);
784
  set_gdbarch_double_format         (gdbarch, floatformats_ieee_double);
785
  set_gdbarch_long_double_bit       (gdbarch, 64);
786
  set_gdbarch_long_double_format    (gdbarch, floatformats_ieee_double);
787
  set_gdbarch_ptr_bit               (gdbarch, binfo->bits_per_address);
788
  set_gdbarch_addr_bit              (gdbarch, binfo->bits_per_address);
789
  set_gdbarch_char_signed           (gdbarch, 1);
790
 
791
  /* Information about the target architecture. */
792
  set_gdbarch_return_value          (gdbarch, scarts_32_return_value);
793
  set_gdbarch_breakpoint_from_pc    (gdbarch, scarts_32_breakpoint_from_pc);
794
  set_gdbarch_print_insn            (gdbarch, scarts_32_print_insn);
795
 
796
  /* Register architecture. */
797
  set_gdbarch_pseudo_register_read  (gdbarch, scarts_32_pseudo_register_read);
798
  set_gdbarch_pseudo_register_write (gdbarch, scarts_32_pseudo_register_write);
799
  set_gdbarch_num_regs              (gdbarch, SCARTS_NUM_REGS);
800
  set_gdbarch_num_pseudo_regs       (gdbarch, SCARTS_NUM_PSEUDO_REGS);
801
  set_gdbarch_sp_regnum             (gdbarch, SCARTS_SP_REGNUM);
802
  set_gdbarch_pc_regnum             (gdbarch, SCARTS_PC_REGNUM);
803
  set_gdbarch_deprecated_fp_regnum  (gdbarch, SCARTS_FP_REGNUM);
804
 
805
  /* Functions to supply register information. */
806
  set_gdbarch_register_name         (gdbarch, scarts_32_register_name);
807
  set_gdbarch_register_type         (gdbarch, scarts_32_register_type);
808
  set_gdbarch_print_registers_info  (gdbarch, scarts_32_registers_info);
809
  set_gdbarch_register_reggroup_p   (gdbarch, scarts_32_register_reggroup_p);
810
 
811
  /* Functions to analyse frames. */
812
  set_gdbarch_skip_prologue         (gdbarch, scarts_32_skip_prologue);
813
  set_gdbarch_inner_than            (gdbarch, core_addr_lessthan);
814
  set_gdbarch_frame_align           (gdbarch, scarts_32_frame_align);
815
  set_gdbarch_frame_red_zone_size   (gdbarch, SCARTS_FRAME_RED_ZONE_SIZE);
816
 
817
  /* Functions to handle addresses. */
818
  set_gdbarch_addr_bits_remove      (gdbarch, scarts_32_addr_bits_remove);
819
 
820
  /* Functions to access frame data. */
821
  set_gdbarch_unwind_pc             (gdbarch, scarts_32_unwind_pc);
822
  set_gdbarch_unwind_sp             (gdbarch, scarts_32_unwind_sp);
823
 
824
  /* Functions handling dummy frames. */
825
  set_gdbarch_push_dummy_call       (gdbarch, scarts_32_push_dummy_call);
826
  set_gdbarch_unwind_dummy_id       (gdbarch, scarts_32_unwind_dummy_id);
827
 
828
  /* High level frame base sniffer. */
829
  scarts_32_frame_base.unwind         = scarts_32_frame_sniffer (NULL);
830
  scarts_32_frame_base.this_base      = scarts_32_frame_base_address;
831
  scarts_32_frame_base.this_locals    = scarts_32_frame_locals_address;
832
  scarts_32_frame_base.this_args      = scarts_32_frame_args_address;
833
  frame_base_set_default            (gdbarch, &scarts_32_frame_base);
834
 
835
  /* Low level frame sniffers. */
836
  frame_unwind_append_sniffer       (gdbarch, dwarf2_frame_sniffer);
837
  frame_unwind_append_sniffer       (gdbarch, scarts_32_frame_sniffer);
838
 
839
  return gdbarch;
840
}
841
 
842
 
843
/*----------------------------------------------------------------------------*/
844
/*!Dump the target specific data for this architecture
845
 *
846
 * @param[in] gdbarch  The architecture of interest
847
 * @param[in] file     Where to dump the data */
848
/*---------------------------------------------------------------------------*/
849
 
850
static void
851
scarts_32_dump_tdep (struct gdbarch *gdbarch,
852
                   struct ui_file *file)
853
{
854
  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
855
 
856
  if (tdep == NULL)
857
    return;
858
 
859
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d general purpose registers\n", tdep->num_gp_regs);
860
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d special purpose registers\n", tdep->num_sp_regs);
861
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d pseudo registers\n",          tdep->num_pseudo_regs);
862
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d is the PC register\n",        tdep->pc_regnum);
863
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d is the FP register\n",        tdep->fp_regnum);
864
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d is the SP register\n",        tdep->sp_regnum);
865
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d bytes per word\n",            tdep->bytes_per_word);
866
  fprintf_unfiltered (file, "scarts_32_dump_tdep: %d bytes per address\n",         tdep->bytes_per_address);
867
}
868
 
869
 
870
/*----------------------------------------------------------------------------*/
871
/*!Main entry point for target architecture initialization
872
 *
873
 * In this version initializes the architecture via
874
 * registers_gdbarch_init(). Add a command to set and show special purpose
875
 * registers. */
876
/*---------------------------------------------------------------------------*/
877
 
878
void
879
_initialize_scarts_32_tdep (void)
880
{
881
  gdbarch_register (bfd_arch_scarts_32, scarts_32_gdbarch_init, scarts_32_dump_tdep);
882
}
883
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.