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,
46 sim_core_mapping *mapping = sim_core_find_mapping (CPU_CORE (cpu), map,
52 if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
54 if (device_io_read_buffer (mapping->device,
58 sizeof (unsigned_N)) != sizeof (unsigned_N))
59 device_error (mapping->device, "internal error - sim_core_read_N() - io_read_buffer should not fail");
64 val = T2H_N (*(unsigned_N*) sim_core_translate (mapping, addr));
65 if (TRACE_P (cpu, TRACE_CORE_IDX))
66 trace_printf (CPU_STATE (cpu), cpu,
67 "sim-n-core.c:%d: read-%d %s:0x%08lx -> 0x%lx\n",
70 sim_core_map_to_str (map),
77 INLINE_SIM_CORE(unsigned_N)
78 sim_core_read_unaligned_N(sim_cpu *cpu,
83 int alignment = sizeof (unsigned_N) - 1;
84 /* if hardwired to forced alignment just do it */
85 if (WITH_ALIGNMENT == FORCED_ALIGNMENT)
86 return sim_core_read_aligned_N (cpu, cia, map, addr & ~alignment);
87 else if ((addr & alignment) == 0)
88 return sim_core_read_aligned_N (cpu, cia, map, addr);
90 switch (CURRENT_ALIGNMENT)
92 case STRICT_ALIGNMENT:
93 /* FIXME - notify abort handler */
94 sim_io_error (CPU_STATE (cpu), "read-%d - misaligned access to 0x%lx",
95 sizeof (unsigned_N), (unsigned long) addr);
97 case NONSTRICT_ALIGNMENT:
100 if (sim_core_read_buffer (CPU_STATE (cpu), map, &val, addr,
102 != sizeof(unsigned_N))
103 sim_io_error(CPU_STATE (cpu), "misaligned %d byte read to 0x%lx failed",
104 sizeof(unsigned_N), (unsigned long) addr);
108 case FORCED_ALIGNMENT:
109 return sim_core_read_aligned_N (cpu, cia, map, addr & ~alignment);
110 case MIXED_ALIGNMENT:
111 sim_io_error (CPU_STATE (cpu), "internal error - sim_core_read_unaligned_N - mixed alignment");
114 sim_io_error (CPU_STATE (cpu), "internal error - sim_core_read_unaligned_N - bad switch");
120 INLINE_SIM_CORE(void)
121 sim_core_write_aligned_N(sim_cpu *cpu,
127 sim_core_mapping *mapping = sim_core_find_mapping(CPU_CORE (cpu), map,
133 if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
134 unsigned_N data = H2T_N (val);
135 if (device_io_write_buffer (mapping->device,
139 sizeof (unsigned_N), /* nr_bytes */
141 cia) != sizeof (unsigned_N))
142 device_error (mapping->device, "internal error - sim_core_write_N() - io_write_buffer should not fail");
146 *(unsigned_N*) sim_core_translate (mapping, addr) = H2T_N (val);
147 if (TRACE_P (cpu, TRACE_CORE_IDX))
148 trace_printf (CPU_STATE (cpu), cpu,
149 "sim-n-core.c:%d: write-%d %s:0x%08lx <- 0x%lx\n",
152 sim_core_map_to_str (map),
153 (unsigned long) addr,
154 (unsigned long) val);
158 INLINE_SIM_CORE(void)
159 sim_core_write_unaligned_N(sim_cpu *cpu,
165 int alignment = sizeof (unsigned_N) - 1;
166 /* if hardwired to forced alignment just do it */
167 if (WITH_ALIGNMENT == FORCED_ALIGNMENT)
168 sim_core_write_aligned_N (cpu, cia, map, addr & ~alignment, val);
169 else if ((addr & alignment) == 0)
170 sim_core_write_aligned_N (cpu, cia, map, addr, val);
172 switch (CURRENT_ALIGNMENT)
174 case STRICT_ALIGNMENT:
175 /* FIXME - notify abort handler */
176 sim_io_error (CPU_STATE (cpu),
177 "write-%d - misaligned access to 0x%lx",
178 sizeof (unsigned_N), (unsigned long) addr);
180 case NONSTRICT_ALIGNMENT:
183 if (sim_core_write_buffer (CPU_STATE (cpu), map, &val, addr,
185 != sizeof(unsigned_N))
186 sim_io_error(CPU_STATE (cpu),
187 "misaligned %d byte read to 0x%lx failed",
188 sizeof(unsigned_N), (unsigned long) addr);
191 case FORCED_ALIGNMENT:
192 sim_core_write_aligned_N (cpu, cia, map, addr & ~alignment, val);
193 case MIXED_ALIGNMENT:
194 sim_io_error (CPU_STATE (cpu), "internal error - sim_core_write_unaligned_N - mixed alignment");
197 sim_io_error (CPU_STATE (cpu), "internal error - sim_core_write_unaligned_N - bad switch");
203 /* NOTE: see start of file for #define of these macros */
207 #undef sim_core_read_aligned_N
208 #undef sim_core_write_aligned_N
209 #undef sim_core_read_unaligned_N
210 #undef sim_core_write_unaligned_N