ppsspp/Core/MIPS/MIPSAsm.cpp

116 lines
2.5 KiB
C++
Raw Normal View History

2013-07-29 00:51:50 +10:00
#ifdef _WIN32
2013-07-28 14:50:25 +02:00
#include "stdafx.h"
2013-07-29 00:51:50 +10:00
#endif
2013-09-01 21:51:06 +10:00
#include <cstdarg>
#include <cstring>
#include <vector>
#include "Common/CommonTypes.h"
2013-07-28 14:50:25 +02:00
#if defined(_WIN32) || defined(__ANDROID__)
// Temporarily turned off on Android
#define USE_ARMIPS
#endif
#ifdef USE_ARMIPS
// This has to be before basictypes to avoid a define conflict.
2014-11-22 00:11:28 +01:00
#include "ext/armips/Core/Assembler.h"
#endif
#include "util/text/utf8.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/MemMapHelpers.h"
#include "Core/MIPS/JitCommon/JitCommon.h"
#include "Core/MIPS/MIPSAsm.h"
2014-11-22 00:11:28 +01:00
namespace MIPSAsm
{
static std::wstring errorText;
2014-11-22 00:11:28 +01:00
std::wstring GetAssembleError()
{
2014-11-22 00:11:28 +01:00
return errorText;
}
#ifdef USE_ARMIPS
2014-11-22 00:11:28 +01:00
class PspAssemblerFile: public AssemblerFile
2013-07-28 14:50:25 +02:00
{
2014-11-22 00:11:28 +01:00
public:
2016-09-18 23:11:00 +02:00
PspAssemblerFile() {
2014-11-22 00:11:28 +01:00
address = 0;
2013-07-28 14:50:25 +02:00
}
2015-10-17 02:55:10 -04:00
bool open(bool onlyCheck) override{ return true; };
void close() override { };
bool isOpen() override { return true; };
bool write(void* data, size_t length) override {
2014-11-22 00:11:28 +01:00
if (!Memory::IsValidAddress((u32)(address+length-1)))
return false;
2013-07-28 14:50:25 +02:00
2014-11-22 00:11:28 +01: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 14:50:25 +02:00
2014-11-22 00:11:28 +01:00
address += length;
return true;
2013-07-28 14:50:25 +02:00
}
2017-03-15 19:33:33 +01:00
int64_t getVirtualAddress() override { return address; };
int64_t getPhysicalAddress() override { return getVirtualAddress(); };
int64_t getHeaderSize() override { return 0; }
bool seekVirtual(int64_t virtualAddress) override {
2014-11-22 00:11:28 +01:00
if (!Memory::IsValidAddress(virtualAddress))
return false;
address = virtualAddress;
return true;
2013-07-28 14:50:25 +02:00
}
2017-03-15 19:33:33 +01:00
bool seekPhysical(int64_t physicalAddress) override { return seekVirtual(physicalAddress); }
2016-09-18 23:11:00 +02:00
const std::wstring &getFileName() override { return dummyWFilename_; }
2014-11-22 00:11:28 +01:00
private:
u64 address;
2016-09-18 23:11:00 +02:00
std::wstring dummyWFilename_;
2014-11-22 00:11:28 +01:00
};
#endif
2013-07-28 14:50:25 +02:00
2014-11-22 00:11:28 +01:00
bool MipsAssembleOpcode(const char* line, DebugInterface* cpu, u32 address)
{
#ifdef USE_ARMIPS
2014-11-22 00:11:28 +01: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 13:04:30 -08:00
args.mode = ArmipsMode::MEMORY;
2014-11-22 00:11:28 +01:00
args.content = str + ConvertUTF8ToWString(line);
args.silent = true;
args.memoryFile = &file;
args.errorsResult = &errors;
g_symbolMap->GetLabels(args.labels);
2014-11-22 00:11:28 +01:00
errorText = L"";
if (!runArmips(args))
{
2014-11-22 00:11:28 +01:00
for (size_t i = 0; i < errors.size(); i++)
{
2014-11-22 00:11:28 +01:00
errorText += errors[i];
if (i != errors.size()-1)
errorText += L"\n";
}
2013-07-28 14:50:25 +02:00
return false;
}
return true;
2014-11-22 00:11:28 +01:00
#else
errorText = L"Unsupported platform";
2013-07-28 14:50:25 +02:00
return false;
2014-11-22 00:11:28 +01:00
#endif
2013-07-28 14:50:25 +02:00
}
} // namespace