arch/mips/net/bpf_jit_comp64.c

Source file repositories/reference/linux-study-clean/arch/mips/net/bpf_jit_comp64.c

File Facts

System
Linux kernel
Corpus path
arch/mips/net/bpf_jit_comp64.c
Extension
.c
Size
30051 bytes
Lines
1072
Domain
Architecture Layer
Bucket
arch/mips
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (half) {
				if (shift)
					emit(ctx, dsll_safe, dst, dst, shift);
				emit(ctx, ori, dst, acc, half);
				acc = dst;
				shift = 0;
			}
		}
		if (shift)
			emit(ctx, dsll_safe, dst, dst, shift);
	}
	clobber_reg(ctx, dst);
}

/* ALU immediate operation (64-bit) */
static void emit_alu_i64(struct jit_context *ctx, u8 dst, s32 imm, u8 op)
{
	switch (BPF_OP(op)) {
	/* dst = dst | imm */
	case BPF_OR:
		emit(ctx, ori, dst, dst, (u16)imm);
		break;
	/* dst = dst ^ imm */
	case BPF_XOR:
		emit(ctx, xori, dst, dst, (u16)imm);
		break;
	/* dst = -dst */
	case BPF_NEG:
		emit(ctx, dsubu, dst, MIPS_R_ZERO, dst);
		break;
	/* dst = dst << imm */
	case BPF_LSH:
		emit(ctx, dsll_safe, dst, dst, imm);
		break;
	/* dst = dst >> imm */
	case BPF_RSH:
		emit(ctx, dsrl_safe, dst, dst, imm);
		break;
	/* dst = dst >> imm (arithmetic) */
	case BPF_ARSH:
		emit(ctx, dsra_safe, dst, dst, imm);
		break;
	/* dst = dst + imm */
	case BPF_ADD:
		emit(ctx, daddiu, dst, dst, imm);
		break;
	/* dst = dst - imm */
	case BPF_SUB:
		emit(ctx, daddiu, dst, dst, -imm);
		break;
	default:
		/* Width-generic operations */
		emit_alu_i(ctx, dst, imm, op);
	}
	clobber_reg(ctx, dst);
}

/* ALU register operation (64-bit) */
static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op)
{
	switch (BPF_OP(op)) {
	/* dst = dst << src */
	case BPF_LSH:
		emit(ctx, dsllv, dst, dst, src);
		break;
	/* dst = dst >> src */
	case BPF_RSH:
		emit(ctx, dsrlv, dst, dst, src);
		break;
	/* dst = dst >> src (arithmetic) */
	case BPF_ARSH:
		emit(ctx, dsrav, dst, dst, src);
		break;
	/* dst = dst + src */
	case BPF_ADD:
		emit(ctx, daddu, dst, dst, src);
		break;
	/* dst = dst - src */
	case BPF_SUB:
		emit(ctx, dsubu, dst, dst, src);
		break;
	/* dst = dst * src */
	case BPF_MUL:
		if (cpu_has_mips64r6) {
			emit(ctx, dmulu, dst, dst, src);
		} else {
			emit(ctx, dmultu, dst, src);
			emit(ctx, mflo, dst);
			/* Ensure multiplication is completed */
			if (IS_ENABLED(CONFIG_CPU_R4000_WORKAROUNDS))

Annotation

Implementation Notes