From 63eaa98a32bd350f9c9b4673ea27c742fbcd73ec Mon Sep 17 00:00:00 2001 From: Simon Eriksson Date: Tue, 19 Sep 2017 16:19:42 +0200 Subject: [PATCH] Add hi/lo expression functions for MIPS --- Archs/MIPS/MipsMacros.cpp | 16 ++++++++-------- Core/ExpressionFunctions.cpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Archs/MIPS/MipsMacros.cpp b/Archs/MIPS/MipsMacros.cpp index 027bcc0d..dadae735 100644 --- a/Archs/MIPS/MipsMacros.cpp +++ b/Archs/MIPS/MipsMacros.cpp @@ -104,20 +104,20 @@ CAssemblerCommand* generateMipsMacroLi(Parser& parser, MipsRegisterData& registe .elseif %imm% & ~0xFFFF .if (%imm% & 0xFFFF8000) == 0xFFFF8000 .if %lower% - addiu %rs%,r0,%imm% & 0xFFFF + addiu %rs%,r0, lo(%imm%) .endif .elseif (%imm% & 0xFFFF) == 0 .if %upper% - lui %rs%,%imm% >> 16 + lui %rs%, hi(%imm%) .elseif %lower% nop .endif .else .if %upper% - lui %rs%,(%imm% >> 16) + ((%imm% & 0x8000) != 0) + lui %rs%, hi(%imm%) .endif .if %lower% - addiu %rs%,%imm% & 0xFFFF + addiu %rs%, lo(%imm%) .endif .endif .else @@ -154,16 +154,16 @@ CAssemblerCommand* generateMipsMacroLoadStore(Parser& parser, MipsRegisterData& .error "Address too big" .elseif %imm% < 0x8000 || (%imm% & 0xFFFF8000) == 0xFFFF8000 .if %lower% - %op% %rs%,%imm% & 0xFFFF(r0) + %op% %rs%, lo(%imm%)(r0) .elseif %upper% nop .endif .else .if %upper% - lui %temp%,(%imm% >> 16) + ((%imm% & 0x8000) != 0) + lui %temp%, hi(%imm%) .endif .if %lower% - %op% %rs%,%imm% & 0xFFFF(%temp%) + %op% %rs%, lo(%imm%)(%temp%) .endif .endif )"; @@ -657,7 +657,7 @@ const MipsMacroDefinition mipsMacros[] = { { L"sw.l", L"s,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_W|MIPSM_LOWER }, { L"sd.l", L"s,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_DW|MIPSM_LOWER }, { L"sc.l", L"s,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_LLSCW|MIPSM_LOWER }, - { L"scd.l", L"s,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_LLSCDW||MIPSM_LOWER }, + { L"scd.l", L"s,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_LLSCDW|MIPSM_LOWER }, { L"swc1.l",L"S,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_COP1|MIPSM_LOWER }, { L"s.s.l", L"S,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_COP1|MIPSM_LOWER }, { L"swc2.l",L"S,I", &generateMipsMacroLoadStore, MIPSM_STORE|MIPSM_COP2|MIPSM_LOWER }, diff --git a/Core/ExpressionFunctions.cpp b/Core/ExpressionFunctions.cpp index bd5e0ec4..b9140d46 100644 --- a/Core/ExpressionFunctions.cpp +++ b/Core/ExpressionFunctions.cpp @@ -499,6 +499,24 @@ ExpressionValue expFuncIsThumb(const std::wstring& funcName, const std::vector& parameters) +{ + int64_t value; + + GET_PARAM(parameters,0,value); + + return ExpressionValue((int64_t)((value >> 16) + ((value & 0x8000) != 0)) & 0xFFFF); +} + +ExpressionValue expFuncLo(const std::wstring& funcName, const std::vector& parameters) +{ + int64_t value; + + GET_PARAM(parameters,0,value); + + return ExpressionValue(value & 0xFFFF); +} + const ExpressionFunctionMap expressionFunctions = { { L"version", { &expFuncVersion, 0, 0, ExpFuncSafety::Safe } }, { L"endianness", { &expFuncEndianness, 0, 0, ExpFuncSafety::Unsafe } }, @@ -538,6 +556,9 @@ const ExpressionFunctionMap expressionFunctions = { { L"reads64", { &expFuncRead, 1, 2, ExpFuncSafety::ConditionalUnsafe } }, { L"readascii", { &expFuncReadAscii, 1, 3, ExpFuncSafety::ConditionalUnsafe } }, + { L"lo", { &expFuncLo, 1, 1, ExpFuncSafety::Safe } }, + { L"hi", { &expFuncHi, 1, 1, ExpFuncSafety::Safe } }, + { L"isarm", { &expFuncIsArm, 0, 0, ExpFuncSafety::Safe } }, { L"isthumb", { &expFuncIsThumb, 0, 0, ExpFuncSafety::Safe } }, };