aboutsummaryrefslogtreecommitdiff
path: root/backends/plugins
diff options
context:
space:
mode:
authorAndre Heider2010-09-05 12:37:36 +0000
committerAndre Heider2010-09-05 12:37:36 +0000
commit07e3a422245e0fb118323ef95f354b81669231d3 (patch)
tree58fe359f115911de744b8a1bd9e945d0696ee00e /backends/plugins
parent2c746709aac3bbd1e228cc9e2e675011d895bbc4 (diff)
downloadscummvm-rg350-07e3a422245e0fb118323ef95f354b81669231d3.tar.gz
scummvm-rg350-07e3a422245e0fb118323ef95f354b81669231d3.tar.bz2
scummvm-rg350-07e3a422245e0fb118323ef95f354b81669231d3.zip
PLUGINS: Cleanup includes and debug output.
Use the common debug functions instead of spamming #defines. svn-id: r52547
Diffstat (limited to 'backends/plugins')
-rw-r--r--backends/plugins/arm-loader.cpp36
-rw-r--r--backends/plugins/arm-loader.h4
-rw-r--r--backends/plugins/elf-loader.cpp94
-rw-r--r--backends/plugins/elf-loader.h6
-rw-r--r--backends/plugins/elf-provider.cpp13
-rw-r--r--backends/plugins/elf-provider.h6
-rw-r--r--backends/plugins/mips-loader.cpp58
-rw-r--r--backends/plugins/mips-loader.h4
-rw-r--r--backends/plugins/shorts-segment-manager.cpp18
-rw-r--r--backends/plugins/shorts-segment-manager.h3
10 files changed, 100 insertions, 142 deletions
diff --git a/backends/plugins/arm-loader.cpp b/backends/plugins/arm-loader.cpp
index 916516aed9..7fd4c12e65 100644
--- a/backends/plugins/arm-loader.cpp
+++ b/backends/plugins/arm-loader.cpp
@@ -25,20 +25,10 @@
#if defined(DYNAMIC_MODULES) && defined(ARM_TARGET)
-#include "backends/fs/ds/ds-fs.h"
-#include "elf-loader.h"
-#include "dsmain.h"
-#include "arm-loader.h"
+#include "backends/plugins/elf-loader.h"
+#include "backends/plugins/arm-loader.h"
-//#define __DEBUG_PLUGINS__
-
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) consolePrintf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) consolePrintf(x, ## __VA_ARGS__)
+#include "common/debug.h"
/**
* Follow the instruction of a relocation section.
@@ -53,14 +43,14 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
// Allocate memory for relocation table
if (!(rel = (Elf32_Rel *)malloc(size))) {
- seterror("Out of memory.");
+ warning("elfloader: Out of memory.");
return false;
}
// Read in our relocation table
if (DLFile->seek(offset, SEEK_SET) < 0 ||
DLFile->read(rel, size) != (ssize_t)size) {
- seterror("Relocation table load failed.");
+ warning("elfloader: Relocation table load failed.");
free(rel);
return false;
}
@@ -68,7 +58,7 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
// Treat each relocation entry. Loop over all of them
int cnt = size / sizeof(*rel);
- DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment);
+ debug(2, "elfloader: Loaded relocation table. %d entries. base address=%p", cnt, relSegment);
int a = 0;
unsigned int relocation = 0;
@@ -94,28 +84,28 @@ bool ARMDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long off
*target = relocation;
- DBG("R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target);
+ debug(8, "elfloader: R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x", i, a, origTarget, *target);
}
break;
case R_ARM_THM_CALL:
- DBG("R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n");
+ debug(8, "elfloader: R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.");
break;
case R_ARM_CALL:
- DBG("R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n");
+ debug(8, "elfloader: R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.");
break;
case R_ARM_JUMP24:
- DBG("R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.\n");
+ debug(8, "elfloader: R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.");
break;
case R_ARM_V4BX:
- DBG("R_ARM_V4BX: No relocation calculation necessary.\n");
+ debug(8, "elfloader: R_ARM_V4BX: No relocation calculation necessary.");
break;
default:
- seterror("Unknown relocation type %d.", REL_TYPE(rel[i].r_info));
+ warning("elfloader: Unknown relocation type %d.", REL_TYPE(rel[i].r_info));
free(rel);
return false;
}
@@ -140,7 +130,7 @@ bool ARMDLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *e
(shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory
if (curShdr->sh_type == SHT_RELA) {
- seterror("RELA entries not supported yet!\n");
+ warning("elfloader: RELA entries not supported yet!");
return false;
}
diff --git a/backends/plugins/arm-loader.h b/backends/plugins/arm-loader.h
index d377912bbe..c0ad94ef43 100644
--- a/backends/plugins/arm-loader.h
+++ b/backends/plugins/arm-loader.h
@@ -25,9 +25,7 @@
#if defined(DYNAMIC_MODULES) && defined(ARM_TARGET)
-#include "backends/fs/ds/ds-fs.h"
-#include "elf-loader.h"
-#include "dsmain.h"
+#include "backends/plugins/elf-loader.h"
class ARMDLObject : public DLObject {
protected:
diff --git a/backends/plugins/elf-loader.cpp b/backends/plugins/elf-loader.cpp
index 231c2ffa22..ac65bcb8e8 100644
--- a/backends/plugins/elf-loader.cpp
+++ b/backends/plugins/elf-loader.cpp
@@ -27,18 +27,8 @@
#include <string.h>
#include <stdarg.h>
-#include <stdio.h>
-#include <malloc.h> // for memalign() (Linux specific)
-#include <unistd.h>
-#include <sys/fcntl.h>
-#include <sys/_default_fcntl.h> // FIXME: Why do we need this DevKitPro specific header?
-
-#include "common/file.h"
-#include "common/fs.h"
-#include "elf-loader.h"
#ifdef __PSP__
-#include "backends/platform/psp/powerman.h"
#include <psputils.h>
#include <psputilsforkernel.h>
#endif
@@ -47,15 +37,11 @@
#include <nds.h>
#endif
-#define __DEBUG_PLUGINS__
+#include "backends/plugins/elf-loader.h"
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
+#include "common/debug.h"
+#include "common/file.h"
+#include "common/fs.h"
/**
* Flushes the data cache (Platform Specific).
@@ -106,12 +92,12 @@ bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehd
#endif
ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header
ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header
- seterror("Invalid file type.");
+ warning("elfloader: Invalid file type.");
return false;
}
- DBG("phoff = %d, phentsz = %d, phnum = %d\n",
- ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum);
+ debug(2, "elfloader: phoff = %d, phentsz = %d, phnum = %d",
+ ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum);
return true;
}
@@ -120,18 +106,18 @@ bool DLObject::readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr
// Read program header
if (DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 ||
DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) {
- seterror("Program header load failed.");
+ warning("elfloader: Program header load failed.");
return false;
}
// Check program header values
if (phdr->p_type != PT_LOAD || phdr->p_filesz > phdr->p_memsz) {
- seterror("Invalid program header.");
+ warning("elfloader: Invalid program header.");
return false;
}
- DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n",
- phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align);
+ debug(2, "elfloader: offs = %x, filesz = %x, memsz = %x, align = %x",
+ phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align);
return true;
}
@@ -141,14 +127,14 @@ bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr)
// Attempt to allocate memory for segment
int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
- DBG("extra mem is %x\n", extra);
+ debug(2, "elfloader: Extra mem is %x", extra);
if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) {
- seterror("Out of memory.\n");
+ warning("elfloader: Out of memory.");
return false;
}
- DBG("allocated segment @ %p\n", _segment);
+ debug(2, "elfloader: Allocated segment @ %p", _segment);
// Get offset to load segment into
baseAddress = (char *)_segment + phdr->p_vaddr;
@@ -156,20 +142,20 @@ bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr)
// Set bss segment to 0 if necessary (assumes bss is at the end)
if (phdr->p_memsz > phdr->p_filesz) {
- DBG("Setting %p to %p to 0 for bss\n", 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);
}
- DBG("Reading the segment into memory\n");
+ debug(2, "elfloader: Reading the segment into memory");
// Read the segment into memory
if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 ||
DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
- seterror("Segment load failed.");
+ warning("elfloader: Segment load failed.");
return false;
}
- DBG("Segment has been read into memory\n");
+ debug(2, "elfloader: Segment has been read into memory");
return true;
}
@@ -179,7 +165,7 @@ Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, El
// Allocate memory for section headers
if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) {
- seterror("Out of memory.");
+ warning("elfloader: Out of memory.");
return NULL;
}
@@ -187,7 +173,7 @@ Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, El
if (DLFile->seek(ehdr->e_shoff, SEEK_SET) < 0 ||
DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) !=
ehdr->e_shnum * sizeof(*shdr)) {
- seterror("Section headers load failed.");
+ warning("elfloader: Section headers load failed.");
return NULL;
}
@@ -208,15 +194,15 @@ int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *eh
// Check for no symbol table
if (_symtab_sect < 0) {
- seterror("No symbol table.");
+ warning("elfloader: No symbol table.");
return -1;
}
- DBG("Symbol section at section %d, size %x\n", _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 = malloc(shdr[_symtab_sect].sh_size))) {
- seterror("Out of memory.");
+ warning("elfloader: Out of memory.");
return -1;
}
@@ -224,13 +210,13 @@ int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *eh
if (DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 ||
DLFile->read(_symtab, shdr[_symtab_sect].sh_size) !=
shdr[_symtab_sect].sh_size) {
- seterror("Symbol table load failed.");
+ warning("elfloader: Symbol table load failed.");
return -1;
}
// Set number of symbols
_symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym);
- DBG("Loaded %d symbols.\n", _symbol_cnt);
+ debug(2, "elfloader: Loaded %d symbols.", _symbol_cnt);
return _symtab_sect;
}
@@ -240,7 +226,7 @@ bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *s
// Allocate memory for string table
if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) {
- seterror("Out of memory.");
+ warning("elfloader: Out of memory.");
return false;
}
@@ -248,7 +234,7 @@ bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *s
if (DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) < 0 ||
DLFile->read(_strtab, shdr[string_sect].sh_size) !=
shdr[string_sect].sh_size) {
- seterror("Symbol table strings load failed.");
+ warning("elfloader: Symbol table strings load failed.");
return false;
}
@@ -263,7 +249,7 @@ void DLObject::relocateSymbols(Elf32_Addr offset) {
if (s->st_shndx < SHN_LOPROC) {
s->st_value += offset;
if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize)
- seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+ warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
}
}
}
@@ -279,7 +265,7 @@ bool DLObject::load(Common::SeekableReadStream* DLFile) {
}
for (int i = 0; i < ehdr.e_phnum; i++) { //Load our segments
- DBG("Loading segment %d\n", i);
+ debug(2, "elfloader: Loading segment %d", i);
if (readProgramHeaders(DLFile, &ehdr, &phdr, i) == false)
return false;
@@ -312,16 +298,16 @@ bool DLObject::open(const char *path) {
Common::SeekableReadStream* DLFile;
void *ctors_start, *ctors_end;
- DBG("open(\"%s\")\n", path);
+ debug(2, "elfloader: open(\"%s\")", path);
Common::FSNode file(path);
if (!(DLFile = file.createReadStream())) {
- seterror("%s not found.", path);
+ warning("elfloader: %s not found.", path);
return false;
}
- DBG("%s found!\n", path);
+ debug(2, "elfloader: %s found!", path);
/*Try to load and relocate*/
if (!load(DLFile)) {
@@ -329,7 +315,7 @@ bool DLObject::open(const char *path) {
return false;
}
- DBG("loaded!/n");
+ debug(2, "elfloader: Loaded!");
flushDataCache(_segment, _segmentSize);
@@ -340,17 +326,17 @@ bool DLObject::open(const char *path) {
if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL ||
_dtors_end == NULL) {
- seterror("Missing ctors/dtors.");
+ warning("elfloader: Missing ctors/dtors.");
_dtors_start = _dtors_end = NULL;
unload();
return false;
}
- DBG("Calling constructors.\n");
+ debug(2, "elfloader: Calling constructors.");
for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++)
(**f)();
- DBG("%s opened ok.\n", path);
+ debug(2, "elfloader: %s opened ok.", path);
return true;
}
@@ -365,10 +351,10 @@ bool DLObject::close() {
}
void *DLObject::symbol(const char *name) {
- DBG("symbol(\"%s\")\n", name);
+ debug(2, "elfloader: Symbol(\"%s\")", name);
if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) {
- seterror("No symbol table loaded.");
+ warning("elfloader: No symbol table loaded.");
return NULL;
}
@@ -379,12 +365,12 @@ void *DLObject::symbol(const char *name) {
!strcmp(name, _strtab + s->st_name)) {
// We found the symbol
- DBG("=> %p\n", (void*)s->st_value);
+ debug(2, "elfloader: => %p", (void*)s->st_value);
return (void*)s->st_value;
}
// We didn't find the symbol
- seterror("Symbol \"%s\" not found.", name);
+ warning("elfloader: Symbol \"%s\" not found.", name);
return NULL;
}
diff --git a/backends/plugins/elf-loader.h b/backends/plugins/elf-loader.h
index fc6a022d34..93a6a15309 100644
--- a/backends/plugins/elf-loader.h
+++ b/backends/plugins/elf-loader.h
@@ -28,9 +28,10 @@
#ifndef ELF_LOADER_H
#define ELF_LOADER_H
-#include "elf32.h"
-#include "common/stream.h"
#include "backends/plugins/dynamic-plugin.h"
+#include "backends/plugins/elf32.h"
+
+#include "common/stream.h"
/**
* DLObject
@@ -49,7 +50,6 @@ protected:
uint32 _segmentSize;
- //void seterror(const char *fmt, ...);
virtual void unload();
virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) = 0;
bool load(Common::SeekableReadStream* DLFile);
diff --git a/backends/plugins/elf-provider.cpp b/backends/plugins/elf-provider.cpp
index e6edd4c578..47f0436ab9 100644
--- a/backends/plugins/elf-provider.cpp
+++ b/backends/plugins/elf-provider.cpp
@@ -27,9 +27,8 @@
#include "backends/plugins/elf-provider.h"
#include "backends/plugins/dynamic-plugin.h"
-#include "common/fs.h"
-#include "backends/plugins/elf-loader.h"
+#include "common/fs.h"
DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
void *func;
@@ -42,9 +41,9 @@ DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
}
if (!func) {
if (handleNull) {
- warning("Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.c_str());
+ warning("elfloader: Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.c_str());
} else {
- warning("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
+ warning("elfloader: Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
}
}
@@ -69,7 +68,7 @@ bool ELFPlugin::loadPlugin() {
}
if (!_dlHandle) {
- warning("Failed loading plugin '%s'", _filename.c_str());
+ warning("elfloader: Failed loading plugin '%s'", _filename.c_str());
return false;
}
@@ -80,13 +79,13 @@ bool ELFPlugin::loadPlugin() {
}
return ret;
-};
+}
void ELFPlugin::unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (!_dlHandle->close()) {
- warning("Failed unloading plugin '%s'", _filename.c_str());
+ warning("elfloader: Failed unloading plugin '%s'", _filename.c_str());
}
delete _dlHandle;
_dlHandle = 0;
diff --git a/backends/plugins/elf-provider.h b/backends/plugins/elf-provider.h
index 200d4faf40..f6cede0219 100644
--- a/backends/plugins/elf-provider.h
+++ b/backends/plugins/elf-provider.h
@@ -28,12 +28,10 @@
#ifndef BACKENDS_PLUGINS_ELF_PROVIDER_H
#define BACKENDS_PLUGINS_ELF_PROVIDER_H
-#include "base/plugins.h"
-#include "backends/plugins/dynamic-plugin.h"
-#include "common/fs.h"
-
#include "backends/plugins/elf-loader.h"
+#include "common/fs.h"
+
/**
* ELFPlugin
*
diff --git a/backends/plugins/mips-loader.cpp b/backends/plugins/mips-loader.cpp
index dfa2765cfa..67e12949d8 100644
--- a/backends/plugins/mips-loader.cpp
+++ b/backends/plugins/mips-loader.cpp
@@ -25,17 +25,9 @@
#if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
-#include "mips-loader.h"
+#include "backends/plugins/mips-loader.h"
-//#define __DEBUG_PLUGINS__
-
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
+#include "common/debug.h"
/**
* Follow the instruction of a relocation section.
@@ -51,14 +43,14 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
// Allocate memory for relocation table
if (!(rel = (Elf32_Rel *)malloc(size))) {
- seterror("Out of memory.");
+ warning("elfloader: Out of memory.");
return false;
}
// Read in our relocation table
if (DLFile->seek(offset, SEEK_SET) < 0 ||
DLFile->read(rel, size) != (ssize_t)size) {
- seterror("Relocation table load failed.");
+ warning("elfloader: Relocation table load failed.");
free(rel);
return false;
}
@@ -66,7 +58,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
// Treat each relocation entry. Loop over all of them
int cnt = size / sizeof(*rel);
- DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment);
+ debug(2, "elfloader: Loaded relocation table. %d entries. base address=%p", cnt, relSegment);
bool seenHi16 = false; // For treating HI/LO16 commands
int firstHi16 = -1; // Mark the point of the first hi16 seen
@@ -105,7 +97,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
lastHiSymVal = sym->st_value;
hi16InShorts = (ShortsMan.inGeneralSegment((char *)sym->st_value)); // Fix for problem with switching btw segments
if (debugRelocs[0]++ < DEBUG_NUM) // Print only a set number
- DBG("R_MIPS_HI16: i=%d, offset=%x, ahl = %x, target = %x\n",
+ debug(8, "elfloader: R_MIPS_HI16: i=%d, offset=%x, ahl = %x, target = %x",
i, rel[i].r_offset, ahl, *target);
}
break;
@@ -113,7 +105,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
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
- seterror("R_MIPS_LO16 w/o preceding R_MIPS_HI16 at relocation %d!\n", i);
+ debug(8, "elfloader: R_MIPS_LO16 w/o preceding R_MIPS_HI16 at relocation %d!", i);
free(rel);
return false;
}
@@ -158,10 +150,10 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
*target |= relocation & 0xffff; // Take the lower 16 bits of the relocation
if (debugRelocs[1]++ < DEBUG_NUM)
- DBG("R_MIPS_LO16: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x\n",
+ 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)
- DBG("R_MIPS_LO16s: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x\n",
+ 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;
@@ -175,11 +167,11 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
*target |= (relocation & 0x03ffffff);
if (debugRelocs[3]++ < DEBUG_NUM)
- DBG("R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x\n",
+ 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)
- DBG("R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x\n",
+ 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;
@@ -196,7 +188,7 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
*target |= relocation & 0xffff;
if (debugRelocs[5]++ < DEBUG_NUM)
- DBG("R_MIPS_GPREL16: i=%d, a=%x, gpVal=%x, origTarget=%x, target=%x, offset=%x\n",
+ 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());
}
@@ -213,18 +205,18 @@ bool MIPSDLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long of
*target = relocation;
if (debugRelocs[6]++ < DEBUG_NUM)
- DBG("R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target);
+ debug("8, elfloader: R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x", i, a, origTarget, *target);
}
break;
default:
- seterror("Unknown relocation type %x at relocation %d.\n", REL_TYPE(rel[i].r_info), i);
+ warning("elfloader: Unknown relocation type %x at relocation %d.", REL_TYPE(rel[i].r_info), i);
free(rel);
return false;
}
}
- DBG("Done with relocation. extendedHi16=%d\n\n", extendedHi16);
+ debug(2, "elfloader: Done with relocation. extendedHi16=%d", extendedHi16);
free(rel);
return true;
@@ -274,12 +266,12 @@ void MIPSDLObject::relocateSymbols(Elf32_Addr offset) {
mainCount++;
s->st_value += offset;
if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize)
- seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+ warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
} else { // shorts section
shortsCount++;
s->st_value += _shortsSegment->getOffset();
if (!_shortsSegment->inSegment((char *)s->st_value))
- seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+ warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
}
}
@@ -295,15 +287,15 @@ bool MIPSDLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *p
// Attempt to allocate memory for segment
int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
- DBG("extra mem is %x\n", extra);
+ 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 (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) {
- seterror("Out of memory.\n");
+ warning("elfloader: Out of memory.");
return false;
}
- DBG("allocated segment @ %p\n", _segment);
+ debug(2, "elfloader: Allocated segment @ %p", _segment);
// Get offset to load segment into
baseAddress = (char *)_segment + phdr->p_vaddr;
@@ -312,26 +304,26 @@ bool MIPSDLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *p
_shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *)phdr->p_vaddr);
baseAddress = _shortsSegment->getStart();
- DBG("shorts segment @ %p to %p. Segment wants to be at %x. Offset=%x\n",
+ 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());
}
// Set bss segment to 0 if necessary (assumes bss is at the end)
if (phdr->p_memsz > phdr->p_filesz) {
- DBG("Setting %p to %p to 0 for bss\n", 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);
}
- DBG("Reading the segment into memory\n");
+ debug(2, "elfloader: Reading the segment into memory");
// Read the segment into memory
if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 ||
DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) {
- seterror("Segment load failed.");
+ warning("elfloader: Segment load failed.");
return false;
}
- DBG("Segment has been read into memory\n");
+ debug(2, "elfloader: Segment has been read into memory");
return true;
}
diff --git a/backends/plugins/mips-loader.h b/backends/plugins/mips-loader.h
index 0b66412485..90e0bf92b2 100644
--- a/backends/plugins/mips-loader.h
+++ b/backends/plugins/mips-loader.h
@@ -26,8 +26,8 @@
#if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
-#include "elf-loader.h"
-#include "shorts-segment-manager.h"
+#include "backends/plugins/elf-loader.h"
+#include "backends/plugins/shorts-segment-manager.h"
class MIPSDLObject : public DLObject {
protected:
diff --git a/backends/plugins/shorts-segment-manager.cpp b/backends/plugins/shorts-segment-manager.cpp
index 2376759919..788d7807ce 100644
--- a/backends/plugins/shorts-segment-manager.cpp
+++ b/backends/plugins/shorts-segment-manager.cpp
@@ -25,20 +25,14 @@
#if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
-#include "shorts-segment-manager.h"
+#include "backends/plugins/shorts-segment-manager.h"
+
+#include "common/debug.h"
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
-#ifdef DEBUG_PLUGINS
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
-
DECLARE_SINGLETON(ShortSegmentManager); // For singleton
ShortSegmentManager::ShortSegmentManager() {
@@ -63,7 +57,7 @@ ShortSegmentManager::Segment *ShortSegmentManager::newSegment(int size, char *or
lastAddress += 4 - ((Elf32_Addr)lastAddress & 3); // Round up to multiple of 4
if (lastAddress + size > _shortsEnd) {
- seterror("Error. No space in shorts segment for %x bytes. Last address is %p, max address is %p.\n",
+ warning("elfloader: No space in shorts segment for %x bytes. Last address is %p, max address is %p.",
size, lastAddress, _shortsEnd);
return NULL;
}
@@ -74,14 +68,14 @@ ShortSegmentManager::Segment *ShortSegmentManager::newSegment(int size, char *or
_list.insert(i, seg);
- DBG("Shorts segment size %x allocated. End = %p. Remaining space = %x. Highest so far is %p.\n",
+ 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);
return seg;
}
void ShortSegmentManager::deleteSegment(ShortSegmentManager::Segment *seg) {
- DBG("Deleting shorts segment from %p to %p.\n\n", seg->getStart(), seg->getEnd());
+ debug(2, "elfloader: Deleting shorts segment from %p to %p.", seg->getStart(), seg->getEnd());
_list.remove(seg);
delete seg;
}
diff --git a/backends/plugins/shorts-segment-manager.h b/backends/plugins/shorts-segment-manager.h
index 2710a7b9ff..bf583c021a 100644
--- a/backends/plugins/shorts-segment-manager.h
+++ b/backends/plugins/shorts-segment-manager.h
@@ -28,9 +28,10 @@
#ifndef SHORTS_SEGMENT_MANAGER_H
#define SHORTS_SEGMENT_MANAGER_H
+#include "backends/plugins/elf32.h"
+
#include "common/singleton.h"
#include "common/list.h"
-#include "elf32.h"
#define ShortsMan ShortSegmentManager::instance()