| [163] | 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, SoC |
|---|
| 24 | * Mohamed Lamine Karaoui <Mohamed.Karaoui@lip6.fr>, 2012 |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | #ifndef SOCLIB_PSEG_H_ |
|---|
| 28 | #define SOCLIB_PSEG_H_ |
|---|
| 29 | |
|---|
| 30 | #include <string> |
|---|
| 31 | #include <vector> |
|---|
| 32 | #include <ios> |
|---|
| 33 | #include <elfpp/section> |
|---|
| 34 | |
|---|
| 35 | #include "stdint.h" |
|---|
| [210] | 36 | #include "mapping_info.h" |
|---|
| [163] | 37 | |
|---|
| 38 | |
|---|
| 39 | class MeMo; |
|---|
| 40 | |
|---|
| 41 | class VSeg |
|---|
| 42 | { |
|---|
| 43 | friend class PSegHandler; |
|---|
| 44 | friend class PSeg; |
|---|
| 45 | friend class MeMo; |
|---|
| 46 | |
|---|
| 47 | std::string m_name; |
|---|
| 48 | std::string m_file; |
|---|
| 49 | uintptr_t m_vma; //The address of the section to load in the binary file. |
|---|
| 50 | uintptr_t m_lma; //Physical address to which we load the seg (getted from the associated PSeg), setted by PSeg::add/addIdent. |
|---|
| 51 | size_t m_length; |
|---|
| [210] | 52 | size_t m_type; |
|---|
| [163] | 53 | bool m_loadable; // wether this is a loadable vseg ( code, data...) |
|---|
| 54 | |
|---|
| 55 | public: |
|---|
| 56 | bool m_ident;//Indicate if the idententy mapping is activited. used by PSegHandler::makeIdent() |
|---|
| 57 | |
|---|
| 58 | const std::string& name() const; |
|---|
| 59 | const std::string& file() const; |
|---|
| 60 | uintptr_t vma() const; |
|---|
| 61 | uintptr_t lma() const; |
|---|
| 62 | size_t length() const; |
|---|
| [210] | 63 | size_t type() const; |
|---|
| [163] | 64 | //void add( VObj& vobj );//add a VObj |
|---|
| 65 | |
|---|
| 66 | void print( std::ostream &o ) const; |
|---|
| 67 | friend std::ostream &operator<<( std::ostream &o, const VSeg &s ) |
|---|
| 68 | { |
|---|
| 69 | s.print(o); |
|---|
| 70 | return o; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | VSeg& operator=( const VSeg &ref ); |
|---|
| 74 | |
|---|
| 75 | VSeg(); |
|---|
| 76 | VSeg( const VSeg &ref ); |
|---|
| 77 | VSeg(std::string& binaryName, std::string& name, uintptr_t vma, size_t length, bool loadable, bool ident); |
|---|
| 78 | |
|---|
| 79 | ~VSeg(); |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | class PSeg |
|---|
| 84 | { |
|---|
| 85 | std::string m_name; |
|---|
| 86 | uintptr_t m_lma; |
|---|
| 87 | size_t m_length; |
|---|
| [210] | 88 | size_t m_type; |
|---|
| [163] | 89 | |
|---|
| 90 | uintptr_t m_pageLimit; //The end (m_lma + m_length) address of the segment pageSize aligned |
|---|
| 91 | uintptr_t m_nextLma; //next free base |
|---|
| 92 | |
|---|
| 93 | void confNextLma(); //check that m_nextLma has a correct value: whithin the seg limits |
|---|
| 94 | |
|---|
| 95 | public: |
|---|
| 96 | std::vector<VSeg> m_vsegs; |
|---|
| 97 | uintptr_t m_limit;// m_lma + m_length |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | const std::string& name() const; |
|---|
| 101 | uintptr_t lma() const; |
|---|
| 102 | size_t length() const; |
|---|
| [210] | 103 | size_t type() const; |
|---|
| [163] | 104 | uintptr_t limit() const; |
|---|
| 105 | uintptr_t nextLma() const; |
|---|
| 106 | |
|---|
| 107 | void check() const; |
|---|
| 108 | |
|---|
| 109 | void setName(std::string& name); |
|---|
| 110 | void setLma( uintptr_t lma); |
|---|
| 111 | void setLength(size_t length); |
|---|
| 112 | |
|---|
| 113 | static size_t align( unsigned toAlign, unsigned alignPow2); |
|---|
| 114 | static size_t pageAlign( size_t toAlign ); |
|---|
| 115 | static void setPageSize(size_t pg); |
|---|
| 116 | static size_t& pageSize(); |
|---|
| 117 | |
|---|
| 118 | void add( VSeg& vseg );//add a VSeg |
|---|
| 119 | void addIdent( VSeg& vseg ); |
|---|
| 120 | |
|---|
| 121 | void setNextLma( uintptr_t nextLma); |
|---|
| 122 | void incNextLma( size_t inc_next); |
|---|
| 123 | |
|---|
| 124 | void print( std::ostream &o ) const; |
|---|
| 125 | |
|---|
| 126 | friend std::ostream &operator<<( std::ostream &o, const PSeg &s ) |
|---|
| 127 | { |
|---|
| 128 | s.print(o); |
|---|
| 129 | return o; |
|---|
| 130 | } |
|---|
| 131 | PSeg & operator=( const PSeg &ref ); |
|---|
| 132 | |
|---|
| 133 | PSeg(); |
|---|
| 134 | PSeg( const PSeg &ref ); |
|---|
| 135 | PSeg( const std::string &name); |
|---|
| 136 | PSeg( const uintptr_t lma); |
|---|
| 137 | PSeg( const std::string &name, |
|---|
| 138 | uintptr_t lma, |
|---|
| [210] | 139 | size_t length, |
|---|
| 140 | size_t type); |
|---|
| [163] | 141 | ~PSeg(); |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | #endif /* SOCLIB_PSEG_H_ */ |
|---|