[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 | #include <algorithm> |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <cassert> |
---|
| 30 | #include <cstring> |
---|
| 31 | #include <stdexcept> |
---|
| 32 | |
---|
| 33 | #include <iostream> |
---|
| 34 | #include <iomanip> |
---|
| 35 | |
---|
| 36 | #include "pseg_handler.h" |
---|
| 37 | #include "exception.h" |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | * PSegHandler |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | PSeg& PSegHandler::get( size_t pos ) |
---|
| 46 | { |
---|
| 47 | try |
---|
| 48 | { |
---|
| 49 | return m_pSegs.at( pos ); |
---|
| 50 | |
---|
| 51 | }catch (std::out_of_range& oor) { |
---|
| 52 | std::cerr << "PSeg "<< pos <<"(id) is missing" << std::endl; |
---|
| 53 | } |
---|
| 54 | exit(1); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | const PSeg& PSegHandler::getByAddr(uintptr_t segAddress) const |
---|
| 58 | { |
---|
| 59 | std::vector<PSeg>::const_iterator it ; |
---|
| 60 | for(it = m_pSegs.begin(); it < m_pSegs.end(); it++) |
---|
| 61 | { |
---|
| 62 | uintptr_t lma = (*it).lma(); |
---|
| 63 | if( lma == segAddress ) |
---|
| 64 | return *it; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | std::cerr << "Unfound Physical segment: " |
---|
| 68 | << std::hex << std::showbase |
---|
| 69 | << segAddress << std::endl; |
---|
| 70 | exit(1); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void PSegHandler::check() const |
---|
| 74 | { |
---|
| 75 | std::vector<PSeg>::const_iterator it ; |
---|
| 76 | for(it = m_pSegs.begin(); it < m_pSegs.end(); it++) |
---|
| 77 | { |
---|
| 78 | (*it).check(); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void PSegHandler::print( std::ostream &o ) const |
---|
| 83 | { |
---|
| 84 | o << std::dec ; |
---|
| 85 | o << "< " << m_pSegs.size() << " Segments (page size = " << PSeg::pageSize() << ") :"<< std::endl; |
---|
| 86 | std::vector<PSeg>::const_iterator it ; |
---|
| 87 | for(it = m_pSegs.begin(); it < m_pSegs.end(); it++) |
---|
| 88 | o << *it << std::endl; |
---|
| 89 | o << ">"; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | PSegHandler::~PSegHandler() |
---|
| 93 | { |
---|
| 94 | // std::cout << "Deleted PSegHandler " << *this << std::endl; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | PSegHandler::PSegHandler() |
---|
| 98 | { |
---|
| 99 | //std::cout << "New empty PSegHandler " << *this << std::endl; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | // Local Variables: |
---|
| 104 | // tab-width: 4 |
---|
| 105 | // c-basic-offset: 4 |
---|
| 106 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 107 | // indent-tabs-mode: nil |
---|
| 108 | // End: |
---|
| 109 | |
---|
| 110 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 111 | |
---|