]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/sparcnbsd-nat.c
* elf-bfd.h (struct elf_link_hash_entry): Remove linker_section_pointer
[thirdparty/binutils-gdb.git] / gdb / sparcnbsd-nat.c
CommitLineData
9ce5c36a
JT
1/* Native-dependent code for SPARC systems running NetBSD.
2 Copyright 2002 Free Software Foundation, Inc.
3 Contributed by Wasabi Systems, Inc.
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,
20 Boston, MA 02111-1307, USA. */
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
25
26#include "sparcnbsd-tdep.h"
27
28#include <sys/types.h>
29#include <sys/ptrace.h>
30#include <machine/reg.h>
31
32/* NOTE: We don't bother with any of the deferred_store nonsense; it
33 makes things a lot more complicated than they need to be. */
34
35/* Determine if PT_GETREGS fetches this register. */
36static int
37getregs_supplies (int regno)
38{
39 return (regno == PS_REGNUM
40 || regno == PC_REGNUM
41 || regno == NPC_REGNUM
42 || regno == Y_REGNUM
43 || (regno >= G0_REGNUM && regno <= G7_REGNUM)
44 || (regno >= O0_REGNUM && regno <= O7_REGNUM)
45 /* stack regs (handled by sparcnbsd_supply_reg) */
46 || (regno >= L0_REGNUM && regno <= I7_REGNUM));
47}
48
49/* Determine if PT_GETFPREGS fetches this register. */
50static int
51getfpregs_supplies (int regno)
52{
53 return ((regno >= FP0_REGNUM && regno <= (FP0_REGNUM + 31))
54 || regno == FPS_REGNUM);
55}
56
57void
58fetch_inferior_registers (int regno)
59{
60 /* We don't use deferred stores. */
61 if (deferred_stores)
62 internal_error (__FILE__, __LINE__,
63 "fetch_inferior_registers: deferred stores pending");
64
65 if (regno == -1 || getregs_supplies (regno))
66 {
67 struct reg regs;
68
69 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
70 (PTRACE_ARG3_TYPE) &regs, 0) == -1)
71 perror_with_name ("Couldn't get registers");
72
73 sparcnbsd_supply_reg32 ((char *) &regs, regno);
74 if (regno != -1)
75 return;
76 }
77
78 if (regno == -1 || getfpregs_supplies (regno))
79 {
80 struct fpreg fpregs;
81
82 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
83 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
84 perror_with_name ("Couldn't get floating point registers");
85
86 sparcnbsd_supply_fpreg32 ((char *) &fpregs, regno);
87 if (regno != -1)
88 return;
89 }
90}
91
92void
93store_inferior_registers (int regno)
94{
95 /* We don't use deferred stores. */
96 if (deferred_stores)
97 internal_error (__FILE__, __LINE__,
98 "store_inferior_registers: deferred stores pending");
99
100 if (regno == -1 || getregs_supplies (regno))
101 {
102 struct reg regs;
103
104 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
105 (PTRACE_ARG3_TYPE) &regs, 0) == -1)
106 perror_with_name ("Couldn't get registers");
107
108 sparcnbsd_fill_reg32 ((char *) &regs, regno);
109
110 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
111 (PTRACE_ARG3_TYPE) &regs, 0) == -1)
112 perror_with_name ("Couldn't write registers");
113
114 /* Deal with the stack regs. */
115 if (regno == -1 || regno == SP_REGNUM
116 || (regno >= L0_REGNUM && regno <= I7_REGNUM))
117 {
118 CORE_ADDR sp = read_register (SP_REGNUM);
119 int i;
120 char buf[4];
121
122 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
123 {
124 if (regno == -1 || regno == SP_REGNUM || regno == i)
125 {
126 regcache_collect (i, buf);
127 target_write_memory (sp + ((i - L0_REGNUM) * 4),
128 buf, sizeof (buf));
129 }
130 }
131 }
132
133 if (regno != -1)
134 return;
135 }
136
137 if (regno == -1 || getfpregs_supplies (regno))
138 {
139 struct fpreg fpregs;
140
141 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
142 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
143 perror_with_name ("Couldn't get floating point registers");
144
145 sparcnbsd_fill_fpreg32 ((char *) &fpregs, regno);
146
147 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
148 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
149 perror_with_name ("Couldn't write floating point registers");
150
151 if (regno != -1)
152 return;
153 }
154}