1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #error "N must be #defined"
28 /* NOTE: see end of file for #undef of these macros */
29 #define unsigned_N XCONCAT2(unsigned_,N)
30 #define T2H_N XCONCAT2(T2H_,N)
31 #define H2T_N XCONCAT2(H2T_,N)
33 #define sim_core_read_aligned_N XCONCAT2(sim_core_read_aligned_,N)
34 #define sim_core_write_aligned_N XCONCAT2(sim_core_write_aligned_,N)
35 #define sim_core_read_unaligned_N XCONCAT2(sim_core_read_unaligned_,N)
36 #define sim_core_write_unaligned_N XCONCAT2(sim_core_write_unaligned_,N)
38 /* TAGS: sim_core_read_aligned_1 sim_core_read_aligned_2 */
39 /* TAGS: sim_core_read_aligned_4 sim_core_read_aligned_8 */
40 /* TAGS: sim_core_read_aligned_word */
42 INLINE_SIM_CORE(unsigned_N
)
43 sim_core_read_aligned_N(sim_cpu
*cpu
,
48 sim_cpu_core
*cpu_core
= CPU_CORE (cpu
);
49 sim_core_common
*core
= &cpu_core
->common
;
51 sim_core_mapping
*mapping
;
53 #if WITH_XOR_ENDIAN != 0
55 addr
= xaddr
^ cpu_core
->xor[(sizeof(unsigned_N
) - 1) % WITH_XOR_ENDIAN
];
59 mapping
= sim_core_find_mapping (core
, map
,
63 1 /*abort*/, cpu
, cia
);
65 if (WITH_CALLBACK_MEMORY
&& mapping
->device
!= NULL
) {
67 if (device_io_read_buffer (mapping
->device
,
71 sizeof (unsigned_N
)) != sizeof (unsigned_N
))
72 device_error (mapping
->device
, "internal error - %s - io_read_buffer should not fail",
73 XSTRING (sim_core_read_aligned_N
));
78 val
= T2H_N (*(unsigned_N
*) sim_core_translate (mapping
, addr
));
79 PROFILE_COUNT_CORE (cpu
, addr
, sizeof (unsigned_N
), map
);
80 if (TRACE_P (cpu
, TRACE_CORE_IDX
))
81 if (sizeof (unsigned_N
) > 4)
82 trace_printf (CPU_STATE (cpu
), cpu
,
83 "sim-n-core.h:%d: read-%d %s:0x%08lx -> 0x%08lx%08lx\n",
86 sim_core_map_to_str (map
),
88 (unsigned long) (((unsigned64
)(val
)) >> 32),
91 trace_printf (CPU_STATE (cpu
), cpu
,
92 "sim-n-core.h:%d: read-%d %s:0x%08lx -> 0x%0*lx\n",
95 sim_core_map_to_str (map
),
97 sizeof (unsigned_N
) * 2,
102 /* TAGS: sim_core_read_unaligned_1 sim_core_read_unaligned_2 */
103 /* TAGS: sim_core_read_unaligned_4 sim_core_read_unaligned_8 */
104 /* TAGS: sim_core_read_unaligned_word */
106 INLINE_SIM_CORE(unsigned_N
)
107 sim_core_read_unaligned_N(sim_cpu
*cpu
,
112 int alignment
= sizeof (unsigned_N
) - 1;
113 /* if hardwired to forced alignment just do it */
114 if (WITH_ALIGNMENT
== FORCED_ALIGNMENT
)
115 return sim_core_read_aligned_N (cpu
, cia
, map
, addr
& ~alignment
);
116 else if ((addr
& alignment
) == 0)
117 return sim_core_read_aligned_N (cpu
, cia
, map
, addr
);
119 switch (CURRENT_ALIGNMENT
)
121 case STRICT_ALIGNMENT
:
122 SIM_CORE_SIGNAL (CPU_STATE (cpu
), cpu
, cia
, map
,
123 sizeof (unsigned_N
), addr
,
124 read_transfer
, sim_core_unaligned_signal
);
126 case NONSTRICT_ALIGNMENT
:
129 if (sim_core_xor_read_buffer (CPU_STATE (cpu
), cpu
, map
, &val
, addr
,
131 != sizeof(unsigned_N
))
132 SIM_CORE_SIGNAL (CPU_STATE (cpu
), cpu
, cia
, map
,
133 sizeof (unsigned_N
), addr
,
134 read_transfer
, sim_core_unaligned_signal
);
136 PROFILE_COUNT_CORE (cpu
, addr
, sizeof (unsigned_N
), map
);
139 case FORCED_ALIGNMENT
:
140 return sim_core_read_aligned_N (cpu
, cia
, map
, addr
& ~alignment
);
141 case MIXED_ALIGNMENT
:
142 sim_engine_abort (CPU_STATE (cpu
), cpu
, cia
,
143 "internal error - %s - mixed alignment",
144 XSTRING (sim_core_read_unaligned_N
));
147 sim_engine_abort (CPU_STATE (cpu
), cpu
, cia
,
148 "internal error - %s - bad switch",
149 XSTRING (sim_core_read_unaligned_N
));
154 /* TAGS: sim_core_write_aligned_1 sim_core_write_aligned_2 */
155 /* TAGS: sim_core_write_aligned_4 sim_core_write_aligned_8 */
156 /* TAGS: sim_core_write_aligned_word */
158 INLINE_SIM_CORE(void)
159 sim_core_write_aligned_N(sim_cpu
*cpu
,
165 sim_cpu_core
*cpu_core
= CPU_CORE (cpu
);
166 sim_core_common
*core
= &cpu_core
->common
;
167 sim_core_mapping
*mapping
;
169 #if WITH_XOR_ENDIAN != 0
171 addr
= xaddr
^ cpu_core
->xor[(sizeof(unsigned_N
) - 1) % WITH_XOR_ENDIAN
];
175 mapping
= sim_core_find_mapping(core
, map
,
179 1 /*abort*/, cpu
, cia
);
181 if (WITH_CALLBACK_MEMORY
&& mapping
->device
!= NULL
) {
182 unsigned_N data
= H2T_N (val
);
183 if (device_io_write_buffer (mapping
->device
,
187 sizeof (unsigned_N
), /* nr_bytes */
189 cia
) != sizeof (unsigned_N
))
190 device_error (mapping
->device
, "internal error - %s - io_write_buffer should not fail",
191 XSTRING (sim_core_write_aligned_N
));
195 *(unsigned_N
*) sim_core_translate (mapping
, addr
) = H2T_N (val
);
196 PROFILE_COUNT_CORE (cpu
, addr
, sizeof (unsigned_N
), map
);
197 if (TRACE_P (cpu
, TRACE_CORE_IDX
))
198 if (sizeof (unsigned_N
) > 4)
199 trace_printf (CPU_STATE (cpu
), cpu
,
200 "sim-n-core.h:%d: write-%d %s:0x%08lx <- 0x%08lx%08lx\n",
203 sim_core_map_to_str (map
),
204 (unsigned long) addr
,
205 (unsigned long) (((unsigned64
)(val
)) >> 32),
206 (unsigned long) val
);
208 trace_printf (CPU_STATE (cpu
), cpu
,
209 "sim-n-core.h:%d: write-%d %s:0x%08lx <- 0x%0*lx\n",
212 sim_core_map_to_str (map
),
213 (unsigned long) addr
,
214 sizeof (unsigned_N
) * 2,
215 (unsigned long) val
);
218 /* TAGS: sim_core_write_unaligned_1 sim_core_write_unaligned_2 */
219 /* TAGS: sim_core_write_unaligned_4 sim_core_write_unaligned_8 */
220 /* TAGS: sim_core_write_unaligned_word */
222 INLINE_SIM_CORE(void)
223 sim_core_write_unaligned_N(sim_cpu
*cpu
,
229 int alignment
= sizeof (unsigned_N
) - 1;
230 /* if hardwired to forced alignment just do it */
231 if (WITH_ALIGNMENT
== FORCED_ALIGNMENT
)
232 sim_core_write_aligned_N (cpu
, cia
, map
, addr
& ~alignment
, val
);
233 else if ((addr
& alignment
) == 0)
234 sim_core_write_aligned_N (cpu
, cia
, map
, addr
, val
);
236 switch (CURRENT_ALIGNMENT
)
238 case STRICT_ALIGNMENT
:
239 SIM_CORE_SIGNAL (CPU_STATE (cpu
), cpu
, cia
, map
,
240 sizeof (unsigned_N
), addr
,
241 write_transfer
, sim_core_unaligned_signal
);
243 case NONSTRICT_ALIGNMENT
:
245 unsigned_N val
= H2T_N (val
);
246 if (sim_core_xor_write_buffer (CPU_STATE (cpu
), cpu
, map
, &val
, addr
,
248 != sizeof(unsigned_N
))
249 SIM_CORE_SIGNAL (CPU_STATE (cpu
), cpu
, cia
, map
,
250 sizeof (unsigned_N
), addr
,
251 write_transfer
, sim_core_unaligned_signal
);
252 PROFILE_COUNT_CORE (cpu
, addr
, sizeof (unsigned_N
), map
);
255 case FORCED_ALIGNMENT
:
256 sim_core_write_aligned_N (cpu
, cia
, map
, addr
& ~alignment
, val
);
258 case MIXED_ALIGNMENT
:
259 sim_engine_abort (CPU_STATE (cpu
), cpu
, cia
,
260 "internal error - %s - mixed alignment",
261 XSTRING (sim_core_write_unaligned_N
));
264 sim_engine_abort (CPU_STATE (cpu
), cpu
, cia
,
265 "internal error - %s - bad switch",
266 XSTRING (sim_core_write_unaligned_N
));
272 /* NOTE: see start of file for #define of these macros */
276 #undef sim_core_read_aligned_N
277 #undef sim_core_write_aligned_N
278 #undef sim_core_read_unaligned_N
279 #undef sim_core_write_unaligned_N