⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elf_loader.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
字号:
/* -*- C++ -*- */

/**
 *  Copyright (c) 2005 Zhejiang University, P.R.China
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
///==================================================
/**
 * @file        ELF_Loader.h
 * @brief      
 * @author      lijiecong <lijiecong@yahoo.com.cn>   2004/11/10
 				Wei He <hwzd1997@163.com> 
 *
 * $Id: ELF_Loader.h,v 1.6 2005/03/30 12:37:40 shengj Exp $
 */
///==================================================

#ifndef ELF_LOADER_H_INCLUDE
#define ELF_LOADER_H_INCLUDE

#ifndef INCLUDE_FSTREAM
#define INCLUDE_FSTREAM
#include <fstream>
#endif

#include "Core/Global.h"
#include "Core/Loader.h"
#include "Core/Log.h"
#include "./Elf.h"

#define LOAD_ADDRESS 0x0000
#define BIG_ENDIAN   0x02


namespace ELF_LOADER {


	class  ELF_Loader : public Core::Binary_Loader
	{	
	 public:

		 ELF_Loader(void ){
			
			 on_create();
			 program_header = 0;
			
		 }

		 ~ELF_Loader(){
		 
			 delete [] program_header;
			 on_destroy();
		 
		 }

		 //! do nothing
		 void on_create(){
		 
			 name_ ="ELF_LOADER";
			 #ifdef _DEBUG
			 WUKONG_STDOUT<<"ELF_Loader created"<<std::endl;
			 #endif
		 }

		 std::string get_name(void) const{
			return "ELF_LOADER";
		 
		 }
		 //! do nothing
		 void on_destroy(){

			 #ifdef _DEBUG
			 WUKONG_STDOUT<<"ELF_Loader destoried"<<std::endl;
			 #endif
		 
		 }

		bool load_binary(std::string filepath);


		 typedef enum
		 {
			 EXECUTABLEFILE = 1,
			 FILEOPENERROR  = -1,
			 NOTEXECUTABLEFILE = -2,
			 LOADADDRESSERROR = -3
		 }File_Error_Type;
	
	protected:

		// //the file handler of elf file
		std::ifstream  in_elf_file;
		Elf32_Ehdr     elf_header;
		Elf32_Phdr     *program_header;
		//u32 pc;

	private:

		Core::s32 read_exec_elf(void);
		// !if the file you want to load is executable, the function return true ,		else return false
		Core::s32 is_executable_file(void);
		// !can only read static compiled executable file on arm.
		// !and,return the value of entry point.if this function read file failed
		// !it returns a minus digit.
		Core::u32 load_static_elf(void);

		Core::u32 load_dynamic_elf(void);
		
		//for big endian  lijiecong 2005/3/16 
		void elf_head_big2small( );
		
		void program_head_big2small( Elf32_Phdr     *program_header );
		
		void section_head_big2small(Elf32_Shdr *section_header);
		
		Core::s32 big_to_small( Core::s32 temp,Core::s32 size);

		void set_pc(Core::u32 pc);
	};

}//namespace

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -