forked from ionescu007/SimpleVisor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shvx64.asm
64 lines (50 loc) · 1.9 KB
/
shvx64.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;++
;
; Copyright (c) Alex Ionescu. All rights reserved.
;
; Module:
;
; shvx64.asm
;
; Abstract:
;
; This module implements AMD64-specific routines for the Simple Hyper Visor.
;
; Author:
;
; Alex Ionescu (@aionescu) 16-Mar-2016 - Initial version
;
; Environment:
;
; Kernel mode only.
;
;--
include ksamd64.inc
extern ShvVmxEntryHandler:proc
extern RtlCaptureContext:proc
NESTED_ENTRY ShvVmxEntry, _TEXT$00
push_reg rcx ; save RCX, as we will need to orverride it
END_PROLOGUE ; done messing with the stack
lea rcx, [rsp+8h] ; store the context in the stack, bias for
; the return address and the push we just did.
call RtlCaptureContext ; save the current register state.
; note that this is a specially written function
; which has the following key characteristics:
; 1) it does not taint the value of RCX
; 2) it does not spill any registers, nor
; expect home space to be allocated for it
jmp ShvVmxEntryHandler ; jump to the C code handler. we assume that it
; compiled with optimizations and does not use
; home space, which is true of release builds.
NESTED_END ShvVmxEntry, _TEXT$00
LEAF_ENTRY ShvVmxCleanup, _TEXT$00
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
LEAF_END ShvVmxCleanup, _TEXT$00
LEAF_ENTRY __lgdt, _TEXT$00
lgdt fword ptr [rcx] ; load the GDTR with the value in parameter 1
ret ; return
LEAF_END __lgdt, _TEXT$00
end