Skip to content

Better wrapper system, warning fixes, small bugfixes, module loading implementation #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Common/CPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ void CPUInfo::Detect()
if (max_ex_fn >= 0x80000001) {
// Check for more features.
__cpuid(cpu_id, 0x80000001);
bool cmp_legacy = false;
//bool cmp_legacy = false;
if (cpu_id[2] & 1) bLAHFSAHF64 = true;
if (cpu_id[2] & 2) cmp_legacy = true; //wtf is this?
//if (cpu_id[2] & 2) cmp_legacy = true; //wtf is this?
if ((cpu_id[3] >> 29) & 1) bLongMode = true;
}

Expand Down
6 changes: 3 additions & 3 deletions Common/FixedSizeUnorderedSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FixedSizeUnorderedSet

bool remove(T item)
{
for (int i = 0; i < count_; i++)
for (u32 i = 0; i < count_; i++)
{
if (data_[i] == item)
{
Expand Down Expand Up @@ -62,5 +62,5 @@ class FixedSizeUnorderedSet

private:
T data_[maxCount];
int count_;
};
u32 count_;
};
6 changes: 0 additions & 6 deletions Common/x64Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ bool DisassembleMov(const unsigned char *codePtr, InstructionInfo &info, int acc
info.hasImmediate = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why the changes in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variables give me warnings, so I just removed them. Feel free to keep them if you think you'll need them later. ;)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather you commented them out, at least the ones that look like they could be semi-useful in the future :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I kept the variables that I knew they would be needed in the future,
but since I thought the JIT was completed, I didn't think they'd be needed.
Please re-add them then. :)

Le 4 nov. 2012 23:34, "Henrik Rydgård" [email protected] a écrit :

In Common/x64Analyzer.cpp:

@@ -31,12 +31,9 @@ bool DisassembleMov(const unsigned char *codePtr, I...

I'd rather you commented them out, at least the ones that look like they
could be semi-useful in the future :)


Reply to this email directly or view it on GitHub.

[image]

info.isMemoryWrite = false;

int addressSize = 8;
u8 modRMbyte = 0;
u8 sibByte = 0;
bool hasModRM = false;
bool hasSIBbyte = false;
bool hasDisplacement = false;

int displacementSize = 0;

Expand All @@ -47,7 +44,6 @@ bool DisassembleMov(const unsigned char *codePtr, InstructionInfo &info, int acc
}
else if (*codePtr == 0x67)
{
addressSize = 4;
codePtr++;
}

Expand Down Expand Up @@ -113,7 +109,6 @@ bool DisassembleMov(const unsigned char *codePtr, InstructionInfo &info, int acc
info.otherReg = (sibByte & 7);
if (rex & 2) info.scaledReg += 8;
if (rex & 1) info.otherReg += 8;
hasSIBbyte = true;
}
else
{
Expand All @@ -122,7 +117,6 @@ bool DisassembleMov(const unsigned char *codePtr, InstructionInfo &info, int acc
}
if (mrm.mod == 1 || mrm.mod == 2)
{
hasDisplacement = true;
if (mrm.mod == 1)
displacementSize = 1;
else
Expand Down
2 changes: 1 addition & 1 deletion Common/x64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "MemoryUtil.h"

#if !defined(_M_IX86) && !defined(_M_X64)
#error Don't build this on arm.
#error Do not build this on arm.
#endif

namespace Gen
Expand Down
19 changes: 14 additions & 5 deletions Core/ELF/ElfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ bool ElfReader::LoadInto(u32 vaddr)
bRelocate = (header->e_type != ET_EXEC);

entryPoint = header->e_entry;
u32 totalSize = 0;
for (int i=0; i<header->e_phnum; i++)
{
Elf32_Phdr *p = segments + i;
if (p->p_type == PT_LOAD && p->p_vaddr + p->p_memsz > totalSize)
{
totalSize = p->p_vaddr + p->p_memsz;
}
}
if (vaddr)
vaddr = userMemory.AllocAt(vaddr, totalSize, "ELF");
else
vaddr = userMemory.Alloc(totalSize, false, "ELF");

if (bRelocate)
{
DEBUG_LOG(LOADER,"Relocatable module");
Expand Down Expand Up @@ -109,8 +123,6 @@ bool ElfReader::LoadInto(u32 vaddr)
u32 srcSize = p->p_filesz;
u32 dstSize = p->p_memsz;

userMemory.AllocAt(writeAddr, dstSize, "ELF");

memcpy(dst, src, srcSize);
if (srcSize < dstSize)
{
Expand Down Expand Up @@ -154,7 +166,6 @@ bool ElfReader::LoadInto(u32 vaddr)
if (s->sh_type == SHT_PSPREL)
{
//We have a relocation table!
int symbolSection = s->sh_link;
int sectionToModify = s->sh_info;

if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
Expand Down Expand Up @@ -289,7 +300,6 @@ bool ElfReader::LoadInto(u32 vaddr)
else
{
//We have a relocation table!
int symbolSection = s->sh_link;
int sectionToModify = s->sh_info;
if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
{
Expand Down Expand Up @@ -341,7 +351,6 @@ bool ElfReader::LoadSymbols()
if (size == 0)
continue;

int bind = symtab[sym].st_info >> 4;
int type = symtab[sym].st_info & 0xF;
int sectionIndex = symtab[sym].st_shndx;
int value = symtab[sym].st_value;
Expand Down
9 changes: 9 additions & 0 deletions Core/ELF/ElfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ class ElfReader
}
SectionID GetSectionByName(const char *name, int firstSection=0); //-1 for not found

u32 GetSegmentPaddr(int segment)
{
return segments[segment].p_paddr;
}
u32 GetSegmentOffset(int segment)
{
return segments[segment].p_offset;
}

bool DidRelocate() {
return bRelocate;
}
Expand Down
3 changes: 2 additions & 1 deletion Core/FileSystems/ISOFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(std::string path)
for (size_t i=0; i<e->children.size(); i++)
{
std::string n = e->children[i]->name;
if (path.compare(0, n.length(), n) == 0) //TODO : bad
std::string curPath = path.substr(0, path.find_first_of('/'));
if (curPath == n)
{
//yay we got it
ne = e->children[i];
Expand Down
103 changes: 89 additions & 14 deletions Core/HLE/FunctionWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,141 @@

// For easy parameter parsing and return value processing.

template<void func()> void WrapV_V() {
template<void func()> void Wrap() {
func();
}

template<u32 func()> void WrapU_V() {
template<u32 func()> void Wrap() {
RETURN(func());
}

template<float func()> void WrapF_V() {
template<float func()> void Wrap() {
RETURNF(func());
}

template<u32 func(u32)> void WrapU_U() {
template<u32 func(u32)> void Wrap() {
u32 retval = func(PARAM(0));
RETURN(retval);
}
template<int func(int)> void Wrap() {
int retval = func(PARAM(0));
RETURN(retval);
}
template<u32 func(int)> void Wrap() {
u32 retval = func(PARAM(0));
RETURN(retval);
}

template<void func(u32)> void WrapV_U() {
template<void func(u32)> void Wrap() {
func(PARAM(0));
}

template<void func(u32, u32)> void WrapV_UU() {
template <u32 func(time_t *)> void Wrap() {
u32 retval = func((time_t*)Memory::GetPointer(PARAM(0)));
RETURN(retval);
}

template<void func(u32, u32)> void Wrap() {
func(PARAM(0), PARAM(1));
}

template<u32 func(u32, u32)> void WrapU_UU() {
template<u32 func(u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1));
RETURN(retval);
}
template<u32 func(timeval *, u32)> void Wrap() {
u32 retval = func((timeval*)Memory::GetPointer(PARAM(0)), PARAM(1));
RETURN(retval);
}
template<u32 func(int, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1));
RETURN(retval);
}

template<int func(const char *, u32)> void WrapI_CU() {
template<u32 func(const char *, u32)> void Wrap() {
int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
RETURN((u32)retval);
}
template<int func(const char *, u32)> void Wrap() {
int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
RETURN((u32)retval);
}
template<u32 func(const char *, int)> void Wrap() {
u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
RETURN(retval);
}

template<u32 func(const char *, u32, u32)> void WrapU_CUU() {
template<u32 func(const char *, u32, u32)> void Wrap() {
int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
RETURN((u32)retval);
}
template<u32 func(const char *, int, int)> void Wrap() {
int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
RETURN((u32)retval);
}

template<u32 func(u32, u32, u32)> void WrapU_UUU() {
template<u32 func(u32, u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
RETURN(retval);
}
template<u32 func(int, int, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
RETURN(retval);
}
template<u32 func(int, u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
RETURN(retval);
}

template<void func(u32, u32, u32)> void WrapV_UUU() {
template<void func(u32, u32, u32)> void Wrap() {
func(PARAM(0), PARAM(1), PARAM(2));
}

template<u32 func(u32, u32, u32, u32)> void WrapU_UUUU() {
template<u32 func(u32, u32, u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
RETURN(retval);
}
template<u32 func(u32, int, int, int)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
RETURN(retval);
}
template<u32 func(u32, u32, u32, int)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
RETURN(retval);
}

template<u32 func(u32, u32, u32, u32, u32)> void WrapU_UUUUU() {
template<u32 func(u32, u32, u32, u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
RETURN(retval);
}

template<u32 func(u32, u32, u32, u32, u32, u32)> void WrapU_UUUUUU() {
template<u32 func(u32, u32, u32, u32, u32, u32)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
RETURN(retval);
}
template<u32 func(u32, int, u32, int, u32, int)> void Wrap() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
RETURN(retval);
}

template<u32 func(u64)> void Wrap() {
u32 retval = func(((u64)PARAM(1) << 32) | PARAM(0));
RETURN(retval);
}

template<u64 func(u32, u64, u32)> void Wrap() {
u64 retval = func(PARAM(0), ((u64)PARAM(3) << 32) | PARAM(2), PARAM(4));
RETURN(retval);
RETURN2(retval >> 32);
}
template<u64 func(int, s64, u32)> void Wrap() {
u64 retval = func(PARAM(0), ((u64)PARAM(3) << 32) | PARAM(2), PARAM(4));
RETURN(retval);
RETURN2(retval >> 32);
}

template<u32 func(int, s64, u32)> void Wrap() {
u32 retval = func(PARAM(0), ((u64)PARAM(3) << 32) | PARAM(2), PARAM(4));
RETURN(retval);
}

59 changes: 31 additions & 28 deletions Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "../MIPS/MIPSCodeUtils.h"

static std::vector<HLEModule> moduleDB;
static std::vector<Syscall> unresolvedSyscalls;

void HLEInit()
{
Expand All @@ -39,32 +40,6 @@ void HLEShutdown()
moduleDB.clear();
}

/*
//unused
struct PSPHeader
{
char psp[4];
u32 version; //00080000
short whatever; //0101
char sometext[28];
short whatever2; //0102
u32 filesizedecrypted;
u32 filesize;
u32 unknownoffsets[3];
short whatever3[2]; //0x40 0x40
u32 whatever4[2]; //00
u32 whatever5; //1067008
u32 whatever6[2]; //00
u32 whatever7; //1067008
u32 whatever8; //2553296
u32 whatever9[8]; //0
u32 whatever10; //12
u32 encryptedStuff[12];
u32 filesizedecrypted2;
u32 whatever11;//0x80
u32 whatever12[6];
};*/

void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable)
{
HLEModule module = {name, numFunctions, funcTable};
Expand Down Expand Up @@ -157,8 +132,36 @@ void WriteSyscall(const char *moduleName, u32 nib, u32 address)
Memory::Write_U32(MIPS_MAKE_NOP(), address+4); //patched out?
return;
}
Memory::Write_U32(MIPS_MAKE_JR_RA(), address); // jr ra
Memory::Write_U32(GetSyscallOp(moduleName, nib), address + 4);
int modindex = GetModuleIndex(moduleName);
if (modindex != -1)
{
Memory::Write_U32(MIPS_MAKE_JR_RA(), address); // jr ra
Memory::Write_U32(GetSyscallOp(moduleName, nib), address + 4);
}
else
{
// Module inexistent.. for now; let's store the syscall for it to be resolved later
INFO_LOG(HLE,"Syscall (%s,%08x) unresolved, storing for later resolving", moduleName, nib);
Syscall sysc = {"", address, nib};
strncpy(sysc.moduleName, moduleName, 32);
sysc.moduleName[31] = '\0';
unresolvedSyscalls.push_back(sysc);
}
}

void ResolveSyscall(const char *moduleName, u32 nib, u32 address)
{
for (size_t i = 0; i < unresolvedSyscalls.size(); i++)
{
Syscall *sysc = &unresolvedSyscalls[i];
if (strncmp(sysc->moduleName, moduleName, 32) == 0 && sysc->nid == nib)
{
INFO_LOG(HLE,"Resolving %s/%08x",moduleName,nib);
// Note: doing that, we can't trace external module calls, so maybe something else should be done to debug more efficiently
Memory::Write_U32(MIPS_MAKE_JAL(address), sysc->symAddr);
Memory::Write_U32(MIPS_MAKE_NOP(), sysc->symAddr + 4);
}
}
}

const char *GetFuncName(int moduleIndex, int func)
Expand Down
Loading