| 1 | /* Builtin registers, for GDB, the GNU debugger. |
| 2 | |
| 3 | Copyright 2002 Free Software Foundation, Inc. |
| 4 | |
| 5 | Contributed by Red Hat. |
| 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 2 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, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 22 | Boston, MA 02111-1307, USA. */ |
| 23 | |
| 24 | #include "defs.h" |
| 25 | #include "builtin-regs.h" |
| 26 | #include "gdbtypes.h" |
| 27 | #include "gdb_string.h" |
| 28 | #include "gdb_assert.h" |
| 29 | |
| 30 | /* Implement builtin register types. Builtin registers have regnum's |
| 31 | that live above of the range [0 .. NUM_REGS + NUM_PSEUDO_REGS) |
| 32 | (which is controlled by the target). The target should never see a |
| 33 | builtin register's regnum value. */ |
| 34 | |
| 35 | /* An array of builtin registers. Always append, never delete. By |
| 36 | doing this, the relative regnum (offset from NUM_REGS + |
| 37 | NUM_PSEUDO_REGS) assigned to each builtin register never changes. */ |
| 38 | |
| 39 | struct builtin_reg |
| 40 | { |
| 41 | const char *name; |
| 42 | struct value *(*value) (struct frame_info * frame); |
| 43 | }; |
| 44 | |
| 45 | static struct builtin_reg *builtin_regs; |
| 46 | int nr_builtin_regs; |
| 47 | |
| 48 | void |
| 49 | add_builtin_reg (const char *name, struct value *(*value) (struct frame_info * frame)) |
| 50 | { |
| 51 | nr_builtin_regs++; |
| 52 | builtin_regs = xrealloc (builtin_regs, |
| 53 | nr_builtin_regs * sizeof (builtin_regs[0])); |
| 54 | builtin_regs[nr_builtin_regs - 1].name = name; |
| 55 | builtin_regs[nr_builtin_regs - 1].value = value; |
| 56 | } |
| 57 | |
| 58 | int |
| 59 | builtin_reg_map_name_to_regnum (const char *name, int len) |
| 60 | { |
| 61 | int reg; |
| 62 | for (reg = 0; reg < nr_builtin_regs; reg++) |
| 63 | { |
| 64 | if (len == strlen (builtin_regs[reg].name) |
| 65 | && strncmp (builtin_regs[reg].name, name, len) == 0) |
| 66 | return NUM_REGS + NUM_PSEUDO_REGS + reg; |
| 67 | } |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | struct value * |
| 72 | value_of_builtin_reg (int regnum, struct frame_info *frame) |
| 73 | { |
| 74 | int reg = regnum - (NUM_REGS + NUM_PSEUDO_REGS); |
| 75 | gdb_assert (reg >= 0 && reg < nr_builtin_regs); |
| 76 | return builtin_regs[reg].value (frame); |
| 77 | } |