arch/mips/net/bpf_jit_comp32.c
Source file repositories/reference/linux-study-clean/arch/mips/net/bpf_jit_comp32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/net/bpf_jit_comp32.c- Extension
.c- Size
- 54970 bytes
- Lines
- 1907
- 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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/math64.hlinux/errno.hlinux/filter.hlinux/bpf.hasm/cpu-features.hasm/isa-rev.hasm/uasm.hbpf_jit_comp.h
Detected Declarations
function lofunction hifunction clobber_reg64function emit_mov_se_i64function emit_zext_verfunction emit_load_delayfunction emit_alu_i64function emit_alu_r64function emit_neg_i64function emit_shift_i64function emit_shift_r64function emit_mul_i64function emit_mul_r64function jit_mod64function emit_divmod_r64function emit_swap8_rfunction emit_swap16_rfunction emit_bswap_r64function emit_trunc_r64function emit_ldxfunction emit_stxfunction emit_atomic_r32function jit_xchg64function emit_atomic_r64function emit_cmpxchg_r32function emit_cmpxchg_r64function emit_movz_rfunction emit_movn_rfunction emit_sltiu_r64function emit_sltu_r64function emit_slti_r64function emit_slt_r64function emit_jmp_i64function emit_jmp_r64function emit_callfunction emit_tail_callfunction programfunction build_epiloguefunction build_insn
Annotated Snippet
switch (op) {
case BPF_ADD:
op = BPF_SUB;
imm = -imm;
break;
case BPF_SUB:
op = BPF_ADD;
imm = -imm;
break;
}
/* Move immediate to temporary register */
emit_mov_i(ctx, src, imm);
switch (op) {
/* dst = dst + imm */
case BPF_ADD:
emit(ctx, addu, lo(dst), lo(dst), src);
emit(ctx, sltu, MIPS_R_T9, lo(dst), src);
emit(ctx, addu, hi(dst), hi(dst), MIPS_R_T9);
if (imm < 0)
emit(ctx, addiu, hi(dst), hi(dst), -1);
break;
/* dst = dst - imm */
case BPF_SUB:
emit(ctx, sltu, MIPS_R_T9, lo(dst), src);
emit(ctx, subu, lo(dst), lo(dst), src);
emit(ctx, subu, hi(dst), hi(dst), MIPS_R_T9);
if (imm < 0)
emit(ctx, addiu, hi(dst), hi(dst), 1);
break;
/* dst = dst | imm */
case BPF_OR:
emit(ctx, or, lo(dst), lo(dst), src);
if (imm < 0)
emit(ctx, addiu, hi(dst), MIPS_R_ZERO, -1);
break;
/* dst = dst & imm */
case BPF_AND:
emit(ctx, and, lo(dst), lo(dst), src);
if (imm >= 0)
emit(ctx, move, hi(dst), MIPS_R_ZERO);
break;
/* dst = dst ^ imm */
case BPF_XOR:
emit(ctx, xor, lo(dst), lo(dst), src);
if (imm < 0) {
emit(ctx, subu, hi(dst), MIPS_R_ZERO, hi(dst));
emit(ctx, addiu, hi(dst), hi(dst), -1);
}
break;
}
clobber_reg64(ctx, dst);
}
/* ALU register operation (64-bit) */
static void emit_alu_r64(struct jit_context *ctx,
const u8 dst[], const u8 src[], u8 op)
{
switch (BPF_OP(op)) {
/* dst = dst + src */
case BPF_ADD:
if (src == dst) {
emit(ctx, srl, MIPS_R_T9, lo(dst), 31);
emit(ctx, addu, lo(dst), lo(dst), lo(dst));
} else {
emit(ctx, addu, lo(dst), lo(dst), lo(src));
emit(ctx, sltu, MIPS_R_T9, lo(dst), lo(src));
}
emit(ctx, addu, hi(dst), hi(dst), hi(src));
emit(ctx, addu, hi(dst), hi(dst), MIPS_R_T9);
break;
/* dst = dst - src */
case BPF_SUB:
emit(ctx, sltu, MIPS_R_T9, lo(dst), lo(src));
emit(ctx, subu, lo(dst), lo(dst), lo(src));
emit(ctx, subu, hi(dst), hi(dst), hi(src));
emit(ctx, subu, hi(dst), hi(dst), MIPS_R_T9);
break;
/* dst = dst | src */
case BPF_OR:
emit(ctx, or, lo(dst), lo(dst), lo(src));
emit(ctx, or, hi(dst), hi(dst), hi(src));
break;
/* dst = dst & src */
case BPF_AND:
emit(ctx, and, lo(dst), lo(dst), lo(src));
emit(ctx, and, hi(dst), hi(dst), hi(src));
break;
/* dst = dst ^ src */
Annotation
- Immediate include surface: `linux/math64.h`, `linux/errno.h`, `linux/filter.h`, `linux/bpf.h`, `asm/cpu-features.h`, `asm/isa-rev.h`, `asm/uasm.h`, `bpf_jit_comp.h`.
- Detected declarations: `function lo`, `function hi`, `function clobber_reg64`, `function emit_mov_se_i64`, `function emit_zext_ver`, `function emit_load_delay`, `function emit_alu_i64`, `function emit_alu_r64`, `function emit_neg_i64`, `function emit_shift_i64`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.