Lines Matching refs:src_reg
281 /* Encode 'dst_reg' and 'src_reg' registers into x86-64 opcode 'byte' */
282 static u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
284 return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
984 static void emit_mov_reg(u8 **pprog, bool is64, u32 dst_reg, u32 src_reg)
990 EMIT_mov(dst_reg, src_reg);
993 if (is_ereg(dst_reg) || is_ereg(src_reg))
994 EMIT1(add_2mod(0x40, dst_reg, src_reg));
995 EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
1002 u32 src_reg)
1009 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbe,
1010 add_2reg(0xC0, src_reg, dst_reg));
1012 EMIT4(add_2mod(0x48, src_reg, dst_reg), 0x0f, 0xbf,
1013 add_2reg(0xC0, src_reg, dst_reg));
1015 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x63,
1016 add_2reg(0xC0, src_reg, dst_reg));
1020 EMIT4(add_2mod(0x40, src_reg, dst_reg), 0x0f, 0xbe,
1021 add_2reg(0xC0, src_reg, dst_reg));
1023 if (is_ereg(dst_reg) || is_ereg(src_reg))
1024 EMIT1(add_2mod(0x40, src_reg, dst_reg));
1025 EMIT3(add_2mod(0x0f, src_reg, dst_reg), 0xbf,
1026 add_2reg(0xC0, src_reg, dst_reg));
1068 static void maybe_emit_mod(u8 **pprog, u32 dst_reg, u32 src_reg, bool is64)
1073 EMIT1(add_2mod(0x48, dst_reg, src_reg));
1074 else if (is_ereg(dst_reg) || is_ereg(src_reg))
1075 EMIT1(add_2mod(0x40, dst_reg, src_reg));
1093 /* LDX: dst_reg = *(u8*)(src_reg + off) */
1094 static void emit_ldx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1101 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
1105 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
1109 if (is_ereg(dst_reg) || is_ereg(src_reg))
1110 EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
1116 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
1119 emit_insn_suffix(&prog, src_reg, dst_reg, off);
1123 /* LDSX: dst_reg = *(s8*)(src_reg + off) */
1124 static void emit_ldsx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1131 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBE);
1135 EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xBF);
1139 EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x63);
1142 emit_insn_suffix(&prog, src_reg, dst_reg, off);
1146 static void emit_ldx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1153 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB6);
1157 EMIT3(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x0F, 0xB7);
1161 EMIT2(add_3mod(0x40, src_reg, dst_reg, index_reg), 0x8B);
1165 EMIT2(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x8B);
1168 emit_insn_suffix_SIB(&prog, src_reg, dst_reg, index_reg, off);
1172 static void emit_ldsx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1179 EMIT3(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x0F, 0xBE);
1183 EMIT3(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x0F, 0xBF);
1187 EMIT2(add_3mod(0x48, src_reg, dst_reg, index_reg), 0x63);
1190 emit_insn_suffix_SIB(&prog, src_reg, dst_reg, index_reg, off);
1194 static void emit_ldx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1196 emit_ldx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1199 static void emit_ldsx_r12(u8 **prog, u32 size, u32 dst_reg, u32 src_reg, int off)
1201 emit_ldsx_index(prog, size, dst_reg, src_reg, X86_REG_R12, off);
1204 /* STX: *(u8*)(dst_reg + off) = src_reg */
1205 static void emit_stx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1212 if (is_ereg(dst_reg) || is_ereg_8l(src_reg))
1213 /* Add extra byte for eregs or SIL,DIL,BPL in src_reg */
1214 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
1219 if (is_ereg(dst_reg) || is_ereg(src_reg))
1220 EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
1225 if (is_ereg(dst_reg) || is_ereg(src_reg))
1226 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
1231 EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
1234 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1238 /* STX: *(u8*)(dst_reg + index_reg + off) = src_reg */
1239 static void emit_stx_index(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, u32 index_reg, int off)
1246 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x88);
1250 EMIT3(0x66, add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1254 EMIT2(add_3mod(0x40, dst_reg, src_reg, index_reg), 0x89);
1258 EMIT2(add_3mod(0x48, dst_reg, src_reg, index_reg), 0x89);
1261 emit_insn_suffix_SIB(&prog, dst_reg, src_reg, index_reg, off);
1265 static void emit_stx_r12(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
1267 emit_stx_index(pprog, size, dst_reg, src_reg, X86_REG_R12, off);
1314 u32 dst_reg, u32 src_reg, s16 off, u8 bpf_size)
1321 maybe_emit_mod(&prog, dst_reg, src_reg, bpf_size == BPF_DW);
1329 /* lock *(u32/u64*)(dst_reg + off) <op>= src_reg */
1333 /* src_reg = atomic_fetch_add(dst_reg + off, src_reg); */
1337 /* src_reg = atomic_xchg(dst_reg + off, src_reg); */
1341 /* r0 = atomic_cmpxchg(dst_reg + off, r0, src_reg); */
1349 emit_insn_suffix(&prog, dst_reg, src_reg, off);
1356 u32 dst_reg, u32 src_reg, u32 index_reg,
1366 EMIT1(add_3mod(0x40, dst_reg, src_reg, index_reg));
1369 EMIT1(add_3mod(0x48, dst_reg, src_reg, index_reg));
1382 /* lock *(u32/u64*)(dst_reg + idx_reg + off) <op>= src_reg */
1386 /* src_reg = atomic_fetch_add(dst_reg + idx_reg + off, src_reg); */
1390 /* src_reg = atomic_xchg(dst_reg + idx_reg + off, src_reg); */
1394 /* r0 = atomic_cmpxchg(dst_reg + idx_reg + off, r0, src_reg); */
1401 emit_insn_suffix_SIB(&prog, dst_reg, src_reg, index_reg, off);
1407 u32 src_reg, s16 off, u8 bpf_size)
1411 /* dst_reg = smp_load_acquire(src_reg + off16) */
1412 emit_ldx(pprog, bpf_size, dst_reg, src_reg, off);
1415 /* smp_store_release(dst_reg + off16, src_reg) */
1416 emit_stx(pprog, bpf_size, dst_reg, src_reg, off);
1428 u32 dst_reg, u32 src_reg, u32 index_reg,
1433 /* dst_reg = smp_load_acquire(src_reg + idx_reg + off16) */
1434 emit_ldx_index(pprog, size, dst_reg, src_reg, index_reg, off);
1437 /* smp_store_release(dst_reg + idx_reg + off16, src_reg) */
1438 emit_stx_index(pprog, size, dst_reg, src_reg, index_reg, off);
1519 if (insn->dst_reg == BPF_REG_6 || insn->src_reg == BPF_REG_6)
1521 if (insn->dst_reg == BPF_REG_7 || insn->src_reg == BPF_REG_7)
1523 if (insn->dst_reg == BPF_REG_8 || insn->src_reg == BPF_REG_8)
1525 if (insn->dst_reg == BPF_REG_9 || insn->src_reg == BPF_REG_9)
1578 static void emit_shiftx(u8 **pprog, u32 dst_reg, u8 src_reg, bool is64, u8 op)
1584 emit_3vex(&prog, r, false, r, m, is64, src_reg, false, op);
1729 u32 src_reg = insn->src_reg;
1739 if (src_reg == BPF_REG_FP)
1740 src_reg = X86_REG_R9;
1758 maybe_emit_mod(&prog, dst_reg, src_reg,
1761 EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
1766 if (dst_reg != src_reg)
1768 emit_mov_reg(&prog, false, dst_reg, src_reg);
1798 EMIT_mov(dst_reg, src_reg);
1812 dst_reg, src_reg);
1816 dst_reg, src_reg);
1904 if (src_reg == BPF_REG_0 ||
1905 src_reg == BPF_REG_3) {
1906 /* mov r11, src_reg */
1907 EMIT_mov(AUX_REG, src_reg);
1908 src_reg = AUX_REG;
1913 src_reg = AUX_REG;
1927 /* div src_reg */
1928 maybe_emit_1mod(&prog, src_reg, is64);
1929 EMIT2(0xF7, add_1reg(0xF0, src_reg));
1936 /* idiv src_reg */
1937 maybe_emit_1mod(&prog, src_reg, is64);
1938 EMIT2(0xF7, add_1reg(0xF8, src_reg));
1975 maybe_emit_mod(&prog, src_reg, dst_reg,
1978 /* imul dst_reg, src_reg */
1979 EMIT3(0x0F, 0xAF, add_2reg(0xC0, src_reg, dst_reg));
2006 if (boot_cpu_has(X86_FEATURE_BMI2) && src_reg != BPF_REG_4) {
2007 /* shrx/sarx/shlx dst_reg, dst_reg, src_reg */
2023 emit_shiftx(&prog, dst_reg, src_reg, w, op);
2028 if (src_reg != BPF_REG_4) { /* common case */
2037 /* mov rcx, src_reg */
2038 EMIT_mov(BPF_REG_4, src_reg);
2048 if (src_reg != BPF_REG_4) {
2151 /* STX: *(u8*)(dst_reg + off) = src_reg */
2156 emit_stx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
2167 /* LDX: dst_reg = *(u8*)(src_reg + r12 + off) */
2182 emit_ldsx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
2184 emit_ldx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
2186 emit_stx_r12(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn->off);
2213 * src_reg/dst_reg holds the address in the arena region with upper
2222 arena_reg = reg2pt_regs[src_reg];
2238 /* LDX: dst_reg = *(u8*)(src_reg + off) */
2247 /* LDXS: dst_reg = *(s8*)(src_reg + off) */
2258 /* Conservatively check that src_reg + insn->off is a kernel address:
2259 * src_reg + insn->off > TASK_SIZE_MAX + PAGE_SIZE
2261 * src_reg + insn->off < VSYSCALL_ADDR
2271 /* mov src_reg, r11 */
2272 EMIT_mov(AUX_REG, src_reg);
2307 emit_ldsx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
2309 emit_ldx(&prog, BPF_SIZE(insn->code), dst_reg, src_reg, insn_off);
2370 u32 real_src_reg = src_reg;
2381 if (src_reg == BPF_REG_0)
2418 err = emit_atomic_ld_st(&prog, insn->imm, dst_reg, src_reg,
2421 err = emit_atomic_rmw(&prog, insn->imm, dst_reg, src_reg,
2441 src_reg, X86_REG_R12, insn->off);
2444 dst_reg, src_reg, X86_REG_R12,
2455 if (src_reg == BPF_PSEUDO_CALL && tail_call_reachable) {
2511 /* cmp dst_reg, src_reg */
2512 maybe_emit_mod(&prog, dst_reg, src_reg,
2514 EMIT2(0x39, add_2reg(0xC0, dst_reg, src_reg));
2519 /* test dst_reg, src_reg */
2520 maybe_emit_mod(&prog, dst_reg, src_reg,
2522 EMIT2(0x85, add_2reg(0xC0, dst_reg, src_reg));