Skip to content

Commit

Permalink
Add hi/lo expression functions for MIPS
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1187 committed Sep 19, 2017
1 parent 07853e5 commit 63eaa98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Archs/MIPS/MipsMacros.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
)";
Expand Down Expand Up @@ -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 },
Expand Down
21 changes: 21 additions & 0 deletions Core/ExpressionFunctions.cpp
Expand Up @@ -499,6 +499,24 @@ ExpressionValue expFuncIsThumb(const std::wstring& funcName, const std::vector<E
return ExpressionValue(isThumb ? INT64_C(1) : INT64_C(0));
}

ExpressionValue expFuncHi(const std::wstring& funcName, const std::vector<ExpressionValue>& 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<ExpressionValue>& 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 } },
Expand Down Expand Up @@ -538,6 +556,9 @@ const ExpressionFunctionMap expressionFunctions = {
{ L"reads64", { &expFuncRead<int64_t>, 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 } },
};

0 comments on commit 63eaa98

Please sign in to comment.