Commit 5606c91a authored by Aleksey R.'s avatar Aleksey R.

ARM64 minimal support

parent dd9c6bb0
......@@ -46,7 +46,8 @@ enum BreakpointType {
enum CPUType {
CPU_I386 = 0,
CPU_AMD64 = 1,
CPU_MAX = 2
CPU_ARM64 = 2,
CPU_MAX = 3
};
enum CPURegType {
......
......@@ -128,8 +128,9 @@ enum RegRealativeIds
////////////////////////////////////////////////////////////////////////////////
enum MachineTypes {
machine_I386 = 0x014c,
machine_AMD64 = 0x8664
machine_I386 = 0x014c,
machine_AMD64 = 0x8664,
machine_ARM64 = 0xaa64,
};
////////////////////////////////////////////////////////////////////////////////
......
......@@ -471,8 +471,9 @@ public:
{
switch (m_machineType)
{
case IMAGE_FILE_MACHINE_I386: return machine_I386;
case IMAGE_FILE_MACHINE_I386: return machine_I386;
case IMAGE_FILE_MACHINE_AMD64: return machine_AMD64;
case IMAGE_FILE_MACHINE_ARM64: return machine_ARM64;
}
throw SymbolException(L"Unkonw machine type");
......@@ -527,7 +528,8 @@ private:
return;
}
if ( m_machineType == IMAGE_FILE_MACHINE_AMD64 )
if ( m_machineType == IMAGE_FILE_MACHINE_AMD64 ||
m_machineType == IMAGE_FILE_MACHINE_ARM64 )
{
GetExport<IMAGE_NT_HEADERS64>( moduleBase );
return;
......
......@@ -107,14 +107,30 @@ bool getArrayExpression( std::wstring &suffix, size_t &arraySize )
return false;
}
///////////////////////////////////////////////////////////////////////////////
} // end nameless namespace
namespace kdlib {
///////////////////////////////////////////////////////////////////////////////
size_t getPointerSizeByMachine(const SymbolPtr &symbol)
{
const auto machineType = symbol->getMachineType();
switch (machineType)
{
case machine_I386:
return 4;
case machine_AMD64:
case machine_ARM64:
return 8;
default:
throw TypeException(L"unknown machine type");
}
}
///////////////////////////////////////////////////////////////////////////////
......@@ -671,7 +687,7 @@ TypeInfoPtr TypeInfo::getComplexTypeInfo( const std::wstring &typeName, SymbolPt
size_t pointerSize;
if ( symbolScope )
pointerSize = symbolScope->getMachineType() == machine_AMD64 ? 8 : 4;
pointerSize = getPointerSizeByMachine(symbolScope);
else
pointerSize = ptrSize();
......@@ -1660,7 +1676,7 @@ size_t TypeInfoVtbl::getElementCount()
size_t TypeInfoVtbl::getSize()
{
return ((m_symbol->getMachineType() == machine_AMD64) ? 8 : 4) * getElementCount();
return getPointerSizeByMachine(m_symbol) * getElementCount();
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -9,12 +9,13 @@ namespace kdlib {
///////////////////////////////////////////////////////////////////////////////
size_t getPointerSizeByMachine(const SymbolPtr &symbol);
inline size_t getPtrSizeBySymbol( SymbolPtr &typeSym )
{
SymTags symTag = typeSym->getSymTag();
if ( symTag != SymTagPointerType )
return (typeSym->getMachineType() == machine_AMD64) ? 8 : 4;
return getPointerSizeByMachine(typeSym);
return typeSym->getSize();
}
......
......@@ -178,6 +178,7 @@ int alignStackPointer( int byteCount )
break;
case CPU_AMD64:
case CPU_ARM64:
machineWord = 8;
break;
......@@ -387,6 +388,10 @@ MEMOFFSET_64 CPUContextImpl::getIP()
{
return addr64( getRegisterByName(L"rip").asULongLong() );
}
else if ( m_cpuMode == CPU_ARM64 )
{
return addr64( getRegisterByName(L"pc").asULongLong() );
}
throw DbgException("Unknown CPU type");
}
......@@ -403,6 +408,10 @@ void CPUContextImpl::setIP(MEMOFFSET_64 ip)
{
setRegisterByName(L"rip", NumVariant(ip));
}
else if ( m_cpuMode == CPU_ARM64 )
{
setRegisterByName(L"pc", NumVariant(ip));
}
assert(0);
}
......@@ -419,6 +428,10 @@ MEMOFFSET_64 CPUContextImpl::getSP()
{
return addr64( getRegisterByName(L"rsp").asULongLong() );
}
else if ( m_cpuMode == CPU_ARM64 )
{
return addr64( getRegisterByName(L"sp").asULongLong() );
}
throw DbgException("Unknown CPU type");
}
......@@ -431,9 +444,13 @@ void CPUContextImpl::setSP(MEMOFFSET_64 sp)
{
setRegisterByName(L"esp", NumVariant(sp));
}
else if ( m_cpuMode == CPU_I386 )
else if ( m_cpuMode == CPU_AMD64 )
{
setRegisterByName(L"esp", NumVariant(sp));
setRegisterByName(L"rsp", NumVariant(sp));
}
else if ( m_cpuMode == CPU_ARM64 )
{
setRegisterByName(L"sp", NumVariant(sp));
}
throw DbgException("Unknown CPU type");
......@@ -451,6 +468,10 @@ MEMOFFSET_64 CPUContextImpl::getFP()
{
return addr64( getRegisterByName(L"rbp").asULongLong() );
}
else if ( m_cpuMode == CPU_ARM64 )
{
return addr64( getRegisterByName(L"fp").asULongLong() );
}
throw DbgException("Unknown CPU type");
}
......@@ -467,8 +488,14 @@ void CPUContextImpl::setFP(MEMOFFSET_64 fp)
{
setRegisterByName(L"rbp", NumVariant(fp));
}
assert(0);
else if (m_cpuMode == CPU_ARM64 )
{
setRegisterByName(L"fp", NumVariant(fp));
}
else
{
throw DbgException("Unknown CPU type");
}
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -767,8 +767,8 @@ bool is64bitSystem()
hres = g_dbgMgr->control->GetActualProcessorType( &procType );
if ( FAILED( hres ) )
throw DbgEngException( L"IDebugControl::GetActualProcessorType", hres );
return procType == IMAGE_FILE_MACHINE_AMD64;
return (procType == IMAGE_FILE_MACHINE_AMD64 || procType == IMAGE_FILE_MACHINE_ARM64);
}
///////////////////////////////////////////////////////////////////////////////
......@@ -1548,6 +1548,10 @@ void setInstructionOffset(MEMOFFSET_64 offset)
regIndex = getRegisterIndex(L"rip");
break;
case CPU_ARM64:
regIndex = getRegisterIndex(L"pc");
break;
default:
throw DbgException( "Unknown processor type" );
}
......@@ -1573,6 +1577,10 @@ void setStackOffset(MEMOFFSET_64 offset)
regIndex = getRegisterIndex(L"rsp");
break;
case CPU_ARM64:
regIndex = getRegisterIndex(L"sp");
break;
default:
throw DbgException( "Unknown processor type" );
}
......@@ -1598,6 +1606,10 @@ void setFrameOffset(MEMOFFSET_64 offset)
regIndex = getRegisterIndex(L"rbp");
break;
case CPU_ARM64:
regIndex = getRegisterIndex(L"fp");
break;
default:
throw DbgException( "Unknown processor type" );
}
......@@ -1617,6 +1629,9 @@ MEMOFFSET_64 getReturnReg()
case CPU_AMD64:
return static_cast<MEMOFFSET_64>(getRegisterByName(L"rax").asULongLong());
case CPU_ARM64:
return static_cast<MEMOFFSET_64>(getRegisterByName(L"r8").asULongLong());
}
throw DbgException( "Unknown processor type" );
......@@ -1953,6 +1968,9 @@ CPUType getCPUType()
case IMAGE_FILE_MACHINE_AMD64:
return CPU_AMD64;
case IMAGE_FILE_MACHINE_ARM64:
return CPU_ARM64;
}
throw DbgException( "Unknown processor type" );
......@@ -1976,6 +1994,9 @@ CPUType getCPUMode()
case IMAGE_FILE_MACHINE_AMD64:
return CPU_AMD64;
case IMAGE_FILE_MACHINE_ARM64:
return CPU_ARM64;
}
throw DbgException( "Unknown processor type" );
......@@ -1998,6 +2019,10 @@ void setCPUMode(CPUType mode )
processorMode = IMAGE_FILE_MACHINE_AMD64;
break;
case CPU_ARM64:
processorMode = IMAGE_FILE_MACHINE_ARM64;
break;
default:
DbgException( "Unknown processor type" );
}
......
......@@ -33,6 +33,7 @@ MEMOFFSET_64 addr64( MEMOFFSET_64 offset )
return (ULONG64)(LONG)offset;
case IMAGE_FILE_MACHINE_AMD64:
case IMAGE_FILE_MACHINE_ARM64:
break;
default:
......
......@@ -242,7 +242,8 @@ bool isModuleManaged( MEMOFFSET_64 baseOffset )
return ntHeader.OptionalHeader.DataDirectory[14].Size != 0;
}
if ( machineType == IMAGE_FILE_MACHINE_AMD64 )
if ( machineType == IMAGE_FILE_MACHINE_AMD64 ||
machineType == IMAGE_FILE_MACHINE_ARM64 )
{
IMAGE_NT_HEADERS64 ntHeader;
readMemory( ntHeaderOffset, &ntHeader, sizeof(ntHeader) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment