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)
39 INLINE_SIM_CORE(unsigned_N)
40 sim_core_read_aligned_N(sim_cpu *cpu,
45 sim_cpu_core *cpu_core = CPU_CORE (cpu);
46 sim_core *core = &cpu_core->common;
48 sim_core_mapping *mapping;
51 addr = xaddr ^ cpu_core->xor[(sizeof(unsigned_N) - 1) % WITH_XOR_ENDIAN];
54 mapping = sim_core_find_mapping (core, map,
58 1 /*abort*/, cpu, cia);
60 if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
62 if (device_io_read_buffer (mapping->device,
66 sizeof (unsigned_N)) != sizeof (unsigned_N))
67 device_error (mapping->device, "internal error - %s - io_read_buffer should not fail",
68 XSTRING (sim_core_read_aligned_N));
73 val = T2H_N (*(unsigned_N*) sim_core_translate (mapping, addr));
74 if (TRACE_P (cpu, TRACE_CORE_IDX))
75 trace_printf (CPU_STATE (cpu), cpu,
76 "sim-n-core.c:%d: read-%d %s:0x%08lx -> 0x%lx\n",
79 sim_core_map_to_str (map),
86 INLINE_SIM_CORE(unsigned_N)
87 sim_core_read_unaligned_N(sim_cpu *cpu,
92 int alignment = sizeof (unsigned_N) - 1;
93 /* if hardwired to forced alignment just do it */
94 if (WITH_ALIGNMENT == FORCED_ALIGNMENT)
95 return sim_core_read_aligned_N (cpu, cia, map, addr & ~alignment);
96 else if ((addr & alignment) == 0)
97 return sim_core_read_aligned_N (cpu, cia, map, addr);
99 switch (CURRENT_ALIGNMENT)
101 case STRICT_ALIGNMENT:
102 SIM_CORE_SIGNAL (CPU_STATE (cpu), cpu, cia, map,
103 sizeof (unsigned_N), addr,
104 read_transfer, sim_core_unaligned_signal);
106 case NONSTRICT_ALIGNMENT:
109 if (sim_core_read_buffer (CPU_STATE (cpu), map, &val, addr,
111 != sizeof(unsigned_N))
112 SIM_CORE_SIGNAL (CPU_STATE (cpu), cpu, cia, map,
113 sizeof (unsigned_N), addr,
114 read_transfer, sim_core_unaligned_signal);
118 case FORCED_ALIGNMENT:
119 return sim_core_read_aligned_N (cpu, cia, map, addr & ~alignment);
120 case MIXED_ALIGNMENT:
121 sim_engine_abort (CPU_STATE (cpu), cpu, cia,
122 "internal error - %s - mixed alignment",
123 XSTRING (sim_core_read_unaligned_N));
126 sim_engine_abort (CPU_STATE (cpu), cpu, cia,
127 "internal error - %s - bad switch",
128 XSTRING (sim_core_read_unaligned_N));
134 INLINE_SIM_CORE(void)
135 sim_core_write_aligned_N(sim_cpu *cpu,
141 sim_cpu_core *cpu_core = CPU_CORE (cpu);
142 sim_core *core = &cpu_core->common;
143 sim_core_mapping *mapping;
146 addr = xaddr ^ cpu_core->xor[(sizeof(unsigned_N) - 1) % WITH_XOR_ENDIAN];
149 mapping = sim_core_find_mapping(core, map,
153 1 /*abort*/, cpu, cia);
155 if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
156 unsigned_N data = H2T_N (val);
157 if (device_io_write_buffer (mapping->device,
161 sizeof (unsigned_N), /* nr_bytes */
163 cia) != sizeof (unsigned_N))
164 device_error (mapping->device, "internal error - %s - io_write_buffer should not fail",
165 XSTRING (sim_core_write_aligned_N));
169 *(unsigned_N*) sim_core_translate (mapping, addr) = H2T_N (val);
170 if (TRACE_P (cpu, TRACE_CORE_IDX))
171 trace_printf (CPU_STATE (cpu), cpu,
172 "sim-n-core.c:%d: write-%d %s:0x%08lx <- 0x%lx\n",
175 sim_core_map_to_str (map),
176 (unsigned long) addr,
177 (unsigned long) val);
181 INLINE_SIM_CORE(void)
182 sim_core_write_unaligned_N(sim_cpu *cpu,
188 int alignment = sizeof (unsigned_N) - 1;
189 /* if hardwired to forced alignment just do it */
190 if (WITH_ALIGNMENT == FORCED_ALIGNMENT)
191 sim_core_write_aligned_N (cpu, cia, map, addr & ~alignment, val);
192 else if ((addr & alignment) == 0)
193 sim_core_write_aligned_N (cpu, cia, map, addr, val);
195 switch (CURRENT_ALIGNMENT)
197 case STRICT_ALIGNMENT:
198 SIM_CORE_SIGNAL (CPU_STATE (cpu), cpu, cia, map,
199 sizeof (unsigned_N), addr,
200 write_transfer, sim_core_unaligned_signal);
202 case NONSTRICT_ALIGNMENT:
205 if (sim_core_write_buffer (CPU_STATE (cpu), map, &val, addr,
207 != sizeof(unsigned_N))
208 SIM_CORE_SIGNAL (CPU_STATE (cpu), cpu, cia, map,
209 sizeof (unsigned_N), addr,
210 write_transfer, sim_core_unaligned_signal);
213 case FORCED_ALIGNMENT:
214 sim_core_write_aligned_N (cpu, cia, map, addr & ~alignment, val);
215 case MIXED_ALIGNMENT:
216 sim_engine_abort (CPU_STATE (cpu), cpu, cia,
217 "internal error - %s - mixed alignment",
218 XSTRING (sim_core_write_unaligned_N));
221 sim_engine_abort (CPU_STATE (cpu), cpu, cia,
222 "internal error - %s - bad switch",
223 XSTRING (sim_core_write_unaligned_N));
229 /* NOTE: see start of file for #define of these macros */
233 #undef sim_core_read_aligned_N
234 #undef sim_core_write_aligned_N
235 #undef sim_core_read_unaligned_N
236 #undef sim_core_write_unaligned_N