00001 /************************************************************************************** 00002 Copyright (c) 2002 The UbixOS Project 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00006 00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. 00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors 00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its 00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission. 00011 00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00019 00020 $Id$ 00021 00022 **************************************************************************************/ 00023 00024 #ifndef _ELF_H 00025 #define _ELF_H 00026 00027 #include <ubixos/types.h> 00028 00029 #define elfExecutable 0x002 00030 #define elfLibrary 0x003 00031 00032 00033 /* Elf Types */ 00034 #define ET_NONE 0 // No file type 00035 #define ET_REL 1 // Relocatable file 00036 #define ET_EXEC 2 // Executable file 00037 #define ET_DYN 3 // Shared object file 00038 #define ET_CORE 4 // Core file 00039 #define ET_LOPROC 0xff00 // Processor-specific 00040 #define ET_HIPROC 0xffff 00041 /* End Elf Types */ 00042 00043 /* Elf Machine Types */ 00044 #define EM_NONE 0 // No machine 00045 #define EM_M32 1 // AT&T WE 32100 00046 #define EM_SPARC 2 // SPARC 00047 #define EM_386 3 // Intel 80386 00048 #define EM_68K 4 // Motorola 68000 00049 #define EM_88K 5 // Motorola 88000 00050 #define EM_860 7 // Intel 80860 00051 #define EM_MIPS 8 // MIPS RS3000 00052 /* End Elf Machines Types */ 00053 00054 /* Elf Version */ 00055 #define EV_NONE 0 // Invalid version 00056 #define EV_CURRENT 1 // Current version 00057 /* End Elf Version */ 00058 00059 /* Elf Program Header Types */ 00060 #define PT_NULL 0 00061 #define PT_LOAD 1 00062 #define PT_DYNAMIC 2 00063 /* End Elf Program Header Types */ 00064 00065 typedef struct { 00066 uChar eIdent[16]; /* File identification. */ 00067 uShort eType; /* File type. */ 00068 uShort eMachine; /* Machine architecture. */ 00069 uLong eVersion; /* ELF format version. */ 00070 uLong eEntry; /* Entry point. */ 00071 uLong ePhoff; /* Program header file offset. */ 00072 uLong eShoff; /* Section header file offset. */ 00073 uLong eFlags; /* Architecture-specific flags. */ 00074 uShort eEhsize; /* Size of ELF header in bytes. */ 00075 uShort ePhentsize; /* Size of program header entry. */ 00076 uShort ePhnum; /* Number of program header entries. */ 00077 uShort eShentsize; /* Size of section header entry. */ 00078 uShort eShnum; /* Number of section header entries. */ 00079 uShort eShstrndx; /* Section name strings section. */ 00080 } elfHeader; 00081 00082 typedef struct { 00083 uLong phType; /* Entry type. */ 00084 uLong phOffset; /* File offset of contents. */ 00085 uLong phVaddr; /* Virtual address in memory image. */ 00086 uLong phPaddr; /* Physical address (not used). */ 00087 uLong phFilesz; /* Size of contents in file. */ 00088 uLong phMemsz; /* Size of contents in memory. */ 00089 uLong phFlags; /* Access permission flags. */ 00090 uLong phAlign; /* Alignment in memory and file. */ 00091 } elfProgramheader; 00092 00093 typedef struct { 00094 uLong shName; /* Section name (index into the section header string table). */ 00095 uLong shType; /* Section type. */ 00096 uLong shFlags; /* Section flags. */ 00097 uLong shAddr; /* Address in memory image. */ 00098 uLong shOffset; /* Offset in file. */ 00099 uLong shSize; /* Size in bytes. */ 00100 uLong shLink; /* Index of a related section. */ 00101 uLong shInfo; /* Depends on section type. */ 00102 uLong shAddralign; /* Alignment in bytes. */ 00103 uLong shEntsize; /* Size of each entry in section. */ 00104 } elfSectionheader; 00105 00106 typedef struct { 00107 uLong pltOffset; 00108 uLong pltInfo; 00109 } elfPltInfo; 00110 00111 typedef struct { 00112 uLong dynName; 00113 uLong dynValue; 00114 uLong dynSize; 00115 uLong dynInfo; 00116 } elfDynsym; 00117 00118 typedef struct { 00119 uInt32 dynVal; 00120 uInt32 dynPtr; 00121 } elfDynamic; 00122 00123 char *elfGetShType(int); 00124 char *elfGetPhType(int); 00125 00126 #endif 00127