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

📄 elf.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- 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.h
 * @brief      
 * @author      Wei He <hwzd1997@163.com> 
 *
 * $Id: Elf.h,v 1.1 2005/03/06 03:40:09 hewei Exp $
 */
///==================================================


#ifndef ELF_H_INCLUDE
#define ELF_H_INCLUDE


#include "Core/Global.h"
#include "Core/Datatype.h"

namespace ELF_LOADER{

	//! 32-bit ELF base types
	typedef   Core::u32	Elf32_Addr;
	typedef   Core::u16	Elf32_Half;
	typedef   Core::u32	Elf32_Off;
	typedef   Core::s32	Elf32_Sword;
	typedef   Core::u32	Elf32_Word;

	//! 64-bit ELF base types
	typedef   Core::u64	Elf64_Addr;
	typedef   Core::u16	Elf64_Half;
	typedef   Core::s16	Elf64_SHalf;
	typedef   Core::u64	Elf64_Off;
	typedef   Core::s32	Elf64_Sword;
	typedef   Core::u32	Elf64_Word;
	typedef   Core::u64	Elf64_Xword;
	typedef   Core::s64	Elf64_Sxword;

	//! These constants are for the segment types stored in the image	headers 
	#define PT_NULL					0
	#define PT_LOAD                 1
	#define PT_DYNAMIC				2
	#define PT_INTERP				3
	#define PT_NOTE					4
	#define PT_SHLIB				5
	#define PT_PHDR					6
	#define PT_LOPROC				0x70000000
	#define PT_HIPROC				0x7fffffff
	#define PT_MIPS_REGINFO			0x70000000

	//! Flags in the e_flags field of the header 
	#define EF_MIPS_NOREORDER		0x00000001
	#define EF_MIPS_PIC				0x00000002
	#define EF_MIPS_CPIC			0x00000004
	#define EF_MIPS_ARCH			0xf0000000

	//! These constants define the different elf file types 
	#define ET_NONE					0
	#define ET_REL					1
	#define ET_EXEC					2
	#define ET_DYN					3
	#define ET_CORE					4
	#define ET_LOPROC				0xff00
	#define ET_HIPROC				0xffff

	//! These constants define the various ELF target machines 
	#define EM_NONE					0
	#define EM_M32					1
	#define EM_SPARC				2
	#define EM_386					3
	#define EM_68K					4
	#define EM_88K					5
	#define EM_486					6   // Perhaps disused 
	#define EM_860					7

	#define EM_MIPS					8	// MIPS R3000 (officially, big-endian only) 

	#define EM_MIPS_RS4_BE			10	// MIPS R4000 big-endian 

	#define EM_PARISC				15	// HPPA 

	#define EM_SPARC32PLUS			18	// Sun's "v8plus" 

	#define EM_PPC					20	// PowerPC 
	#define EM_PPC64				21 // PowerPC64
	#define EM_ARM					40 // ARM 
	#define EM_SH					42	// SuperH 

	#define EM_SPARCV9				43	// SPARC v9 64-bit 

	#define EM_IA_64				50	// HP/Intel IA-64 

	#define EM_X8664				62	// AMD x86-64 

	#define EM_S390					22	// IBM S/390 

	#define EM_CRIS					76 // Axis Communications 32-bit embedded processor 
	//! This is an interim value that we will use until the committee	comes
	//! up with a final number.
 
	#define EM_ALPHA				0x9026

	//! This is the old interim value for S/390 architecture

	#define EM_S390_OLD				0xA390

	//! This is the info that is needed to parse the dynamic section of the file 

	#define DT_NULL					0
	#define DT_NEEDED				1
	#define DT_PLTRELSZ				2
	#define DT_PLTGOT				3
	#define DT_HASH					4
	#define DT_STRTAB				5
	#define DT_SYMTAB				6
	#define DT_RELASZ				8
	#define DT_RELAENT				9
	#define DT_STRSZ				10
	#define DT_SYMENT				11
	#define DT_FINI					13
	#define DT_SONAME				14
	#define DT_RPATH 				15
	#define DT_SYMBOLIC				16
	#define DT_REL					17
	#define DT_RELSZ				18
	#define DT_RELENT				19
	#define DT_PLTREL				20
	#define DT_DEBUG				21
	#define DT_TEXTREL				22
	#define DT_JMPREL				23
	#define DT_LOPROC				0x70000000
	#define DT_HIPROC				0x7fffffff
	#define DT_MIPS_RLD_VERSION		0x70000001
	#define DT_MIPS_TIME_STAMP		0x70000002
	#define DT_MIPS_ICHECKSUM		0x70000003
	#define DT_MIPS_IVERSION		0x70000004
	#define DT_MIPS_FLAGS			0x70000005
	#define RHF_NONE				0
	#define RHF_HARDWAY				1
	#define RHF_NOTPOT				2
	#define DT_MIPS_BASE_ADDRESS	0x70000006
	#define DT_MIPS_CONFLICT		0x70000008
	#define DT_MIPS_LIBLIST			0x70000009
	#define DT_MIPS_LOCAL_GOTNO		0x7000000a
	#define DT_MIPS_CONFLICTNO		0x7000000b
	#define DT_MIPS_LIBLISTNO		0x70000010
	#define DT_MIPS_SYMTABNO		0x70000011
	#define DT_MIPS_UNREFEXTNO		0x70000012
	#define DT_MIPS_GOTSYM			0x70000013
	#define DT_MIPS_HIPAGENO		0x70000014
	#define DT_MIPS_RLD_MAP			0x70000016

	//! This info is needed when parsing the symbol table 

	#define STB_LOCAL				0
	#define STB_GLOBAL				1
	#define STB_WEAK				2

	#define STT_NOTYPE				0
	#define STT_OBJECT				1
	#define STT_FUNC				2
	#define STT_SECTION				3
	#define STT_FILE				4

	#define ELF32_ST_BIND(x)		((x) >> 4)
	#define ELF32_ST_TYPE(x)		(((unsigned int) x) & 0xf)

	//! Symbolic values for the entries in the auxiliary table
	//! put on the initial stack

	#define AT_NULL					0	 // end of vector 
	#define AT_IGNORE				1	 // entry should be ignored 
	#define AT_EXECFD				2	 // file descriptor of program 
	#define AT_PHDR					3	 // program headers for program 
	#define AT_PHENT				4	 // size of program header entry 
	#define AT_PHNUM				5	 // number of program headers 
	#define AT_PAGESZ				6	 // system page size 
	#define AT_BASE					7	 // base address of interpreter 
	#define AT_FLAGS				8	 // flags 
	#define AT_ENTRY				9	 // entry point of program 
	#define AT_NOTELF				10   // program is not ELF 
	#define AT_UID					11   // real uid 
	#define AT_EUID					12   // effective uid 
	#define AT_GID					13   // real gid 
	#define AT_EGID					14   // effective gid 
	#define AT_PLATFORM				15   // string identifying CPU for optimizations 
	#define AT_HWCAP				16   // arch dependent hints at CPU capabilities 
	#define AT_CLKTCK				17	 // frequency at which times() increments 

	typedef struct dynamic{
		Elf32_Sword d_tag;
		union{
			Elf32_Sword	d_val;
			Elf32_Addr	d_ptr;
		} d_un;
	} Elf32_Dyn;

	typedef struct {
		Elf64_Sxword d_tag;		// entry tag value 
		union{
		Elf64_Xword d_val;
		Elf64_Addr d_ptr;
		} d_un;
	} Elf64_Dyn;

	//! The following are used with relocations 
	#define ELF32_R_SYM(x)		   ((x) >> 8)
	#define ELF32_R_TYPE(x)		   ((x) & 0xff)

	#define R_386_NONE			   0
	#define R_386_32			   1
	#define R_386_PC32			   2
	#define R_386_GOT32			   3
	#define R_386_PLT32	           4
	#define R_386_COPY	           5
	#define R_386_GLOB_DAT	       6
	#define R_386_JMP_SLOT	       7
	#define R_386_RELATIVE	       8
	#define R_386_GOTOFF	       9
	#define R_386_GOTPC	           10
	#define R_386_NUM	           11

	#define R_MIPS_NONE		       0
	#define R_MIPS_16		       1
	#define R_MIPS_32		       2
	#define R_MIPS_REL32	       3
	#define R_MIPS_26		       4
	#define R_MIPS_HI16		       5
	#define R_MIPS_LO16		       6
	#define R_MIPS_GPREL16	       7
	#define R_MIPS_LITERAL	       8
	#define R_MIPS_GOT16	       9
	#define R_MIPS_PC16		       10
	#define R_MIPS_CALL16	       11
	#define R_MIPS_GPREL32	       12

	//! The remaining relocs are defined on Irix, although they are not
	//! in the MIPS ELF ABI.  
	#define R_MIPS_UNUSED1	       13
	#define R_MIPS_UNUSED2	       14
	#define R_MIPS_UNUSED3	       15
	#define R_MIPS_SHIFT5	       16
	#define R_MIPS_SHIFT6	       17
	#define R_MIPS_64		       18
	#define R_MIPS_GOT_DISP	       19
	#define R_MIPS_GOT_PAGE	       20
	#define R_MIPS_GOT_OFST	       21

	//! The following two relocation types are specified in the MIPS ABI
	//! conformance guide version 1.2 but not yet in the psABI.

	#define R_MIPS_GOTHI16	       22
	#define R_MIPS_GOTLO16	       23
	#define R_MIPS_SUB		       24
	#define R_MIPS_INSERT_A	       25
	#define R_MIPS_INSERT_B	       26
	#define R_MIPS_DELETE	       27
	#define R_MIPS_HIGHER	       28
	#define R_MIPS_HIGHEST	       29

	//! The following two relocation types are specified in the MIPS ABI
	//! conformance guide version 1.2 but not yet in the psABI.

	#define R_MIPS_CALLHI16	       30
	#define R_MIPS_CALLLO16	       31

	//! This range is reserved for vendor specific relocations.

	#define R_MIPS_LOVENDOR	       100
	#define R_MIPS_HIVENDOR	       127


	// Sparc ELF relocation types

	#define	R_SPARC_NONE		   0
	#define	R_SPARC_8		       1
	#define	R_SPARC_16		       2
	#define	R_SPARC_32		       3
	#define	R_SPARC_DISP8		   4
	#define	R_SPARC_DISP16		   5
	#define	R_SPARC_DISP32		   6
	#define	R_SPARC_WDISP30		   7
	#define	R_SPARC_WDISP22		   8
	#define	R_SPARC_HI22		   9
	#define	R_SPARC_22		       10
	#define	R_SPARC_13		       11
	#define	R_SPARC_LO10		   12
	#define	R_SPARC_GOT10		   13
	#define	R_SPARC_GOT13		   14
	#define	R_SPARC_GOT22		   15
	#define	R_SPARC_PC10		   16
	#define	R_SPARC_PC22		   17
	#define	R_SPARC_WPLT30		   18
	#define	R_SPARC_COPY		   19
	#define	R_SPARC_GLOB_DAT	   20
	#define	R_SPARC_JMP_SLOT	   21
	#define	R_SPARC_RELATIVE	   22
	#define	R_SPARC_UA32		   23
	#define R_SPARC_PLT32		   24
	#define R_SPARC_HIPLT22		   25
	#define R_SPARC_LOPLT10		   26
	#define R_SPARC_PCPLT32		   27
	#define R_SPARC_PCPLT22		   28
	#define R_SPARC_PCPLT10		   29
	#define R_SPARC_10		       30

⌨️ 快捷键说明

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