aboutsummaryrefslogtreecommitdiff
path: root/backends/plugins
diff options
context:
space:
mode:
authorAndre Heider2010-09-05 12:39:28 +0000
committerAndre Heider2010-09-05 12:39:28 +0000
commit5986aa96f2d8f06c1a54be614f483712e7d4d8f0 (patch)
treefc24526bf3269ad7afd12bb6ded873f9157bd76b /backends/plugins
parentc5a189f4d5f5a9f94b7e063077ba0ee5aaf1a788 (diff)
downloadscummvm-rg350-5986aa96f2d8f06c1a54be614f483712e7d4d8f0.tar.gz
scummvm-rg350-5986aa96f2d8f06c1a54be614f483712e7d4d8f0.tar.bz2
scummvm-rg350-5986aa96f2d8f06c1a54be614f483712e7d4d8f0.zip
PLUGINS: Formatting.
svn-id: r52552
Diffstat (limited to 'backends/plugins')
-rw-r--r--backends/plugins/arm-loader.cpp29
-rw-r--r--backends/plugins/arm-loader.h6
-rw-r--r--backends/plugins/dynamic-plugin.h1
-rw-r--r--backends/plugins/elf-loader.cpp30
-rw-r--r--backends/plugins/elf-loader.h45
-rw-r--r--backends/plugins/elf-provider.cpp37
-rw-r--r--backends/plugins/elf-provider.h2
-rw-r--r--backends/plugins/elf32.h28
-rw-r--r--backends/plugins/mips-loader.cpp63
-rw-r--r--backends/plugins/mips-loader.h10
-rw-r--r--backends/plugins/ps2/ps2-provider.h2
-rw-r--r--backends/plugins/shorts-segment-manager.cpp5
12 files changed, 120 insertions, 138 deletions
diff --git a/backends/plugins/arm-loader.cpp b/backends/plugins/arm-loader.cpp
index e2aa8e9fe1..5c71c7e433 100644
--- a/backends/plugins/arm-loader.cpp
+++ b/backends/plugins/arm-loader.cpp
@@ -33,10 +33,10 @@
/**
* Follow the instruction of a relocation section.
*
- * @param DLFile SeekableReadStream of File
- * @param offset Offset into the File
- * @param size Size of relocation section
- *
+ * @param DLFile SeekableReadStream of File
+ * @param fileOffset Offset into the File
+ * @param size Size of relocation section
+ * @param relSegment Base address of relocated segment in memory (memory offset)
*/
bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) {
Elf32_Rel *rel = 0; //relocation entry
@@ -48,8 +48,8 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
}
// Read in our relocation table
- if (DLFile->seek(offset, SEEK_SET) < 0 ||
- DLFile->read(rel, size) != size) {
+ if (!DLFile->seek(offset, SEEK_SET) ||
+ DLFile->read(rel, size) != size) {
warning("elfloader: Relocation table load failed.");
free(rel);
return false;
@@ -65,7 +65,6 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
// Loop over relocation entries
for (int i = 0; i < cnt; i++) {
-
// Get the symbol this relocation entry is referring to
Elf32_Sym *sym = (Elf32_Sym *)(_symtab) + (REL_INDEX(rel[i].r_info));
@@ -76,7 +75,6 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
// Act differently based on the type of relocation
switch (REL_TYPE(rel[i].r_info)) {
-
case R_ARM_ABS32:
if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section.
a = *target; // Get full 32 bits of addend
@@ -109,7 +107,6 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
free(rel);
return false;
}
-
}
free(rel);
@@ -117,27 +114,23 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
}
bool ARMDLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
-
// Loop over sections, finding relocation sections
for (int i = 0; i < ehdr->e_shnum; i++) {
-
Elf32_Shdr *curShdr = &(shdr[i]);
if ((curShdr->sh_type == SHT_REL || curShdr->sh_type == SHT_RELA) && // Check for a relocation section
- curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
- (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table
- curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists
- (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory
+ curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
+ (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table
+ curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists
+ (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory
if (curShdr->sh_type == SHT_RELA) {
warning("elfloader: RELA entries not supported yet!");
return false;
}
- if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) {
+ if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment))
return false;
- }
-
}
}
diff --git a/backends/plugins/arm-loader.h b/backends/plugins/arm-loader.h
index c0ad94ef43..24290d5c6d 100644
--- a/backends/plugins/arm-loader.h
+++ b/backends/plugins/arm-loader.h
@@ -29,11 +29,11 @@
class ARMDLObject : public DLObject {
protected:
- bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
- bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+ virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
+ virtual bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
public:
- ARMDLObject() : DLObject() {}
+ ARMDLObject() : DLObject() {}
};
#endif /* defined(DYNAMIC_MODULES) && defined(ARM_TARGET) */
diff --git a/backends/plugins/dynamic-plugin.h b/backends/plugins/dynamic-plugin.h
index ec051c4ed7..970ac3531d 100644
--- a/backends/plugins/dynamic-plugin.h
+++ b/backends/plugins/dynamic-plugin.h
@@ -28,7 +28,6 @@
#include "base/plugins.h"
-
class DynamicPlugin : public Plugin {
protected:
typedef int32 (*IntFunc)();
diff --git a/backends/plugins/elf-loader.cpp b/backends/plugins/elf-loader.cpp
index 406f99913e..478ec564bf 100644
--- a/backends/plugins/elf-loader.cpp
+++ b/backends/plugins/elf-loader.cpp
@@ -156,7 +156,7 @@ bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehd
bool DLObject::readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) {
// Read program header
if (!DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) ||
- DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) {
+ DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) {
warning("elfloader: Program header load failed.");
return false;
}
@@ -201,7 +201,7 @@ bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr)
// Read the segment into memory
if (!DLFile->seek(phdr->p_offset, SEEK_SET) ||
- DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
+ DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
warning("elfloader: Segment load failed.");
return false;
}
@@ -222,8 +222,8 @@ Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, El
// Read from file into section headers
if (!DLFile->seek(ehdr->e_shoff, SEEK_SET) ||
- DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) !=
- ehdr->e_shnum * sizeof(*shdr)) {
+ DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) !=
+ ehdr->e_shnum * sizeof(*shdr)) {
warning("elfloader: Section headers load failed.");
return 0;
}
@@ -235,10 +235,10 @@ int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *eh
// Loop over sections, looking for symbol table linked to a string table
for (int i = 0; i < ehdr->e_shnum; i++) {
if (shdr[i].sh_type == SHT_SYMTAB &&
- shdr[i].sh_entsize == sizeof(Elf32_Sym) &&
- shdr[i].sh_link < ehdr->e_shnum &&
- shdr[shdr[i].sh_link].sh_type == SHT_STRTAB &&
- _symtab_sect < 0) {
+ shdr[i].sh_entsize == sizeof(Elf32_Sym) &&
+ shdr[i].sh_link < ehdr->e_shnum &&
+ shdr[shdr[i].sh_link].sh_type == SHT_STRTAB &&
+ _symtab_sect < 0) {
_symtab_sect = i;
}
}
@@ -259,8 +259,8 @@ int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *eh
// Read symbol table into memory
if (!DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) ||
- DLFile->read(_symtab, shdr[_symtab_sect].sh_size) !=
- shdr[_symtab_sect].sh_size) {
+ DLFile->read(_symtab, shdr[_symtab_sect].sh_size) !=
+ shdr[_symtab_sect].sh_size) {
warning("elfloader: Symbol table load failed.");
return -1;
}
@@ -283,8 +283,8 @@ bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *s
// Read string table into memory
if (!DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) ||
- DLFile->read(_strtab, shdr[string_sect].sh_size) !=
- shdr[string_sect].sh_size) {
+ DLFile->read(_strtab, shdr[string_sect].sh_size) !=
+ shdr[string_sect].sh_size) {
warning("elfloader: Symbol table strings load failed.");
return false;
}
@@ -414,9 +414,9 @@ void *DLObject::symbol(const char *name) {
Elf32_Sym *s = (Elf32_Sym *)_symtab;
for (int c = _symbol_cnt; c--; s++)
// We can only import symbols that are global or weak in the plugin
- if ((SYM_BIND(s->st_info) == STB_GLOBAL || SYM_BIND(s->st_info) == STB_WEAK) &&
- !strcmp(name, _strtab + s->st_name)) {
-
+ if ((SYM_BIND(s->st_info) == STB_GLOBAL ||
+ SYM_BIND(s->st_info) == STB_WEAK) &&
+ !strcmp(name, _strtab + s->st_name)) {
// We found the symbol
debug(2, "elfloader: => %p", (void*)s->st_value);
return (void*)s->st_value;
diff --git a/backends/plugins/elf-loader.h b/backends/plugins/elf-loader.h
index 8d974eccb7..c1dd39a52e 100644
--- a/backends/plugins/elf-loader.h
+++ b/backends/plugins/elf-loader.h
@@ -44,36 +44,37 @@
*/
class DLObject {
protected:
- void *_segment, *_symtab;
- char *_strtab;
- int _symbol_cnt;
- int _symtab_sect;
- void *_dtors_start, *_dtors_end;
+ void *_segment, *_symtab;
+ char *_strtab;
+ int _symbol_cnt;
+ int _symtab_sect;
+ void *_dtors_start, *_dtors_end;
- uint32 _segmentSize;
+ uint32 _segmentSize;
ptrdiff_t _segmentOffset;
- virtual void unload();
- virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) = 0;
- bool load(Common::SeekableReadStream* DLFile);
+ virtual void unload();
+ bool load(Common::SeekableReadStream* DLFile);
- bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr);
- bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num);
- virtual bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr);
- Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr);
- int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
- bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr);
- virtual void relocateSymbols(ptrdiff_t offset);
- virtual bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) = 0;
+ bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr);
+ bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num);
+ virtual bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr);
+ Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr);
+ int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+ bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr);
+ virtual void relocateSymbols(ptrdiff_t offset);
-public:
- bool open(const char *path);
- bool close();
- void *symbol(const char *name);
- void discard_symtab();
+ virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) = 0;
+ virtual bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) = 0;
+public:
DLObject();
virtual ~DLObject();
+
+ bool open(const char *path);
+ bool close();
+ void *symbol(const char *name);
+ void discard_symtab();
};
#endif /* ELF_LOADER_H */
diff --git a/backends/plugins/elf-provider.cpp b/backends/plugins/elf-provider.cpp
index 00d93fcd34..997a43b653 100644
--- a/backends/plugins/elf-provider.cpp
+++ b/backends/plugins/elf-provider.cpp
@@ -54,27 +54,26 @@ DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
}
bool ELFPlugin::loadPlugin() {
- assert(!_dlHandle);
- DLObject *obj = makeDLObject();
- if (obj->open(_filename.c_str())) {
- _dlHandle = obj;
- } else {
- delete obj;
- _dlHandle = 0;
- }
+ assert(!_dlHandle);
+ DLObject *obj = makeDLObject();
+ if (obj->open(_filename.c_str())) {
+ _dlHandle = obj;
+ } else {
+ delete obj;
+ _dlHandle = 0;
+ }
- if (!_dlHandle) {
- warning("elfloader: Failed loading plugin '%s'", _filename.c_str());
- return false;
- }
+ if (!_dlHandle) {
+ warning("elfloader: Failed loading plugin '%s'", _filename.c_str());
+ return false;
+ }
- bool ret = DynamicPlugin::loadPlugin();
+ bool ret = DynamicPlugin::loadPlugin();
- if (ret && _dlHandle) {
- _dlHandle->discard_symtab();
- }
+ if (ret && _dlHandle)
+ _dlHandle->discard_symtab();
- return ret;
+ return ret;
}
void ELFPlugin::unloadPlugin() {
@@ -91,9 +90,9 @@ void ELFPlugin::unloadPlugin() {
bool ELFPluginProvider::isPluginFilename(const Common::FSNode &node) const {
// Check the plugin suffix
Common::String filename = node.getName();
- if (!filename.hasSuffix(".PLG") && !filename.hasSuffix(".plg") && !filename.hasSuffix(".PLUGIN") && !filename.hasSuffix(".plugin")) {
+ if (!filename.hasSuffix(".PLG") && !filename.hasSuffix(".plg") && !filename.hasSuffix(".PLUGIN") && !filename.hasSuffix(".plugin"))
return false;
- }
+
return true;
}
diff --git a/backends/plugins/elf-provider.h b/backends/plugins/elf-provider.h
index f6cede0219..df9c503674 100644
--- a/backends/plugins/elf-provider.h
+++ b/backends/plugins/elf-provider.h
@@ -61,7 +61,6 @@ public:
bool loadPlugin();
void unloadPlugin();
-
};
class ELFPluginProvider : public FilePluginProvider {
@@ -69,7 +68,6 @@ protected:
virtual Plugin* createPlugin(const Common::FSNode &node) const = 0;
bool isPluginFilename(const Common::FSNode &node) const;
-
};
#endif /* BACKENDS_PLUGINS_ELF_PROVIDER_H */
diff --git a/backends/plugins/elf32.h b/backends/plugins/elf32.h
index f18f4090a2..9d69a7128e 100644
--- a/backends/plugins/elf32.h
+++ b/backends/plugins/elf32.h
@@ -61,7 +61,7 @@ typedef struct {
} Elf32_Ehdr;
// Should be in e_ident
-#define ELFMAG "\177ELF" /* ELF Magic number */
+#define ELFMAG "\177ELF" /* ELF Magic number */
#define EI_CLASS 4 /* File class byte index */
#define ELFCLASS32 1 /* 32-bit objects */
@@ -129,7 +129,7 @@ typedef struct {
// sh_type values
#define SHT_NULL 0 /* Inactive section */
-#define SHT_PROGBITS 1 /* Proprietary */
+#define SHT_PROGBITS 1 /* Proprietary */
#define SHT_SYMTAB 2 /* Symbol table */
#define SHT_STRTAB 3 /* String table */
#define SHT_RELA 4 /* Relocation entries with addend */
@@ -143,9 +143,9 @@ typedef struct {
#define SHT_MIPS_LIBLSIT 0x70000000 /* Info about dynamic shared object libs for MIPS*/
#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicts btw executables and shared objects for MIPS */
#define SHT_MIPS_GPTAB 0x70000003 /* Global pointer table for MIPS*/
-#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table for ARM*/
-#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map for ARM */
-#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes for ARM*/
+#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table for ARM*/
+#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map for ARM */
+#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes for ARM*/
// sh_flags values
#define SHF_WRITE 0 /* writable section */
@@ -168,8 +168,8 @@ typedef struct {
#define SYM_BIND(x) ((x)>>4)
// Symbol binding values from st_info
-#define STB_LOCAL 0 /* Symbol not visible outside object */
-#define STB_GLOBAL 1 /* Symbol visible to all object files */
+#define STB_LOCAL 0 /* Symbol not visible outside object */
+#define STB_GLOBAL 1 /* Symbol visible to all object files */
#define STB_WEAK 2 /* Similar to STB_GLOBAL */
// Symbol type values from st_info
@@ -180,12 +180,12 @@ typedef struct {
#define STT_FILE 4 /* Source file associated with object file */
// Special section header index values from st_shndex
-#define SHN_UNDEF 0
-#define SHN_LOPROC 0xFF00 /* Extended values */
-#define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */
-#define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */
-#define SHN_HIPROC 0xFF1F
-#define SHN_HIRESERVE 0xFFFF
+#define SHN_UNDEF 0
+#define SHN_LOPROC 0xFF00 /* Extended values */
+#define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */
+#define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */
+#define SHN_HIPROC 0xFF1F
+#define SHN_HIRESERVE 0xFFFF
// Relocation entry with implicit addend (info about how to relocate)
typedef struct {
@@ -227,7 +227,7 @@ typedef struct
// ARM relocation types
#define R_ARM_NONE 0
#define R_ARM_ABS32 2
-#define R_ARM_THM_CALL 10
+#define R_ARM_THM_CALL 10
#define R_ARM_CALL 28
#define R_ARM_JUMP24 29
#define R_ARM_TARGET1 38
diff --git a/backends/plugins/mips-loader.cpp b/backends/plugins/mips-loader.cpp
index 5a0db74041..729c8f4224 100644
--- a/backends/plugins/mips-loader.cpp
+++ b/backends/plugins/mips-loader.cpp
@@ -32,11 +32,10 @@
/**
* Follow the instruction of a relocation section.
*
- * @param DLFile SeekableReadStream of File
- * @param offset Offset into the File
- * @param size Size of relocation section
- * @param relSegment Base address of relocated segment in memory (memory offset)
- *
+ * @param DLFile SeekableReadStream of File
+ * @param fileOffset Offset into the File
+ * @param size Size of relocation section
+ * @param relSegment Base address of relocated segment in memory (memory offset)
*/
bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) {
Elf32_Rel *rel = 0; // relocation entry
@@ -49,7 +48,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
// Read in our relocation table
if (!DLFile->seek(offset, SEEK_SET) ||
- DLFile->read(rel, size) != size) {
+ DLFile->read(rel, size) != size) {
warning("elfloader: Relocation table load failed.");
free(rel);
return false;
@@ -86,10 +85,9 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
// Act differently based on the type of relocation
switch (REL_TYPE(rel[i].r_info)) {
-
case R_MIPS_HI16: // Absolute addressing.
if (sym->st_shndx < SHN_LOPROC && // Only shift for plugin section (ie. has a real section index)
- firstHi16 < 0) { // Only process first in block of HI16s
+ firstHi16 < 0) { // Only process first in block of HI16s
firstHi16 = i; // Keep the first Hi16 we saw
seenHi16 = true;
ahl = (*target & 0xffff) << 16; // Take lower 16 bits shifted up
@@ -98,7 +96,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
hi16InShorts = (ShortsMan.inGeneralSegment((char *)sym->st_value)); // Fix for problem with switching btw segments
if (debugRelocs[0]++ < DEBUG_NUM) // Print only a set number
debug(8, "elfloader: R_MIPS_HI16: i=%d, offset=%x, ahl = %x, target = %x",
- i, rel[i].r_offset, ahl, *target);
+ i, rel[i].r_offset, ahl, *target);
}
break;
@@ -127,9 +125,9 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
ahl += a; // Add lower 16 bits. AHL is now complete
// Fix: we can have LO16 access to the short segment sometimes
- if (lo16InShorts) {
+ if (lo16InShorts)
relocation = ahl + _shortsSegment->getOffset(); // Add in the short segment offset
- } else // It's in the regular segment
+ else // It's in the regular segment
relocation = ahl + (Elf32_Addr)_segment; // Add in the new offset for the segment
if (firstHi16 >= 0) { // We haven't treated the HI16s yet so do it now
@@ -139,7 +137,8 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
lastTarget = (unsigned int *)((char *)relSegment + rel[j].r_offset); // get hi16 target
*lastTarget &= 0xffff0000; // Clear the lower 16 bits of the last target
*lastTarget |= (relocation >> 16) & 0xffff; // Take the upper 16 bits of the relocation
- if (relocation & 0x8000)(*lastTarget)++; // Subtle: we need to add 1 to the HI16 in this case
+ if (relocation & 0x8000)
+ (*lastTarget)++; // Subtle: we need to add 1 to the HI16 in this case
}
firstHi16 = -1; // Reset so we'll know we treated it
} else {
@@ -151,10 +150,10 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
if (debugRelocs[1]++ < DEBUG_NUM)
debug(8, "elfloader: R_MIPS_LO16: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x",
- i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
+ i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
if (lo16InShorts && debugRelocs[2]++ < DEBUG_NUM)
debug(8, "elfloader: R_MIPS_LO16s: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x",
- i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
+ i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
}
break;
@@ -168,17 +167,17 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
if (debugRelocs[3]++ < DEBUG_NUM)
debug(8, "elfloader: R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x",
- i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
+ i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
} else {
if (debugRelocs[4]++ < DEBUG_NUM)
debug(8, "elfloader: R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x",
- i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
+ i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
}
break;
case R_MIPS_GPREL16: // GP Relative addressing
if (_shortsSegment->getOffset() != 0 && // Only relocate if we shift the shorts section
- ShortsMan.inGeneralSegment((char *)sym->st_value)) { // Only relocate things in the plugin hole
+ ShortsMan.inGeneralSegment((char *)sym->st_value)) { // Only relocate things in the plugin hole
a = *target & 0xffff; // Get 16 bits' worth of the addend
a = (a << 16) >> 16; // Sign extend it
@@ -189,7 +188,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
if (debugRelocs[5]++ < DEBUG_NUM)
debug(8, "elfloader: R_MIPS_GPREL16: i=%d, a=%x, gpVal=%x, origTarget=%x, target=%x, offset=%x",
- i, a, _gpVal, origTarget, *target, _shortsSegment->getOffset());
+ i, a, _gpVal, origTarget, *target, _shortsSegment->getOffset());
}
break;
@@ -223,7 +222,6 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
}
bool MIPSDLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
-
// Loop over sections, finding relocation sections
for (int i = 0; i < ehdr->e_shnum; i++) {
@@ -231,20 +229,17 @@ bool MIPSDLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *
//Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]);
if (curShdr->sh_type == SHT_REL && // Check for a relocation section
- curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
- (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table
- curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists
- (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory
+ curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
+ (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table
+ curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists
+ (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory
if (!ShortsMan.inGeneralSegment((char *)shdr[curShdr->sh_info].sh_addr)) { // regular segment
- if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) {
+ if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment))
return false;
- }
} else { // In Shorts segment
- if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, (void *)_shortsSegment->getOffset())) {
+ if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, (void *)_shortsSegment->getOffset()))
return false;
- }
}
-
}
}
@@ -252,14 +247,12 @@ bool MIPSDLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *
}
void MIPSDLObject::relocateSymbols(Elf32_Addr offset) {
-
int mainCount = 0;
int shortsCount= 0;
// Loop over symbols, add relocation offset
Elf32_Sym *s = (Elf32_Sym *)_symtab;
for (int c = _symbol_cnt; c--; s++) {
-
// Make sure we don't relocate special valued symbols
if (s->st_shndx < SHN_LOPROC) {
if (!ShortsMan.inGeneralSegment((char *)s->st_value)) {
@@ -273,23 +266,21 @@ void MIPSDLObject::relocateSymbols(Elf32_Addr offset) {
if (!_shortsSegment->inSegment((char *)s->st_value))
warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
}
-
}
}
}
bool MIPSDLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) {
-
char *baseAddress = 0;
// We need to take account of non-allocated segment for shorts
if (phdr->p_flags & PF_X) { // This is a relocated segment
-
// Attempt to allocate memory for segment
int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
debug(2, "elfloader: Extra mem is %x", extra);
- if (phdr->p_align < 0x10000) phdr->p_align = 0x10000; // Fix for wrong alignment on e.g. AGI
+ if (phdr->p_align < 0x10000)
+ phdr->p_align = 0x10000; // Fix for wrong alignment on e.g. AGI
if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) {
warning("elfloader: Out of memory.");
@@ -305,7 +296,7 @@ bool MIPSDLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *p
baseAddress = _shortsSegment->getStart();
debug(2, "elfloader: Shorts segment @ %p to %p. Segment wants to be at %x. Offset=%x",
- _shortsSegment->getStart(), _shortsSegment->getEnd(), phdr->p_vaddr, _shortsSegment->getOffset());
+ _shortsSegment->getStart(), _shortsSegment->getEnd(), phdr->p_vaddr, _shortsSegment->getOffset());
}
// Set bss segment to 0 if necessary (assumes bss is at the end)
@@ -318,7 +309,7 @@ bool MIPSDLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *p
// Read the segment into memory
if (!DLFile->seek(phdr->p_offset, SEEK_SET) ||
- DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
+ DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
warning("elfloader: Segment load failed.");
return false;
}
diff --git a/backends/plugins/mips-loader.h b/backends/plugins/mips-loader.h
index 90e0bf92b2..98bda5263f 100644
--- a/backends/plugins/mips-loader.h
+++ b/backends/plugins/mips-loader.h
@@ -34,11 +34,11 @@ protected:
ShortSegmentManager::Segment *_shortsSegment; // For assigning shorts ranges
unsigned int _gpVal; // Value of Global Pointer
- bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
- bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
- void relocateSymbols(Elf32_Addr offset);
- bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr);
- void unload();
+ virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
+ virtual bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+ virtual void relocateSymbols(Elf32_Addr offset);
+ virtual bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr);
+ virtual void unload();
public:
MIPSDLObject() : DLObject() {
diff --git a/backends/plugins/ps2/ps2-provider.h b/backends/plugins/ps2/ps2-provider.h
index dfadfffc29..809b88920a 100644
--- a/backends/plugins/ps2/ps2-provider.h
+++ b/backends/plugins/ps2/ps2-provider.h
@@ -37,7 +37,7 @@ class PS2PluginProvider : public ELFPluginProvider {
};
public:
- Plugin* PS2PluginProvider::createPlugin(const Common::FSNode &node) const {
+ Plugin* createPlugin(const Common::FSNode &node) const {
return new PS2Plugin(node.getPath());
}
};
diff --git a/backends/plugins/shorts-segment-manager.cpp b/backends/plugins/shorts-segment-manager.cpp
index dfb3f9093a..17af17aa45 100644
--- a/backends/plugins/shorts-segment-manager.cpp
+++ b/backends/plugins/shorts-segment-manager.cpp
@@ -64,12 +64,13 @@ ShortSegmentManager::Segment *ShortSegmentManager::newSegment(int size, char *or
Segment *seg = new Segment(lastAddress, size, origAddr); // Create a new segment
- if (lastAddress + size > _highestAddress) _highestAddress = lastAddress + size; // Keep track of maximum
+ if (lastAddress + size > _highestAddress)
+ _highestAddress = lastAddress + size; // Keep track of maximum
_list.insert(i, seg);
debug(2, "elfloader: Shorts segment size %x allocated. End = %p. Remaining space = %x. Highest so far is %p.",
- size, lastAddress + size, _shortsEnd - _list.back()->getEnd(), _highestAddress);
+ size, lastAddress + size, _shortsEnd - _list.back()->getEnd(), _highestAddress);
return seg;
}