Lines Matching refs:dst_reg

222 /* Encode 'dst_reg' register into x86-64 opcode 'byte' */
223 static u8 add_1reg(u8 byte, u32 dst_reg)
225 return byte + reg2hex[dst_reg];
228 /* Encode 'dst_reg' and 'src_reg' registers into x86-64 opcode 'byte' */
229 static u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
231 return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
777 u32 dst_reg, const u32 imm32)
788 b1 = add_1mod(0x48, dst_reg);
791 EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
800 if (is_ereg(dst_reg))
801 EMIT1(add_2mod(0x40, dst_reg, dst_reg));
804 EMIT2(b2, add_2reg(b3, dst_reg, dst_reg));
809 if (is_ereg(dst_reg))
810 EMIT1(add_1mod(0x40, dst_reg));
811 EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
816 static void emit_mov_imm64(u8 **pprog, u32 dst_reg,
828 emit_mov_imm32(&prog, false, dst_reg, imm32_lo);
831 EMIT2(add_1mod(0x48, dst_reg), add_1reg(0xB8, dst_reg));
839 static void emit_mov_reg(u8 **pprog, bool is64, u32 dst_reg, u32 src_reg)
845 EMIT_mov(dst_reg, src_reg);
848 if (is_ereg(dst_reg) || is_ereg(src_reg))
849 EMIT1(add_2mod(0x40, dst_reg, src_reg));
850 EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
856 static void emit_movsx_reg(u8 **pprog, int num_bits, bool is64, u32 dst_reg,
864 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbe,
865 add_2reg(0xC0, src_reg, dst_reg));
867 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbf,
868 add_2reg(0xC0, src_reg, dst_reg));
870 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x63,
871 add_2reg(0xC0, src_reg, dst_reg));
875 EMIT4(add_2mod(0x40, src_reg, dst_reg), 0x0f, 0xbe,
876 add_2reg(0xC0, src_reg, dst_reg));
878 if (is_ereg(dst_reg) || is_ereg(src_reg))
879 EMIT1(add_2mod(0x40, src_reg, dst_reg));
880 EMIT3(add_2mod(0x0f, src_reg, dst_reg), 0xbf,
881 add_2reg(0xC0, src_reg, dst_reg));
923 static void maybe_emit_mod(u8 **pprog, u32 dst_reg, u32 src_reg, bool is64)
928 EMIT1(add_2mod(0x48, dst_reg, src_reg));
929 else if (is_ereg(dst_reg) || is_ereg(src_reg))
930 EMIT1(add_2mod(0x40, dst_reg, src_reg));
948 /* LDX: dst_reg = *(u8*)(src_reg + off) */
949 static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
956 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
960 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
964 if (is_ereg(dst_reg) || is_ereg(src_reg))
965 EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
971 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
974 emit_insn_suffix(&prog, src_reg, dst_reg, off);
978 /* LDSX: dst_reg = *(s8*)(src_reg + off) */
979 static void emit_ldsx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
986 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBE);
990 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBF);
994 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x63);
997 emit_insn_suffix(&prog, src_reg, dst_reg, off);
1001 static void emit_ldx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1008 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB6);
1012 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB7);
1016 EMIT2(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x8B);
1020 EMIT2(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x8B);
1023 emit_insn_suffix_SIB(&prog, src_reg, dst_reg, index_reg, off);
1027 static void emit_ldx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1029 emit_ldx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1032 /* STX: *(u8*)(dst_reg + off) = src_reg */
1033 static void emit_stx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1040 if (is_ereg(dst_reg) || is_ereg_8l(src_reg))
1042 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
1047 if (is_ereg(dst_reg) || is_ereg(src_reg))
1048 EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
1053 if (is_ereg(dst_reg) || is_ereg(src_reg))
1054 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
1059 EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
1062 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1066 /* STX: *(u8*)(dst_reg + index_reg + off) = src_reg */
1067 static void emit_stx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1074 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x88);
1078 EMIT3(0x66, add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1082 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1086 EMIT2(add_3mod(0x48, dst_reg, src_reg, index_reg), 0x89);
1089 emit_insn_suffix_SIB(&prog, dst_reg, src_reg, index_reg, off);
1093 static void emit_stx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1095 emit_stx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1098 /* ST: *(u8*)(dst_reg + index_reg + off) = imm32 */
1099 static void emit_st_index(u8 **pprog, u32 size, u32 dst_reg, u32 index_reg, int off, int imm)
1106 EMIT2(add_3mod(0x40, dst_reg, 0, index_reg), 0xC6);
1110 EMIT3(0x66, add_3mod(0x40, dst_reg, 0, index_reg), 0xC7);
1114 EMIT2(add_3mod(0x40, dst_reg, 0, index_reg), 0xC7);
1118 EMIT2(add_3mod(0x48, dst_reg, 0, index_reg), 0xC7);
1121 emit_insn_suffix_SIB(&prog, dst_reg, 0, index_reg, off);
1126 static void emit_st_r12(u8 **pprog, u32 size, u32 dst_reg, int off, int imm)
1128 emit_st_index(pprog, size, dst_reg, X86_REG_R12, off, imm);
1132 u32 dst_reg, u32 src_reg, s16 off, u8 bpf_size)
1138 maybe_emit_mod(&prog, dst_reg, src_reg, bpf_size == BPF_DW);
1146 /* lock *(u32/u64*)(dst_reg + off) <op>= src_reg */
1150 /* src_reg = atomic_fetch_add(dst_reg + off, src_reg); */
1154 /* src_reg = atomic_xchg(dst_reg + off, src_reg); */
1158 /* r0 = atomic_cmpxchg(dst_reg + off, r0, src_reg); */
1166 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1193 if (insn->dst_reg == BPF_REG_6 || insn->src_reg == BPF_REG_6)
1195 if (insn->dst_reg == BPF_REG_7 || insn->src_reg == BPF_REG_7)
1197 if (insn->dst_reg == BPF_REG_8 || insn->src_reg == BPF_REG_8)
1199 if (insn->dst_reg == BPF_REG_9 || insn->src_reg == BPF_REG_9)
1252 static void emit_shiftx(u8 **pprog, u32 dst_reg, u8 src_reg, bool is64, u8 op)
1255 bool r = is_ereg(dst_reg);
1259 EMIT2(0xf7, add_2reg(0xC0, dst_reg, dst_reg));
1325 u32 dst_reg = insn->dst_reg;
1347 maybe_emit_mod(&prog, dst_reg, src_reg,
1350 EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
1356 if (dst_reg != src_reg)
1358 emit_mov_reg(&prog, false, dst_reg, src_reg);
1359 /* shl dst_reg, 32 */
1360 maybe_emit_1mod(&prog, dst_reg, true);
1361 EMIT3(0xC1, add_1reg(0xE0, dst_reg), 32);
1363 /* or dst_reg, user_vm_start */
1364 maybe_emit_1mod(&prog, dst_reg, true);
1365 if (is_axreg(dst_reg))
1368 EMIT2_off32(0x81, add_1reg(0xC8, dst_reg), user_vm_start >> 32);
1370 /* rol dst_reg, 32 */
1371 maybe_emit_1mod(&prog, dst_reg, true);
1372 EMIT3(0xC1, add_1reg(0xC0, dst_reg), 32);
1378 maybe_emit_mod(&prog, dst_reg, dst_reg, false);
1379 EMIT2(0x85, add_2reg(0xC0, dst_reg, dst_reg));
1381 /* cmove r11, dst_reg; if so, set dst_reg to zero */
1383 maybe_emit_mod(&prog, AUX_REG, dst_reg, true);
1384 EMIT3(0x0F, 0x44, add_2reg(0xC0, AUX_REG, dst_reg));
1392 dst_reg, src_reg);
1396 dst_reg, src_reg);
1402 maybe_emit_1mod(&prog, dst_reg,
1404 EMIT2(0xF7, add_1reg(0xD8, dst_reg));
1417 maybe_emit_1mod(&prog, dst_reg,
1448 EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
1449 else if (is_axreg(dst_reg))
1452 EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
1458 dst_reg, imm32);
1462 emit_mov_imm64(&prog, dst_reg, insn[1].imm, insn[0].imm);
1478 if (dst_reg != BPF_REG_0)
1480 if (dst_reg != BPF_REG_3)
1496 if (dst_reg != BPF_REG_0)
1497 /* mov rax, dst_reg */
1498 emit_mov_reg(&prog, is64, BPF_REG_0, dst_reg);
1522 dst_reg != BPF_REG_3)
1523 /* mov dst_reg, rdx */
1524 emit_mov_reg(&prog, is64, dst_reg, BPF_REG_3);
1526 dst_reg != BPF_REG_0)
1527 /* mov dst_reg, rax */
1528 emit_mov_reg(&prog, is64, dst_reg, BPF_REG_0);
1530 if (dst_reg != BPF_REG_3)
1532 if (dst_reg != BPF_REG_0)
1539 maybe_emit_mod(&prog, dst_reg, dst_reg,
1543 /* imul dst_reg, dst_reg, imm8 */
1544 EMIT3(0x6B, add_2reg(0xC0, dst_reg, dst_reg),
1547 /* imul dst_reg, dst_reg, imm32 */
1549 add_2reg(0xC0, dst_reg, dst_reg),
1555 maybe_emit_mod(&prog, src_reg, dst_reg,
1558 /* imul dst_reg, src_reg */
1559 EMIT3(0x0F, 0xAF, add_2reg(0xC0, src_reg, dst_reg));
1569 maybe_emit_1mod(&prog, dst_reg,
1574 EMIT2(0xD1, add_1reg(b3, dst_reg));
1576 EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
1587 /* shrx/sarx/shlx dst_reg, dst_reg, src_reg */
1603 emit_shiftx(&prog, dst_reg, src_reg, w, op);
1609 /* Check for bad case when dst_reg == rcx */
1610 if (dst_reg == BPF_REG_4) {
1611 /* mov r11, dst_reg */
1612 EMIT_mov(AUX_REG, dst_reg);
1613 dst_reg = AUX_REG;
1622 maybe_emit_1mod(&prog, dst_reg,
1626 EMIT2(0xD3, add_1reg(b3, dst_reg));
1629 if (insn->dst_reg == BPF_REG_4)
1630 /* mov dst_reg, r11 */
1631 EMIT_mov(insn->dst_reg, AUX_REG);
1644 if (is_ereg(dst_reg))
1646 EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
1649 if (is_ereg(dst_reg))
1653 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
1657 if (is_ereg(dst_reg))
1661 EMIT1(add_1reg(0xC8, dst_reg));
1665 EMIT3(add_1mod(0x48, dst_reg), 0x0F,
1666 add_1reg(0xC8, dst_reg));
1678 if (is_ereg(dst_reg))
1682 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
1686 if (is_ereg(dst_reg))
1688 EMIT2(0x89, add_2reg(0xC0, dst_reg, dst_reg));
1701 /* ST: *(u8*)(dst_reg + off) = imm */
1703 if (is_ereg(dst_reg))
1709 if (is_ereg(dst_reg))
1715 if (is_ereg(dst_reg))
1721 EMIT2(add_1mod(0x48, dst_reg), 0xC7);
1724 EMIT2(add_1reg(0x40, dst_reg), insn->off);
1726 EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
1731 /* STX: *(u8*)(dst_reg + off) = src_reg */
1736 emit_stx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
1744 emit_st_r12(&prog, BPF_SIZE(insn->code), dst_reg, insn->off, insn->imm);
1747 /* LDX: dst_reg = *(u8*)(src_reg + r12 + off) */
1758 emit_ldx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
1760 emit_stx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
1785 ((BPF_CLASS(insn->code) == BPF_LDX ? reg2pt_regs[dst_reg] : DONT_CLEAR) << 8);
1789 /* LDX: dst_reg = *(u8*)(src_reg + off) */
1798 /* LDXS: dst_reg = *(s8*)(src_reg + off) */
1842 /* xor dst_reg, dst_reg */
1843 emit_mov_imm32(&prog, false, dst_reg, 0);
1853 emit_ldsx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
1855 emit_ldx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
1865 if (insn->off && src_reg != dst_reg) {
1868 * if statement. But if src_reg == dst_reg, emit_ldx
1898 if (dst_reg > BPF_REG_9) {
1910 ex->fixup = (prog - start_of_ldx) | (reg2pt_regs[dst_reg] << 8);
1921 u32 real_dst_reg = dst_reg;
1933 if (dst_reg == BPF_REG_0)
1967 err = emit_atomic(&prog, insn->imm, dst_reg, src_reg,
2028 /* cmp dst_reg, src_reg */
2029 maybe_emit_mod(&prog, dst_reg, src_reg,
2031 EMIT2(0x39, add_2reg(0xC0, dst_reg, src_reg));
2036 /* test dst_reg, src_reg */
2037 maybe_emit_mod(&prog, dst_reg, src_reg,
2039 EMIT2(0x85, add_2reg(0xC0, dst_reg, src_reg));
2044 /* test dst_reg, imm32 */
2045 maybe_emit_1mod(&prog, dst_reg,
2047 EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
2070 /* test dst_reg, dst_reg to save one extra byte */
2072 maybe_emit_mod(&prog, dst_reg, dst_reg,
2074 EMIT2(0x85, add_2reg(0xC0, dst_reg, dst_reg));
2078 /* cmp dst_reg, imm8/32 */
2079 maybe_emit_1mod(&prog, dst_reg,
2083 EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
2085 EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);