| 1 | /* -*- c++ -*- |
|---|
| 2 | * |
|---|
| 3 | * SOCLIB_LGPL_HEADER_BEGIN |
|---|
| 4 | * |
|---|
| 5 | * This file is part of SoCLib, GNU LGPLv2.1. |
|---|
| 6 | * |
|---|
| 7 | * SoCLib is free software; you can redistribute it and/or modify it |
|---|
| 8 | * under the terms of the GNU Lesser General Public License as published |
|---|
| 9 | * by the Free Software Foundation; version 2.1 of the License. |
|---|
| 10 | * |
|---|
| 11 | * SoCLib is distributed in the hope that it will be useful, but |
|---|
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 14 | * Lesser General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU Lesser General Public |
|---|
| 17 | * License along with SoCLib; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 19 | * 02110-1301 USA |
|---|
| 20 | * |
|---|
| 21 | * SOCLIB_LGPL_HEADER_END |
|---|
| 22 | * |
|---|
| 23 | * Copyright (c) UPMC, Lip6, Asim |
|---|
| 24 | * Nicolas Pouillon <nipo@ssji.net>, 2007 |
|---|
| 25 | * |
|---|
| 26 | * Based on previous works by Francois Pecheux & Alain Greiner |
|---|
| 27 | * |
|---|
| 28 | * Maintainers: nipo |
|---|
| 29 | */ |
|---|
| 30 | #ifndef SOCLIB_SEGMENT_H_ |
|---|
| 31 | #define SOCLIB_SEGMENT_H_ |
|---|
| 32 | |
|---|
| 33 | #include "exception.h" |
|---|
| 34 | #include "int_tab.h" |
|---|
| 35 | #include "stdint.h" |
|---|
| 36 | #include <string> |
|---|
| 37 | |
|---|
| 38 | namespace soclib { namespace common { |
|---|
| 39 | |
|---|
| 40 | class Segment |
|---|
| 41 | { |
|---|
| 42 | typedef uint64_t addr_t; |
|---|
| 43 | |
|---|
| 44 | std::string m_name; |
|---|
| 45 | addr_t m_base_address; |
|---|
| 46 | size_t m_size; |
|---|
| 47 | IntTab m_target_index; |
|---|
| 48 | bool m_cacheability; |
|---|
| 49 | bool m_initiator; |
|---|
| 50 | IntTab m_initiator_index; |
|---|
| 51 | |
|---|
| 52 | public: |
|---|
| 53 | Segment( const std::string &name, |
|---|
| 54 | addr_t base_address, |
|---|
| 55 | size_t size, |
|---|
| 56 | const IntTab &target_index, |
|---|
| 57 | bool cacheability, |
|---|
| 58 | bool initiator = false, |
|---|
| 59 | const IntTab &initiator_index = soclib::common::IntTab() ) |
|---|
| 60 | : m_name(name), m_base_address(base_address), |
|---|
| 61 | m_size(size), m_target_index(target_index), |
|---|
| 62 | m_cacheability(cacheability), |
|---|
| 63 | m_initiator(initiator), |
|---|
| 64 | m_initiator_index(initiator_index) |
|---|
| 65 | { |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | const Segment &operator=( const Segment &ref ) |
|---|
| 69 | { |
|---|
| 70 | if ( &ref == this ) |
|---|
| 71 | return *this; |
|---|
| 72 | |
|---|
| 73 | m_name = ref.m_name; |
|---|
| 74 | m_base_address = ref.m_base_address; |
|---|
| 75 | m_size = ref.m_size; |
|---|
| 76 | m_target_index = ref.m_target_index; |
|---|
| 77 | m_cacheability = ref.m_cacheability; |
|---|
| 78 | m_initiator = ref.m_initiator; |
|---|
| 79 | m_initiator_index = ref.m_initiator_index; |
|---|
| 80 | |
|---|
| 81 | return *this; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | inline addr_t baseAddress() const |
|---|
| 85 | { |
|---|
| 86 | return m_base_address; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | inline size_t size() const |
|---|
| 90 | { |
|---|
| 91 | return m_size; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | inline bool cacheable() const |
|---|
| 95 | { |
|---|
| 96 | return m_cacheability; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | inline bool initiator() const |
|---|
| 100 | { |
|---|
| 101 | return m_initiator; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | inline const std::string &name() const |
|---|
| 105 | { |
|---|
| 106 | return m_name; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | inline const IntTab &index() const |
|---|
| 110 | { |
|---|
| 111 | return m_target_index; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | inline const IntTab &initiator_index() const |
|---|
| 115 | { |
|---|
| 116 | return m_initiator_index; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | bool isOverlapping( const Segment &other ) const; |
|---|
| 120 | |
|---|
| 121 | void print( std::ostream &o ) const; |
|---|
| 122 | |
|---|
| 123 | friend std::ostream &operator << (std::ostream &o, const Segment &s) |
|---|
| 124 | { |
|---|
| 125 | s.print(o); |
|---|
| 126 | return o; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | inline bool contains( addr_t addr ) const |
|---|
| 130 | { |
|---|
| 131 | return ( addr >= m_base_address && |
|---|
| 132 | ( addr < m_base_address+m_size |
|---|
| 133 | || m_base_address+m_size < m_base_address) ); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | inline Segment masked( addr_t addr ) const |
|---|
| 137 | { |
|---|
| 138 | Segment s = *this; |
|---|
| 139 | s.m_base_address &= addr; |
|---|
| 140 | return s; |
|---|
| 141 | } |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | }} |
|---|
| 145 | |
|---|
| 146 | #endif /* SOCLIB_SEGMENT_H_ */ |
|---|
| 147 | |
|---|
| 148 | // Local Variables: |
|---|
| 149 | // tab-width: 4 |
|---|
| 150 | // c-basic-offset: 4 |
|---|
| 151 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 152 | // indent-tabs-mode: nil |
|---|
| 153 | // End: |
|---|
| 154 | |
|---|
| 155 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 156 | |
|---|