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

toneman1138 at users.sourceforge.net toneman1138 at users.sourceforge.net
Sat Jun 26 06:15:16 CEST 2010


Revision: 50305
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50305&view=rev
Author:   toneman1138
Date:     2010-06-26 04:15:16 +0000 (Sat, 26 Jun 2010)

Log Message:
-----------
various fixes to the loader to allow compilation

Modified Paths:
--------------
    scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/elf32.h
    scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.cpp
    scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.h

Modified: scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/elf32.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/elf32.h	2010-06-26 04:12:09 UTC (rev 50304)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/elf32.h	2010-06-26 04:15:16 UTC (rev 50305)
@@ -175,8 +175,8 @@
 } Elf32_Rela;
 
 // Access macros for the relocation info
-#define REL_TYPE(x)		((unsigned char) (x))	/* Extract relocation type */
-#define REL_INDEX(x)	((x)>>8)				/* Extract relocation index into symbol table */
+#define REL_TYPE(x)	((unsigned char) (x))	/* Extract relocation type */
+#define REL_INDEX(x)	((x)>>8)		/* Extract relocation index into symbol table */
 
 // ARM relocation types
 #define R_ARM_NONE			0

Modified: scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.cpp	2010-06-26 04:12:09 UTC (rev 50304)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.cpp	2010-06-26 04:15:16 UTC (rev 50305)
@@ -34,10 +34,12 @@
 
 #include "backends/platform/gp2xwiz/gp2xwiz-loader.h"
 
+#define __WIZ_DEBUG_PLUGINS__
+
 #ifdef __WIZ_DEBUG_PLUGINS__
-#define DBG(x) printf(x, ## __VA_ARGS__)
+#define DBG(x,...) printf(x, ## __VA_ARGS__)
 #else
-#define DBG(x)
+#define DBG(x,...)
 #endif
 
 #define seterror(x,...) fprintf(stderr,x, ## __VA_ARGS__)
@@ -55,7 +57,7 @@
 void DLObject::unload() {
 	discard_symtab();
 	free(_segment);
-	segment = NULL;
+	_segment = NULL;
 }
 
 /**
@@ -66,7 +68,7 @@
  * @param size   	 Size of relocation section
  *
  */
-bool DLObject::relocate(int fd, unsigned long offset, unsigned long size) {
+bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) {
 	Elf32_Rela *rela; //relocation entry
 
 	// Allocate memory for relocation table
@@ -93,15 +95,15 @@
 
 		//void *target = ???;
 
-		switch (/*relocation type*/) {
+	//	switch (/*relocation type*/) {
 		//case ??? :
 			//TODO: Cases for each relocation type.
 			//break;
-		default:
-			seterror("Unknown relocation type %d.", ?? ?);
+	//	default:
+			//seterror("Unknown relocation type %d.", ?? ?);
 			free(rela);
 			return false;
-		}
+	//	}
 
 	}
 
@@ -126,7 +128,7 @@
 	if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) ||
 	        memcmp(ehdr->e_ident, ELFMAG, SELFMAG) ||			// Check MAGIC
 	        ehdr->e_type != ET_EXEC ||							// Check for executable
-	        ehdr->e_machine != EM_MIPS ||						// Check for ARM machine type TODO: change EM_MIPS to ??_ARM and add to ELF32.H (figure out what ??_ARM should be)
+	        ehdr->e_machine != EM_ARM ||						// Check for ARM machine type
 	        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.");
@@ -281,7 +283,7 @@
 
 void DLObject::relocateSymbols(Elf32_Addr offset) {
 
-	relocCount = 0;
+	int relocCount = 0;
 	DBG("Relocating symbols by %x\n", offset);
 
 	// Loop over symbols, add relocation offset
@@ -310,7 +312,7 @@
 		//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
+		        curShdr->sh_entsize == sizeof(Elf32_Rela) &&		    // 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
@@ -331,7 +333,7 @@
 	Elf32_Shdr *shdr;
 	bool ret = true;
 
-	int symtab_sect = -1;
+	//int symtab_sect = -1;
 
 	if (readElfHeader(fd, &ehdr) == false) {
 		return false;
@@ -375,10 +377,10 @@
 
 	DBG(("open(\"%s\")\n", path));
 
-	if ((fd = ::open(path, O_RDONLY)) < 0) {
+	/*if ((fd = ::open(path, O_RDONLY)) < 0) {
 		seterror("%s not found.", path);
 		return false;
-	}
+	} TODO: reimplement this "attempt to open" code */
 
 	// Try to load and relocate
 	if (!load(fd)) {
@@ -430,14 +432,14 @@
 	}
 
 	Elf32_Sym *s = (Elf32_Sym *)_symtab;
-	for (int c = symbol_cnt; c--; s++)
+	for (int c = _symbol_cnt; c--; s++)
 
 		//TODO: Figure out which symbols should be detected here
 		if ((s->st_info >> 4 == 1 || s->st_info >> 4 == 2) &&
-		        strtab[s->st_name] == '_' && !strcmp(name, strtab + s->st_name + 1)) {
+		        _strtab[s->st_name] == '_' && !strcmp(name, _strtab + s->st_name + 1)) {
 
 			// We found the symbol
-			DBG(("=> %p\n", (void*)s->st_value));
+			DBG("=> %p\n", (void*)s->st_value);
 			return (void*)s->st_value;
 		}
 

Modified: scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.h	2010-06-26 04:12:09 UTC (rev 50304)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/gp2xwiz/gp2xwiz-loader.h	2010-06-26 04:15:16 UTC (rev 50305)
@@ -32,25 +32,37 @@
 
 class DLObject {
 	protected:
-		char *errbuf; /* For error messages, at least MAXDLERRLEN in size */
+		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(int fd, unsigned long offset, unsigned long size);
+		bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment);
 		bool load(int fd);
 
+		bool readElfHeader(int fd, Elf32_Ehdr *ehdr);
+		bool readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num);
+		bool loadSegment(int fd, Elf32_Phdr *phdr);
+		Elf32_Shdr *loadSectionHeaders(int fd, Elf32_Ehdr *ehdr);
+		int loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+		bool loadStringTable(int fd, Elf32_Shdr *shdr);
+		void relocateSymbols(Elf32_Addr offset);
+		bool relocateRels(int fd, 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),
+		DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL),_symtab(NULL),
 				_strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {}
 };
 


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