Andrew's latest changes & print all instruction counts if -I
[external/binutils.git] / sim / ppc / vm_n.h
1 /*  This file is part of the program psim.
2
3     Copyright (C) 1994-1995, 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 #undef unsigned_N
27 #define unsigned_N XCONCAT2(unsigned_,N)
28 #undef T2H_N
29 #define T2H_N XCONCAT2(T2H_,N)
30 #undef H2T_N
31 #define H2T_N XCONCAT2(H2T_,N)
32
33
34 INLINE_VM unsigned_N
35 XCONCAT2(vm_data_map_read_,N)(vm_data_map *map,
36                               unsigned_word ea,
37                               cpu *processor,
38                               unsigned_word cia)
39 {
40   if ((ea & (sizeof(unsigned_N)-1)) == 0) {
41     unsigned ra = vm_real_data_addr(map, ea, 1/*is-read*/, processor, cia);
42     unsigned_N val = XCONCAT2(core_map_read_,N)(map->read, ra, processor, cia);
43     if (WITH_MON & MONITOR_LOAD_STORE_UNIT)
44       mon_read(ea, ra, sizeof(unsigned_N), processor, cia);
45     TRACE(trace_load_store, ("load cia=0x%x ea=0x%x N=%d val=0x%x\n",
46                              cia, ea, sizeof(unsigned_N), val));
47     return val;
48   }
49   else {
50     switch (CURRENT_ALIGNMENT) {
51     case STRICT_ALIGNMENT:
52       alignment_interrupt(processor, cia, ea);
53       return 0;
54     case NONSTRICT_ALIGNMENT:
55       {
56         unsigned_N rval;
57         unsigned_N val;
58         if (vm_data_map_read_buffer(map, &val, ea, sizeof(unsigned_N))
59             != sizeof(unsigned_N))
60           alignment_interrupt(processor, cia, ea);
61         val = T2H_N(val);
62         if (WITH_MON & MONITOR_LOAD_STORE_UNIT) {
63           /* YUCK */
64           unsigned ra = vm_real_data_addr(map, ea, 1, processor, cia);
65           mon_read(ea, ra, sizeof(unsigned_N), processor, cia);
66         }
67         TRACE(trace_load_store, ("load cia=0x%x ea=0x%x N=%d data=0x%x\n",
68                                  cia, ea, sizeof(unsigned_N), val));
69         return val;
70       }
71     default:
72       error("unknown alignment support\n");
73       return 0;
74     }
75   }
76 }
77
78 INLINE_VM void
79 XCONCAT2(vm_data_map_write_,N)(vm_data_map *map,
80                                unsigned_word ea,
81                                unsigned_N val,
82                                cpu *processor,
83                                unsigned_word cia)
84 {
85   if ((ea & (sizeof(unsigned_N)-1)) == 0) {
86     unsigned ra = vm_real_data_addr(map, ea, 0/*is-read?*/, processor, cia);
87     XCONCAT2(core_map_write_,N)(map->write, ra, val, processor, cia);
88     if (WITH_MON & MONITOR_LOAD_STORE_UNIT)
89       mon_write(ea, ra, sizeof(unsigned_N), processor, cia);
90     TRACE(trace_load_store, ("store cia=0x%x ea=0x%x N=%d val=0x%x\n",
91                              cia, ea, sizeof(unsigned_N), val));
92   }
93   else {
94     switch (CURRENT_ALIGNMENT) {
95     case STRICT_ALIGNMENT:
96       alignment_interrupt(processor, cia, ea);
97       break;
98     case NONSTRICT_ALIGNMENT:
99       {
100         unsigned_N data = H2T_N(val);
101         if (vm_data_map_write_buffer(map, &data, ea, sizeof(unsigned_N), 0)
102             != sizeof(unsigned_N))
103           alignment_interrupt(processor, cia, ea);
104         if (WITH_MON & MONITOR_LOAD_STORE_UNIT) {
105           /* YUCK */
106           unsigned ra = vm_real_data_addr(map, ea, 1, processor, cia);
107           mon_write(ea, ra, sizeof(unsigned_N), processor, cia);
108         }
109         TRACE(trace_load_store, ("store cia=0x%x ea=0x%x N=%d val=0x%x\n",
110                                  cia, ea, sizeof(unsigned_N), val));
111       }
112       break;
113     default:
114       error("unknown alignment support\n");
115     }
116   }
117 }