2001-12-17 Fernando Nasser <fnasser@redhat.com>
[deliverable/binutils-gdb.git] / gdb / ppc-linux-nat.c
CommitLineData
c877c8e6 1/* PPC linux native support.
b6ba6518
KB
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001
3 Free Software Foundation, Inc.
c877c8e6
KB
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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "frame.h"
23#include "inferior.h"
24#include "gdbcore.h"
4e052eda 25#include "regcache.h"
c877c8e6
KB
26
27#include <sys/types.h>
28#include <sys/param.h>
29#include <signal.h>
30#include <sys/user.h>
31#include <sys/ioctl.h>
32#include <sys/wait.h>
33#include <fcntl.h>
34#include <sys/procfs.h>
35
c60c0f5f
MS
36/* Prototypes for supply_gregset etc. */
37#include "gregset.h"
16333c4f 38#include "ppc-tdep.h"
c60c0f5f 39
c877c8e6 40int
fba45db2 41kernel_u_size (void)
c877c8e6
KB
42{
43 return (sizeof (struct user));
44}
45
16333c4f
EZ
46/* *INDENT-OFF* */
47/* registers layout, as presented by the ptrace interface:
48PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
49PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
50PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
51PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
52PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
53PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
54PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
55PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
56PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
57/* *INDENT_ON * */
c877c8e6
KB
58
59int
16333c4f 60ppc_register_u_addr (int ustart, int regno)
c877c8e6 61{
16333c4f
EZ
62 int u_addr = -1;
63
64 /* General purpose registers occupy 1 slot each in the buffer */
2188cbdd
EZ
65 if (regno >= gdbarch_tdep (current_gdbarch)->ppc_gp0_regnum
66 && regno <= gdbarch_tdep (current_gdbarch)->ppc_gplast_regnum )
16333c4f
EZ
67 u_addr = (ustart + (PT_R0 + regno) * 4);
68
69 /* Floating point regs: 2 slots each */
70 if (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM)
71 u_addr = (ustart + (PT_FPR0 + (regno - FP0_REGNUM) * 2) * 4);
72
73 /* UISA special purpose registers: 1 slot each */
74 if (regno == PC_REGNUM)
75 u_addr = ustart + PT_NIP * 4;
2188cbdd 76 if (regno == gdbarch_tdep (current_gdbarch)->ppc_lr_regnum)
16333c4f 77 u_addr = ustart + PT_LNK * 4;
2188cbdd 78 if (regno == gdbarch_tdep (current_gdbarch)->ppc_cr_regnum)
16333c4f 79 u_addr = ustart + PT_CCR * 4;
2188cbdd 80 if (regno == gdbarch_tdep (current_gdbarch)->ppc_xer_regnum)
16333c4f 81 u_addr = ustart + PT_XER * 4;
2188cbdd 82 if (regno == gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum)
16333c4f 83 u_addr = ustart + PT_CTR * 4;
2188cbdd 84 if (regno == gdbarch_tdep (current_gdbarch)->ppc_mq_regnum)
16333c4f 85 u_addr = ustart + PT_MQ * 4;
2188cbdd 86 if (regno == gdbarch_tdep (current_gdbarch)->ppc_ps_regnum)
16333c4f
EZ
87 u_addr = ustart + PT_MSR * 4;
88
89 return u_addr;
c877c8e6
KB
90}
91
50c9bd31 92void
8ae45c11 93supply_gregset (gdb_gregset_t *gregsetp)
c877c8e6
KB
94{
95 int regi;
2ac44c70 96 register elf_greg_t *regp = (elf_greg_t *) gregsetp;
c877c8e6
KB
97
98 for (regi = 0; regi < 32; regi++)
99 supply_register (regi, (char *) (regp + regi));
100
16333c4f 101 supply_register (PC_REGNUM, (char *) (regp + PT_NIP));
2188cbdd
EZ
102 supply_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum,
103 (char *) (regp + PT_LNK));
104 supply_register (gdbarch_tdep (current_gdbarch)->ppc_cr_regnum,
105 (char *) (regp + PT_CCR));
106 supply_register (gdbarch_tdep (current_gdbarch)->ppc_xer_regnum,
107 (char *) (regp + PT_XER));
108 supply_register (gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum,
109 (char *) (regp + PT_CTR));
110 supply_register (gdbarch_tdep (current_gdbarch)->ppc_mq_regnum,
111 (char *) (regp + PT_MQ));
112 supply_register (gdbarch_tdep (current_gdbarch)->ppc_ps_regnum,
113 (char *) (regp + PT_MSR));
114
c877c8e6
KB
115}
116
fdb28ac4 117void
8ae45c11 118fill_gregset (gdb_gregset_t *gregsetp, int regno)
fdb28ac4
KB
119{
120 int regi;
2ac44c70 121 elf_greg_t *regp = (elf_greg_t *) gregsetp;
fdb28ac4 122
fdb28ac4
KB
123 for (regi = 0; regi < 32; regi++)
124 {
16333c4f
EZ
125 if ((regno == -1) || regno == regi)
126 regcache_collect (regi, regp + PT_R0 + regi);
fdb28ac4
KB
127 }
128
16333c4f
EZ
129 if ((regno == -1) || regno == PC_REGNUM)
130 regcache_collect (PC_REGNUM, regp + PT_NIP);
2188cbdd
EZ
131 if ((regno == -1)
132 || regno == gdbarch_tdep (current_gdbarch)->ppc_lr_regnum)
133 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum,
134 regp + PT_LNK);
135 if ((regno == -1)
136 || regno == gdbarch_tdep (current_gdbarch)->ppc_cr_regnum)
137 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_cr_regnum,
138 regp + PT_CCR);
139 if ((regno == -1)
140 || regno == gdbarch_tdep (current_gdbarch)->ppc_xer_regnum)
141 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_xer_regnum,
142 regp + PT_XER);
143 if ((regno == -1)
144 || regno == gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum)
145 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_ctr_regnum,
146 regp + PT_CTR);
147 if ((regno == -1)
148 || regno == gdbarch_tdep (current_gdbarch)->ppc_mq_regnum)
149 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_mq_regnum,
150 regp + PT_MQ);
151 if ((regno == -1)
152 || regno == gdbarch_tdep (current_gdbarch)->ppc_ps_regnum)
153 regcache_collect (gdbarch_tdep (current_gdbarch)->ppc_ps_regnum,
154 regp + PT_MSR);
fdb28ac4
KB
155}
156
50c9bd31 157void
8ae45c11 158supply_fpregset (gdb_fpregset_t * fpregsetp)
c877c8e6
KB
159{
160 int regi;
161 for (regi = 0; regi < 32; regi++)
162 {
163 supply_register (FP0_REGNUM + regi, (char *) (*fpregsetp + regi));
164 }
165}
fdb28ac4
KB
166
167/* Given a pointer to a floating point register set in /proc format
168 (fpregset_t *), update the register specified by REGNO from gdb's idea
169 of the current floating point register set. If REGNO is -1, update
170 them all. */
171
172void
8ae45c11 173fill_fpregset (gdb_fpregset_t *fpregsetp, int regno)
fdb28ac4
KB
174{
175 int regi;
fdb28ac4
KB
176
177 for (regi = 0; regi < 32; regi++)
178 {
179 if ((regno == -1) || (regno == FP0_REGNUM + regi))
f00d3753 180 regcache_collect (FP0_REGNUM + regi, (char *) (*fpregsetp + regi));
fdb28ac4
KB
181 }
182}
This page took 0.140888 seconds and 4 git commands to generate.