MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / special_handling

Function special_handling

arch/powerpc/assembler.cpp:2515–2626  ·  view source on GitHub ↗

for certain instructions with difficult inter-field dependencies inputs: seed: the seed value that may need the special case insword: instruction word bit: last bit changed

Source from the content-addressed store, hash-verified

2513// insword: instruction word
2514// bit: last bit changed
2515uint32_t special_handling(uint32_t seed, uint32_t insword, int bit)
2516{
2517 switch(seed) {
2518 /* sldi is extended mnemonic for rldicr (when mask = 63-shift) and hops
2519 to it or other extended mnemonics easily */
2520 case 0x780007C6:
2521 /* if shift field changed, update mask */
2522 if(bit==1 || (bit>=11 && bit<=15)) {
2523 uint32_t shift = ((insword>>1)&1) | ((insword>>10)&0x3E);
2524 uint32_t mask = 63-shift;
2525 return (insword&0xFFFFF81F) | (mask<<5);
2526 }
2527 /* if mask field changed, update shift */
2528 if(bit>=5 && bit<=10) {
2529 uint32_t mask = (insword>>5)&0x3F;
2530 uint32_t shift = 63-mask;
2531 return (insword&0xFFFF07FD) | ((shift&0x3E)<<11) | ((shift&0x1)<<1);
2532 }
2533 /* neither field updated */
2534 return insword;
2535
2536 case 0x54000FFE: // srwi
2537 if(bit>=6 && bit<=10) {
2538 uint32_t tmp = 32 - ((insword>>6) & 0x1F);
2539 return (insword&0xFFFF07FF) | (tmp<<11);
2540 }
2541 if(bit>=11 && bit<=15) {
2542 uint32_t tmp = 32 - ((insword>>11) & 0x1F);
2543 return (insword&0xFFFFF83F) | (tmp<<6);
2544 }
2545 /* neither field updated */
2546 return insword;
2547
2548 case 0x5400003E: // slwi
2549 if(bit>=1 && bit<=5) {
2550 uint32_t tmp = 31 - ((insword>>1) & 0x1F);
2551 return (insword&0xFFFF07FF) | (tmp<<11);
2552 }
2553 if(bit>=11 && bit<=15) {
2554 uint32_t tmp = 31 - ((insword>>11) & 0x1F);
2555 return (insword&0xFFFFFFC1) | (tmp<<1);
2556 }
2557 /* neither field updated */
2558 return insword;
2559
2560 /* crclr is when crxor has three 5-bit fields match! unlikely! */
2561 case 0x4c000182:
2562 {
2563 vector<struct match> matches = {{25,21,20,16},{25,21,15,11},
2564 {20,16,25,21},{20,16,15,11},
2565 {15,11,25,21},{15,11,20,16}};
2566
2567 return enforce_bit_match(insword, bit, matches);
2568 }
2569
2570 /* xxpermdi is 111100xxxxxxxxxxxxxxx0xx01010xxx */
2571 // xxspltd T,A,0 <=> xxpermdi T,A,A,0b00
2572 // xxspltd T,A,1 <=> xxpermdi T,A,A,0b11

Callers 1

assemble_singleFunction · 0.85

Calls 1

enforce_bit_matchFunction · 0.85

Tested by

no test coverage detected