]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/std-regs.c
Switch the license of all .c files to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / std-regs.c
CommitLineData
0406ec40
AC
1/* Builtin frame register, for GDB, the GNU debugger.
2
6aba47ca 3 Copyright (C) 2002, 2005, 2007 Free Software Foundation, Inc.
0406ec40
AC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
0406ec40
AC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0406ec40
AC
21
22#include "defs.h"
eb8bc282 23#include "user-regs.h"
0406ec40
AC
24#include "frame.h"
25#include "gdbtypes.h"
26#include "value.h"
b66d6d2e 27#include "gdb_string.h"
0406ec40 28
0406ec40
AC
29
30static struct value *
123dc839 31value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
0406ec40 32{
064f5156 33 if (gdbarch_deprecated_fp_regnum (current_gdbarch) >= 0)
0ba6dca9
AC
34 /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
35 register name table overrides this built-in $fp register, there
064f5156 36 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
0ba6dca9
AC
37 An architecture wanting to implement "$fp" as alias for a raw
38 register can do so by adding "fp" to register name table (mind
39 you, doing this is probably a dangerous thing). */
064f5156
UW
40 return value_of_register (gdbarch_deprecated_fp_regnum (current_gdbarch),
41 frame);
0ba6dca9
AC
42 else
43 {
44 struct value *val = allocate_value (builtin_type_void_data_ptr);
10c42a71 45 gdb_byte *buf = value_contents_raw (val);
0ba6dca9 46 if (frame == NULL)
170cd118 47 memset (buf, 0, TYPE_LENGTH (value_type (val)));
0ba6dca9 48 else
76e71323
UW
49 gdbarch_address_to_pointer (current_gdbarch, builtin_type_void_data_ptr,
50 buf, get_frame_base_address (frame));
0ba6dca9
AC
51 return val;
52 }
0406ec40
AC
53}
54
55static struct value *
123dc839 56value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
0406ec40 57{
3e8c568d
UW
58 if (gdbarch_pc_regnum (current_gdbarch) >= 0)
59 return value_of_register (gdbarch_pc_regnum (current_gdbarch), frame);
82de1e5b
AC
60 else
61 {
62 struct value *val = allocate_value (builtin_type_void_data_ptr);
10c42a71 63 gdb_byte *buf = value_contents_raw (val);
82de1e5b 64 if (frame == NULL)
170cd118 65 memset (buf, 0, TYPE_LENGTH (value_type (val)));
82de1e5b 66 else
76e71323
UW
67 gdbarch_address_to_pointer (current_gdbarch, builtin_type_void_data_ptr,
68 buf, get_frame_pc (frame));
82de1e5b
AC
69 return val;
70 }
0406ec40
AC
71}
72
73static struct value *
123dc839 74value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
0406ec40 75{
3e8c568d
UW
76 if (gdbarch_sp_regnum (current_gdbarch) >= 0)
77 return value_of_register (gdbarch_sp_regnum (current_gdbarch), frame);
8a3fe4f8 78 error (_("Standard register ``$sp'' is not available for this target"));
0406ec40
AC
79}
80
81static struct value *
123dc839 82value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
0406ec40 83{
3e8c568d
UW
84 if (gdbarch_ps_regnum (current_gdbarch) >= 0)
85 return value_of_register (gdbarch_ps_regnum (current_gdbarch), frame);
8a3fe4f8 86 error (_("Standard register ``$ps'' is not available for this target"));
0406ec40
AC
87}
88
b9362cc7
AC
89extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
90
0406ec40
AC
91void
92_initialize_frame_reg (void)
93{
0406ec40
AC
94 /* Frame based $fp, $pc, $sp and $ps. These only come into play
95 when the target does not define its own version of these
96 registers. */
123dc839
DJ
97 user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
98 user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
99 user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
100 user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
0406ec40 101}