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

toneman1138 at users.sourceforge.net toneman1138 at users.sourceforge.net
Tue Jul 13 08:48:44 CEST 2010


Revision: 50843
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50843&view=rev
Author:   toneman1138
Date:     2010-07-13 06:48:43 +0000 (Tue, 13 Jul 2010)

Log Message:
-----------
Changed loader to use Common::SeekableReadStream (compiles but doesn't run and needs polishing)

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-13 05:38:10 UTC (rev 50842)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.cpp	2010-07-13 06:48:43 UTC (rev 50843)
@@ -33,12 +33,8 @@
 #include <unistd.h>
 #include <sys/_default_fcntl.h>
 
-#include "common/str.h"
-#include "common/util.h"
-#include "backends/fs/stdiostream.h"
+//#include "backends/fs/stdiostream.h"
 #include "backends/fs/ds/ds-fs.h"
-#include "dsmain.h"
-#include "fat/gba_nds_fat.h"
 
 #include "backends/platform/ds/arm9/source/dsloader.h"
 
@@ -71,12 +67,12 @@
 /**
  * Follow the instruction of a relocation section.
  *
- * @param fd 		 File Descriptor
+ * @param DLFile 	 SeekableReadStream of File
  * @param offset 	 Offset into the File
  * @param size   	 Size of relocation section
  *
  */
-bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) {
+bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) {
 	Elf32_Rela *rela; //relocation entry
 
 	// Allocate memory for relocation table
@@ -86,8 +82,8 @@
 	}
 
 	// Read in our relocation table
-	if (lseek(fd, offset, SEEK_SET) < 0 ||
-	        read(fd, rela, size) != (ssize_t)size) {
+	if (DLFile->seek(offset, SEEK_SET) < 0 ||
+	        DLFile->read(rela, size) != (ssize_t)size) {
 		seterror("Relocation table load failed.");
 		free(rela);
 		return false;
@@ -121,10 +117,10 @@
 	return true;
 }
 
-bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) {
+bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) {
 
 	// Start reading the elf header. Check for errors
-	if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) ||
+	if (DLFile->read(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_ARM ||						// Check for ARM machine type
@@ -140,11 +136,11 @@
 	return true;
 }
 
-bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) {
+bool DLObject::readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) {
 
 	// Read program header
-	if (lseek(fd, ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 ||
-	    read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr)) {
+	if (DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 ||
+	    DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) {
 		seterror("Program header load failed.");
 		return false;
 	}
@@ -162,7 +158,7 @@
 
 }
 
-bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) {
+bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) {
 
 	char *baseAddress = 0;
 
@@ -186,8 +182,8 @@
 		memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
 	}
 	// Read the segment into memory
-	if (lseek(fd, phdr->p_offset, SEEK_SET) < 0 ||
-	        read(fd, baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) {
+	if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 ||
+	        DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) {
 		seterror("Segment load failed.");
 		return false;
 	}
@@ -195,7 +191,7 @@
 	return true;
 }
 
-Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) {
+Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) {
 
 	Elf32_Shdr *shdr = NULL;
 
@@ -206,8 +202,8 @@
 	}
 
 	// Read from file into section headers
-	if (lseek(fd, ehdr->e_shoff, SEEK_SET) < 0 ||
-	        read(fd, shdr, ehdr->e_shnum * sizeof(*shdr)) !=
+	if (DLFile->seek(ehdr->e_shoff, SEEK_SET) < 0 ||
+	        DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) !=
 	        (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) {
 		seterror("Section headers load failed.");
 		return NULL;
@@ -216,7 +212,7 @@
 	return shdr;
 }
 
-int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
+int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
 
 	// Loop over sections, looking for symbol table linked to a string table
 	for (int i = 0; i < ehdr->e_shnum; i++) {
@@ -244,8 +240,8 @@
 	}
 
 	// Read symbol table into memory
-	if (lseek(fd, shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 ||
-	        read(fd, _symtab, shdr[_symtab_sect].sh_size) !=
+	if (DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 ||
+	        DLFile->read(_symtab, shdr[_symtab_sect].sh_size) !=
 	        (ssize_t)shdr[_symtab_sect].sh_size) {
 		seterror("Symbol table load failed.");
 		return -1;
@@ -259,7 +255,7 @@
 
 }
 
-bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) {
+bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr) {
 
 	int string_sect = shdr[_symtab_sect].sh_link;
 
@@ -270,8 +266,8 @@
 	}
 
 	// Read string table into memory
-	if (lseek(fd, shdr[string_sect].sh_offset, SEEK_SET) < 0 ||
-	        read(fd, _strtab, shdr[string_sect].sh_size) !=
+	if (DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) < 0 ||
+	        DLFile->read(_strtab, shdr[string_sect].sh_size) !=
 	        (ssize_t)shdr[string_sect].sh_size) {
 		seterror("Symbol table strings load failed.");
 		return false;
@@ -302,7 +298,7 @@
 	DBG("Relocated %d symbols.\n",relocCount);
 }
 
-bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
+bool DLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) {
 
 	// Loop over sections, finding relocation sections
 	for (int i = 0; i < ehdr->e_shnum; i++) {
@@ -316,7 +312,7 @@
 		        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 (!relocate(fd, curShdr->sh_offset, curShdr->sh_size, _segment)) {
+			if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) {
 				return false;
 			}
 
@@ -326,7 +322,7 @@
 	return true;
 }
 
-bool DLObject::load(int fd) {
+bool DLObject::load(Common::SeekableReadStream* DLFile) {
 	Elf32_Ehdr ehdr;
 	Elf32_Phdr phdr;
 	Elf32_Shdr *shdr;
@@ -334,7 +330,7 @@
 
 	//int symtab_sect = -1;
 
-	if (readElfHeader(fd, &ehdr) == false) {
+	if (readElfHeader(DLFile, &ehdr) == false) {
 		return false;
 	}
 
@@ -342,26 +338,26 @@
 
 		DBG("Loading segment %d\n", i);
 
-		if (readProgramHeaders(fd, &ehdr, &phdr, i) == false)
+		if (readProgramHeaders(DLFile, &ehdr, &phdr, i) == false)
 			return false;
 
-		if (!loadSegment(fd, &phdr))
+		if (!loadSegment(DLFile, &phdr))
 			return false;
 	}
 
-	if ((shdr = loadSectionHeaders(fd, &ehdr)) == NULL)
+	if ((shdr = loadSectionHeaders(DLFile, &ehdr)) == NULL)
 		ret = false;
 
-	if (ret && ((_symtab_sect = loadSymbolTable(fd, &ehdr, shdr)) < 0))
+	if (ret && ((_symtab_sect = loadSymbolTable(DLFile, &ehdr, shdr)) < 0))
 		ret = false;
 
-	if (ret && (loadStringTable(fd, shdr) == false))
+	if (ret && (loadStringTable(DLFile, shdr) == false))
 		ret = false;
 
 	if (ret)
 		relocateSymbols((Elf32_Addr)_segment);	// Offset by our segment allocated address
 
-	if (ret && (relocateRels(fd, &ehdr, shdr) == false))
+	if (ret && (relocateRels(DLFile, &ehdr, shdr) == false))
 		ret = false;
 
 	free(shdr);
@@ -371,9 +367,8 @@
 }
 
 bool DLObject::open(const char *path) {
-	int fd;
 
-	Common::SeekableReadStream* DLFile; //TODO: reimplement everything with SeekableReadStream instead of fd
+	Common::SeekableReadStream* DLFile;
 	void *ctors_start, *ctors_end;
 
 	DBG("open(\"%s\")\n", path);
@@ -388,13 +383,13 @@
 	DBG("%s found!\n", path);
 
 	/*Try to load and relocate*/
-	if (!load(fd)) {
-		::close(fd);
+	if (!load(DLFile)) {
+		//DLFile->finalize();
 		unload();
 		return false;
 	}
 
-	::close(fd);
+	//DLFile->finalize();
 
 	//TODO: flush data cache
 

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-13 05:38:10 UTC (rev 50842)
+++ scummvm/branches/gsoc2010-plugins/backends/platform/ds/arm9/source/dsloader.h	2010-07-13 06:48:43 UTC (rev 50843)
@@ -44,17 +44,17 @@
 
 		void seterror(const char *fmt, ...);
 		void unload();
-		bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment);
-		bool load(int fd);
+		bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment);
+		bool load(Common::SeekableReadStream* DLFile);
 
-		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);
+		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(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
+		bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
 
 	public:
 		bool open(const char *path);


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