FreeBSD/sys/amd64/vmm/amd/vmcb.c
/*
 * Read from segment selector, control and general purpose register of VMCB.
 */
Read from segment selector, control and general purpose register of VMCB.
Read from segment selector control and general purpose register of VMCB .
int
vmcb_read(struct svm_softc *sc, int vcpu, int ident, uint64_t *retval)
{
	struct vmcb *vmcb;
	struct vmcb_state *state;
	struct vmcb_segment *seg;
	int err;
	vmcb = svm_get_vmcb(sc, vcpu);
	state = &vmcb->state;
	err = 0;
	if (VMCB_ACCESS_OK(ident))
		return (vmcb_access(sc, vcpu, 0, ident, retval));
	switch (ident) {
	case VM_REG_GUEST_CR0:
		*retval = state->cr0;
		break;
	case VM_REG_GUEST_CR2:
		*retval = state->cr2;
		break;
	case VM_REG_GUEST_CR3:
		*retval = state->cr3;
		break;
	case VM_REG_GUEST_CR4:
		*retval = state->cr4;
		break;
	case VM_REG_GUEST_DR7:
		*retval = state->dr7;
		break;
	case VM_REG_GUEST_EFER:
		*retval = state->efer;
		break;
	case VM_REG_GUEST_RAX:
		*retval = state->rax;
		break;
	case VM_REG_GUEST_RFLAGS:
		*retval = state->rflags;
		break;
	case VM_REG_GUEST_RIP:
		*retval = state->rip;
		break;
	case VM_REG_GUEST_RSP:
		*retval = state->rsp;
		break;
	case VM_REG_GUEST_CS:
	case VM_REG_GUEST_DS:
	case VM_REG_GUEST_ES:
	case VM_REG_GUEST_FS:
	case VM_REG_GUEST_GS:
	case VM_REG_GUEST_SS:
	case VM_REG_GUEST_LDTR:
	case VM_REG_GUEST_TR:
		seg = vmcb_segptr(vmcb, ident);
		KASSERT(seg != NULL, ("%s: unable to get segment %d from VMCB",
		    __func__, ident));
		*retval = seg->selector;
		break;
	case VM_REG_GUEST_GDTR:
	case VM_REG_GUEST_IDTR:
		err = EINVAL;
		break;
	default:
		err =  EINVAL;
		break;
	}
	return (err);
}
int vmcb_read ( struct svm_softc * sc , int vcpu , int ident , uint64_t * retval ) { struct vmcb * vmcb ; struct vmcb_state * state ; struct vmcb_segment * seg ; int err ; vmcb = svm_get_vmcb ( sc , vcpu ) ; state = & vmcb -> state ; err = 0 ; if ( VMCB_ACCESS_OK ( ident ) ) return ( vmcb_access ( sc , vcpu , 0 , ident , retval ) ) ; switch ( ident ) { case VM_REG_GUEST_CR0 : * retval = state -> cr0 ; break ; case VM_REG_GUEST_CR2 : * retval = state -> cr2 ; break ; case VM_REG_GUEST_CR3 : * retval = state -> cr3 ; break ; case VM_REG_GUEST_CR4 : * retval = state -> cr4 ; break ; case VM_REG_GUEST_DR7 : * retval = state -> dr7 ; break ; case VM_REG_GUEST_EFER : * retval = state -> efer ; break ; case VM_REG_GUEST_RAX : * retval = state -> rax ; break ; case VM_REG_GUEST_RFLAGS : * retval = state -> rflags ; break ; case VM_REG_GUEST_RIP : * retval = state -> rip ; break ; case VM_REG_GUEST_RSP : * retval = state -> rsp ; break ; case VM_REG_GUEST_CS : case VM_REG_GUEST_DS : case VM_REG_GUEST_ES : case VM_REG_GUEST_FS : case VM_REG_GUEST_GS : case VM_REG_GUEST_SS : case VM_REG_GUEST_LDTR : case VM_REG_GUEST_TR : seg = vmcb_segptr ( vmcb , ident ) ; KASSERT ( seg != NULL , ( " " , __func__ , ident ) ) ; * retval = seg -> selector ; break ; case VM_REG_GUEST_GDTR : case VM_REG_GUEST_IDTR : err = EINVAL ; break ; default : err = EINVAL ; break ; } return ( err ) ; }
Read from segment selector, control and general purpose register of VMCB.
Read from segment selector control and general purpose register of VMCB .
/* GDTR and IDTR don't have segment selectors */