gem5  v22.0.0.2
simpleAddressMap.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __simpleAddressMap_h__
21 #define __simpleAddressMap_h__
22 
23 #include <systemc>
24 #include <map>
25 
26 
27 //--------------------------------------------------------------------------
31 //--------------------------------------------------------------------------
33 {
34  typedef std::map<sc_dt::uint64, unsigned int> mapType;
35  typedef std::map<sc_dt::uint64, unsigned int>::iterator addressMapIterator;
36 
37 public:
38  SimpleAddressMap() {}
39 
40  //--------------------------------------------------------------------------
44  //--------------------------------------------------------------------------
45  void checkSanity()
46  {
48  for (pos=m_addressMap.begin();pos!=m_addressMap.end();++pos){
49  if(pos->second!=255)
50  SC_REPORT_ERROR("SimpleAddressMap","Overlapping Address Regions.");
51  else
52  ++pos;
53  if(pos->second==255)
54  SC_REPORT_ERROR("SimpleAddressMap","Overlapping Address Regions.");
55  }
56  std::cout<<"Address check successful."<<std::endl;
57  }
58 
59 
60  //--------------------------------------------------------------------------
64  //--------------------------------------------------------------------------
65  void dumpMap()
66  {
67  std::cout<<"SimpleAddressMap: printing the sorted MAP:"<<std::endl;
69  for (pos=m_addressMap.begin();pos!=m_addressMap.end();++pos){
70  if(pos->second==255)
71  printf("key: %x value: %i \n", (unsigned int) ((pos->first+1)>>1)-1, pos->second);
72  else
73  printf("key: %x value: %i \n", (unsigned int) (pos->first>>1)-1, pos->second);
74  }
75  }
76 
77 
78  //--------------------------------------------------------------------------
84  //--------------------------------------------------------------------------
85  unsigned int decode(sc_dt::uint64 address_)
86  {
87  addressMapIterator lbound;
88 
89  lbound=m_addressMap.lower_bound((address_+1)<<1);
90  if((lbound->second == 255) | (lbound==m_addressMap.end())){
91  SC_REPORT_ERROR("SimpleAddressMap", "Address does not match any registered address range.");
92  }
93  else{
94  return lbound->second;
95  }
96  return 255;
97  }
98 
99  const sc_dt::uint64& get_max(){
100  if (m_addressMap.size()){
102  i--;
103  retval=(i->first>>1)-1;
104  return retval;
105  }
106  else {
107  SC_REPORT_ERROR("SimpleAddressMap", "get_max() called on empty address map.");
108  return retval;
109  }
110  }
111 
112  const sc_dt::uint64& get_min(){
113  if (m_addressMap.size()){
115  retval=((i->first+1)>>1)-1;
116  return retval;
117  }
118  else {
119  SC_REPORT_ERROR("SimpleAddressMap", "get_min() called on empty address map.");
120  return retval;
121  }
122  }
123 
124  //--------------------------------------------------------------------------
128  //--------------------------------------------------------------------------
129  void insert(sc_dt::uint64 baseAddress_, sc_dt::uint64 highAddress_, unsigned int portNumber_)
130  {
131  if(baseAddress_>highAddress_)
132  SC_REPORT_ERROR("SimpleAddressMap", "Base address must be lower than high address.");
133  if(portNumber_>=255)
134  SC_REPORT_ERROR("SimpleAddressMap", "Only ;-) 255 targets can be handled.");
135  m_addressMap.insert(mapType::value_type(((baseAddress_+1)<<1)-1, 255 ));
136  m_addressMap.insert(mapType::value_type( (highAddress_+1)<<1 ,portNumber_));
137  }
138 
139 private:
143 };
144 
145 
146 
147 
148 #endif
SimpleAddressMap::get_min
const sc_dt::uint64 & get_min()
Definition: simpleAddressMap.h:129
SimpleAddressMap::dumpMap
void dumpMap()
Print map.
Definition: simpleAddressMap.h:82
SimpleAddressMap::checkSanity
void checkSanity()
Check for overlapping address ranges.
Definition: simpleAddressMap.h:62
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
SimpleAddressMap::SimpleAddressMap
SimpleAddressMap()
Definition: simpleAddressMap.h:55
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
SimpleAddressMap::get_max
const sc_dt::uint64 & get_max()
Definition: simpleAddressMap.h:116
SimpleAddressMap
Simple address map implementation for the generic protocol.
Definition: simpleAddressMap.h:32
SimpleAddressMap::mapType
std::map< sc_dt::uint64, unsigned int > mapType
Definition: simpleAddressMap.h:51
SimpleAddressMap::m_addressMap
mapType m_addressMap
the address map
Definition: simpleAddressMap.h:159
SimpleAddressMap::decode
unsigned int decode(sc_dt::uint64 address_)
Decode slave address.
Definition: simpleAddressMap.h:102
SimpleAddressMap::insert
void insert(sc_dt::uint64 baseAddress_, sc_dt::uint64 highAddress_, unsigned int portNumber_)
Insert a slave into the address map.
Definition: simpleAddressMap.h:146
SimpleAddressMap::addressMapIterator
std::map< sc_dt::uint64, unsigned int >::iterator addressMapIterator
Definition: simpleAddressMap.h:52
SimpleAddressMap::retval
sc_dt::uint64 retval
Definition: simpleAddressMap.h:157

Generated on Thu Jul 28 2022 13:32:43 for gem5 by doxygen 1.8.17