| 1 | /* -*- c++ -*-
|
|---|
| 2 | *
|
|---|
| 3 | * GIET_VM_LGPL_HEADER_BEGIN
|
|---|
| 4 | *
|
|---|
| 5 | * This file is part of GIET_VM, GNU LGPLv2.1.
|
|---|
| 6 | *
|
|---|
| 7 | * GIET_VM 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 | * GIET_VM 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 GIET_VM; if not, write to the Free Software
|
|---|
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 19 | * 02110-1301 USA
|
|---|
| 20 | *
|
|---|
| 21 | * GIET_VM_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 | * PSegHandler
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | /////////////////////////////////////
|
|---|
| 44 | PSeg& PSegHandler::get( size_t pos )
|
|---|
| 45 | {
|
|---|
| 46 | try
|
|---|
| 47 | {
|
|---|
| 48 | return m_pSegs.at( pos );
|
|---|
| 49 |
|
|---|
| 50 | }catch (std::out_of_range& oor) {
|
|---|
| 51 | std::cerr << "PSeg "<< pos <<"(id) is missing" << std::endl;
|
|---|
| 52 | }
|
|---|
| 53 | exit(1);
|
|---|
| 54 | }
|
|---|
| 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 | paddr_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 | ///////////////////////////////
|
|---|
| 74 | void PSegHandler::check() const
|
|---|
| 75 | {
|
|---|
| 76 | std::vector<PSeg>::const_iterator it ;
|
|---|
| 77 | for(it = m_pSegs.begin(); it < m_pSegs.end(); it++)
|
|---|
| 78 | {
|
|---|
| 79 | (*it).check();
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void PSegHandler::print( std::ostream &o ) const
|
|---|
| 84 | {
|
|---|
| 85 | o << std::dec ;
|
|---|
| 86 | o << "< " << m_pSegs.size() << " Segments (page size = " << PSeg::pageSize() << ") :"<< std::endl;
|
|---|
| 87 | std::vector<PSeg>::const_iterator it ;
|
|---|
| 88 | for(it = m_pSegs.begin(); it < m_pSegs.end(); it++)
|
|---|
| 89 | o << *it << std::endl;
|
|---|
| 90 | o << ">";
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | PSegHandler::~PSegHandler()
|
|---|
| 94 | {
|
|---|
| 95 | // std::cout << "Deleted PSegHandler " << *this << std::endl;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | PSegHandler::PSegHandler()
|
|---|
| 99 | {
|
|---|
| 100 | //std::cout << "New empty PSegHandler " << *this << std::endl;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | // Local Variables:
|
|---|
| 105 | // tab-width: 4
|
|---|
| 106 | // c-basic-offset: 4
|
|---|
| 107 | // c-file-offsets:((innamespace . 0)(inline-open . 0))
|
|---|
| 108 | // indent-tabs-mode: nil
|
|---|
| 109 | // End:
|
|---|
| 110 |
|
|---|
| 111 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
|
|---|
| 112 |
|
|---|