aboutsummaryrefslogtreecommitdiff
path: root/gdb/builtin-regs.c
blob: 07e5fcca58a334ec124292ff42cc0e50ddc12e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Builtin registers, for GDB, the GNU debugger.

   Copyright 2002 Free Software Foundation, Inc.

   Contributed by Red Hat.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#include "defs.h"
#include "builtin-regs.h"
#include "gdbtypes.h"
#include "gdb_string.h"
#include "gdb_assert.h"

/* Implement builtin register types.  Builtin registers have regnum's
   that live above of the range [0 .. NUM_REGS + NUM_PSEUDO_REGS)
   (which is controlled by the target).  The target should never see a
   builtin register's regnum value.  */

/* An array of builtin registers.  Always append, never delete.  By
   doing this, the relative regnum (offset from NUM_REGS +
   NUM_PSEUDO_REGS) assigned to each builtin register never changes.  */

struct builtin_reg
{
  const char *name;
  struct value *(*value) (struct frame_info * frame);
};

static struct builtin_reg *builtin_regs;
int nr_builtin_regs;

void
add_builtin_reg (const char *name, struct value *(*value) (struct frame_info * frame))
{
  nr_builtin_regs++;
  builtin_regs = xrealloc (builtin_regs,
			   nr_builtin_regs * sizeof (builtin_regs[0]));
  builtin_regs[nr_builtin_regs - 1].name = name;
  builtin_regs[nr_builtin_regs - 1].value = value;
}

int
builtin_reg_map_name_to_regnum (const char *name, int len)
{
  int reg;
  for (reg = 0; reg < nr_builtin_regs; reg++)
    {
      if (len == strlen (builtin_regs[reg].name)
	  && strncmp (builtin_regs[reg].name, name, len) == 0)
	return NUM_REGS + NUM_PSEUDO_REGS + reg;
    }
  return -1;
}

const char *
builtin_reg_map_regnum_to_name (int regnum)
{
  int reg = regnum - (NUM_REGS + NUM_PSEUDO_REGS);
  if (reg < 0 || reg >= nr_builtin_regs)
    return NULL;
  return builtin_regs[reg].name;
}

struct value *
value_of_builtin_reg (int regnum, struct frame_info *frame)
{
  int reg = regnum - (NUM_REGS + NUM_PSEUDO_REGS);
  gdb_assert (reg >= 0 && reg < nr_builtin_regs);
  return builtin_regs[reg].value (frame);
}