Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
x64
.vs
.VC.db
.VC.db
*.user
25,408 changes: 25,408 additions & 0 deletions ia32.h

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions nt/shvos.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,6 @@ ShvOsRunCallbackOnProcessors (
KeGenericCallDpc(ShvOsDpcRoutine, &dpcContext);
}

VOID
ShvOsRestoreContext(
_In_ PCONTEXT ContextRecord
)
{
ShvOsRestoreContext2(ContextRecord, NULL);
}

VOID
ShvOsCaptureContext (
_In_ PCONTEXT ContextRecord
)
{
//
// Windows provides a nice OS function to do this
//
RtlCaptureContext(ContextRecord);
}

INT32
ShvOsGetCurrentProcessorNumber (
VOID
Expand Down
91 changes: 0 additions & 91 deletions nt/shvosx64.asm

This file was deleted.

3 changes: 3 additions & 0 deletions ntint.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Header Name:
--*/

#pragma once
#pragma pack(push, 1)
#pragma warning(disable:4201)
#pragma warning(disable:4214)

Expand Down Expand Up @@ -148,3 +149,5 @@ typedef union _LARGE_INTEGER
};
UINT64 QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;

#pragma pack(pop)
19 changes: 18 additions & 1 deletion shv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Header Name:

#ifndef __BASE_H__
#include <basetsd.h>
#define MAX_UINT32 0xFFFFFFFF
#define MAX_UINT64 0xFFFFFFFFFFFFFFFF
#endif
#define _INC_MALLOC
#include <intrin.h>
Expand Down Expand Up @@ -180,5 +182,20 @@ ShvOsRunCallbackOnProcessors (
_In_opt_ VOID* Context
);

extern PSHV_VP_DATA* ShvGlobalData;
unsigned long long
ShvSelectEffectiveRegister (
_In_ PCONTEXT guestContext,
_In_ UINT64 registerIndex
);

UINT64
ShvAdjustCr0 (
_In_ UINT64 cr0
);

UINT64
ShvAdjustCr4(
_In_ UINT64 cr4
);

extern PSHV_VP_DATA* ShvGlobalData;
5 changes: 3 additions & 2 deletions shv.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
<ClCompile Include="shvvmx.c" />
<ClCompile Include="shvvmxhv.c" />
<ClCompile Include="shvvp.c" />
<ClCompile Include="$(Configuration)\shvos.c"/>
<ClCompile Include="$(Configuration)\shvos.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ia32.h" />
<ClInclude Include="shv.h" />
<ClInclude Include="ntint.h" />
<ClInclude Include="shv_x.h" />
<ClInclude Include="vmx.h" />
</ItemGroup>
<ItemGroup>
<MASM Include="shvosx64.asm" />
<MASM Include="shvvmxhvx64.asm" />
<MASM Include="$(Configuration)\shvosx64.asm"/>
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions uefi/shvosx64.asm → shvosx64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@

.code

_str PROC
str word ptr [rcx] ; Store TR value
ret ; Return
_str ENDP

_sldt PROC
sldt word ptr [rcx] ; Store LDTR value
ret ; Return
_sldt ENDP

ShvVmxCleanup PROC
mov ds, cx ; set DS to parameter 1
mov es, cx ; set ES to parameter 1
mov fs, dx ; set FS to parameter 2
ret ; return
ShvVmxCleanup ENDP

__lgdt PROC
lgdt fword ptr [rcx] ; load the GDTR with the value in parameter 1
ret ; return
__lgdt ENDP

_ltr PROC
ltr cx
_ltr ENDP
Expand Down Expand Up @@ -52,6 +74,14 @@
mov [rcx+0E8h], r14
mov [rcx+0F0h], r15

movdqu [rcx+0198h], xmm0
movdqu [rcx+01a8h], xmm1
movdqu [rcx+01b8h], xmm2
movdqu [rcx+01c8h], xmm3
movdqu [rcx+01d8h], xmm4
movdqu [rcx+01e8h], xmm5


lea rax, [rsp+10h]
mov [rcx+98h], rax
mov rax, [rsp+8]
Expand Down Expand Up @@ -81,6 +111,13 @@
mov r9, [rcx+0C0h]
mov r10, [rcx+0C8h]
mov r11, [rcx+0D0h]

movdqu xmm0, [rcx+0198h]
movdqu xmm1, [rcx+01a8h]
movdqu xmm2, [rcx+01b8h]
movdqu xmm3, [rcx+01c8h]
movdqu xmm4, [rcx+01d8h]
movdqu xmm5, [rcx+01e8h]
cli

mov rbx, [rcx+90h]
Expand Down
65 changes: 65 additions & 0 deletions shvutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Module Name:
--*/

#include "shv.h"
#include "ia32.h"

VOID
ShvUtilConvertGdtEntry (
Expand Down Expand Up @@ -104,3 +105,67 @@ ShvUtilAdjustMsr (
return DesiredValue;
}

unsigned long long
ShvSelectEffectiveRegister (
_In_ PCONTEXT guestContext,
_In_ UINT64 registerIndex
)
{
switch (registerIndex)
{
case 0:
return guestContext->Rax;
case 1:
return guestContext->Rcx;
case 2:
return guestContext->Rdx;
case 3:
return guestContext->Rbx;
case 4:
return guestContext->Rsp;
case 5:
return guestContext->Rbp;
case 6:
return guestContext->Rsi;
case 7:
return guestContext->Rdi;
case 8:
return guestContext->R8;
case 9:
return guestContext->R9;
case 10:
return guestContext->R10;
case 11:
return guestContext->R11;
case 12:
return guestContext->R12;
case 13:
return guestContext->R13;
case 14:
return guestContext->R14;
case 15:
return guestContext->R15;
default:
return 0;
}
}

UINT64
ShvAdjustCr0 (
_In_ UINT64 cr0
)
{
cr0 |= __readmsr(IA32_VMX_CR0_FIXED0);
cr0 &= __readmsr(IA32_VMX_CR0_FIXED1);
return cr0;
}

UINT64
ShvAdjustCr4(
_In_ UINT64 cr4
)
{
cr4 |= __readmsr(IA32_VMX_CR4_FIXED0);
cr4 &= __readmsr(IA32_VMX_CR4_FIXED1);
return cr4;
}
3 changes: 3 additions & 0 deletions shvvmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ ShvVmxSetupVmcsForVp (
SECONDARY_EXEC_ENABLE_RDTSCP |
SECONDARY_EXEC_ENABLE_INVPCID |
SECONDARY_EXEC_XSAVES |
SECONDARY_EXEC_UNRESTRICTED_GUEST |
VpData->EptControls));

//
Expand Down Expand Up @@ -473,6 +474,7 @@ ShvVmxSetupVmcsForVp (
//
// Load CR0
//
__vmx_vmwrite(CR0_GUEST_HOST_MASK, MAX_UINT64);
__vmx_vmwrite(CR0_READ_SHADOW, state->Cr0);
__vmx_vmwrite(HOST_CR0, state->Cr0);
__vmx_vmwrite(GUEST_CR0, state->Cr0);
Expand All @@ -491,6 +493,7 @@ ShvVmxSetupVmcsForVp (
__vmx_vmwrite(HOST_CR4, state->Cr4);
__vmx_vmwrite(GUEST_CR4, state->Cr4);
__vmx_vmwrite(CR4_READ_SHADOW, state->Cr4);
__vmx_vmwrite(CR4_GUEST_HOST_MASK, MAX_UINT64);

//
// Load debug MSR and register (DR7)
Expand Down
Loading