[Scummvm-cvs-logs] SF.net SVN: scummvm:[50869] scummvm/branches/gsoc2010-plugins/backends/ platform/ds/arm9/source

toneman1138 at users.sourceforge.net toneman1138 at users.sourceforge.net
Wed Jul 14 05:57:36 CEST 2010


Revision: 50869
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50869&view=rev
Author:   toneman1138
Date:     2010-07-14 03:57:36 +0000 (Wed, 14 Jul 2010)

Log Message:
-----------
various dsloader fixes, including initializing _symtab_sect to -1 in the header

Modified Paths:
--------------
    scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.cpp
    scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.h

Modified: scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.cpp	2010-07-14 03:55:11 UTC (rev 50868)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.cpp	2010-07-14 03:57:36 UTC (rev 50869)
@@ -73,30 +73,30 @@
  *
  */
 bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) {
-	Elf32_Rela *rela; //relocation entry
+	Elf32_Rel *rel = NULL; //relocation entry
 
 	// Allocate memory for relocation table
-	if (!(rela = (Elf32_Rela *)malloc(size))) {
+	if (!(rel = (Elf32_Rel *)malloc(size))) {
 		seterror("Out of memory.");
 		return false;
 	}
 
 	// Read in our relocation table
 	if (DLFile->seek(offset, SEEK_SET) < 0 ||
-	        DLFile->read(rela, size) != (ssize_t)size) {
+	        DLFile->read(rel, size) != (ssize_t)size) {
 		seterror("Relocation table load failed.");
-		free(rela);
+		free(rel);
 		return false;
 	}
 
 	// Treat each relocation entry. Loop over all of them
-	int cnt = size / sizeof(*rela);
+	int cnt = size / sizeof(*rel);
 
+	DBG("# of relocation entries is %d.\n", cnt);
+
 	// TODO: Loop over relocation entries
 	for (int i = 0; i < cnt; i++) {
 
-		DBG("attempting to relocate!");
-
 	    //Elf32_Sym *sym = ???;
 
 		//void *target = ???;
@@ -107,13 +107,13 @@
 			//break;
 	//	default:
 			//seterror("Unknown relocation type %d.", ?? ?);
-			free(rela);
+			free(rel);
 			return false;
 	//	}
 
 	}
 
-	free(rela);
+	free(rel);
 	return true;
 }
 
@@ -170,17 +170,24 @@
 		seterror("Out of memory.\n");
 		return false;
 	}
+
 	DBG("allocated segment @ %p\n", _segment);
 
 	// Get offset to load segment into
 	baseAddress = (char *)_segment + phdr->p_vaddr;
 	_segmentSize = phdr->p_memsz + extra;
 
+	DBG("base address is %p\n", baseAddress);
+	DBG("_segmentSize is %p\n", _segmentSize);
+
 	// 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);
 		memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
 	}
+
+	DBG("Reading the segment into memory\n");
+
 	// 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) {
@@ -188,6 +195,8 @@
 		return false;
 	}
 
+	DBG("Segment has been read into memory\n");
+
 	return true;
 }
 
@@ -288,8 +297,8 @@
 		if (s->st_shndx < SHN_LOPROC) {
 				relocCount++;
 				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);
+				//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);
 
 		}
 
@@ -307,7 +316,7 @@
 		//Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]);
 
 		if (curShdr->sh_type == SHT_REL && 						// Check for a relocation section
-		        curShdr->sh_entsize == sizeof(Elf32_Rela) &&		    // Check for proper relocation size
+		        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
@@ -328,13 +337,11 @@
 	Elf32_Shdr *shdr;
 	bool ret = true;
 
-	//int symtab_sect = -1;
-
 	if (readElfHeader(DLFile, &ehdr) == false) {
 		return false;
 	}
 
-	for (int i = 0; i < ehdr.e_phnum; i++) {	//	Load our 2 segments
+	for (int i = 0; i < ehdr.e_phnum; i++) {	//Load our segments
 
 		DBG("Loading segment %d\n", i);
 
@@ -389,9 +396,11 @@
 		return false;
 	}
 
+	DBG("loaded!/n");
+
 	//DLFile->finalize();
 
-	//TODO: flush data cache
+	//TODO?: flush data cache
 
 	ctors_start = symbol("___plugin_ctors");
 	ctors_end = symbol("___plugin_ctors_end");
@@ -411,7 +420,7 @@
 		(**f)();
 
 	DBG(("%s opened ok.\n", path));
-	return false;
+
 	return true;
 }
 

Modified: scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.h	2010-07-14 03:55:11 UTC (rev 50868)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.h	2010-07-14 03:57:36 UTC (rev 50869)
@@ -27,6 +27,7 @@
 #define DS_LOADER_H
 
 #include "elf32.h"
+#include "common/list.h"
 
 #define MAXDLERRLEN 80
 
@@ -63,7 +64,8 @@
     void discard_symtab();
 
     DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL), _symtab(NULL),
-            _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {}
+            _strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL),
+            _segmentSize(0) {}
 };
 
 #define RTLD_LAZY 0


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