| 37 | #define RZF 4 |
| 38 | |
| 39 | static ExprId operToIL(LowLevelILFunction &il, struct cs_ppc_op *op, |
| 40 | int options=PPC_IL_OPTIONS_DEFAULT, uint64_t extra=PPC_IL_EXTRA_DEFAULT, size_t regsz=4) |
| 41 | { |
| 42 | ExprId res; |
| 43 | |
| 44 | if(!op) { |
| 45 | MYLOG("ERROR: operToIL() got NULL operand\n"); |
| 46 | return il.Unimplemented(); |
| 47 | } |
| 48 | |
| 49 | switch(op->type) { |
| 50 | case PPC_OP_REG: |
| 51 | //MYLOG("case PPC_OP_REG returning reg %d\n", op->reg); |
| 52 | if (options & OTI_GPR0_ZERO && op->reg == PPC_REG_R0) |
| 53 | res = il.Const(regsz, 0); |
| 54 | else |
| 55 | res = il.Register(regsz, op->reg); |
| 56 | break; |
| 57 | case PPC_OP_IMM: |
| 58 | /* the immediate is a constant pointer (eg: absolute address) */ |
| 59 | if(options & OTI_IMM_CPTR) { |
| 60 | res = il.ConstPointer(regsz, op->imm); |
| 61 | } |
| 62 | /* the immediate is a displacement (eg: relative addressing) */ |
| 63 | else if(options & OTI_IMM_REL_CPTR) { |
| 64 | res = il.ConstPointer(regsz, op->imm + extra); |
| 65 | } |
| 66 | /* the immediate should be biased with given value */ |
| 67 | else if(options & OTI_IMM_BIAS) { |
| 68 | res = il.Const(regsz, op->imm + extra); |
| 69 | } |
| 70 | /* the immediate is just a plain boring immediate */ |
| 71 | else { |
| 72 | res = il.Const(regsz, op->imm); |
| 73 | } |
| 74 | break; |
| 75 | |
| 76 | case PPC_OP_MEM: |
| 77 | //MYLOG("case PPC_OP_MEM returning regs (%d,%d)\n", op->mem.base, op->mem.disp); |
| 78 | |
| 79 | if (options & OTI_GPR0_ZERO && op->mem.base == PPC_REG_R0) |
| 80 | res = il.Const(regsz, 0); |
| 81 | else |
| 82 | res = il.Register(regsz, op->mem.base); |
| 83 | |
| 84 | if(options & OTI_IMM_BIAS) |
| 85 | res = il.Add(regsz, res, il.Const(4, op->mem.disp + extra)); |
| 86 | else |
| 87 | res = il.Add(regsz, res, il.Const(4, op->mem.disp)); |
| 88 | break; |
| 89 | |
| 90 | case PPC_OP_CRX: |
| 91 | case PPC_OP_INVALID: |
| 92 | default: |
| 93 | MYLOG("ERROR: don't know how to convert operand to IL\n"); |
| 94 | res = il.Unimplemented(); |
| 95 | } |
| 96 |
no test coverage detected