Update devo version of m32r sim to build with recent sim/common changes.
[external/binutils.git] / sim / common / sim-n-core.h
1 /*  This file is part of the program psim.
2
3     Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4
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.
9
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.
14  
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.
18  
19     */
20
21
22 #ifndef N
23 #error "N must be #defined"
24 #endif
25
26 #include "sim-xcat.h"
27
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)
32
33 #define sim_core_read_N XCONCAT2(sim_core_read_,N)
34 #define sim_core_write_N XCONCAT2(sim_core_write_,N)
35
36
37 INLINE_SIM_CORE(unsigned_N)
38 sim_core_read_N(SIM_DESC sd,
39                 sim_core_maps map,
40                 unsigned_word addr,
41                 sim_cpu *cpu,
42                 sim_cia cia)
43 {
44   unsigned_N val;
45   sim_core_mapping *mapping = sim_core_find_mapping (sd, map,
46                                                      addr,
47                                                      sizeof (unsigned_N),
48                                                      1,
49                                                      cpu, cia); /*abort*/
50 #if (WITH_DEVICES)
51   if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
52     unsigned_N data;
53     if (device_io_read_buffer (mapping->device,
54                                &data,
55                                mapping->space,
56                                addr,
57                                sizeof (unsigned_N)) != sizeof (unsigned_N))
58       device_error (mapping->device, "internal error - sim_core_read_N() - io_read_buffer should not fail");
59     val = T2H_N (data);
60   }
61   else
62 #endif
63     val = T2H_N (*(unsigned_N*) sim_core_translate (mapping, addr));
64   if (STATE_CORE (sd)->trace)
65     trace_printf (sd, cpu, "sim-n-core.c:%d: read-%d %s:0x%08lx -> 0x%lx\n",
66                   __LINE__,
67                   sizeof (unsigned_N),
68                   sim_core_map_to_str (map),
69                   (unsigned long) addr,
70                   (unsigned long) val);
71   return val;
72 }
73
74
75
76 INLINE_SIM_CORE(void)
77 sim_core_write_N(SIM_DESC sd,
78                  sim_core_maps map,
79                  unsigned_word addr,
80                  unsigned_N val,
81                  sim_cpu *cpu,
82                  sim_cia cia)
83 {
84   sim_core_mapping *mapping = sim_core_find_mapping(sd, map,
85                                                     addr,
86                                                     sizeof (unsigned_N),
87                                                     1,
88                                                     cpu, cia); /*abort*/
89 #if (WITH_DEVICES)
90   if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
91     unsigned_N data = H2T_N (val);
92     if (device_io_write_buffer (mapping->device,
93                                 &data,
94                                 mapping->space,
95                                 addr,
96                                 sizeof (unsigned_N), /* nr_bytes */
97                                 cpu,
98                                 cia) != sizeof (unsigned_N))
99       device_error (mapping->device, "internal error - sim_core_write_N() - io_write_buffer should not fail");
100   }
101   else
102 #endif
103     *(unsigned_N*) sim_core_translate (mapping, addr) = H2T_N (val);
104   if (STATE_CORE (sd)->trace)
105     trace_printf (sd, cpu, "sim-n-core.c:%d: write-%d %s:0x%08lx <- 0x%lx\n",
106                   __LINE__,
107                   sizeof (unsigned_N),
108                   sim_core_map_to_str (map),
109                   (unsigned long) addr,
110                   (unsigned long) val);
111 }
112
113
114 /* NOTE: see start of file for #define of these macros */
115 #undef unsigned_N
116 #undef T2H_N
117 #undef H2T_N
118 #undef sim_core_read_N
119 #undef sim_core_write_N