Lines Matching refs:dst_reg
272 /* Encode 'dst_reg' register into x86-64 opcode 'byte' */
273 static u8 add_1reg(u8 byte, u32 dst_reg)
275 return byte + reg2hex[dst_reg];
278 /* Encode 'dst_reg' and 'src_reg' registers into x86-64 opcode 'byte' */
279 static u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
281 return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
896 u32 dst_reg, const u32 imm32)
907 b1 = add_1mod(0x48, dst_reg);
910 EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
919 if (is_ereg(dst_reg))
920 EMIT1(add_2mod(0x40, dst_reg, dst_reg));
923 EMIT2(b2, add_2reg(b3, dst_reg, dst_reg));
928 if (is_ereg(dst_reg))
929 EMIT1(add_1mod(0x40, dst_reg));
930 EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
935 static void emit_mov_imm64(u8 **pprog, u32 dst_reg,
948 emit_mov_imm32(&prog, false, dst_reg, imm32_lo);
950 emit_mov_imm32(&prog, true, dst_reg, imm32_lo);
953 EMIT2(add_1mod(0x48, dst_reg), add_1reg(0xB8, dst_reg));
961 static void emit_mov_reg(u8 **pprog, bool is64, u32 dst_reg, u32 src_reg)
967 EMIT_mov(dst_reg, src_reg);
970 if (is_ereg(dst_reg) || is_ereg(src_reg))
971 EMIT1(add_2mod(0x40, dst_reg, src_reg));
972 EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
978 static void emit_movsx_reg(u8 **pprog, int num_bits, bool is64, u32 dst_reg,
986 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbe,
987 add_2reg(0xC0, src_reg, dst_reg));
989 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbf,
990 add_2reg(0xC0, src_reg, dst_reg));
992 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x63,
993 add_2reg(0xC0, src_reg, dst_reg));
997 EMIT4(add_2mod(0x40, src_reg, dst_reg), 0x0f, 0xbe,
998 add_2reg(0xC0, src_reg, dst_reg));
1000 if (is_ereg(dst_reg) || is_ereg(src_reg))
1001 EMIT1(add_2mod(0x40, src_reg, dst_reg));
1002 EMIT3(add_2mod(0x0f, src_reg, dst_reg), 0xbf,
1003 add_2reg(0xC0, src_reg, dst_reg));
1045 static void maybe_emit_mod(u8 **pprog, u32 dst_reg, u32 src_reg, bool is64)
1050 EMIT1(add_2mod(0x48, dst_reg, src_reg));
1051 else if (is_ereg(dst_reg) || is_ereg(src_reg))
1052 EMIT1(add_2mod(0x40, dst_reg, src_reg));
1070 /* LDX: dst_reg = *(u8*)(src_reg + off) */
1071 static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1078 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
1082 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
1086 if (is_ereg(dst_reg) || is_ereg(src_reg))
1087 EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
1093 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
1096 emit_insn_suffix(&prog, src_reg, dst_reg, off);
1100 /* LDSX: dst_reg = *(s8*)(src_reg + off) */
1101 static void emit_ldsx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1108 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBE);
1112 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBF);
1116 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x63);
1119 emit_insn_suffix(&prog, src_reg, dst_reg, off);
1123 static void emit_ldx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1130 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB6);
1134 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB7);
1138 EMIT2(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x8B);
1142 EMIT2(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x8B);
1145 emit_insn_suffix_SIB(&prog, src_reg, dst_reg, index_reg, off);
1149 static void emit_ldx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1151 emit_ldx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1154 /* STX: *(u8*)(dst_reg + off) = src_reg */
1155 static void emit_stx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1162 if (is_ereg(dst_reg) || is_ereg_8l(src_reg))
1164 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
1169 if (is_ereg(dst_reg) || is_ereg(src_reg))
1170 EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
1175 if (is_ereg(dst_reg) || is_ereg(src_reg))
1176 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
1181 EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
1184 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1188 /* STX: *(u8*)(dst_reg + index_reg + off) = src_reg */
1189 static void emit_stx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1196 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x88);
1200 EMIT3(0x66, add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1204 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1208 EMIT2(add_3mod(0x48, dst_reg, src_reg, index_reg), 0x89);
1211 emit_insn_suffix_SIB(&prog, dst_reg, src_reg, index_reg, off);
1215 static void emit_stx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1217 emit_stx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1220 /* ST: *(u8*)(dst_reg + index_reg + off) = imm32 */
1221 static void emit_st_index(u8 **pprog, u32 size, u32 dst_reg, u32 index_reg, int off, int imm)
1228 EMIT2(add_3mod(0x40, dst_reg, 0, index_reg), 0xC6);
1232 EMIT3(0x66, add_3mod(0x40, dst_reg, 0, index_reg), 0xC7);
1236 EMIT2(add_3mod(0x40, dst_reg, 0, index_reg), 0xC7);
1240 EMIT2(add_3mod(0x48, dst_reg, 0, index_reg), 0xC7);
1243 emit_insn_suffix_SIB(&prog, dst_reg, 0, index_reg, off);
1248 static void emit_st_r12(u8 **pprog, u32 size, u32 dst_reg, int off, int imm)
1250 emit_st_index(pprog, size, dst_reg, X86_REG_R12, off, imm);
1254 u32 dst_reg, u32 src_reg, s16 off, u8 bpf_size)
1260 maybe_emit_mod(&prog, dst_reg, src_reg, bpf_size == BPF_DW);
1268 /* lock *(u32/u64*)(dst_reg + off) <op>= src_reg */
1272 /* src_reg = atomic_fetch_add(dst_reg + off, src_reg); */
1276 /* src_reg = atomic_xchg(dst_reg + off, src_reg); */
1280 /* r0 = atomic_cmpxchg(dst_reg + off, r0, src_reg); */
1288 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1295 u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1302 EMIT1(add_3mod(0x40, dst_reg, src_reg, index_reg));
1305 EMIT1(add_3mod(0x48, dst_reg, src_reg, index_reg));
1318 /* lock *(u32/u64*)(dst_reg + idx_reg + off) <op>= src_reg */
1322 /* src_reg = atomic_fetch_add(dst_reg + idx_reg + off, src_reg); */
1326 /* src_reg = atomic_xchg(dst_reg + idx_reg + off, src_reg); */
1330 /* r0 = atomic_cmpxchg(dst_reg + idx_reg + off, r0, src_reg); */
1337 emit_insn_suffix_SIB(&prog, dst_reg, src_reg, index_reg, off);
1361 if (insn->dst_reg == BPF_REG_6 || insn->src_reg == BPF_REG_6)
1363 if (insn->dst_reg == BPF_REG_7 || insn->src_reg == BPF_REG_7)
1365 if (insn->dst_reg == BPF_REG_8 || insn->src_reg == BPF_REG_8)
1367 if (insn->dst_reg == BPF_REG_9 || insn->src_reg == BPF_REG_9)
1420 static void emit_shiftx(u8 **pprog, u32 dst_reg, u8 src_reg, bool is64, u8 op)
1423 bool r = is_ereg(dst_reg);
1427 EMIT2(0xf7, add_2reg(0xC0, dst_reg, dst_reg));
1525 u32 dst_reg = insn->dst_reg;
1539 if (dst_reg == BPF_REG_FP)
1540 dst_reg = X86_REG_R9;
1555 maybe_emit_mod(&prog, dst_reg, src_reg,
1558 EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
1563 if (dst_reg != src_reg)
1565 emit_mov_reg(&prog, false, dst_reg, src_reg);
1566 /* shl dst_reg, 32 */
1567 maybe_emit_1mod(&prog, dst_reg, true);
1568 EMIT3(0xC1, add_1reg(0xE0, dst_reg), 32);
1570 /* or dst_reg, user_vm_start */
1571 maybe_emit_1mod(&prog, dst_reg, true);
1572 if (is_axreg(dst_reg))
1575 EMIT2_off32(0x81, add_1reg(0xC8, dst_reg), user_vm_start >> 32);
1577 /* rol dst_reg, 32 */
1578 maybe_emit_1mod(&prog, dst_reg, true);
1579 EMIT3(0xC1, add_1reg(0xC0, dst_reg), 32);
1585 maybe_emit_mod(&prog, dst_reg, dst_reg, false);
1586 EMIT2(0x85, add_2reg(0xC0, dst_reg, dst_reg));
1588 /* cmove r11, dst_reg; if so, set dst_reg to zero */
1590 maybe_emit_mod(&prog, AUX_REG, dst_reg, true);
1591 EMIT3(0x0F, 0x44, add_2reg(0xC0, AUX_REG, dst_reg));
1595 EMIT_mov(dst_reg, src_reg);
1598 EMIT2(0x65, add_1mod(0x48, dst_reg));
1599 EMIT3(0x03, add_2reg(0x04, 0, dst_reg), 0x25);
1609 dst_reg, src_reg);
1613 dst_reg, src_reg);
1619 maybe_emit_1mod(&prog, dst_reg,
1621 EMIT2(0xF7, add_1reg(0xD8, dst_reg));
1634 maybe_emit_1mod(&prog, dst_reg,
1665 EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
1666 else if (is_axreg(dst_reg))
1669 EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
1675 dst_reg, imm32);
1679 emit_mov_imm64(&prog, dst_reg, insn[1].imm, insn[0].imm);
1695 if (dst_reg != BPF_REG_0)
1697 if (dst_reg != BPF_REG_3)
1713 if (dst_reg != BPF_REG_0)
1714 /* mov rax, dst_reg */
1715 emit_mov_reg(&prog, is64, BPF_REG_0, dst_reg);
1739 dst_reg != BPF_REG_3)
1740 /* mov dst_reg, rdx */
1741 emit_mov_reg(&prog, is64, dst_reg, BPF_REG_3);
1743 dst_reg != BPF_REG_0)
1744 /* mov dst_reg, rax */
1745 emit_mov_reg(&prog, is64, dst_reg, BPF_REG_0);
1747 if (dst_reg != BPF_REG_3)
1749 if (dst_reg != BPF_REG_0)
1756 maybe_emit_mod(&prog, dst_reg, dst_reg,
1760 /* imul dst_reg, dst_reg, imm8 */
1761 EMIT3(0x6B, add_2reg(0xC0, dst_reg, dst_reg),
1764 /* imul dst_reg, dst_reg, imm32 */
1766 add_2reg(0xC0, dst_reg, dst_reg),
1772 maybe_emit_mod(&prog, src_reg, dst_reg,
1775 /* imul dst_reg, src_reg */
1776 EMIT3(0x0F, 0xAF, add_2reg(0xC0, src_reg, dst_reg));
1786 maybe_emit_1mod(&prog, dst_reg,
1791 EMIT2(0xD1, add_1reg(b3, dst_reg));
1793 EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
1804 /* shrx/sarx/shlx dst_reg, dst_reg, src_reg */
1820 emit_shiftx(&prog, dst_reg, src_reg, w, op);
1826 /* Check for bad case when dst_reg == rcx */
1827 if (dst_reg == BPF_REG_4) {
1828 /* mov r11, dst_reg */
1829 EMIT_mov(AUX_REG, dst_reg);
1830 dst_reg = AUX_REG;
1839 maybe_emit_1mod(&prog, dst_reg,
1843 EMIT2(0xD3, add_1reg(b3, dst_reg));
1846 if (insn->dst_reg == BPF_REG_4)
1847 /* mov dst_reg, r11 */
1848 EMIT_mov(insn->dst_reg, AUX_REG);
1861 if (is_ereg(dst_reg))
1863 EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
1866 if (is_ereg(dst_reg))
1870 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
1874 if (is_ereg(dst_reg))
1878 EMIT1(add_1reg(0xC8, dst_reg));
1882 EMIT3(add_1mod(0x48, dst_reg), 0x0F,
1883 add_1reg(0xC8, dst_reg));
1895 if (is_ereg(dst_reg))
1899 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
1903 if (is_ereg(dst_reg))
1905 EMIT2(0x89, add_2reg(0xC0, dst_reg, dst_reg));
1918 /* ST: *(u8*)(dst_reg + off) = imm */
1920 if (is_ereg(dst_reg))
1926 if (is_ereg(dst_reg))
1932 if (is_ereg(dst_reg))
1938 EMIT2(add_1mod(0x48, dst_reg), 0xC7);
1941 EMIT2(add_1reg(0x40, dst_reg), insn->off);
1943 EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
1948 /* STX: *(u8*)(dst_reg + off) = src_reg */
1953 emit_stx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
1961 emit_st_r12(&prog, BPF_SIZE(insn->code), dst_reg, insn->off, insn->imm);
1964 /* LDX: dst_reg = *(u8*)(src_reg + r12 + off) */
1975 emit_ldx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
1977 emit_stx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
2002 ((BPF_CLASS(insn->code) == BPF_LDX ? reg2pt_regs[dst_reg] : DONT_CLEAR) << 8);
2006 /* LDX: dst_reg = *(u8*)(src_reg + off) */
2015 /* LDXS: dst_reg = *(s8*)(src_reg + off) */
2064 /* xor dst_reg, dst_reg */
2065 emit_mov_imm32(&prog, false, dst_reg, 0);
2075 emit_ldsx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
2077 emit_ldx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
2108 if (dst_reg > BPF_REG_9) {
2120 ex->fixup = (prog - start_of_ldx) | (reg2pt_regs[dst_reg] << 8);
2131 u32 real_dst_reg = dst_reg;
2143 if (dst_reg == BPF_REG_0)
2177 err = emit_atomic(&prog, insn->imm, dst_reg, src_reg,
2187 dst_reg, src_reg, X86_REG_R12, insn->off);
2253 /* cmp dst_reg, src_reg */
2254 maybe_emit_mod(&prog, dst_reg, src_reg,
2256 EMIT2(0x39, add_2reg(0xC0, dst_reg, src_reg));
2261 /* test dst_reg, src_reg */
2262 maybe_emit_mod(&prog, dst_reg, src_reg,
2264 EMIT2(0x85, add_2reg(0xC0, dst_reg, src_reg));
2269 /* test dst_reg, imm32 */
2270 maybe_emit_1mod(&prog, dst_reg,
2272 EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
2295 /* test dst_reg, dst_reg to save one extra byte */
2297 maybe_emit_mod(&prog, dst_reg, dst_reg,
2299 EMIT2(0x85, add_2reg(0xC0, dst_reg, dst_reg));
2303 /* cmp dst_reg, imm8/32 */
2304 maybe_emit_1mod(&prog, dst_reg,
2308 EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
2310 EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);