* alpha-linux-tdep.c: Include "gdb_string.h", "regset.h",
[external/binutils.git] / gdb / alpha-linux-nat.c
1 /* Low level Alpha GNU/Linux interface, for GDB when running native.
2    Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.  */
20
21 #include "defs.h"
22 #include "target.h"
23 #include "linux-nat.h"
24
25 #include "alpha-tdep.h"
26
27 #include <sys/ptrace.h>
28 #include <alpha/ptrace.h>
29
30 #include <sys/procfs.h>
31 #include "gregset.h"
32
33 /* Given a pointer to either a gregset_t or fpregset_t, return a
34    pointer to the first register.  */
35 #define ALPHA_REGSET_BASE(regsetp)  ((long *) (regsetp))
36
37 /* Given a pointer to a gregset_t, locate the UNIQUE value.  */
38 #define ALPHA_REGSET_UNIQUE(regsetp)  ((long *)(regsetp) + 32)
39
40 /* The address of UNIQUE for ptrace.  */
41 #define ALPHA_UNIQUE_PTRACE_ADDR 65
42
43
44 /*
45  * See the comment in m68k-tdep.c regarding the utility of these functions.
46  */
47
48 void
49 supply_gregset (gdb_gregset_t *gregsetp)
50 {
51   long *regp = ALPHA_REGSET_BASE (gregsetp);
52   void *unique = ALPHA_REGSET_UNIQUE (gregsetp);
53
54   /* PC is in slot 32.  */
55   alpha_supply_int_regs (-1, regp, regp + 31, unique);
56 }
57
58 void
59 fill_gregset (gdb_gregset_t *gregsetp, int regno)
60 {
61   long *regp = ALPHA_REGSET_BASE (gregsetp);
62   void *unique = ALPHA_REGSET_UNIQUE (gregsetp);
63
64   /* PC is in slot 32.  */
65   alpha_fill_int_regs (regno, regp, regp + 31, unique);
66 }
67
68 /*
69  * Now we do the same thing for floating-point registers.
70  * Again, see the comments in m68k-tdep.c.
71  */
72
73 void
74 supply_fpregset (gdb_fpregset_t *fpregsetp)
75 {
76   long *regp = ALPHA_REGSET_BASE (fpregsetp);
77
78   /* FPCR is in slot 32.  */
79   alpha_supply_fp_regs (-1, regp, regp + 31);
80 }
81
82 void
83 fill_fpregset (gdb_fpregset_t *fpregsetp, int regno)
84 {
85   long *regp = ALPHA_REGSET_BASE (fpregsetp);
86
87   /* FPCR is in slot 32.  */
88   alpha_fill_fp_regs (regno, regp, regp + 31);
89 }
90
91
92 static CORE_ADDR
93 alpha_linux_register_u_offset (int regno)
94 {
95   if (regno == PC_REGNUM)
96     return PC;
97   if (regno == ALPHA_UNIQUE_REGNUM)
98     return ALPHA_UNIQUE_PTRACE_ADDR;
99   if (regno < FP0_REGNUM)
100     return GPR_BASE + regno;
101   else
102     return FPR_BASE + regno - FP0_REGNUM;
103 }
104
105 void _initialialize_alpha_linux_nat (void);
106
107 void
108 _initialize_alpha_linux_nat (void)
109 {
110   linux_nat_add_target (linux_trad_target (alpha_linux_register_u_offset));
111 }