[163] | 1 | /* -*- c++ -*- |
---|
| 2 | * |
---|
[238] | 3 | * GIET-VM_LGPL_HEADER_BEGIN |
---|
[163] | 4 | * |
---|
[238] | 5 | * This file is part of the GIET-VMS, GNU LGPLv2.1. |
---|
[163] | 6 | * |
---|
[238] | 7 | * The GIET-VM is free software; you can redistribute it and/or modify it |
---|
[163] | 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 | * |
---|
[238] | 11 | * THe GIET-VM is distributed in the hope that it will be useful, but |
---|
[163] | 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 | * |
---|
[238] | 21 | * GIET-VM_LGPL_HEADER_END |
---|
[163] | 22 | * |
---|
| 23 | * Copyright (c) UPMC, Lip6, SoC |
---|
| 24 | * Mohamed Lamine Karaoui <Mohamed.Karaoui@lip6.fr>, 2012 |
---|
| 25 | * |
---|
| 26 | */ |
---|
[238] | 27 | #ifndef GIET_MEMO_PSEG_H |
---|
| 28 | #define GIET_MEMO_PSEG_H |
---|
[163] | 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 | |
---|
[238] | 41 | ////////// |
---|
[163] | 42 | class VSeg |
---|
| 43 | { |
---|
| 44 | friend class PSegHandler; |
---|
| 45 | friend class PSeg; |
---|
| 46 | friend class MeMo; |
---|
| 47 | |
---|
[238] | 48 | typedef unsigned long long paddr_t; |
---|
[163] | 49 | |
---|
[238] | 50 | std::string m_name; // vseg name |
---|
| 51 | std::string m_file; // file name |
---|
| 52 | uintptr_t m_vma; // Virtual address of the section to load in the binary file. |
---|
| 53 | paddr_t m_lma; // Physical address |
---|
| 54 | size_t m_length; |
---|
| 55 | size_t m_type; |
---|
| 56 | bool m_loadable; // loadable vseg ( code, data...) |
---|
| 57 | |
---|
[163] | 58 | public: |
---|
| 59 | |
---|
[238] | 60 | bool m_ident; // identity mapping required if true |
---|
| 61 | |
---|
[163] | 62 | const std::string& name() const; |
---|
| 63 | const std::string& file() const; |
---|
| 64 | uintptr_t vma() const; |
---|
[238] | 65 | paddr_t lma() const; |
---|
[163] | 66 | size_t length() const; |
---|
[210] | 67 | size_t type() const; |
---|
[163] | 68 | //void add( VObj& vobj );//add a VObj |
---|
| 69 | |
---|
| 70 | void print( std::ostream &o ) const; |
---|
| 71 | friend std::ostream &operator<<( std::ostream &o, const VSeg &s ) |
---|
| 72 | { |
---|
| 73 | s.print(o); |
---|
| 74 | return o; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | VSeg& operator=( const VSeg &ref ); |
---|
| 78 | |
---|
| 79 | VSeg(); |
---|
| 80 | VSeg( const VSeg &ref ); |
---|
[238] | 81 | VSeg(std::string& binaryName, |
---|
| 82 | std::string& name, |
---|
| 83 | uintptr_t vma, |
---|
| 84 | size_t length, |
---|
| 85 | bool loadable, |
---|
| 86 | bool ident); |
---|
[163] | 87 | |
---|
| 88 | ~VSeg(); |
---|
| 89 | }; |
---|
| 90 | |
---|
[238] | 91 | ////////// |
---|
[163] | 92 | class PSeg |
---|
| 93 | { |
---|
[238] | 94 | std::string m_name; |
---|
| 95 | paddr_t m_lma; |
---|
| 96 | paddr_t m_length; |
---|
| 97 | size_t m_type; |
---|
[163] | 98 | |
---|
[238] | 99 | paddr_t m_pageLimit; // m_lma + m_length aligned on page size |
---|
| 100 | paddr_t m_nextLma; // next free base |
---|
[163] | 101 | |
---|
[238] | 102 | void confNextLma(); // check m_nextLma is whithin the seg limits |
---|
[163] | 103 | |
---|
| 104 | public: |
---|
[238] | 105 | |
---|
[163] | 106 | std::vector<VSeg> m_vsegs; |
---|
| 107 | |
---|
[238] | 108 | paddr_t m_limit; // m_lma + m_length |
---|
[163] | 109 | |
---|
| 110 | const std::string& name() const; |
---|
[238] | 111 | paddr_t lma() const; |
---|
| 112 | paddr_t length() const; |
---|
[210] | 113 | size_t type() const; |
---|
[238] | 114 | paddr_t limit() const; |
---|
| 115 | paddr_t nextLma() const; |
---|
[163] | 116 | |
---|
| 117 | void check() const; |
---|
| 118 | |
---|
| 119 | void setName(std::string& name); |
---|
[238] | 120 | void setLma( paddr_t lma); |
---|
| 121 | void setLength(paddr_t length); |
---|
[163] | 122 | |
---|
[238] | 123 | static paddr_t align( paddr_t toAlign, unsigned alignPow2); |
---|
| 124 | static paddr_t pageAlign( paddr_t toAlign ); |
---|
| 125 | |
---|
[163] | 126 | static void setPageSize(size_t pg); |
---|
[238] | 127 | |
---|
[163] | 128 | static size_t& pageSize(); |
---|
| 129 | |
---|
[238] | 130 | void add( VSeg& vseg ); //add a VSeg |
---|
[163] | 131 | void addIdent( VSeg& vseg ); |
---|
| 132 | |
---|
[238] | 133 | void setNextLma( paddr_t nextLma); |
---|
| 134 | void incNextLma( size_t inc); |
---|
[163] | 135 | |
---|
| 136 | void print( std::ostream &o ) const; |
---|
| 137 | |
---|
| 138 | friend std::ostream &operator<<( std::ostream &o, const PSeg &s ) |
---|
| 139 | { |
---|
| 140 | s.print(o); |
---|
| 141 | return o; |
---|
| 142 | } |
---|
| 143 | PSeg & operator=( const PSeg &ref ); |
---|
| 144 | |
---|
| 145 | PSeg(); |
---|
| 146 | PSeg( const PSeg &ref ); |
---|
| 147 | PSeg( const std::string &name); |
---|
[238] | 148 | PSeg( const paddr_t lma); |
---|
[163] | 149 | PSeg( const std::string &name, |
---|
[238] | 150 | paddr_t lma, |
---|
| 151 | paddr_t length, |
---|
| 152 | size_t type); |
---|
[163] | 153 | ~PSeg(); |
---|
| 154 | }; |
---|
| 155 | |
---|
| 156 | |
---|
[238] | 157 | #endif /* GIET_MEMO_PSEG_H */ |
---|