diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/elf/elf_reader.cpp | 76 |
1 files changed, 13 insertions, 63 deletions
diff --git a/src/core/elf/elf_reader.cpp b/src/core/elf/elf_reader.cpp index 2b03caa0f..c62332cec 100644 --- a/src/core/elf/elf_reader.cpp +++ b/src/core/elf/elf_reader.cpp | |||
| @@ -6,13 +6,10 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common.h" | 7 | #include "common/common.h" |
| 8 | 8 | ||
| 9 | #include "common/symbols.h" | ||
| 9 | #include "core/mem_map.h" | 10 | #include "core/mem_map.h" |
| 10 | #include "core/elf/elf_reader.h" | 11 | #include "core/elf/elf_reader.h" |
| 11 | 12 | ||
| 12 | //#include "Core/Debugger/Debugger_SymbolMap.h" | ||
| 13 | //#include "Core/HW/Memmap.h" | ||
| 14 | //#include "Core/PowerPC/PPCSymbolDB.h" | ||
| 15 | |||
| 16 | //void bswap(Elf32_Word &w) {w = Common::swap32(w);} | 13 | //void bswap(Elf32_Word &w) {w = Common::swap32(w);} |
| 17 | //void bswap(Elf32_Half &w) {w = Common::swap16(w);} | 14 | //void bswap(Elf32_Half &w) {w = Common::swap16(w);} |
| 18 | 15 | ||
| @@ -71,16 +68,9 @@ ElfReader::ElfReader(void *ptr) | |||
| 71 | segments = (Elf32_Phdr *)(base + header->e_phoff); | 68 | segments = (Elf32_Phdr *)(base + header->e_phoff); |
| 72 | sections = (Elf32_Shdr *)(base + header->e_shoff); | 69 | sections = (Elf32_Shdr *)(base + header->e_shoff); |
| 73 | 70 | ||
| 74 | //for (int i = 0; i < GetNumSegments(); i++) | ||
| 75 | //{ | ||
| 76 | // byteswapSegment(segments[i]); | ||
| 77 | //} | ||
| 78 | |||
| 79 | //for (int i = 0; i < GetNumSections(); i++) | ||
| 80 | //{ | ||
| 81 | // byteswapSection(sections[i]); | ||
| 82 | //} | ||
| 83 | entryPoint = header->e_entry; | 71 | entryPoint = header->e_entry; |
| 72 | |||
| 73 | LoadSymbols(); | ||
| 84 | } | 74 | } |
| 85 | 75 | ||
| 86 | const char *ElfReader::GetSectionName(int section) const | 76 | const char *ElfReader::GetSectionName(int section) const |
| @@ -101,9 +91,6 @@ bool ElfReader::LoadInto(u32 vaddr) | |||
| 101 | { | 91 | { |
| 102 | DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx); | 92 | DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx); |
| 103 | 93 | ||
| 104 | // sectionOffsets = new u32[GetNumSections()]; | ||
| 105 | // sectionAddrs = new u32[GetNumSections()]; | ||
| 106 | |||
| 107 | // Should we relocate? | 94 | // Should we relocate? |
| 108 | bRelocate = (header->e_type != ET_EXEC); | 95 | bRelocate = (header->e_type != ET_EXEC); |
| 109 | 96 | ||
| @@ -153,30 +140,8 @@ bool ElfReader::LoadInto(u32 vaddr) | |||
| 153 | } | 140 | } |
| 154 | } | 141 | } |
| 155 | 142 | ||
| 156 | /* | ||
| 157 | LOG(MASTER_LOG,"%i sections:", header->e_shnum); | ||
| 158 | |||
| 159 | for (int i=0; i<GetNumSections(); i++) | ||
| 160 | { | ||
| 161 | Elf32_Shdr *s = §ions[i]; | ||
| 162 | const char *name = GetSectionName(i); | ||
| 163 | 143 | ||
| 164 | u32 writeAddr = s->sh_addr + baseAddress; | 144 | INFO_LOG(MASTER_LOG,"Done loading."); |
| 165 | sectionOffsets[i] = writeAddr - vaddr; | ||
| 166 | sectionAddrs[i] = writeAddr; | ||
| 167 | |||
| 168 | if (s->sh_flags & SHF_ALLOC) | ||
| 169 | { | ||
| 170 | LOG(MASTER_LOG,"Data Section found: %s Sitting at %08x, size %08x", name, writeAddr, s->sh_size); | ||
| 171 | |||
| 172 | } | ||
| 173 | else | ||
| 174 | { | ||
| 175 | LOG(MASTER_LOG,"NonData Section found: %s Ignoring (size=%08x) (flags=%08x)", name, s->sh_size, s->sh_flags); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | */ | ||
| 179 | INFO_LOG(MASTER_LOG,"Done loading."); | ||
| 180 | return true; | 145 | return true; |
| 181 | } | 146 | } |
| 182 | 147 | ||
| @@ -192,8 +157,6 @@ SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const | |||
| 192 | return -1; | 157 | return -1; |
| 193 | } | 158 | } |
| 194 | 159 | ||
| 195 | /* TODO(bunnei): The following is verbatim from Dolphin - needs to be updated for this project: | ||
| 196 | |||
| 197 | bool ElfReader::LoadSymbols() | 160 | bool ElfReader::LoadSymbols() |
| 198 | { | 161 | { |
| 199 | bool hasSymbols = false; | 162 | bool hasSymbols = false; |
| @@ -208,33 +171,20 @@ bool ElfReader::LoadSymbols() | |||
| 208 | int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym); | 171 | int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym); |
| 209 | for (int sym = 0; sym < numSymbols; sym++) | 172 | for (int sym = 0; sym < numSymbols; sym++) |
| 210 | { | 173 | { |
| 211 | int size = Common::swap32(symtab[sym].st_size); | 174 | int size = symtab[sym].st_size; |
| 212 | if (size == 0) | 175 | if (size == 0) |
| 213 | continue; | 176 | continue; |
| 214 | 177 | ||
| 215 | // int bind = symtab[sym].st_info >> 4; | 178 | // int bind = symtab[sym].st_info >> 4; |
| 216 | int type = symtab[sym].st_info & 0xF; | 179 | int type = symtab[sym].st_info & 0xF; |
| 217 | int sectionIndex = Common::swap16(symtab[sym].st_shndx); | 180 | |
| 218 | int value = Common::swap32(symtab[sym].st_value); | 181 | const char *name = stringBase + symtab[sym].st_name; |
| 219 | const char *name = stringBase + Common::swap32(symtab[sym].st_name); | 182 | |
| 220 | if (bRelocate) | 183 | Symbols::Add(symtab[sym].st_value, name, size, type); |
| 221 | value += sectionAddrs[sectionIndex]; | 184 | |
| 222 | 185 | hasSymbols = true; | |
| 223 | int symtype = Symbol::SYMBOL_DATA; | ||
| 224 | switch (type) | ||
| 225 | { | ||
| 226 | case STT_OBJECT: | ||
| 227 | symtype = Symbol::SYMBOL_DATA; break; | ||
| 228 | case STT_FUNC: | ||
| 229 | symtype = Symbol::SYMBOL_FUNCTION; break; | ||
| 230 | default: | ||
| 231 | continue; | ||
| 232 | } | ||
| 233 | g_symbolDB.AddKnownSymbol(value, size, name, symtype); | ||
| 234 | hasSymbols = true; | ||
| 235 | } | 186 | } |
| 236 | } | 187 | } |
| 237 | g_symbolDB.Index(); | 188 | |
| 238 | return hasSymbols; | 189 | return hasSymbols; |
| 239 | } | 190 | } |
| 240 | */ | ||