ppsspp/Core/MIPS/MIPSAsm.cpp

104 lines
2.2 KiB
C++
Raw Normal View History

2013-07-28 14:51:50 +00:00
#ifdef _WIN32
2013-07-28 12:50:25 +00:00
#include "stdafx.h"
2013-07-28 14:51:50 +00:00
#endif
2013-07-28 12:50:25 +00:00
#include "MIPSAsm.h"
2013-09-01 11:51:06 +00:00
#include <cstdarg>
#include <cstring>
2014-11-21 23:11:28 +00:00
#include "util/text/utf8.h"
#include "Core/MemMap.h"
#include "Core/MIPS/JitCommon/NativeJit.h"
2014-11-21 23:11:28 +00:00
#include "Core/Debugger/SymbolMap.h"
2013-07-28 12:50:25 +00:00
#if defined(_WIN32) || defined(ANDROID)
2014-11-21 23:11:28 +00:00
#include "ext/armips/Core/Assembler.h"
#endif
2014-11-21 23:11:28 +00:00
namespace MIPSAsm
{
static std::wstring errorText;
2014-11-21 23:11:28 +00:00
std::wstring GetAssembleError()
{
2014-11-21 23:11:28 +00:00
return errorText;
}
#if defined(_WIN32) || defined(ANDROID)
2014-11-21 23:11:28 +00:00
class PspAssemblerFile: public AssemblerFile
2013-07-28 12:50:25 +00:00
{
2014-11-21 23:11:28 +00:00
public:
PspAssemblerFile()
2013-07-28 12:50:25 +00:00
{
2014-11-21 23:11:28 +00:00
address = 0;
2013-07-28 12:50:25 +00:00
}
2014-11-21 23:11:28 +00:00
virtual bool open(bool onlyCheck) { return true; };
virtual void close() { };
virtual bool isOpen() { return true; };
virtual bool write(void* data, size_t length)
2013-07-28 12:50:25 +00:00
{
2014-11-21 23:11:28 +00:00
if (!Memory::IsValidAddress((u32)(address+length-1)))
return false;
2013-07-28 12:50:25 +00:00
2014-11-21 23:11:28 +00:00
Memory::Memcpy((u32)address,data,(u32)length);
// In case this is a delay slot or combined instruction, clear cache above it too.
if (MIPSComp::jit)
MIPSComp::jit->InvalidateCacheAt((u32)(address - 4),(int)length+4);
2013-07-28 12:50:25 +00:00
2014-11-21 23:11:28 +00:00
address += length;
return true;
2013-07-28 12:50:25 +00:00
}
2014-11-21 23:11:28 +00:00
virtual u64 getVirtualAddress() { return address; };
virtual u64 getPhysicalAddress() { return getVirtualAddress(); };
virtual bool seekVirtual(u64 virtualAddress)
2013-07-28 12:50:25 +00:00
{
2014-11-21 23:11:28 +00:00
if (!Memory::IsValidAddress(virtualAddress))
return false;
address = virtualAddress;
return true;
2013-07-28 12:50:25 +00:00
}
2014-11-21 23:11:28 +00:00
virtual bool seekPhysical(u64 physicalAddress) { return seekVirtual(physicalAddress); }
private:
u64 address;
};
#endif
2013-07-28 12:50:25 +00:00
2014-11-21 23:11:28 +00:00
bool MipsAssembleOpcode(const char* line, DebugInterface* cpu, u32 address)
{
#if defined(_WIN32) || defined(ANDROID)
2014-11-21 23:11:28 +00:00
PspAssemblerFile file;
StringList errors;
wchar_t str[64];
swprintf(str,64,L".psp\n.org 0x%08X\n",address);
ArmipsArguments args;
2015-01-04 21:04:30 +00:00
args.mode = ArmipsMode::MEMORY;
2014-11-21 23:11:28 +00:00
args.content = str + ConvertUTF8ToWString(line);
args.silent = true;
args.memoryFile = &file;
args.errorsResult = &errors;
symbolMap.GetLabels(args.labels);
2014-11-21 23:11:28 +00:00
errorText = L"";
if (!runArmips(args))
{
2014-11-21 23:11:28 +00:00
for (size_t i = 0; i < errors.size(); i++)
{
2014-11-21 23:11:28 +00:00
errorText += errors[i];
if (i != errors.size()-1)
errorText += L"\n";
}
2013-07-28 12:50:25 +00:00
return false;
}
return true;
2014-11-21 23:11:28 +00:00
#else
errorText = L"Unsupported platform";
2013-07-28 12:50:25 +00:00
return false;
2014-11-21 23:11:28 +00:00
#endif
2013-07-28 12:50:25 +00:00
}
2014-11-21 23:11:28 +00:00
}