Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / sim / common / cgen-mem.h
CommitLineData
c906108c 1/* Memory ops header for CGEN-based simulators.
88b9d363 2 Copyright (C) 1996-2022 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Solutions.
4
5This file is part of the GNU Simulators.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#ifndef CGEN_MEM_H
21#define CGEN_MEM_H
22
5a394431 23/* TODO: This should get moved into sim-inline.h. */
c906108c
SS
24#ifdef MEMOPS_DEFINE_INLINE
25#define MEMOPS_INLINE
26#else
5a394431 27#define MEMOPS_INLINE EXTERN_INLINE
c906108c
SS
28#endif
29
43ff13b4
JM
30/* Integer memory read support.
31
32 There is no floating point support. In this context there are no
33 floating point modes, only floating point operations (whose arguments
34 and results are arrays of bits that we treat as integer modes). */
c906108c 35
2d922d86
MF
36#define DECLARE_GETMEM_EXTERN(mode, size) \
37extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR);
38
c906108c
SS
39#if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
40#define DECLARE_GETMEM(mode, size) \
2d922d86 41DECLARE_GETMEM_EXTERN (mode, size) \
c906108c
SS
42MEMOPS_INLINE mode \
43XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \
44{ \
45 PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode)); \
46 /* Don't read anything into "unaligned" here. Bad name choice. */\
47 return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \
48}
49#else
2d922d86 50#define DECLARE_GETMEM(mode, size) DECLARE_GETMEM_EXTERN (mode, size)
c906108c
SS
51#endif
52
adf40b2e
JM
53DECLARE_GETMEM (QI, 1) /* TAGS: GETMEMQI */
54DECLARE_GETMEM (UQI, 1) /* TAGS: GETMEMUQI */
55DECLARE_GETMEM (HI, 2) /* TAGS: GETMEMHI */
56DECLARE_GETMEM (UHI, 2) /* TAGS: GETMEMUHI */
57DECLARE_GETMEM (SI, 4) /* TAGS: GETMEMSI */
58DECLARE_GETMEM (USI, 4) /* TAGS: GETMEMUSI */
59DECLARE_GETMEM (DI, 8) /* TAGS: GETMEMDI */
60DECLARE_GETMEM (UDI, 8) /* TAGS: GETMEMUDI */
c906108c 61
c906108c 62#undef DECLARE_GETMEM
2d922d86 63#undef DECLARE_GETMEM_EXTERN
c906108c 64\f
43ff13b4 65/* Integer memory write support. */
c906108c 66
2d922d86
MF
67#define DECLARE_SETMEM_EXTERN(mode, size) \
68extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode);
69
c906108c
SS
70#if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
71#define DECLARE_SETMEM(mode, size) \
2d922d86 72DECLARE_SETMEM_EXTERN (mode, size) \
c906108c
SS
73MEMOPS_INLINE void \
74XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \
75{ \
76 PROFILE_COUNT_WRITE (cpu, a, XCONCAT2 (MODE_,mode)); \
77 /* Don't read anything into "unaligned" here. Bad name choice. */ \
78 XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \
79}
80#else
2d922d86 81#define DECLARE_SETMEM(mode, size) DECLARE_SETMEM_EXTERN (mode, size)
c906108c
SS
82#endif
83
adf40b2e
JM
84DECLARE_SETMEM (QI, 1) /* TAGS: SETMEMQI */
85DECLARE_SETMEM (UQI, 1) /* TAGS: SETMEMUQI */
86DECLARE_SETMEM (HI, 2) /* TAGS: SETMEMHI */
87DECLARE_SETMEM (UHI, 2) /* TAGS: SETMEMUHI */
88DECLARE_SETMEM (SI, 4) /* TAGS: SETMEMSI */
89DECLARE_SETMEM (USI, 4) /* TAGS: SETMEMUSI */
90DECLARE_SETMEM (DI, 8) /* TAGS: SETMEMDI */
91DECLARE_SETMEM (UDI, 8) /* TAGS: SETMEMUDI */
c906108c 92
c906108c 93#undef DECLARE_SETMEM
2d922d86 94#undef DECLARE_SETMEM_EXTERN
c906108c
SS
95\f
96/* Instruction read support. */
97
2d922d86
MF
98#define DECLARE_GETIMEM_EXTERN(mode, size) \
99extern mode XCONCAT2 (GETIMEM,mode) (SIM_CPU *, ADDR);
100
c906108c
SS
101#if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
102#define DECLARE_GETIMEM(mode, size) \
2d922d86 103DECLARE_GETIMEM_EXTERN (mode, size) \
c906108c
SS
104MEMOPS_INLINE mode \
105XCONCAT2 (GETIMEM,mode) (SIM_CPU *cpu, IADDR a) \
106{ \
107 /*PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode));*/ \
108 /* Don't read anything into "unaligned" here. Bad name choice. */\
109 return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, a, exec_map, a); \
110}
111#else
2d922d86 112#define DECLARE_GETIMEM(mode, size) DECLARE_GETIMEM_EXTERN (mode, size)
c906108c
SS
113#endif
114
adf40b2e
JM
115DECLARE_GETIMEM (UQI, 1) /* TAGS: GETIMEMUQI */
116DECLARE_GETIMEM (UHI, 2) /* TAGS: GETIMEMUHI */
117DECLARE_GETIMEM (USI, 4) /* TAGS: GETIMEMUSI */
118DECLARE_GETIMEM (UDI, 8) /* TAGS: GETIMEMUDI */
c906108c
SS
119
120#undef DECLARE_GETIMEM
2d922d86 121#undef DECLARE_GETIMEM_EXTERN
c906108c 122\f
43ff13b4
JM
123/* Floating point support.
124
125 ??? One can specify that the integer memory ops should be used instead,
126 and treat fp values as just a series of bits. One might even bubble
127 that notion up into the description language. However, that departs from
128 gcc. One could cross over from gcc's notion and a "series of bits" notion
129 between there and here, and thus still not require these routines. However,
130 that's a complication of its own (not that having these fns isn't).
131 But for now, we do things this way. */
132
2d922d86
MF
133#define DECLARE_GETMEM_EXTERN(mode, size) \
134extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR);
135
43ff13b4
JM
136#if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
137#define DECLARE_GETMEM(mode, size) \
2d922d86 138DECLARE_GETMEM_EXTERN (mode, size) \
43ff13b4
JM
139MEMOPS_INLINE mode \
140XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \
141{ \
142 PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode)); \
143 /* Don't read anything into "unaligned" here. Bad name choice. */\
144 return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \
145}
146#else
2d922d86 147#define DECLARE_GETMEM(mode, size) DECLARE_GETMEM_EXTERN (mode, size)
43ff13b4
JM
148#endif
149
adf40b2e
JM
150DECLARE_GETMEM (SF, 4) /* TAGS: GETMEMSF */
151DECLARE_GETMEM (DF, 8) /* TAGS: GETMEMDF */
43ff13b4
JM
152
153#undef DECLARE_GETMEM
2d922d86
MF
154#undef DECLARE_GETMEM_EXTERN
155
156#define DECLARE_SETMEM_EXTERN(mode, size) \
157extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode);
43ff13b4
JM
158
159#if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
160#define DECLARE_SETMEM(mode, size) \
2d922d86 161DECLARE_SETMEM_EXTERN (mode, size) \
43ff13b4
JM
162MEMOPS_INLINE void \
163XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \
164{ \
165 PROFILE_COUNT_WRITE (cpu, a, XCONCAT2 (MODE_,mode)); \
166 /* Don't read anything into "unaligned" here. Bad name choice. */ \
167 XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \
168}
169#else
2d922d86 170#define DECLARE_SETMEM(mode, size) DECLARE_SETMEM_EXTERN (mode, size
43ff13b4
JM
171#endif
172
adf40b2e
JM
173DECLARE_SETMEM (SF, 4) /* TAGS: SETMEMSF */
174DECLARE_SETMEM (DF, 8) /* TAGS: SETMEMDF */
43ff13b4
JM
175
176#undef DECLARE_SETMEM
2d922d86 177#undef DECLARE_SETMEM_EXTERN
43ff13b4 178\f
c906108c
SS
179/* GETT<mode>: translate target value at P to host value.
180 This needn't be very efficient (i.e. can call memcpy) as this is
181 only used when interfacing with the outside world (e.g. gdb). */
182
2d922d86
MF
183#define DECLARE_GETT_EXTERN(mode, size) \
184extern mode XCONCAT2 (GETT,mode) (unsigned char *);
185
ca25db52 186#if defined (MEMOPS_DEFINE_INLINE)
c906108c 187#define DECLARE_GETT(mode, size) \
2d922d86 188DECLARE_GETT_EXTERN (mode, size) \
ca25db52 189mode \
c906108c
SS
190XCONCAT2 (GETT,mode) (unsigned char *p) \
191{ \
192 mode tmp; \
193 memcpy (&tmp, p, sizeof (mode)); \
194 return XCONCAT2 (T2H_,size) (tmp); \
195}
196#else
2d922d86 197#define DECLARE_GETT(mode, size) DECLARE_GETT_EXTERN (mode, size)
c906108c
SS
198#endif
199
adf40b2e
JM
200DECLARE_GETT (QI, 1) /* TAGS: GETTQI */
201DECLARE_GETT (UQI, 1) /* TAGS: GETTUQI */
202DECLARE_GETT (HI, 2) /* TAGS: GETTHI */
203DECLARE_GETT (UHI, 2) /* TAGS: GETTUHI */
204DECLARE_GETT (SI, 4) /* TAGS: GETTSI */
205DECLARE_GETT (USI, 4) /* TAGS: GETTUSI */
206DECLARE_GETT (DI, 8) /* TAGS: GETTDI */
207DECLARE_GETT (UDI, 8) /* TAGS: GETTUDI */
208
209#if 0 /* ??? defered until necessary */
210DECLARE_GETT (SF, 4) /* TAGS: GETTSF */
211DECLARE_GETT (DF, 8) /* TAGS: GETTDF */
212DECLARE_GETT (TF, 16) /* TAGS: GETTTF */
213#endif
c906108c
SS
214
215#undef DECLARE_GETT
2d922d86 216#undef DECLARE_GETT_EXTERN
c906108c
SS
217\f
218/* SETT<mode>: translate host value to target value and store at P.
219 This needn't be very efficient (i.e. can call memcpy) as this is
220 only used when interfacing with the outside world (e.g. gdb). */
221
2d922d86
MF
222#define DECLARE_SETT_EXTERN(mode, size) \
223extern void XCONCAT2 (SETT,mode) (unsigned char *, mode);
224
ca25db52 225#if defined (MEMOPS_DEFINE_INLINE)
c906108c 226#define DECLARE_SETT(mode, size) \
2d922d86 227DECLARE_SETT_EXTERN (mode, size) \
ca25db52 228void \
c906108c
SS
229XCONCAT2 (SETT,mode) (unsigned char *buf, mode val) \
230{ \
231 mode tmp; \
232 tmp = XCONCAT2 (H2T_,size) (val); \
233 memcpy (buf, &tmp, sizeof (mode)); \
234}
235#else
2d922d86 236#define DECLARE_SETT(mode, size) DECLARE_SETT_EXTERN (mode, size)
c906108c
SS
237#endif
238
adf40b2e
JM
239DECLARE_SETT (QI, 1) /* TAGS: SETTQI */
240DECLARE_SETT (UQI, 1) /* TAGS: SETTUQI */
241DECLARE_SETT (HI, 2) /* TAGS: SETTHI */
242DECLARE_SETT (UHI, 2) /* TAGS: SETTUHI */
243DECLARE_SETT (SI, 4) /* TAGS: SETTSI */
244DECLARE_SETT (USI, 4) /* TAGS: SETTUSI */
245DECLARE_SETT (DI, 8) /* TAGS: SETTDI */
246DECLARE_SETT (UDI, 8) /* TAGS: SETTUDI */
247
248#if 0 /* ??? defered until necessary */
249DECLARE_SETT (SF, 4) /* TAGS: SETTSF */
250DECLARE_SETT (DF, 8) /* TAGS: SETTDF */
251DECLARE_SETT (TF, 16) /* TAGS: SETTTF */
252#endif
c906108c
SS
253
254#undef DECLARE_SETT
2d922d86 255#undef DECLARE_SETT_EXTERN
c906108c
SS
256
257#endif /* CGEN_MEM_H */
This page took 1.002032 seconds and 4 git commands to generate.