[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_VLOADER_H_ |
---|
| 28 | #define SOCLIB_VLOADER_H_ |
---|
| 29 | |
---|
| 30 | #include <stdlib.h> |
---|
| 31 | #include <cstdlib> |
---|
| 32 | #include <fcntl.h> |
---|
| 33 | #include <unistd.h> |
---|
| 34 | #include <cstdio> |
---|
| 35 | #include <string.h> |
---|
| 36 | |
---|
| 37 | #include <string> |
---|
| 38 | #include <ios> |
---|
| 39 | #include <vector> |
---|
| 40 | #include <map> |
---|
| 41 | #include <fstream> |
---|
| 42 | |
---|
| 43 | #include <dpp/foreach> |
---|
| 44 | |
---|
| 45 | #include <elfpp/object> |
---|
| 46 | #include <elfpp/symbol> |
---|
| 47 | #include <elfpp/section> |
---|
| 48 | #include <elfpp/segment> |
---|
| 49 | #include <elfpp/elfpp_bits.hh> |
---|
| 50 | |
---|
| 51 | #include "stdint.h" |
---|
| 52 | #include "pseg_handler.h" |
---|
| 53 | #include "path_handler.h" |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | class MeMo |
---|
| 58 | { |
---|
| 59 | |
---|
| 60 | std::string m_path; //map_info path name |
---|
| 61 | std::string m_wd; //map_info path to directory TODO: make the name defined in the map_info relative to this wd. |
---|
| 62 | std::string m_simpleName; //map_info filename TODO |
---|
| 63 | void* m_data; //map_info structure |
---|
| 64 | uintptr_t m_addr; //map_info address (virtual) |
---|
| 65 | size_t m_size; //size of the structure |
---|
| 66 | mutable std::map<std::string, elfpp::object*> m_loaders; |
---|
| 67 | PSegHandler m_psegh; |
---|
| 68 | PathHandler m_pathHandler; |
---|
| 69 | |
---|
| 70 | bool m_ginit; |
---|
| 71 | elfpp::object* m_generator;//TODO:delete |
---|
| 72 | |
---|
| 73 | void* load_bin(std::string name); |
---|
| 74 | elfpp::section* get_sect_by_addr(elfpp::object *loader, unsigned int addr); |
---|
| 75 | elfpp::section* get_sect_by_name(elfpp::object *loader, std::string name); |
---|
| 76 | |
---|
| 77 | public: |
---|
| 78 | |
---|
| 79 | MeMo( const std::string &name, const size_t pageSize = 4096); |
---|
| 80 | ~MeMo(); |
---|
| 81 | |
---|
| 82 | void buildSoft(const std::string &filename); |
---|
| 83 | |
---|
| 84 | void print( std::ostream &o ) const; |
---|
| 85 | |
---|
| 86 | void print_mapping() const; |
---|
| 87 | |
---|
| 88 | friend std::ostream &operator<<( std::ostream &o, const MeMo &s ) |
---|
| 89 | { |
---|
| 90 | s.print(o); |
---|
| 91 | return o; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | //The following functions handle the map.bin structure |
---|
| 96 | //inspired from the boot_handler.c of the GIET |
---|
| 97 | mapping_pseg_t* get_pseg_base( mapping_header_t* header ); |
---|
| 98 | mapping_vspace_t* get_vspace_base( mapping_header_t* header ); |
---|
| 99 | mapping_vseg_t* get_vseg_base( mapping_header_t* header ); |
---|
| 100 | mapping_vobj_t* get_vobj_base( mapping_header_t* header ); |
---|
| 101 | void print_mapping_info(void* desc); |
---|
| 102 | void pseg_map( mapping_pseg_t* pseg); |
---|
| 103 | void vseg_map( mapping_vseg_t* vseg); |
---|
| 104 | void buildMap(void* desc); |
---|
| 105 | |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | #endif /* SOCLIB_VLOADER_H_ */ |
---|
| 110 | |
---|
| 111 | // Local Variables: |
---|
| 112 | // tab-width: 4 |
---|
| 113 | // c-basic-offset: 4 |
---|
| 114 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 115 | // indent-tabs-mode: nil |
---|
| 116 | // End: |
---|
| 117 | |
---|
| 118 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 119 | |
---|