/[pcsx2_0.9.7]/trunk/pcsx2/Elfheader.h
ViewVC logotype

Contents of /trunk/pcsx2/Elfheader.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 2 months ago) by william
File MIME type: text/plain
File size: 4696 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #ifndef __ELF_H__
17 #define __ELF_H__
18
19 #include "CDVD/IsoFS/IsoFSCDVD.h"
20 #include "CDVD/IsoFS/IsoFS.h"
21
22 #if 0
23 //2002-09-20 (Florin)
24 extern char args[256]; //to be filled by GUI
25 extern unsigned int args_ptr;
26 #endif
27
28 struct ELF_HEADER {
29 u8 e_ident[16]; //0x7f,"ELF" (ELF file identifier)
30 u16 e_type; //ELF type: 0=NONE, 1=REL, 2=EXEC, 3=SHARED, 4=CORE
31 u16 e_machine; //Processor: 8=MIPS R3000
32 u32 e_version; //Version: 1=current
33 u32 e_entry; //Entry point address
34 u32 e_phoff; //Start of program headers (offset from file start)
35 u32 e_shoff; //Start of section headers (offset from file start)
36 u32 e_flags; //Processor specific flags = 0x20924001 noreorder, mips
37 u16 e_ehsize; //ELF header size (0x34 = 52 bytes)
38 u16 e_phentsize; //Program headers entry size
39 u16 e_phnum; //Number of program headers
40 u16 e_shentsize; //Section headers entry size
41 u16 e_shnum; //Number of section headers
42 u16 e_shstrndx; //Section header stringtable index
43 };
44
45 struct ELF_PHR {
46 u32 p_type; //see notes1
47 u32 p_offset; //Offset from file start to program segment.
48 u32 p_vaddr; //Virtual address of the segment
49 u32 p_paddr; //Physical address of the segment
50 u32 p_filesz; //Number of bytes in the file image of the segment
51 u32 p_memsz; //Number of bytes in the memory image of the segment
52 u32 p_flags; //Flags for segment
53 u32 p_align; //Alignment. The address of 0x08 and 0x0C must fit this alignment. 0=no alignment
54 };
55
56 /*
57 notes1
58 ------
59 0=Inactive
60 1=Load the segment into memory, no. of bytes specified by 0x10 and 0x14
61 2=Dynamic linking
62 3=Interpreter. The array element must specify a path name
63 4=Note. The array element must specify the location and size of aux. info
64 5=reserved
65 6=The array element must specify location and size of the program header table.
66 */
67
68 struct ELF_SHR {
69 u32 sh_name; //No. to the index of the Section header stringtable index
70 u32 sh_type; //See notes2
71 u32 sh_flags; //see notes3
72 u32 sh_addr; //Section start address
73 u32 sh_offset; //Offset from start of file to section
74 u32 sh_size; //Size of section
75 u32 sh_link; //Section header table index link
76 u32 sh_info; //Info
77 u32 sh_addralign; //Alignment. The adress of 0x0C must fit this alignment. 0=no alignment.
78 u32 sh_entsize; //Fixed size entries.
79 };
80
81 /*
82 notes 2
83 -------
84 Type:
85 0=Inactive
86 1=PROGBITS
87 2=SYMTAB symbol table
88 3=STRTAB string table
89 4=RELA relocation entries
90 5=HASH hash table
91 6=DYNAMIC dynamic linking information
92 7=NOTE
93 8=NOBITS
94 9=REL relocation entries
95 10=SHLIB
96 0x70000000=LOPROC processor specifc
97 0x7fffffff=HIPROC
98 0x80000000=LOUSER lower bound
99 0xffffffff=HIUSER upper bound
100
101 notes 3
102 -------
103 Section Flags: (1 bit, you may combine them like 3 = alloc & write permission)
104 1=Write section contains data the is be writeable during execution.
105 2=Alloc section occupies memory during execution
106 4=Exec section contains executable instructions
107 0xf0000000=Mask bits processor-specific
108 */
109
110 struct Elf32_Sym {
111 u32 st_name;
112 u32 st_value;
113 u32 st_size;
114 u8 st_info;
115 u8 st_other;
116 u16 st_shndx;
117 };
118
119 #define ELF32_ST_TYPE(i) ((i)&0xf)
120
121 struct Elf32_Rel {
122 u32 r_offset;
123 u32 r_info;
124 };
125
126 class ElfObject
127 {
128 private:
129 SafeArray<u8> data;
130 ELF_PHR* proghead;
131 ELF_SHR* secthead;
132 wxString filename;
133
134 void initElfHeaders();
135 void readIso(IsoFile file);
136 void readFile();
137 void checkElfSize(s64 elfsize);
138
139 public:
140 bool isCdvd;
141 ELF_HEADER& header;
142
143 // Destructor!
144 // C++ does all the cleanup automagically for us.
145 virtual ~ElfObject() throw() { }
146
147 ElfObject(const wxString& srcfile, IsoFile isofile);
148 ElfObject( const wxString& srcfile, uint hdrsize );
149
150 void loadProgramHeaders();
151 void loadSectionHeaders();
152 void loadHeaders();
153
154 bool hasProgramHeaders();
155 bool hasSectionHeaders();
156 bool hasHeaders();
157
158 u32 getCRC();
159 };
160
161 //-------------------
162 extern void loadElfFile(const wxString& filename);
163 extern int GetPS2ElfName( wxString& dest );
164
165
166 extern u32 ElfCRC;
167 extern u32 ElfEntry;
168 extern wxString LastELF;
169
170 #endif

  ViewVC Help
Powered by ViewVC 1.1.22