summaryrefslogtreecommitdiff
path: root/src/core/loader
diff options
context:
space:
mode:
authorGravatar bunnei2014-06-16 23:05:10 -0400
committerGravatar bunnei2014-06-16 23:43:32 -0400
commit1da361c7ab55e1dbe6709a738e228bfab5a5bb78 (patch)
tree487be34416c624106a01edf8b075866fb2cb9d33 /src/core/loader
parentLoader: Added support for booting NCCH executables. (diff)
downloadyuzu-1da361c7ab55e1dbe6709a738e228bfab5a5bb78.tar.gz
yuzu-1da361c7ab55e1dbe6709a738e228bfab5a5bb78.tar.xz
yuzu-1da361c7ab55e1dbe6709a738e228bfab5a5bb78.zip
Elf: Renamed modules to be consistent with new loader naming, fixed tabs -> spaces.
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/elf.cpp190
-rw-r--r--src/core/loader/elf.h (renamed from src/core/loader/elf_types.h)232
-rw-r--r--src/core/loader/elf_reader.cpp190
-rw-r--r--src/core/loader/elf_reader.h75
-rw-r--r--src/core/loader/loader.cpp2
5 files changed, 332 insertions, 357 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
new file mode 100644
index 000000000..153c30f51
--- /dev/null
+++ b/src/core/loader/elf.cpp
@@ -0,0 +1,190 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <string>
6
7#include "common/common.h"
8
9#include "common/symbols.h"
10#include "core/mem_map.h"
11#include "core/loader/elf.h"
12
13//void bswap(Elf32_Word &w) {w = Common::swap32(w);}
14//void bswap(Elf32_Half &w) {w = Common::swap16(w);}
15
16#define bswap(w) w // Dirty bswap disable for now... 3DS is little endian, anyway
17
18static void byteswapHeader(Elf32_Ehdr &ELF_H)
19{
20 bswap(ELF_H.e_type);
21 bswap(ELF_H.e_machine);
22 bswap(ELF_H.e_ehsize);
23 bswap(ELF_H.e_phentsize);
24 bswap(ELF_H.e_phnum);
25 bswap(ELF_H.e_shentsize);
26 bswap(ELF_H.e_shnum);
27 bswap(ELF_H.e_shstrndx);
28 bswap(ELF_H.e_version);
29 bswap(ELF_H.e_entry);
30 bswap(ELF_H.e_phoff);
31 bswap(ELF_H.e_shoff);
32 bswap(ELF_H.e_flags);
33}
34
35static void byteswapSegment(Elf32_Phdr &sec)
36{
37 bswap(sec.p_align);
38 bswap(sec.p_filesz);
39 bswap(sec.p_flags);
40 bswap(sec.p_memsz);
41 bswap(sec.p_offset);
42 bswap(sec.p_paddr);
43 bswap(sec.p_vaddr);
44 bswap(sec.p_type);
45}
46
47static void byteswapSection(Elf32_Shdr &sec)
48{
49 bswap(sec.sh_addr);
50 bswap(sec.sh_addralign);
51 bswap(sec.sh_entsize);
52 bswap(sec.sh_flags);
53 bswap(sec.sh_info);
54 bswap(sec.sh_link);
55 bswap(sec.sh_name);
56 bswap(sec.sh_offset);
57 bswap(sec.sh_size);
58 bswap(sec.sh_type);
59}
60
61ElfReader::ElfReader(void *ptr)
62{
63 base = (char*)ptr;
64 base32 = (u32 *)ptr;
65 header = (Elf32_Ehdr*)ptr;
66 byteswapHeader(*header);
67
68 segments = (Elf32_Phdr *)(base + header->e_phoff);
69 sections = (Elf32_Shdr *)(base + header->e_shoff);
70
71 entryPoint = header->e_entry;
72
73 LoadSymbols();
74}
75
76const char *ElfReader::GetSectionName(int section) const
77{
78 if (sections[section].sh_type == SHT_NULL)
79 return nullptr;
80
81 int nameOffset = sections[section].sh_name;
82 char *ptr = (char*)GetSectionDataPtr(header->e_shstrndx);
83
84 if (ptr)
85 return ptr + nameOffset;
86 else
87 return nullptr;
88}
89
90bool ElfReader::LoadInto(u32 vaddr)
91{
92 DEBUG_LOG(MASTER_LOG, "String section: %i", header->e_shstrndx);
93
94 // Should we relocate?
95 bRelocate = (header->e_type != ET_EXEC);
96
97 if (bRelocate)
98 {
99 DEBUG_LOG(MASTER_LOG, "Relocatable module");
100 entryPoint += vaddr;
101 }
102 else
103 {
104 DEBUG_LOG(MASTER_LOG, "Prerelocated executable");
105 }
106
107 INFO_LOG(MASTER_LOG, "%i segments:", header->e_phnum);
108
109 // First pass : Get the bits into RAM
110 u32 segmentVAddr[32];
111
112 u32 baseAddress = bRelocate ? vaddr : 0;
113
114 for (int i = 0; i < header->e_phnum; i++)
115 {
116 Elf32_Phdr *p = segments + i;
117
118 INFO_LOG(MASTER_LOG, "Type: %i Vaddr: %08x Filesz: %i Memsz: %i ", p->p_type, p->p_vaddr, p->p_filesz, p->p_memsz);
119
120 if (p->p_type == PT_LOAD)
121 {
122 segmentVAddr[i] = baseAddress + p->p_vaddr;
123 u32 writeAddr = segmentVAddr[i];
124
125 const u8 *src = GetSegmentPtr(i);
126 u8 *dst = Memory::GetPointer(writeAddr);
127 u32 srcSize = p->p_filesz;
128 u32 dstSize = p->p_memsz;
129 u32 *s = (u32*)src;
130 u32 *d = (u32*)dst;
131 for (int j = 0; j < (int)(srcSize + 3) / 4; j++)
132 {
133 *d++ = /*_byteswap_ulong*/(*s++);
134 }
135 if (srcSize < dstSize)
136 {
137 //memset(dst + srcSize, 0, dstSize-srcSize); //zero out bss
138 }
139 INFO_LOG(MASTER_LOG, "Loadable Segment Copied to %08x, size %08x", writeAddr, p->p_memsz);
140 }
141 }
142
143
144 INFO_LOG(MASTER_LOG, "Done loading.");
145 return true;
146}
147
148SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const
149{
150 for (int i = firstSection; i < header->e_shnum; i++)
151 {
152 const char *secname = GetSectionName(i);
153
154 if (secname != nullptr && strcmp(name, secname) == 0)
155 return i;
156 }
157 return -1;
158}
159
160bool ElfReader::LoadSymbols()
161{
162 bool hasSymbols = false;
163 SectionID sec = GetSectionByName(".symtab");
164 if (sec != -1)
165 {
166 int stringSection = sections[sec].sh_link;
167 const char *stringBase = (const char *)GetSectionDataPtr(stringSection);
168
169 //We have a symbol table!
170 Elf32_Sym *symtab = (Elf32_Sym *)(GetSectionDataPtr(sec));
171 int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
172 for (int sym = 0; sym < numSymbols; sym++)
173 {
174 int size = symtab[sym].st_size;
175 if (size == 0)
176 continue;
177
178 // int bind = symtab[sym].st_info >> 4;
179 int type = symtab[sym].st_info & 0xF;
180
181 const char *name = stringBase + symtab[sym].st_name;
182
183 Symbols::Add(symtab[sym].st_value, name, size, type);
184
185 hasSymbols = true;
186 }
187 }
188
189 return hasSymbols;
190}
diff --git a/src/core/loader/elf_types.h b/src/core/loader/elf.h
index f1bf3db72..2e6b80982 100644
--- a/src/core/loader/elf_types.h
+++ b/src/core/loader/elf.h
@@ -1,34 +1,34 @@
1// Copyright 2013 Dolphin Emulator Project 1// Copyright 2013 Dolphin Emulator Project / Citra Emulator Project
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common.h"
8
7// ELF Header Constants 9// ELF Header Constants
8 10
9// File type 11// File type
10enum ElfType 12enum ElfType {
11{ 13 ET_NONE = 0,
12 ET_NONE = 0, 14 ET_REL = 1,
13 ET_REL = 1, 15 ET_EXEC = 2,
14 ET_EXEC = 2, 16 ET_DYN = 3,
15 ET_DYN = 3, 17 ET_CORE = 4,
16 ET_CORE = 4, 18 ET_LOPROC = 0xFF00,
17 ET_LOPROC = 0xFF00, 19 ET_HIPROC = 0xFFFF,
18 ET_HIPROC = 0xFFFF,
19}; 20};
20 21
21// Machine/Architecture 22// Machine/Architecture
22enum ElfMachine 23enum ElfMachine {
23{ 24 EM_NONE = 0,
24 EM_NONE = 0, 25 EM_M32 = 1,
25 EM_M32 = 1, 26 EM_SPARC = 2,
26 EM_SPARC = 2, 27 EM_386 = 3,
27 EM_386 = 3, 28 EM_68K = 4,
28 EM_68K = 4, 29 EM_88K = 5,
29 EM_88K = 5, 30 EM_860 = 7,
30 EM_860 = 7, 31 EM_MIPS = 8
31 EM_MIPS = 8
32}; 32};
33 33
34// File version 34// File version
@@ -62,8 +62,6 @@ enum ElfMachine
62#define ELFDATA2LSB 1 62#define ELFDATA2LSB 1
63#define ELFDATA2MSB 2 63#define ELFDATA2MSB 2
64 64
65
66
67// Sections constants 65// Sections constants
68 66
69// Section indexes 67// Section indexes
@@ -96,14 +94,13 @@ enum ElfMachine
96// Custom section types 94// Custom section types
97#define SHT_PSPREL 0x700000a0 95#define SHT_PSPREL 0x700000a0
98 96
99
100// Section flags 97// Section flags
101enum ElfSectionFlags 98enum ElfSectionFlags
102{ 99{
103 SHF_WRITE = 0x1, 100 SHF_WRITE = 0x1,
104 SHF_ALLOC = 0x2, 101 SHF_ALLOC = 0x2,
105 SHF_EXECINSTR = 0x4, 102 SHF_EXECINSTR = 0x4,
106 SHF_MASKPROC = 0xF0000000, 103 SHF_MASKPROC = 0xF0000000,
107}; 104};
108 105
109// Symbol binding 106// Symbol binding
@@ -188,63 +185,58 @@ typedef unsigned int Elf32_Off;
188typedef signed int Elf32_Sword; 185typedef signed int Elf32_Sword;
189typedef unsigned int Elf32_Word; 186typedef unsigned int Elf32_Word;
190 187
191
192// ELF file header 188// ELF file header
193struct Elf32_Ehdr 189struct Elf32_Ehdr {
194{ 190 unsigned char e_ident[EI_NIDENT];
195 unsigned char e_ident[EI_NIDENT]; 191 Elf32_Half e_type;
196 Elf32_Half e_type; 192 Elf32_Half e_machine;
197 Elf32_Half e_machine; 193 Elf32_Word e_version;
198 Elf32_Word e_version; 194 Elf32_Addr e_entry;
199 Elf32_Addr e_entry; 195 Elf32_Off e_phoff;
200 Elf32_Off e_phoff; 196 Elf32_Off e_shoff;
201 Elf32_Off e_shoff; 197 Elf32_Word e_flags;
202 Elf32_Word e_flags; 198 Elf32_Half e_ehsize;
203 Elf32_Half e_ehsize; 199 Elf32_Half e_phentsize;
204 Elf32_Half e_phentsize; 200 Elf32_Half e_phnum;
205 Elf32_Half e_phnum; 201 Elf32_Half e_shentsize;
206 Elf32_Half e_shentsize; 202 Elf32_Half e_shnum;
207 Elf32_Half e_shnum; 203 Elf32_Half e_shstrndx;
208 Elf32_Half e_shstrndx;
209}; 204};
210 205
211// Section header 206// Section header
212struct Elf32_Shdr 207struct Elf32_Shdr {
213{ 208 Elf32_Word sh_name;
214 Elf32_Word sh_name; 209 Elf32_Word sh_type;
215 Elf32_Word sh_type; 210 Elf32_Word sh_flags;
216 Elf32_Word sh_flags; 211 Elf32_Addr sh_addr;
217 Elf32_Addr sh_addr; 212 Elf32_Off sh_offset;
218 Elf32_Off sh_offset; 213 Elf32_Word sh_size;
219 Elf32_Word sh_size; 214 Elf32_Word sh_link;
220 Elf32_Word sh_link; 215 Elf32_Word sh_info;
221 Elf32_Word sh_info; 216 Elf32_Word sh_addralign;
222 Elf32_Word sh_addralign; 217 Elf32_Word sh_entsize;
223 Elf32_Word sh_entsize;
224}; 218};
225 219
226// Segment header 220// Segment header
227struct Elf32_Phdr 221struct Elf32_Phdr {
228{ 222 Elf32_Word p_type;
229 Elf32_Word p_type; 223 Elf32_Off p_offset;
230 Elf32_Off p_offset; 224 Elf32_Addr p_vaddr;
231 Elf32_Addr p_vaddr; 225 Elf32_Addr p_paddr;
232 Elf32_Addr p_paddr; 226 Elf32_Word p_filesz;
233 Elf32_Word p_filesz; 227 Elf32_Word p_memsz;
234 Elf32_Word p_memsz; 228 Elf32_Word p_flags;
235 Elf32_Word p_flags; 229 Elf32_Word p_align;
236 Elf32_Word p_align;
237}; 230};
238 231
239// Symbol table entry 232// Symbol table entry
240struct Elf32_Sym 233struct Elf32_Sym {
241{ 234 Elf32_Word st_name;
242 Elf32_Word st_name; 235 Elf32_Addr st_value;
243 Elf32_Addr st_value; 236 Elf32_Word st_size;
244 Elf32_Word st_size; 237 unsigned char st_info;
245 unsigned char st_info; 238 unsigned char st_other;
246 unsigned char st_other; 239 Elf32_Half st_shndx;
247 Elf32_Half st_shndx;
248}; 240};
249 241
250#define ELF32_ST_BIND(i) ((i)>>4) 242#define ELF32_ST_BIND(i) ((i)>>4)
@@ -252,30 +244,88 @@ struct Elf32_Sym
252#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) 244#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
253 245
254// Relocation entries 246// Relocation entries
255struct Elf32_Rel 247struct Elf32_Rel {
256{ 248 Elf32_Addr r_offset;
257 Elf32_Addr r_offset; 249 Elf32_Word r_info;
258 Elf32_Word r_info;
259}; 250};
260 251
261struct Elf32_Rela 252struct Elf32_Rela {
262{ 253 Elf32_Addr r_offset;
263 Elf32_Addr r_offset; 254 Elf32_Word r_info;
264 Elf32_Word r_info; 255 Elf32_Sword r_addend;
265 Elf32_Sword r_addend;
266}; 256};
267 257
268#define ELF32_R_SYM(i) ((i)>>8) 258#define ELF32_R_SYM(i) ((i)>>8)
269#define ELF32_R_TYPE(i) ((unsigned char)(i)) 259#define ELF32_R_TYPE(i) ((unsigned char)(i))
270#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t)) 260#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t))
271 261
262struct Elf32_Dyn {
263 Elf32_Sword d_tag;
264 union {
265 Elf32_Word d_val;
266 Elf32_Addr d_ptr;
267 } d_un;
268};
272 269
273struct Elf32_Dyn 270enum KnownElfTypes {
274{ 271 KNOWNELF_PSP = 0,
275 Elf32_Sword d_tag; 272 KNOWNELF_DS = 1,
276 union 273 KNOWNELF_GBA = 2,
277 { 274 KNOWNELF_GC = 3,
278 Elf32_Word d_val; 275};
279 Elf32_Addr d_ptr; 276
280 } d_un; 277typedef int SectionID;
278
279class ElfReader {
280private:
281 char *base;
282 u32 *base32;
283
284 Elf32_Ehdr *header;
285 Elf32_Phdr *segments;
286 Elf32_Shdr *sections;
287
288 u32 *sectionAddrs;
289 bool bRelocate;
290 u32 entryPoint;
291
292public:
293 ElfReader(void *ptr);
294 ~ElfReader() { }
295
296 u32 Read32(int off) const { return base32[off >> 2]; }
297
298 // Quick accessors
299 ElfType GetType() const { return (ElfType)(header->e_type); }
300 ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); }
301 u32 GetEntryPoint() const { return entryPoint; }
302 u32 GetFlags() const { return (u32)(header->e_flags); }
303 bool LoadInto(u32 vaddr);
304 bool LoadSymbols();
305
306 int GetNumSegments() const { return (int)(header->e_phnum); }
307 int GetNumSections() const { return (int)(header->e_shnum); }
308 const u8 *GetPtr(int offset) const { return (u8*)base + offset; }
309 const char *GetSectionName(int section) const;
310 const u8 *GetSectionDataPtr(int section) const {
311 if (section < 0 || section >= header->e_shnum)
312 return nullptr;
313 if (sections[section].sh_type != SHT_NOBITS)
314 return GetPtr(sections[section].sh_offset);
315 else
316 return nullptr;
317 }
318 bool IsCodeSection(int section) const {
319 return sections[section].sh_type == SHT_PROGBITS;
320 }
321 const u8 *GetSegmentPtr(int segment) {
322 return GetPtr(segments[segment].p_offset);
323 }
324 u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; }
325 int GetSectionSize(SectionID section) const { return sections[section].sh_size; }
326 SectionID GetSectionByName(const char *name, int firstSection = 0) const; //-1 for not found
327
328 bool DidRelocate() {
329 return bRelocate;
330 }
281}; 331};
diff --git a/src/core/loader/elf_reader.cpp b/src/core/loader/elf_reader.cpp
deleted file mode 100644
index 123747f8e..000000000
--- a/src/core/loader/elf_reader.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <string>
6
7#include "common/common.h"
8
9#include "common/symbols.h"
10#include "core/mem_map.h"
11#include "core/loader/elf_reader.h"
12
13//void bswap(Elf32_Word &w) {w = Common::swap32(w);}
14//void bswap(Elf32_Half &w) {w = Common::swap16(w);}
15
16#define bswap(w) w // Dirty bswap disable for now... 3DS is little endian, anyway
17
18static void byteswapHeader(Elf32_Ehdr &ELF_H)
19{
20 bswap(ELF_H.e_type);
21 bswap(ELF_H.e_machine);
22 bswap(ELF_H.e_ehsize);
23 bswap(ELF_H.e_phentsize);
24 bswap(ELF_H.e_phnum);
25 bswap(ELF_H.e_shentsize);
26 bswap(ELF_H.e_shnum);
27 bswap(ELF_H.e_shstrndx);
28 bswap(ELF_H.e_version);
29 bswap(ELF_H.e_entry);
30 bswap(ELF_H.e_phoff);
31 bswap(ELF_H.e_shoff);
32 bswap(ELF_H.e_flags);
33}
34
35static void byteswapSegment(Elf32_Phdr &sec)
36{
37 bswap(sec.p_align);
38 bswap(sec.p_filesz);
39 bswap(sec.p_flags);
40 bswap(sec.p_memsz);
41 bswap(sec.p_offset);
42 bswap(sec.p_paddr);
43 bswap(sec.p_vaddr);
44 bswap(sec.p_type);
45}
46
47static void byteswapSection(Elf32_Shdr &sec)
48{
49 bswap(sec.sh_addr);
50 bswap(sec.sh_addralign);
51 bswap(sec.sh_entsize);
52 bswap(sec.sh_flags);
53 bswap(sec.sh_info);
54 bswap(sec.sh_link);
55 bswap(sec.sh_name);
56 bswap(sec.sh_offset);
57 bswap(sec.sh_size);
58 bswap(sec.sh_type);
59}
60
61ElfReader::ElfReader(void *ptr)
62{
63 base = (char*)ptr;
64 base32 = (u32 *)ptr;
65 header = (Elf32_Ehdr*)ptr;
66 byteswapHeader(*header);
67
68 segments = (Elf32_Phdr *)(base + header->e_phoff);
69 sections = (Elf32_Shdr *)(base + header->e_shoff);
70
71 entryPoint = header->e_entry;
72
73 LoadSymbols();
74}
75
76const char *ElfReader::GetSectionName(int section) const
77{
78 if (sections[section].sh_type == SHT_NULL)
79 return nullptr;
80
81 int nameOffset = sections[section].sh_name;
82 char *ptr = (char*)GetSectionDataPtr(header->e_shstrndx);
83
84 if (ptr)
85 return ptr + nameOffset;
86 else
87 return nullptr;
88}
89
90bool ElfReader::LoadInto(u32 vaddr)
91{
92 DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx);
93
94 // Should we relocate?
95 bRelocate = (header->e_type != ET_EXEC);
96
97 if (bRelocate)
98 {
99 DEBUG_LOG(MASTER_LOG,"Relocatable module");
100 entryPoint += vaddr;
101 }
102 else
103 {
104 DEBUG_LOG(MASTER_LOG,"Prerelocated executable");
105 }
106
107 INFO_LOG(MASTER_LOG,"%i segments:", header->e_phnum);
108
109 // First pass : Get the bits into RAM
110 u32 segmentVAddr[32];
111
112 u32 baseAddress = bRelocate?vaddr:0;
113
114 for (int i = 0; i < header->e_phnum; i++)
115 {
116 Elf32_Phdr *p = segments + i;
117
118 INFO_LOG(MASTER_LOG, "Type: %i Vaddr: %08x Filesz: %i Memsz: %i ", p->p_type, p->p_vaddr, p->p_filesz, p->p_memsz);
119
120 if (p->p_type == PT_LOAD)
121 {
122 segmentVAddr[i] = baseAddress + p->p_vaddr;
123 u32 writeAddr = segmentVAddr[i];
124
125 const u8 *src = GetSegmentPtr(i);
126 u8 *dst = Memory::GetPointer(writeAddr);
127 u32 srcSize = p->p_filesz;
128 u32 dstSize = p->p_memsz;
129 u32 *s = (u32*)src;
130 u32 *d = (u32*)dst;
131 for (int j = 0; j < (int)(srcSize + 3) / 4; j++)
132 {
133 *d++ = /*_byteswap_ulong*/(*s++);
134 }
135 if (srcSize < dstSize)
136 {
137 //memset(dst + srcSize, 0, dstSize-srcSize); //zero out bss
138 }
139 INFO_LOG(MASTER_LOG,"Loadable Segment Copied to %08x, size %08x", writeAddr, p->p_memsz);
140 }
141 }
142
143
144 INFO_LOG(MASTER_LOG,"Done loading.");
145 return true;
146}
147
148SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const
149{
150 for (int i = firstSection; i < header->e_shnum; i++)
151 {
152 const char *secname = GetSectionName(i);
153
154 if (secname != nullptr && strcmp(name, secname) == 0)
155 return i;
156 }
157 return -1;
158}
159
160bool ElfReader::LoadSymbols()
161{
162 bool hasSymbols = false;
163 SectionID sec = GetSectionByName(".symtab");
164 if (sec != -1)
165 {
166 int stringSection = sections[sec].sh_link;
167 const char *stringBase = (const char *)GetSectionDataPtr(stringSection);
168
169 //We have a symbol table!
170 Elf32_Sym *symtab = (Elf32_Sym *)(GetSectionDataPtr(sec));
171 int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
172 for (int sym = 0; sym < numSymbols; sym++)
173 {
174 int size = symtab[sym].st_size;
175 if (size == 0)
176 continue;
177
178 // int bind = symtab[sym].st_info >> 4;
179 int type = symtab[sym].st_info & 0xF;
180
181 const char *name = stringBase + symtab[sym].st_name;
182
183 Symbols::Add(symtab[sym].st_value, name, size, type);
184
185 hasSymbols = true;
186 }
187 }
188
189 return hasSymbols;
190}
diff --git a/src/core/loader/elf_reader.h b/src/core/loader/elf_reader.h
deleted file mode 100644
index 6f0ad84b3..000000000
--- a/src/core/loader/elf_reader.h
+++ /dev/null
@@ -1,75 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/loader/elf_types.h"
8
9enum KnownElfTypes
10{
11 KNOWNELF_PSP = 0,
12 KNOWNELF_DS = 1,
13 KNOWNELF_GBA = 2,
14 KNOWNELF_GC = 3,
15};
16
17typedef int SectionID;
18
19class ElfReader
20{
21private:
22 char *base;
23 u32 *base32;
24
25 Elf32_Ehdr *header;
26 Elf32_Phdr *segments;
27 Elf32_Shdr *sections;
28
29 u32 *sectionAddrs;
30 bool bRelocate;
31 u32 entryPoint;
32
33public:
34 ElfReader(void *ptr);
35 ~ElfReader() { }
36
37 u32 Read32(int off) const { return base32[off>>2]; }
38
39 // Quick accessors
40 ElfType GetType() const { return (ElfType)(header->e_type); }
41 ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); }
42 u32 GetEntryPoint() const { return entryPoint; }
43 u32 GetFlags() const { return (u32)(header->e_flags); }
44 bool LoadInto(u32 vaddr);
45 bool LoadSymbols();
46
47 int GetNumSegments() const { return (int)(header->e_phnum); }
48 int GetNumSections() const { return (int)(header->e_shnum); }
49 const u8 *GetPtr(int offset) const { return (u8*)base + offset; }
50 const char *GetSectionName(int section) const;
51 const u8 *GetSectionDataPtr(int section) const
52 {
53 if (section < 0 || section >= header->e_shnum)
54 return nullptr;
55 if (sections[section].sh_type != SHT_NOBITS)
56 return GetPtr(sections[section].sh_offset);
57 else
58 return nullptr;
59 }
60 bool IsCodeSection(int section) const
61 {
62 return sections[section].sh_type == SHT_PROGBITS;
63 }
64 const u8 *GetSegmentPtr(int segment)
65 {
66 return GetPtr(segments[segment].p_offset);
67 }
68 u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; }
69 int GetSectionSize(SectionID section) const { return sections[section].sh_size; }
70 SectionID GetSectionByName(const char *name, int firstSection = 0) const; //-1 for not found
71
72 bool DidRelocate() {
73 return bRelocate;
74 }
75};
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 41fa9c32e..d8060c0e6 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -6,7 +6,7 @@
6#include "common/file_util.h" 6#include "common/file_util.h"
7 7
8#include "core/loader/loader.h" 8#include "core/loader/loader.h"
9#include "core/loader/elf_reader.h" 9#include "core/loader/elf.h"
10#include "core/loader/ncch.h" 10#include "core/loader/ncch.h"
11#include "core/system.h" 11#include "core/system.h"
12#include "core/core.h" 12#include "core/core.h"