mumbel / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
9 stars 1 forks source link

[tricore] float-point in DVADJ operand #19

Closed esaulenka closed 4 years ago

esaulenka commented 5 years ago

@mumbel, if you dont mind, i will continue describe bugs in tricore sleigh here.

Describe the bug According to p-Code operation manual, abs() function, that used in dvadj constructor, dealing with float-point operands, but any values, used in dvinit / dvstep / dvadj should be integer.

To Reproduce Look at decompiled function, that uses dvadj

Expected behavior I didnt fully understand, how dvXXX works, but according to tricore architecture manual, it should be redone as follows:

:dvadj Ree2831/Reo2831,Ree2427/Reo2427,Rd1215 is PCPMode=0 & Rd1215 & op0007=0x6b & op0811=0x0 ; Ree2427 & Reo2427 & Ree2831 & Reo2831 & op1623=0xd0
{
    #TODO  divide sequence
    local quotient:4 = Ree2427;     # E[d]  0..31
    local remainder:4 = Reo2427;    # E[d] 32..63
    local divisor:4 = Rd1215;       # D[b]

    local x_sign = remainder[31,1];
    local q_sign = quotient[31,1];

    if (q_sign) goto <no_inc_quot>;
        quotient = quotient + 1;
    <no_inc_quot>
    if (((remainder == divisor) || (remainder == - divisor)) && x_sign) goto <nonzero_remainder>;
        remainder = 0;
    <nonzero_remainder>
    Reo2831 = remainder;
    Ree2831 = quotient;
}
mumbel commented 5 years ago

It looks like the issue, across my whole implementation, is the usage of abs().

Hopefully this isn't in the wrong direction, but I have put a PR in https://github.com/NationalSecurityAgency/ghidra/pull/1286

mumbel commented 4 years ago

Thanks again @esaulenka looks merged in master