aboutsummaryrefslogtreecommitdiff
path: root/backends/plugins
diff options
context:
space:
mode:
authorAndre Heider2010-09-05 21:58:45 +0000
committerAndre Heider2010-09-05 21:58:45 +0000
commitd8b85ffcb8a10b1e81a18d3e37a07d9d57d502ad (patch)
tree13af8d86082de6124c2adcc4dcea84ae5d61f621 /backends/plugins
parent284b23092b8f6215d88b31af7ba7f67a58c365cc (diff)
downloadscummvm-rg350-d8b85ffcb8a10b1e81a18d3e37a07d9d57d502ad.tar.gz
scummvm-rg350-d8b85ffcb8a10b1e81a18d3e37a07d9d57d502ad.tar.bz2
scummvm-rg350-d8b85ffcb8a10b1e81a18d3e37a07d9d57d502ad.zip
PLUGINS: Formatting.
Misformatted casts in an earier commit, oops. svn-id: r52572
Diffstat (limited to 'backends/plugins')
-rw-r--r--backends/plugins/ds/plugin.ld3
-rw-r--r--backends/plugins/elf/arm-loader.cpp6
-rw-r--r--backends/plugins/elf/arm-loader.h4
-rw-r--r--backends/plugins/elf/elf-loader.cpp20
-rw-r--r--backends/plugins/elf/elf-loader.h2
-rw-r--r--backends/plugins/elf/elf-provider.cpp10
-rw-r--r--backends/plugins/elf/elf-provider.h8
-rw-r--r--backends/plugins/elf/elf32.h173
-rw-r--r--backends/plugins/elf/mips-loader.cpp99
-rw-r--r--backends/plugins/elf/mips-loader.h7
-rw-r--r--backends/plugins/elf/ppc-loader.cpp12
-rw-r--r--backends/plugins/elf/ppc-loader.h4
-rw-r--r--backends/plugins/elf/shorts-segment-manager.cpp4
-rw-r--r--backends/plugins/ps2/plugin.ld2
-rw-r--r--backends/plugins/psp/plugin.ld7
15 files changed, 192 insertions, 169 deletions
diff --git a/backends/plugins/ds/plugin.ld b/backends/plugins/ds/plugin.ld
index 2b2bca9745..04035b0169 100644
--- a/backends/plugins/ds/plugin.ld
+++ b/backends/plugins/ds/plugin.ld
@@ -1,5 +1,4 @@
-OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
- "elf32-littlearm")
+OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
/* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */
diff --git a/backends/plugins/elf/arm-loader.cpp b/backends/plugins/elf/arm-loader.cpp
index 7534cb1d44..6aac5b5e78 100644
--- a/backends/plugins/elf/arm-loader.cpp
+++ b/backends/plugins/elf/arm-loader.cpp
@@ -41,7 +41,7 @@ bool ARMDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
Elf32_Rel *rel = 0; //relocation entry
// Allocate memory for relocation table
- if (!(rel = (Elf32_Rel *) malloc(size))) {
+ if (!(rel = (Elf32_Rel *)malloc(size))) {
warning("elfloader: Out of memory.");
return false;
}
@@ -67,7 +67,7 @@ bool ARMDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
Elf32_Sym *sym = _symtab + (REL_INDEX(rel[i].r_info));
// Get the target instruction in the code
- uint32 *target = (uint32 *) ((byte *) relSegment + rel[i].r_offset);
+ uint32 *target = (uint32 *)((byte *)relSegment + rel[i].r_offset);
uint32 origTarget = *target; //Save for debugging
@@ -120,7 +120,7 @@ bool ARMDLObject::relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
int32(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
+ (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!");
diff --git a/backends/plugins/elf/arm-loader.h b/backends/plugins/elf/arm-loader.h
index 3a3894d041..acc05cb143 100644
--- a/backends/plugins/elf/arm-loader.h
+++ b/backends/plugins/elf/arm-loader.h
@@ -36,7 +36,9 @@ protected:
virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
public:
- ARMDLObject() : DLObject() {}
+ ARMDLObject() :
+ DLObject() {
+ }
};
#endif /* BACKENDS_PLUGINS_ARM_LOADER_H */
diff --git a/backends/plugins/elf/elf-loader.cpp b/backends/plugins/elf/elf-loader.cpp
index 0503f81c42..df2bc98fb7 100644
--- a/backends/plugins/elf/elf-loader.cpp
+++ b/backends/plugins/elf/elf-loader.cpp
@@ -156,7 +156,7 @@ bool DLObject::loadSegment(Elf32_Phdr *phdr) {
uint32 extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
debug(2, "elfloader: Extra mem is %x", extra);
- _segment = (byte *) allocSegment(phdr->p_align, phdr->p_memsz + extra);
+ _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
if (!_segment) {
warning("elfloader: Out of memory.");
@@ -171,7 +171,8 @@ bool DLObject::loadSegment(Elf32_Phdr *phdr) {
// Set bss segment to 0 if necessary (assumes bss is at the end)
if (phdr->p_memsz > phdr->p_filesz) {
- debug(2, "elfloader: Setting %p to %p to 0 for bss", _segment + phdr->p_filesz, _segment + phdr->p_memsz);
+ debug(2, "elfloader: Setting %p to %p to 0 for bss",
+ _segment + phdr->p_filesz, _segment + phdr->p_memsz);
memset(_segment + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
}
@@ -195,7 +196,7 @@ Elf32_Shdr * DLObject::loadSectionHeaders(Elf32_Ehdr *ehdr) {
Elf32_Shdr *shdr = 0;
// Allocate memory for section headers
- if (!(shdr = (Elf32_Shdr *) malloc(ehdr->e_shnum * sizeof(*shdr)))) {
+ if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) {
warning("elfloader: Out of memory.");
return 0;
}
@@ -231,10 +232,11 @@ int DLObject::loadSymbolTable(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
return -1;
}
- debug(2, "elfloader: Symbol section at section %d, size %x", _symtab_sect, shdr[_symtab_sect].sh_size);
+ debug(2, "elfloader: Symbol section at section %d, size %x",
+ _symtab_sect, shdr[_symtab_sect].sh_size);
// Allocate memory for symbol table
- if (!(_symtab = (Elf32_Sym *) malloc(shdr[_symtab_sect].sh_size))) {
+ if (!(_symtab = (Elf32_Sym *)malloc(shdr[_symtab_sect].sh_size))) {
warning("elfloader: Out of memory.");
return -1;
}
@@ -260,7 +262,7 @@ bool DLObject::loadStringTable(Elf32_Shdr *shdr) {
uint32 string_sect = shdr[_symtab_sect].sh_link;
// Allocate memory for string table
- if (!(_strtab = (char *) malloc(shdr[string_sect].sh_size))) {
+ if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) {
warning("elfloader: Out of memory.");
return false;
}
@@ -284,7 +286,9 @@ void DLObject::relocateSymbols(ptrdiff_t offset) {
// Make sure we don't relocate special valued symbols
if (s->st_shndx < SHN_LOPROC) {
s->st_value += offset;
- if (s->st_value < Elf32_Addr(_segment) || s->st_value > Elf32_Addr(_segment) + _segmentSize)
+
+ if (s->st_value < Elf32_Addr(_segment) ||
+ s->st_value > Elf32_Addr(_segment) + _segmentSize)
warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
}
}
@@ -407,7 +411,7 @@ void *DLObject::symbol(const char *name) {
!strcmp(name, _strtab + s->st_name)) {
// We found the symbol
debug(2, "elfloader: => 0x%08x", s->st_value);
- return (void*) s->st_value;
+ return (void*)s->st_value;
}
// We didn't find the symbol
diff --git a/backends/plugins/elf/elf-loader.h b/backends/plugins/elf/elf-loader.h
index ae226fc2b6..d31f678241 100644
--- a/backends/plugins/elf/elf-loader.h
+++ b/backends/plugins/elf/elf-loader.h
@@ -44,7 +44,7 @@
*/
class DLObject {
protected:
- Common::SeekableReadStream* _file;
+ Common::SeekableReadStream *_file;
byte *_segment;
Elf32_Sym *_symtab;
diff --git a/backends/plugins/elf/elf-provider.cpp b/backends/plugins/elf/elf-provider.cpp
index 9b42d4edd3..a7d2d779d8 100644
--- a/backends/plugins/elf/elf-provider.cpp
+++ b/backends/plugins/elf/elf-provider.cpp
@@ -55,6 +55,7 @@ DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
bool ELFPlugin::loadPlugin() {
assert(!_dlHandle);
+
DLObject *obj = makeDLObject();
if (obj->open(_filename.c_str())) {
_dlHandle = obj;
@@ -78,10 +79,11 @@ bool ELFPlugin::loadPlugin() {
void ELFPlugin::unloadPlugin() {
DynamicPlugin::unloadPlugin();
+
if (_dlHandle) {
- if (!_dlHandle->close()) {
+ if (!_dlHandle->close())
warning("elfloader: Failed unloading plugin '%s'", _filename.c_str());
- }
+
delete _dlHandle;
_dlHandle = 0;
}
@@ -90,7 +92,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/elf-provider.h b/backends/plugins/elf/elf-provider.h
index 447e71ea18..5dc61539e1 100644
--- a/backends/plugins/elf/elf-provider.h
+++ b/backends/plugins/elf/elf-provider.h
@@ -49,8 +49,10 @@ protected:
virtual VoidFunc findSymbol(const char *symbol);
public:
- ELFPlugin(const Common::String &filename)
- : _dlHandle(0), _filename(filename) {}
+ ELFPlugin(const Common::String &filename) :
+ _dlHandle(0),
+ _filename(filename) {
+ }
virtual ~ELFPlugin() {
if (_dlHandle)
@@ -65,7 +67,7 @@ public:
class ELFPluginProvider : public FilePluginProvider {
protected:
- virtual Plugin* createPlugin(const Common::FSNode &node) const = 0;
+ virtual Plugin *createPlugin(const Common::FSNode &node) const = 0;
bool isPluginFilename(const Common::FSNode &node) const;
};
diff --git a/backends/plugins/elf/elf32.h b/backends/plugins/elf/elf32.h
index 4586d8dc4c..c59f158d6e 100644
--- a/backends/plugins/elf/elf32.h
+++ b/backends/plugins/elf/elf32.h
@@ -36,7 +36,7 @@
typedef uint16 Elf32_Half, Elf32_Section;
typedef uint32 Elf32_Word, Elf32_Addr, Elf32_Off;
-typedef int32 Elf32_Sword;
+typedef int32 Elf32_Sword;
typedef Elf32_Half Elf32_Versym;
#define EI_NIDENT (16)
@@ -46,41 +46,41 @@ typedef Elf32_Half Elf32_Versym;
// ELF header (contains info about the file)
typedef struct {
- byte e_ident[EI_NIDENT]; /* Magic number and other info */
- Elf32_Half e_type; /* Object file type */
- Elf32_Half e_machine; /* Architecture */
- Elf32_Word e_version; /* Object file version */
- Elf32_Addr e_entry; /* Entry point virtual address */
- Elf32_Off e_phoff; /* Program header table file offset */
- Elf32_Off e_shoff; /* Section header table file offset */
- Elf32_Word e_flags; /* Processor-specific flags */
- Elf32_Half e_ehsize; /* ELF header size in bytes */
- Elf32_Half e_phentsize; /* Program header table entry size */
- Elf32_Half e_phnum; /* Program header table entry count */
- Elf32_Half e_shentsize; /* Section header table entry size */
- Elf32_Half e_shnum; /* Section header table entry count */
- Elf32_Half e_shstrndx; /* Section header string table index */
+ byte e_ident[EI_NIDENT]; /* Magic number and other info */
+ Elf32_Half e_type; /* Object file type */
+ Elf32_Half e_machine; /* Architecture */
+ Elf32_Word e_version; /* Object file version */
+ Elf32_Addr e_entry; /* Entry point virtual address */
+ Elf32_Off e_phoff; /* Program header table file offset */
+ Elf32_Off e_shoff; /* Section header table file offset */
+ Elf32_Word e_flags; /* Processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size in bytes */
+ Elf32_Half e_phentsize; /* Program header table entry size */
+ Elf32_Half e_phnum; /* Program header table entry count */
+ Elf32_Half e_shentsize; /* Section header table entry size */
+ Elf32_Half e_shnum; /* Section header table entry count */
+ Elf32_Half e_shstrndx; /* Section header string table index */
} Elf32_Ehdr;
// Should be in e_ident
#define ELFMAG "\177ELF" /* ELF Magic number */
-#define EI_CLASS 4 /* File class byte index */
-#define ELFCLASS32 1 /* 32-bit objects */
+#define EI_CLASS 4 /* File class byte index */
+#define ELFCLASS32 1 /* 32-bit objects */
-#define EI_DATA 5 /* Data encoding byte index */
-#define ELFDATA2LSB 1 /* 2's complement, little endian */
-#define ELFDATA2MSB 2 /* 2's complement, big endian */
+#define EI_DATA 5 /* Data encoding byte index */
+#define ELFDATA2LSB 1 /* 2's complement, little endian */
+#define ELFDATA2MSB 2 /* 2's complement, big endian */
#define EI_VERSION 6
-#define EV_CURRENT 1 /* Current version */
+#define EV_CURRENT 1 /* Current version */
// e_type values
-#define ET_NONE 0 /* no file type */
-#define ET_REL 1 /* relocatable */
-#define ET_EXEC 2 /* executable */
-#define ET_DYN 3 /* shared object */
-#define ET_CORE 4 /* core file */
+#define ET_NONE 0 /* no file type */
+#define ET_REL 1 /* relocatable */
+#define ET_EXEC 2 /* executable */
+#define ET_DYN 3 /* shared object */
+#define ET_CORE 4 /* core file */
// e_machine values
#define EM_MIPS 8
@@ -89,27 +89,27 @@ typedef struct {
// Program header (contains info about segment)
typedef struct {
- Elf32_Word p_type; /* Segment type */
- Elf32_Off p_offset; /* Segment file offset */
- Elf32_Addr p_vaddr; /* Segment virtual address */
- Elf32_Addr p_paddr; /* Segment physical address */
- Elf32_Word p_filesz; /* Segment size in file */
- Elf32_Word p_memsz; /* Segment size in memory */
- Elf32_Word p_flags; /* Segment flags */
- Elf32_Word p_align; /* Segment alignment */
+ Elf32_Word p_type; /* Segment type */
+ Elf32_Off p_offset; /* Segment file offset */
+ Elf32_Addr p_vaddr; /* Segment virtual address */
+ Elf32_Addr p_paddr; /* Segment physical address */
+ Elf32_Word p_filesz; /* Segment size in file */
+ Elf32_Word p_memsz; /* Segment size in memory */
+ Elf32_Word p_flags; /* Segment flags */
+ Elf32_Word p_align; /* Segment alignment */
} Elf32_Phdr;
// p_type values
-#define PT_NULL 0 /* ignored */
-#define PT_LOAD 1 /* loadable segment */
-#define PT_DYNAMIC 2 /* dynamic linking info */
-#define PT_INTERP 3 /* info about interpreter */
-#define PT_NOTE 4 /* note segment */
-#define PT_SHLIB 5 /* reserved */
-#define PT_PHDR 6 /* Program header table */
-#define PT_MIPS_REGINFO 0x70000000 /* Register usage info for MIPS */
-#define PT_ARM_ARCHEXT 0x70000000 /* Platform architecture compatibility info for ARM */
-#define PT_ARM_EXIDX 0x70000001 /* Exception unwind tables for ARM */
+#define PT_NULL 0 /* ignored */
+#define PT_LOAD 1 /* loadable segment */
+#define PT_DYNAMIC 2 /* dynamic linking info */
+#define PT_INTERP 3 /* info about interpreter */
+#define PT_NOTE 4 /* note segment */
+#define PT_SHLIB 5 /* reserved */
+#define PT_PHDR 6 /* Program header table */
+#define PT_MIPS_REGINFO 0x70000000 /* Register usage info for MIPS */
+#define PT_ARM_ARCHEXT 0x70000000 /* Platform architecture compatibility info for ARM */
+#define PT_ARM_EXIDX 0x70000001 /* Exception unwind tables for ARM */
// p_flags value
#define PF_X 1 /* execute */
@@ -118,31 +118,31 @@ typedef struct {
// Section header (contains info about section)
typedef struct {
- Elf32_Word sh_name; /* Section name (string tbl index) */
- Elf32_Word sh_type; /* Section type */
- Elf32_Word sh_flags; /* Section flags */
- Elf32_Addr sh_addr; /* Section virtual addr at execution */
- Elf32_Off sh_offset; /* Section file offset */
- Elf32_Word sh_size; /* Section size in bytes */
- Elf32_Word sh_link; /* Link to another section */
- Elf32_Word sh_info; /* Additional section information */
- Elf32_Word sh_addralign; /* Section alignment */
- Elf32_Word sh_entsize; /* Entry size if section holds table */
+ Elf32_Word sh_name; /* Section name (string tbl index) */
+ Elf32_Word sh_type; /* Section type */
+ Elf32_Word sh_flags; /* Section flags */
+ Elf32_Addr sh_addr; /* Section virtual addr at execution */
+ Elf32_Off sh_offset; /* Section file offset */
+ Elf32_Word sh_size; /* Section size in bytes */
+ Elf32_Word sh_link; /* Link to another section */
+ Elf32_Word sh_info; /* Additional section information */
+ Elf32_Word sh_addralign; /* Section alignment */
+ Elf32_Word sh_entsize; /* Entry size if section holds table */
} Elf32_Shdr;
// sh_type values
-#define SHT_NULL 0 /* Inactive section */
-#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 */
-#define SHT_HASH 5 /* Symbol hash table */
-#define SHT_DYNAMIC 6 /* Info for dynamic linking */
-#define SHT_NOTE 7 /* Note section */
-#define SHT_NOBITS 8 /* Occupies no space */
-#define SHT_REL 9 /* Relocation entries without addend */
-#define SHT_SHLIB 10 /* Reserved */
-#define SHT_DYNSYM 11 /* Minimal set of dynamic linking symbols */
+#define SHT_NULL 0 /* Inactive section */
+#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 */
+#define SHT_HASH 5 /* Symbol hash table */
+#define SHT_DYNAMIC 6 /* Info for dynamic linking */
+#define SHT_NOTE 7 /* Note section */
+#define SHT_NOBITS 8 /* Occupies no space */
+#define SHT_REL 9 /* Relocation entries without addend */
+#define SHT_SHLIB 10 /* Reserved */
+#define SHT_DYNSYM 11 /* Minimal set of dynamic linking symbols */
#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*/
@@ -151,24 +151,24 @@ typedef struct {
#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes for ARM*/
// sh_flags values
-#define SHF_WRITE 0 /* writable section */
-#define SHF_ALLOC 2 /* section occupies memory */
-#define SHF_EXECINSTR 4 /* machine instructions */
+#define SHF_WRITE 0 /* writable section */
+#define SHF_ALLOC 2 /* section occupies memory */
+#define SHF_EXECINSTR 4 /* machine instructions */
#define SHF_MIPS_GPREL 0x10000000 /* Must be made part of global data area for MIPS */
// Symbol entry (contain info about a symbol)
typedef struct {
- Elf32_Word st_name; /* Symbol name (string tbl index) */
- Elf32_Addr st_value; /* Symbol value */
- Elf32_Word st_size; /* Symbol size */
- byte st_info; /* Symbol type and binding */
- byte st_other; /* Symbol visibility */
- Elf32_Section st_shndx; /* Section index */
+ Elf32_Word st_name; /* Symbol name (string tbl index) */
+ Elf32_Addr st_value; /* Symbol value */
+ Elf32_Word st_size; /* Symbol size */
+ byte st_info; /* Symbol type and binding */
+ byte st_other; /* Symbol visibility */
+ Elf32_Section st_shndx; /* Section index */
} Elf32_Sym;
// Extract from the st_info
-#define SYM_TYPE(x) ((x)&0xF)
-#define SYM_BIND(x) ((x)>>4)
+#define SYM_TYPE(x) ((x) & 0xf)
+#define SYM_BIND(x) ((x) >> 4)
// Symbol binding values from st_info
#define STB_LOCAL 0 /* Symbol not visible outside object */
@@ -192,16 +192,15 @@ typedef struct {
// Relocation entry with implicit addend (info about how to relocate)
typedef struct {
- Elf32_Addr r_offset; /* Address */
- Elf32_Word r_info; /* Relocation type and symbol index */
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
} Elf32_Rel;
// Relocation entry with explicit addend (info about how to relocate)
-typedef struct
-{
- Elf32_Addr r_offset; /* Address */
- Elf32_Word r_info; /* Relocation type and symbol index */
- Elf32_Sword r_addend; /* Addend */
+typedef struct {
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
+ Elf32_Sword r_addend; /* Addend */
} Elf32_Rela;
// Access macros for the relocation info
@@ -245,11 +244,11 @@ typedef struct
#define R_PPC_REL32 26
// Mock function to get value of global pointer for MIPS
-#define getGP() ({ \
- uint32 __valgp; \
+#define getGP() { \
+ uint32 __valgp; \
__asm__ ("add %0, $gp, $0" : "=r"(__valgp) : ); \
__valgp; \
-})
+}
#endif /* BACKENDS_ELF_H */
diff --git a/backends/plugins/elf/mips-loader.cpp b/backends/plugins/elf/mips-loader.cpp
index 9d5ffe7ebe..46f2ad08b0 100644
--- a/backends/plugins/elf/mips-loader.cpp
+++ b/backends/plugins/elf/mips-loader.cpp
@@ -29,6 +29,8 @@
#include "common/debug.h"
+#define DEBUG_NUM 2
+
/**
* Follow the instruction of a relocation section.
*
@@ -40,7 +42,7 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
Elf32_Rel *rel = 0; // relocation entry
// Allocate memory for relocation table
- if (!(rel = (Elf32_Rel *) malloc(size))) {
+ if (!(rel = (Elf32_Rel *)malloc(size))) {
warning("elfloader: Out of memory.");
return false;
}
@@ -69,36 +71,34 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
Elf32_Addr lastHiSymVal = 0;
bool hi16InShorts = false;
-#define DEBUG_NUM 2
-
// Loop over relocation entries
for (uint32 i = 0; i < cnt; i++) {
// Get the symbol this relocation entry is referring to
Elf32_Sym *sym = _symtab + (REL_INDEX(rel[i].r_info));
// Get the target instruction in the code
- uint32 *target = (uint32 *) ((byte *)relSegment + rel[i].r_offset);
+ uint32 *target = (uint32 *)((byte *)relSegment + rel[i].r_offset);
uint32 origTarget = *target; // Save for debugging
// Act differently based on the type of relocation
switch (REL_TYPE(rel[i].r_info)) {
- case R_MIPS_HI16: // Absolute addressing.
+ 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
lastHiSymVal = sym->st_value;
- hi16InShorts = ShortsMan.inGeneralSegment((char *) sym->st_value); // Fix for problem with switching btw segments
+ 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);
}
break;
- case R_MIPS_LO16: // Absolute addressing. Needs a HI16 to come before it
+ case R_MIPS_LO16: // Absolute addressing. Needs a HI16 to come before it
if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. (ie. has a real section index)
if (!seenHi16) { // We MUST have seen HI16 first
debug(8, "elfloader: R_MIPS_LO16 w/o preceding R_MIPS_HI16 at relocation %d!", i);
@@ -108,8 +108,8 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
// Fix: bug in gcc makes LO16s connect to wrong HI16s sometimes (shorts and regular segment)
// Note that we can check the entire shorts segment because the executable's shorts don't belong to this plugin section
- // and will be screened out above
- bool lo16InShorts = ShortsMan.inGeneralSegment((char *) sym->st_value);
+ // and will be screened out above
+ bool lo16InShorts = ShortsMan.inGeneralSegment((char *)sym->st_value);
// Correct the bug by getting the proper value in ahl (taken from the current symbol)
if ((hi16InShorts && !lo16InShorts) || (!hi16InShorts && lo16InShorts)) {
@@ -133,12 +133,13 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
if (REL_TYPE(rel[j].r_info) != R_MIPS_HI16)
continue; // Skip over non-Hi16s
- lastTarget = (uint32 *) ((char *) relSegment + rel[j].r_offset); // get hi16 target
+ lastTarget = (uint32 *)((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
}
+
firstHi16 = -1; // Reset so we'll know we treated it
} else {
extendedHi16++;
@@ -148,37 +149,42 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
*target |= relocation & 0xffff; // Take the lower 16 bits of the relocation
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",
+ 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);
+
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",
+ 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);
}
break;
- case R_MIPS_26: // Absolute addressing (for jumps and branches only)
- if (sym->st_shndx < SHN_LOPROC) { // Only relocate for main segment
- a = *target & 0x03ffffff; // Get 26 bits' worth of the addend
- a = (a << 6) >> 6; // Sign extend a
+ case R_MIPS_26: // Absolute addressing (for jumps and branches only)
+ if (sym->st_shndx < SHN_LOPROC) { // Only relocate for main segment
+ a = *target & 0x03ffffff; // Get 26 bits' worth of the addend
+ a = (a << 6) >> 6; // Sign extend a
relocation = ((a << 2) + Elf32_Addr(_segment)) >> 2; // a already points to the target. Subtract our offset
- *target &= 0xfc000000; // Clean lower 26 target bits
+ *target &= 0xfc000000; // Clean lower 26 target bits
*target |= (relocation & 0x03ffffff);
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",
+ 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);
} 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",
+ 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);
}
break;
- case R_MIPS_GPREL16: // GP Relative addressing
- if (_shortsSegment->getOffset() != 0 && // Only relocate if we shift the shorts section
+ 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
- a = *target & 0xffff; // Get 16 bits' worth of the addend
- a = (a << 16) >> 16; // Sign extend it
+ a = *target & 0xffff; // Get 16 bits' worth of the addend
+ a = (a << 16) >> 16; // Sign extend it
relocation = a + _shortsSegment->getOffset();
@@ -186,7 +192,8 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
*target |= relocation & 0xffff;
if (debugRelocs[5]++ < DEBUG_NUM)
- debug(8, "elfloader: R_MIPS_GPREL16: i=%d, a=%x, gpVal=%x, origTarget=%x, target=%x, offset=%x",
+ 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());
}
@@ -196,15 +203,18 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section.
a = *target; // Get full 32 bits of addend
- if (ShortsMan.inGeneralSegment((char *) sym->st_value)) // Check if we're in the shorts segment
- relocation = a + _shortsSegment->getOffset(); // Shift by shorts offset
- else // We're in the main section
- relocation = a + Elf32_Addr(_segment); // Shift by main offset
+ if (ShortsMan.inGeneralSegment((char *)sym->st_value)) // Check if we're in the shorts segment
+ relocation = a + _shortsSegment->getOffset(); // Shift by shorts offset
+ else // We're in the main section
+ relocation = a + Elf32_Addr(_segment); // Shift by main offset
+
*target = relocation;
if (debugRelocs[6]++ < DEBUG_NUM)
- debug("8, elfloader: R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x", i, a, origTarget, *target);
+ debug("8, elfloader: R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x",
+ i, a, origTarget, *target);
}
+
break;
default:
@@ -223,20 +233,19 @@ bool MIPSDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
bool MIPSDLObject::relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
// Loop over sections, finding relocation sections
for (uint32 i = 0; i < ehdr->e_shnum; i++) {
-
Elf32_Shdr *curShdr = &(shdr[i]);
//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
+ if (curShdr->sh_type == SHT_REL && // Check for a relocation section
+ curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size
int32(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
+ (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(curShdr->sh_offset, curShdr->sh_size, _segment))
return false;
- } else { // In Shorts segment
- if (!relocate(curShdr->sh_offset, curShdr->sh_size, (byte *) _shortsSegment->getOffset()))
+ } else { // In Shorts segment
+ if (!relocate(curShdr->sh_offset, curShdr->sh_size, (byte *)_shortsSegment->getOffset()))
return false;
}
}
@@ -252,14 +261,14 @@ void MIPSDLObject::relocateSymbols(Elf32_Addr offset) {
for (uint32 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)) {
+ if (!ShortsMan.inGeneralSegment((char *)s->st_value)) {
s->st_value += offset;
if (s->st_value < Elf32_Addr(_segment) || s->st_value > Elf32_Addr(_segment) + _segmentSize)
warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
} else { // shorts section
s->st_value += _shortsSegment->getOffset();
- if (!_shortsSegment->inSegment((char *) s->st_value))
+ if (!_shortsSegment->inSegment((char *)s->st_value))
warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
}
}
@@ -278,7 +287,7 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
if (phdr->p_align < 0x10000)
phdr->p_align = 0x10000; // Fix for wrong alignment on e.g. AGI
- _segment = (byte *) allocSegment(phdr->p_align, phdr->p_memsz + extra);
+ _segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
if (!_segment) {
warning("elfloader: Out of memory.");
@@ -291,16 +300,18 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
baseAddress = _segment + phdr->p_vaddr;
_segmentSize = phdr->p_memsz + extra;
} else { // This is a shorts section.
- _shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *) phdr->p_vaddr);
+ _shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *)phdr->p_vaddr);
- baseAddress = (byte *) _shortsSegment->getStart();
+ baseAddress = (byte *)_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)
if (phdr->p_memsz > phdr->p_filesz) {
- debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz);
+ debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz,
+ baseAddress + phdr->p_memsz);
memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
}
diff --git a/backends/plugins/elf/mips-loader.h b/backends/plugins/elf/mips-loader.h
index bd90e968d7..1a0974d153 100644
--- a/backends/plugins/elf/mips-loader.h
+++ b/backends/plugins/elf/mips-loader.h
@@ -34,7 +34,7 @@
class MIPSDLObject : public DLObject {
protected:
- ShortSegmentManager::Segment *_shortsSegment; // For assigning shorts ranges
+ ShortSegmentManager::Segment *_shortsSegment; // For assigning shorts ranges
uint32 _gpVal; // Value of Global Pointer
virtual bool relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment);
@@ -44,10 +44,11 @@ protected:
virtual void unload();
public:
- MIPSDLObject() : DLObject() {
+ MIPSDLObject() :
+ DLObject() {
_shortsSegment = NULL;
_gpVal = 0;
- }
+ }
};
#endif /* BACKENDS_PLUGINS_MIPS_LOADER_H */
diff --git a/backends/plugins/elf/ppc-loader.cpp b/backends/plugins/elf/ppc-loader.cpp
index 1cd995936b..4be27ac9fc 100644
--- a/backends/plugins/elf/ppc-loader.cpp
+++ b/backends/plugins/elf/ppc-loader.cpp
@@ -56,7 +56,7 @@ bool PPCDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
Elf32_Sym *sym = _symtab + (REL_INDEX(rel[i].r_info));
// Get the target instruction in the code
- src = (uint32 *) ((char *) relSegment + rel[i].r_offset - _segmentVMA);
+ src = (uint32 *)((char *)relSegment + rel[i].r_offset - _segmentVMA);
value = sym->st_value + rel[i].r_addend;
//debug(8, "elfloader: i=%05d %p +0x%04x: (0x%08x) 0x%08x ", i, src, rel[i].r_addend, sym->st_value, *src);
@@ -67,23 +67,23 @@ bool PPCDLObject::relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment)
debug(8, "elfloader: R_PPC_ADDR32 -> 0x%08x", *src);
break;
case R_PPC_ADDR16_LO:
- *((uint16 *) src) = value;
+ *(uint16 *)src = value;
debug(8, "elfloader: R_PPC_ADDR16_LO -> 0x%08x", *src);
break;
case R_PPC_ADDR16_HI:
- *(uint16 *) src = value >> 16;
+ *(uint16 *)src = value >> 16;
debug(8, "elfloader: R_PPC_ADDR16_HA -> 0x%08x", *src);
break;
case R_PPC_ADDR16_HA:
- *(uint16 *) src = (value + 0x8000) >> 16;
+ *(uint16 *)src = (value + 0x8000) >> 16;
debug(8, "elfloader: R_PPC_ADDR16_HA -> 0x%08x", *src);
break;
case R_PPC_REL24:
- *src = (*src & ~0x03fffffc) | ((value - (uint32) src) & 0x03fffffc);
+ *src = (*src & ~0x03fffffc) | ((value - (uint32)src) & 0x03fffffc);
debug(8, "elfloader: R_PPC_REL24 -> 0x%08x", *src);
break;
case R_PPC_REL32:
- *src = value - (uint32) src;
+ *src = value - (uint32)src;
debug(8, "elfloader: R_PPC_REL32 -> 0x%08x", *src);
break;
default:
diff --git a/backends/plugins/elf/ppc-loader.h b/backends/plugins/elf/ppc-loader.h
index 37a3549c6c..5af9682457 100644
--- a/backends/plugins/elf/ppc-loader.h
+++ b/backends/plugins/elf/ppc-loader.h
@@ -36,7 +36,9 @@ protected:
virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
public:
- PPCDLObject() : DLObject() {}
+ PPCDLObject() :
+ DLObject() {
+ }
};
#endif /* BACKENDS_PLUGINS_PPC_LOADER_H */
diff --git a/backends/plugins/elf/shorts-segment-manager.cpp b/backends/plugins/elf/shorts-segment-manager.cpp
index d55ea08c73..f444e9e717 100644
--- a/backends/plugins/elf/shorts-segment-manager.cpp
+++ b/backends/plugins/elf/shorts-segment-manager.cpp
@@ -31,7 +31,7 @@
extern char __plugin_hole_start; // Indicates start of hole in program file for shorts
extern char __plugin_hole_end; // Indicates end of hole in program file
-extern char _gp[]; // Value of gp register
+extern char _gp[]; // Value of gp register
DECLARE_SINGLETON(ShortSegmentManager); // For singleton
@@ -59,7 +59,7 @@ ShortSegmentManager::Segment *ShortSegmentManager::newSegment(uint32 size, char
if (lastAddress + size > _shortsEnd) {
warning("elfloader: No space in shorts segment for %x bytes. Last address is %p, max address is %p.",
- size, lastAddress, _shortsEnd);
+ size, lastAddress, _shortsEnd);
return 0;
}
diff --git a/backends/plugins/ps2/plugin.ld b/backends/plugins/ps2/plugin.ld
index 9879413b98..45efe4db7a 100644
--- a/backends/plugins/ps2/plugin.ld
+++ b/backends/plugins/ps2/plugin.ld
@@ -3,6 +3,7 @@ PHDRS {
plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */
shorts PT_LOAD ; /* Specifies that the shorts segment should be loaded from file */
}
+
SECTIONS {
.text 0: {
_ftext = . ;
@@ -90,5 +91,4 @@ SECTIONS {
*(.gnu.linkonce.sb*)
*(.scommon)
}
-
}
diff --git a/backends/plugins/psp/plugin.ld b/backends/plugins/psp/plugin.ld
index db4df45264..a4456d199d 100644
--- a/backends/plugins/psp/plugin.ld
+++ b/backends/plugins/psp/plugin.ld
@@ -1,11 +1,12 @@
-OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips",
- "elf32-littlemips")
+OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips", "elf32-littlemips")
OUTPUT_ARCH(mips:allegrex)
+
PHDRS
{
plugin PT_LOAD ;
shorts PT_LOAD ;
}
+
/* Do we need any of these for elf?
__DYNAMIC = 0; */
SECTIONS
@@ -234,6 +235,4 @@ SECTIONS
PROVIDE (__sbss_end = .);
PROVIDE (___sbss_end = .);
}
-
-
}