[Scummvm-cvs-logs] SF.net SVN: scummvm:[51195] scummvm/branches/gsoc2010-plugins/backends/ plugins

toneman1138 at users.sourceforge.net toneman1138 at users.sourceforge.net
Fri Jul 23 09:49:02 CEST 2010


Revision: 51195
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51195&view=rev
Author:   toneman1138
Date:     2010-07-23 07:49:02 +0000 (Fri, 23 Jul 2010)

Log Message:
-----------
Began abstraction of generic ELF-loader

Added Paths:
-----------
    scummvm/branches/gsoc2010-plugins/backends/plugins/MIPS-loader.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/loader.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h

Added: scummvm/branches/gsoc2010-plugins/backends/plugins/MIPS-loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/MIPS-loader.h	                        (rev 0)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/MIPS-loader.h	2010-07-23 07:49:02 UTC (rev 51195)
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef MIPS_LOADER_H
+#define MIPS_LOADER_H
+
+#include "loader.h"
+#include "shorts-segment-manager.h"
+
+class MIPS_DLObject : public DLObject {
+protected:
+	ShortSegmentManager::Segment *_shortsSegment;			// For assigning shorts ranges
+	unsigned int _gpVal;									// Value of Global Pointer
+
+public:
+	MIPS_DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _shortsSegment(NULL), _segment(NULL), _symtab(NULL),
+			_strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL), _gpVal(0) ,
+			_segmentSize(0) {}
+};
+
+#endif /* MIPS_LOADER_H */


Property changes on: scummvm/branches/gsoc2010-plugins/backends/plugins/MIPS-loader.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + URL Id
Added: svn:eol-style
   + native

Added: scummvm/branches/gsoc2010-plugins/backends/plugins/loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/loader.h	                        (rev 0)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/loader.h	2010-07-23 07:49:02 UTC (rev 51195)
@@ -0,0 +1,81 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef LOADER_H
+#define LOADER_H
+
+#include "elf32.h"
+#include "common/list.h"
+
+#define MAXDLERRLEN 80
+
+class DLObject {
+protected:
+    char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */
+
+    void *_segment, *_symtab;
+    char *_strtab;
+    int _symbol_cnt;
+    int _symtab_sect;
+    void *_dtors_start, *_dtors_end;
+
+    int _segmentSize;
+
+    void seterror(const char *fmt, ...);
+    void unload();
+    bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
+    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);
+    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);
+    void relocateSymbols(Elf32_Addr offset);
+    bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+
+public:
+    bool open(const char *path);
+    bool close();
+    void *symbol(const char *name);
+    void discard_symtab();
+
+    DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL), _symtab(NULL),
+            _strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL),
+            _segmentSize(0) {}
+};
+
+#define RTLD_LAZY 0
+
+extern "C" {
+    void *dlopen(const char *filename, int flags);
+    int dlclose(void *handle);
+    void *dlsym(void *handle, const char *symbol);
+    const char *dlerror();
+    void dlforgetsyms(void *handle);
+}
+
+#endif /* LOADER_H */


Property changes on: scummvm/branches/gsoc2010-plugins/backends/plugins/loader.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + URL Id
Added: svn:eol-style
   + native

Added: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp	2010-07-23 07:49:02 UTC (rev 51195)
@@ -0,0 +1,78 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#if defined(DYNAMIC_MODULES) //TODO: && defined (MIPS target)
+
+#include "MIPS-loader.h"
+#include "shorts-segment-manager.h"
+
+DECLARE_SINGLETON(ShortSegmentManager);	// For singleton
+
+ShortSegmentManager::ShortSegmentManager() {
+	_shortsStart = &__plugin_hole_start ;
+	_shortsEnd = &__plugin_hole_end;
+}
+
+ShortSegmentManager::Segment *ShortSegmentManager::newSegment(int size, char *origAddr) {
+	char *lastAddress = origAddr;
+	Common::List<Segment *>::iterator i;
+
+	// Find a block that fits, starting from the beginning
+	for (i = _list.begin(); i != _list.end(); ++i) {
+		char *currAddress = (*i)->getStart();
+
+		if ((int)(currAddress - lastAddress) >= size) break;
+
+		lastAddress = (*i)->getEnd();
+	}
+
+	if ((Elf32_Addr)lastAddress & 3)
+		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",
+		         size, lastAddress, _shortsEnd);
+		return NULL;
+	}
+
+	Segment *seg = new Segment(lastAddress, size, origAddr);	// Create a new segment
+
+	if (lastAddress + size > _highestAddress) _highestAddress = lastAddress + size;	// Keep track of maximum
+
+	_list.insert(i, seg);
+
+	DBG("Shorts segment size %x allocated. End = %p. Remaining space = %x. Highest so far is %p.\n",
+	    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());
+	_list.remove(seg);
+	delete seg;
+}
+
+#endif /* DYNAMIC_MODULES */


Property changes on: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + URL Id
Added: svn:eol-style
   + native

Added: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h	                        (rev 0)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h	2010-07-23 07:49:02 UTC (rev 51195)
@@ -0,0 +1,91 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SHORTS_SEGMENT_MANAGER_H
+#define SHORTS_SEGMENT_MANAGER_H
+
+#include "loader.h"
+#include "common/singleton.h"
+
+#define ShortsMan ShortSegmentManager::instance()
+
+class ShortSegmentManager : public Common::Singleton<ShortSegmentManager> {
+private:
+	char *_shortsStart;
+	char *_shortsEnd;
+
+public:
+	char *getShortsStart() {
+		return _shortsStart;
+	}
+	bool inGeneralSegment(char *addr) {
+		return ((char *)addr >= _shortsStart && (char *)addr < _shortsEnd);
+	}
+
+	class Segment {
+	private:
+		friend class ShortSegmentManager;
+		Segment(char *start, int size, char *origAddr) : _startAddress(start), _size(size), _origAddress(origAddr) {}
+		~Segment() {}
+		char *_startAddress;		// Start of shorts segment in memory
+		int  _size;					// Size of shorts segment
+		char *_origAddress;			// Original address this segment was supposed to be at
+	public:
+		char *getStart() {
+			return _startAddress;
+		}
+		char *getEnd() {
+			return (_startAddress + _size);
+		}
+		Elf32_Addr getOffset() {
+			return (Elf32_Addr)(_startAddress - _origAddress);
+		}
+		bool inSegment(char *addr) {
+			return ((char *)addr >= _startAddress && (char *)addr <= _startAddress + _size);
+		}
+	};
+
+	Segment *newSegment(int size, char *origAddr);
+	void deleteSegment(Segment *);
+
+private:
+	ShortSegmentManager();
+	friend class Common::Singleton<ShortSegmentManager>;
+	Common::List<Segment *> _list;
+	char *_highestAddress;
+};
+
+class MIPS_DLObject : public DLObject {
+protected:
+	ShortSegmentManager::Segment *_shortsSegment;			// For assigning shorts ranges
+	unsigned int _gpVal;									// Value of Global Pointer
+
+public:
+	MIPS_DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _shortsSegment(NULL), _segment(NULL), _symtab(NULL),
+			_strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL), _gpVal(0) ,
+			_segmentSize(0) {}
+};
+
+#endif /* SHORTS_SEGMENT_MANAGER_H */


Property changes on: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + URL Id
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list