From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../tests/tlm/multi_sockets/simpleAddressMap.h | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/systemc/tests/tlm/multi_sockets/simpleAddressMap.h (limited to 'src/systemc/tests/tlm/multi_sockets/simpleAddressMap.h') diff --git a/src/systemc/tests/tlm/multi_sockets/simpleAddressMap.h b/src/systemc/tests/tlm/multi_sockets/simpleAddressMap.h new file mode 100644 index 000000000..87ef7851e --- /dev/null +++ b/src/systemc/tests/tlm/multi_sockets/simpleAddressMap.h @@ -0,0 +1,148 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +#ifndef __simpleAddressMap_h__ +#define __simpleAddressMap_h__ + +#include +#include + + +//-------------------------------------------------------------------------- +/** + * Simple address map implementation for the generic protocol. + */ +//-------------------------------------------------------------------------- +class SimpleAddressMap +{ + typedef std::map mapType; + typedef std::map::iterator addressMapIterator; + +public: + SimpleAddressMap() {} + + //-------------------------------------------------------------------------- + /** + * Check for overlapping address ranges + */ + //-------------------------------------------------------------------------- + void checkSanity() + { + addressMapIterator pos; + for (pos=m_addressMap.begin();pos!=m_addressMap.end();++pos){ + if(pos->second!=255) + SC_REPORT_ERROR("SimpleAddressMap","Overlapping Address Regions."); + else + ++pos; + if(pos->second==255) + SC_REPORT_ERROR("SimpleAddressMap","Overlapping Address Regions."); + } + std::cout<<"Address check successful."<second==255) + printf("key: %x value: %i \n", (unsigned int) ((pos->first+1)>>1)-1, pos->second); + else + printf("key: %x value: %i \n", (unsigned int) (pos->first>>1)-1, pos->second); + } + } + + + //-------------------------------------------------------------------------- + /** + * Decode slave address. + * @param address_ A slave address. + * @return The decoded slave port number. On error, the value 255 is returned. + */ + //-------------------------------------------------------------------------- + unsigned int decode(sc_dt::uint64 address_) + { + addressMapIterator lbound; + + lbound=m_addressMap.lower_bound((address_+1)<<1); + if((lbound->second == 255) | (lbound==m_addressMap.end())){ + SC_REPORT_ERROR("SimpleAddressMap", "Address does not match any registered address range."); + } + else{ + return lbound->second; + } + return 255; + } + + const sc_dt::uint64& get_max(){ + if (m_addressMap.size()){ + addressMapIterator i=(m_addressMap.end()); + i--; + retval=(i->first>>1)-1; + return retval; + } + else { + SC_REPORT_ERROR("SimpleAddressMap", "get_max() called on empty address map."); + return retval; + } + } + + const sc_dt::uint64& get_min(){ + if (m_addressMap.size()){ + addressMapIterator i=(m_addressMap.begin()); + retval=((i->first+1)>>1)-1; + return retval; + } + else { + SC_REPORT_ERROR("SimpleAddressMap", "get_min() called on empty address map."); + return retval; + } + } + + //-------------------------------------------------------------------------- + /** + * Insert a slave into the address map + */ + //-------------------------------------------------------------------------- + void insert(sc_dt::uint64 baseAddress_, sc_dt::uint64 highAddress_, unsigned int portNumber_) + { + if(baseAddress_>highAddress_) + SC_REPORT_ERROR("SimpleAddressMap", "Base address must be lower than high address."); + if(portNumber_>=255) + SC_REPORT_ERROR("SimpleAddressMap", "Only ;-) 255 targets can be handled."); + m_addressMap.insert(mapType::value_type(((baseAddress_+1)<<1)-1, 255 )); + m_addressMap.insert(mapType::value_type( (highAddress_+1)<<1 ,portNumber_)); + } + +private: + sc_dt::uint64 retval; + /// the address map + mapType m_addressMap; +}; + + + + +#endif -- cgit v1.2.3