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>
|
2013-12-31 05:37:19 +00:00
|
|
|
#include <cstring>
|
2014-11-21 23:11:28 +00:00
|
|
|
#include "util/text/utf8.h"
|
|
|
|
#include "Core/MemMap.h"
|
2014-12-12 23:09:37 +00:00
|
|
|
#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
|
|
|
|
2014-12-07 23:20:34 +00:00
|
|
|
#if defined(_WIN32) || defined(ANDROID)
|
2014-11-21 23:11:28 +00:00
|
|
|
#include "ext/armips/Core/Assembler.h"
|
|
|
|
#endif
|
2013-09-01 08:21:05 +00:00
|
|
|
|
2014-11-21 23:11:28 +00:00
|
|
|
namespace MIPSAsm
|
|
|
|
{
|
2014-12-07 23:20:34 +00:00
|
|
|
static std::wstring errorText;
|
2013-09-01 08:21:05 +00:00
|
|
|
|
2014-11-21 23:11:28 +00:00
|
|
|
std::wstring GetAssembleError()
|
2013-09-01 08:21:05 +00:00
|
|
|
{
|
2014-11-21 23:11:28 +00:00
|
|
|
return errorText;
|
2013-09-01 08:21:05 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 23:20:34 +00:00
|
|
|
#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)
|
2014-11-09 23:14:07 +00:00
|
|
|
{
|
2014-12-07 23:20:34 +00:00
|
|
|
#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;
|
|
|
|
|
2014-12-07 23:20:34 +00:00
|
|
|
symbolMap.GetLabels(args.labels);
|
2014-11-09 23:14:07 +00:00
|
|
|
|
2014-11-21 23:11:28 +00:00
|
|
|
errorText = L"";
|
|
|
|
if (!runArmips(args))
|
2014-11-09 23:14:07 +00:00
|
|
|
{
|
2014-11-21 23:11:28 +00:00
|
|
|
for (size_t i = 0; i < errors.size(); i++)
|
2014-11-09 23:14:07 +00:00
|
|
|
{
|
2014-11-21 23:11:28 +00:00
|
|
|
errorText += errors[i];
|
|
|
|
if (i != errors.size()-1)
|
|
|
|
errorText += L"\n";
|
2014-11-09 23:14:07 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 12:50:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-11-21 23:11:28 +00:00
|
|
|
#else
|
2014-12-07 23:20:34 +00:00
|
|
|
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
|
|
|
}
|