MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vmcs_init

Function vmcs_init

freebsd/amd64/vmm/intel/vmcs.c:342–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342int
343vmcs_init(struct vmcs *vmcs)
344{
345 int error, codesel, datasel, tsssel;
346 u_long cr0, cr4, efer;
347 uint64_t pat, fsbase, idtrbase;
348
349 codesel = vmm_get_host_codesel();
350 datasel = vmm_get_host_datasel();
351 tsssel = vmm_get_host_tsssel();
352
353 /*
354 * Make sure we have a "current" VMCS to work with.
355 */
356 VMPTRLD(vmcs);
357
358 /* Host state */
359
360 /* Initialize host IA32_PAT MSR */
361 pat = vmm_get_host_pat();
362 if ((error = vmwrite(VMCS_HOST_IA32_PAT, pat)) != 0)
363 goto done;
364
365 /* Load the IA32_EFER MSR */
366 efer = vmm_get_host_efer();
367 if ((error = vmwrite(VMCS_HOST_IA32_EFER, efer)) != 0)
368 goto done;
369
370 /* Load the control registers */
371
372 cr0 = vmm_get_host_cr0();
373 if ((error = vmwrite(VMCS_HOST_CR0, cr0)) != 0)
374 goto done;
375
376 cr4 = vmm_get_host_cr4() | CR4_VMXE;
377 if ((error = vmwrite(VMCS_HOST_CR4, cr4)) != 0)
378 goto done;
379
380 /* Load the segment selectors */
381 if ((error = vmwrite(VMCS_HOST_ES_SELECTOR, datasel)) != 0)
382 goto done;
383
384 if ((error = vmwrite(VMCS_HOST_CS_SELECTOR, codesel)) != 0)
385 goto done;
386
387 if ((error = vmwrite(VMCS_HOST_SS_SELECTOR, datasel)) != 0)
388 goto done;
389
390 if ((error = vmwrite(VMCS_HOST_DS_SELECTOR, datasel)) != 0)
391 goto done;
392
393 if ((error = vmwrite(VMCS_HOST_FS_SELECTOR, datasel)) != 0)
394 goto done;
395
396 if ((error = vmwrite(VMCS_HOST_GS_SELECTOR, datasel)) != 0)
397 goto done;
398
399 if ((error = vmwrite(VMCS_HOST_TR_SELECTOR, tsssel)) != 0)

Callers 1

vmx_initFunction · 0.85

Calls 12

vmm_get_host_codeselFunction · 0.85
vmm_get_host_dataselFunction · 0.85
vmm_get_host_tssselFunction · 0.85
VMPTRLDFunction · 0.85
vmm_get_host_patFunction · 0.85
vmwriteFunction · 0.85
vmm_get_host_eferFunction · 0.85
vmm_get_host_cr0Function · 0.85
vmm_get_host_cr4Function · 0.85
vmm_get_host_fsbaseFunction · 0.85
vmm_get_host_idtrbaseFunction · 0.85
VMCLEARFunction · 0.85

Tested by

no test coverage detected