arch/x86/kvm/emulate.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/emulate.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/emulate.c- Extension
.c- Size
- 148885 bytes
- Lines
- 5648
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_host.hregs.hkvm_emulate.hlinux/stringify.hasm/debugreg.hasm/nospec-branch.hasm/ibt.hasm/text-patching.hx86.htss.hmmu.hpmu.h
Detected Declarations
struct opcodestruct group_dualstruct gprefixstruct escapestruct instr_dualstruct mode_dualenum x86_transfer_typeenum rex_bitsfunction writeback_registersfunction invalidate_registersfunction em_salcfunction emulator_check_interceptfunction assign_maskedfunction assign_registerfunction ad_maskfunction stack_maskfunction stack_sizefunction address_maskfunction register_addressfunction masked_incrementfunction register_address_incrementfunction rsp_incrementfunction desc_limit_scaledfunction seg_basefunction emulate_exceptionfunction emulate_dbfunction emulate_gpfunction emulate_ssfunction emulate_udfunction emulate_tsfunction emulate_defunction emulate_nmfunction get_segment_selectorfunction set_segment_selectorfunction ctxt_virt_addr_bitsfunction emul_is_noncanonical_addressfunction insn_alignmentfunction __linearizefunction linearizefunction assign_eipfunction emulator_recalc_and_set_modefunction assign_eip_nearfunction assign_eip_farfunction jmp_relfunction linear_read_systemfunction linear_write_systemfunction segmented_read_stdfunction segmented_write_std
Annotated Snippet
struct opcode {
u64 flags;
u8 intercept;
u8 pad[7];
union {
int (*execute)(struct x86_emulate_ctxt *ctxt);
const struct opcode *group;
const struct group_dual *gdual;
const struct gprefix *gprefix;
const struct escape *esc;
const struct instr_dual *idual;
const struct mode_dual *mdual;
} u;
int (*check_perm)(struct x86_emulate_ctxt *ctxt);
};
struct group_dual {
struct opcode mod012[8];
struct opcode mod3[8];
};
struct gprefix {
struct opcode pfx_no;
struct opcode pfx_66;
struct opcode pfx_f2;
struct opcode pfx_f3;
};
struct escape {
struct opcode op[8];
struct opcode high[64];
};
struct instr_dual {
struct opcode mod012;
struct opcode mod3;
};
struct mode_dual {
struct opcode mode32;
struct opcode mode64;
};
#define EFLG_RESERVED_ZEROS_MASK 0xffc0802a
enum x86_transfer_type {
X86_TRANSFER_NONE,
X86_TRANSFER_CALL_JMP,
X86_TRANSFER_RET,
X86_TRANSFER_TASK_SWITCH,
};
enum rex_bits {
REX_B = 1,
REX_X = 2,
REX_R = 4,
REX_W = 8,
};
static void writeback_registers(struct x86_emulate_ctxt *ctxt)
{
unsigned long dirty = ctxt->regs_dirty;
unsigned reg;
for_each_set_bit(reg, &dirty, NR_EMULATOR_GPRS)
ctxt->ops->write_gpr(ctxt, reg, ctxt->_regs[reg]);
}
static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
{
ctxt->regs_dirty = 0;
ctxt->regs_valid = 0;
}
/*
* These EFLAGS bits are restored from saved value during emulation, and
* any changes are written back to the saved value after emulation.
*/
#define EFLAGS_MASK (X86_EFLAGS_OF|X86_EFLAGS_SF|X86_EFLAGS_ZF|X86_EFLAGS_AF|\
X86_EFLAGS_PF|X86_EFLAGS_CF)
#ifdef CONFIG_X86_64
#define ON64(x...) x
#else
#define ON64(x...)
#endif
#define EM_ASM_START(op) \
static int em_##op(struct x86_emulate_ctxt *ctxt) \
{ \
Annotation
- Immediate include surface: `linux/kvm_host.h`, `regs.h`, `kvm_emulate.h`, `linux/stringify.h`, `asm/debugreg.h`, `asm/nospec-branch.h`, `asm/ibt.h`, `asm/text-patching.h`.
- Detected declarations: `struct opcode`, `struct group_dual`, `struct gprefix`, `struct escape`, `struct instr_dual`, `struct mode_dual`, `enum x86_transfer_type`, `enum rex_bits`, `function writeback_registers`, `function invalidate_registers`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.