Make previous code cleaner

This commit is contained in:
Arthur Blot 2013-01-02 12:35:37 +01:00
parent c2851467e5
commit e4ce0592c1
4 changed files with 62 additions and 50 deletions

View file

@ -271,7 +271,6 @@ bool ElfReader::LoadInto(u32 loadAddress)
} }
DEBUG_LOG(LOADER,"Relocations:"); DEBUG_LOG(LOADER,"Relocations:");
bool oldRelocs = false;
// Second pass: Do necessary relocations // Second pass: Do necessary relocations
for (int i=0; i<GetNumSections(); i++) for (int i=0; i<GetNumSections(); i++)
@ -300,19 +299,22 @@ bool ElfReader::LoadInto(u32 loadAddress)
else if (s->sh_type == SHT_REL) else if (s->sh_type == SHT_REL)
{ {
DEBUG_LOG(LOADER, "Traditional relocation section found."); DEBUG_LOG(LOADER, "Traditional relocation section found.");
if (bRelocate) if (!bRelocate)
{ {
DEBUG_LOG(LOADER, "Binary is prerelocated. Skipping relocations."); DEBUG_LOG(LOADER, "Binary is prerelocated. Skipping relocations.");
} }
else else
{ {
oldRelocs = true; //We have a relocation table!
} int sectionToModify = s->sh_info;
} if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
}
if (oldRelocs)
{ {
INFO_LOG(LOADER, "Game uses old relocations (often for debugging, should be harmless)"); ERROR_LOG(LOADER,"Trying to relocate non-loaded section %s, ignoring",GetSectionName(sectionToModify));
continue;
}
ERROR_LOG(LOADER,"Traditional relocations unsupported.");
}
}
} }
// Segment relocations (a few games use them) // Segment relocations (a few games use them)

View file

@ -120,6 +120,43 @@ struct dirent {
}; };
#endif #endif
class FileNode : public KernelObject {
public:
FileNode() : callbackID(0), callbackArg(0), asyncResult(0), pendingAsyncResult(false), sectorBlockMode(false) {}
~FileNode() {
pspFileSystem.CloseFile(handle);
}
const char *GetName() {return fullpath.c_str();}
const char *GetTypeName() {return "OpenFile";}
void GetQuickInfo(char *ptr, int size) {
sprintf(ptr, "Seekpos: %08x", (u32)pspFileSystem.GetSeekPos(handle));
}
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_BADF; }
int GetIDType() const { return PPSSPP_KERNEL_TMID_File; }
virtual void DoState(PointerWrap &p) {
p.Do(fullpath);
p.Do(handle);
p.Do(callbackID);
p.Do(callbackArg);
p.Do(asyncResult);
p.Do(pendingAsyncResult);
p.Do(sectorBlockMode);
p.DoMarker("File");
}
std::string fullpath;
u32 handle;
u32 callbackID;
u32 callbackArg;
u32 asyncResult;
bool pendingAsyncResult;
bool sectorBlockMode;
};
void __IoInit() { void __IoInit() {
INFO_LOG(HLE, "Starting up I/O..."); INFO_LOG(HLE, "Starting up I/O...");
@ -175,6 +212,15 @@ void __IoShutdown() {
defParam = 0; defParam = 0;
} }
u32 __IoGetFileHandleFromId(u32 id, u32 &outError)
{
FileNode *f = kernelObjects.Get < FileNode > (id, outError);
if (!f) {
return -1;
}
return f->handle;
}
u32 sceIoAssign(const char *aliasname, const char *physname, const char *devname, u32 flag) { u32 sceIoAssign(const char *aliasname, const char *physname, const char *devname, u32 flag) {
ERROR_LOG(HLE, "UNIMPL sceIoAssign(%s, %s, %s, %08x, ...)", aliasname, ERROR_LOG(HLE, "UNIMPL sceIoAssign(%s, %s, %s, %08x, ...)", aliasname,
physname, devname, flag); physname, devname, flag);

View file

@ -23,46 +23,10 @@
#include "HLE.h" #include "HLE.h"
#include "sceKernel.h" #include "sceKernel.h"
class FileNode : public KernelObject {
public:
FileNode() : callbackID(0), callbackArg(0), asyncResult(0), pendingAsyncResult(false), sectorBlockMode(false) {}
~FileNode() {
pspFileSystem.CloseFile(handle);
}
const char *GetName() {return fullpath.c_str();}
const char *GetTypeName() {return "OpenFile";}
void GetQuickInfo(char *ptr, int size) {
sprintf(ptr, "Seekpos: %08x", (u32)pspFileSystem.GetSeekPos(handle));
}
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_BADF; }
int GetIDType() const { return PPSSPP_KERNEL_TMID_File; }
virtual void DoState(PointerWrap &p) {
p.Do(fullpath);
p.Do(handle);
p.Do(callbackID);
p.Do(callbackArg);
p.Do(asyncResult);
p.Do(pendingAsyncResult);
p.Do(sectorBlockMode);
p.DoMarker("File");
}
std::string fullpath;
u32 handle;
u32 callbackID;
u32 callbackArg;
u32 asyncResult;
bool pendingAsyncResult;
bool sectorBlockMode;
};
void __IoInit(); void __IoInit();
void __IoDoState(PointerWrap &p); void __IoDoState(PointerWrap &p);
void __IoShutdown(); void __IoShutdown();
u32 __IoGetFileHandleFromId(u32 id, u32 &outError);
KernelObject *__KernelFileNodeObject(); KernelObject *__KernelFileNodeObject();
KernelObject *__KernelDirListingObject(); KernelObject *__KernelDirListingObject();

View file

@ -794,8 +794,8 @@ void sceKernelFindModuleByName()
u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr)
{ {
u32 error; u32 error;
FileNode *f = kernelObjects.Get < FileNode > (id, error); u32 handle = __IoGetFileHandleFromId(id, error);
if (!f) { if (handle < 0) {
ERROR_LOG(HLE,"sceKernelLoadModuleByID(%08x, %08x, %08x): could not open file id",id,flags,lmoptionPtr); ERROR_LOG(HLE,"sceKernelLoadModuleByID(%08x, %08x, %08x): could not open file id",id,flags,lmoptionPtr);
return error; return error;
} }
@ -803,13 +803,13 @@ u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr)
if (lmoptionPtr) { if (lmoptionPtr) {
lmoption = (SceKernelLMOption *)Memory::GetPointer(lmoptionPtr); lmoption = (SceKernelLMOption *)Memory::GetPointer(lmoptionPtr);
} }
u32 pos = pspFileSystem.SeekFile(f->handle, 0, FILEMOVE_CURRENT); u32 pos = pspFileSystem.SeekFile(handle, 0, FILEMOVE_CURRENT);
u32 size = pspFileSystem.SeekFile(f->handle, 0, FILEMOVE_END); u32 size = pspFileSystem.SeekFile(handle, 0, FILEMOVE_END);
std::string error_string; std::string error_string;
pspFileSystem.SeekFile(f->handle, pos, FILEMOVE_BEGIN); pspFileSystem.SeekFile(handle, pos, FILEMOVE_BEGIN);
Module *module = 0; Module *module = 0;
u8 *temp = new u8[size]; u8 *temp = new u8[size];
pspFileSystem.ReadFile(f->handle, temp, size); pspFileSystem.ReadFile(handle, temp, size);
module = __KernelLoadELFFromPtr(temp, 0, &error_string); module = __KernelLoadELFFromPtr(temp, 0, &error_string);
delete [] temp; delete [] temp;