BinaryAnalysisPlatform / bap

Binary Analysis Platform
MIT License
2.05k stars 271 forks source link

implements pcode floating-point and special operators #1452

Closed ivg closed 2 years ago

ivg commented 2 years ago

Adds an intrinsic and symbol-concat primitives to Primus Lisp and uses them to implement all floating-point operators in pcode and cpuid routines for pcode-x86.

Also rewrites the subinstruction contraction procedure, which was broken. The new version is more aggressive and contracts all contractable subinstructions.

Another minor fix: fixes the pretty-printing for the attributes parsing error.

Below is the demonstration how intrinsic are reified into BIR code with the ucomisd instruction as an example,

$ bap mc --show-insn=asm --show-bir --x86-backend=ghidra -- 66 0f 2e 05 e6 02 00 00 
UCOMISD XMM0, qword ptr [0x2ee]
0000007d:
0000006c: intrinsic:x0 := extract:63:0[YMM0]
0000006e: call @intrinsic:is_fnan_ieee754_binary with return %00000070
00000070:
00000071: u98944 := intrinsic:y0
0000005e: intrinsic:x0 := mem[0x2EE, el]:u64
00000061: call @intrinsic:is_fnan_ieee754_binary with return %00000063
00000063:
00000064: u99072 := intrinsic:y0
00000057: PF := extract:7:0[u98944] | extract:7:0[u99072]
00000047: intrinsic:x0 := extract:63:0[YMM0]
0000004a: intrinsic:x1 := mem[0x2EE, el]:u64
0000004c: call @intrinsic:forder_ieee754_binary with return %0000004e
0000004e:
0000004f: u99328 := intrinsic:y0 = 0
0000003f: ZF := extract:7:0[PF] | extract:7:0[u99328]
0000002e: intrinsic:x0 := extract:63:0[YMM0]
00000031: intrinsic:x1 := mem[0x2EE, el]:u64
00000034: call @intrinsic:forder_ieee754_binary with return %00000036
00000036:
00000037: u99584 := high:1[intrinsic:y0]
00000026: CF := extract:7:0[PF] | extract:7:0[u99584]
00000020: OF := 0
0000001c: AF := 0
00000018: SF := 0