-
Notifications
You must be signed in to change notification settings - Fork 47
/
int64.asm
195 lines (150 loc) · 2.53 KB
/
int64.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
; --------------------------------------- int 0xF0 long ---------------------------------------
int64_21:
mov bp,ax
mov ax,0x0421
int64:
jmp .ibegin
db 'dmmi'
db 10 dup(0x90)
.ibegin:
; AX 0, find interface
cmp ax,0
jnz .n0
dh_virtualization;
linear rax,numcpus,DATA16
mov dl,[rax]
mov rax,0xFACE
IRETQ
.n0:
; AH 4, call real mode interrupt
; AL = INT NUM
; BP = AX VALUE
; CX,DX,SI,DI = Normal values
; Upper ESI,EDI => DS and ES
cmp ah,4
jnz nx4
push rax
linear r8,From64To16Regs,DATA64
; Mutex Lock
mov rax,mut_i21
call qwaitlock64
; Save: AX,BX,CD,DX,SI,DI,DS,ES
mov word [r8],bp
mov word [r8 + 2],bx
mov word [r8 + 4],cx
mov word [r8 + 6],dx
mov word [r8 + 8],si
mov word [r8 + 10],di
mov eax,esi
shr eax,16
mov word [r8 + 12],ax
mov eax,edi
shr eax,16
mov word [r8 + 14],ax
pop rax
mov byte [r8 + 16],al ; #intr
mov word [r8 + 18],ss ; save for later
mov dword [r8 + 20],esp ; save for later
; go to compatibility mode
push code32_idx
xor rcx,rcx
mov ecx,CompatFromLongIntF0
push rcx
retf
USE64
BackFromExecutingInterruptLM:
linear rax,idt_LM_start
lidt [rax]
mov ax,page64_idx
mov ss,ax
linear r8,From64To16Regs,DATA64
xor rsp,rsp
mov esp,dword [r8 + 20]
qunlock64 mut_i21
iretq
nx4:
; AH 5, mutex functions
cmp ah,5
jnz .n5
; Initialize mutex
cmp al,0
jnz .n50
mov byte [rdi],0xFF
iretq
.n50:
; lock mutex
cmp al,2
jnz .n52
dec byte [rdi]
iretq
.n52:
; unlock mutex
cmp al,3
jnz .n53
cmp byte [rdi],0xFF
jz .okl
inc byte [rdi]
.okl:
iretq
.n53:
; wait mutex
cmp al,4
jnz .n54
.Loop1:
CMP byte [rdi],0xff
JZ .OutLoop1
pause
JMP .Loop1
.OutLoop1:
iretq
.n54:
IRETQ
.n5:
; AX 0x800, disable VMX
cmp ax,0x800
jnz nnn800
call VMX_Disable
IRETQ
nnn800:
; AX 0x801, prepare vmx structures
cmp ax,0x801
jnz nnn801
; r8 host return
; r9 seg vm
; r10 ofs vm
call VMX_Init
call VMX_Enable
call VMXInit
call VMX_InitializeEPT
xor rdx,rdx
bts rdx,1
bts rdx,7
call VMX_Initialize_VMX_Controls
mov rcx,r8
call VMX_Initialize_Host
call VMX_Initialize_UnrestrictedGuest
call VMXInit2
IRETQ
nnn801:
; AX 9, switch to mode
cmp ah,9
jnz nnn9
; AL 0, unreal
cmp al,0
jnz .nnn90
linear eax,segnnn0,CODE16
mov word [eax],cx
shr ecx,16
linear eax,ofsnnn0,CODE16
mov word [eax],cx
; Back to Compatibility Mode
push code32_idx
xor rcx,rcx
mov ecx,nnn90Back
push rcx
retf
IRETQ
.nnn90:
IRETQ
nnn9:
IRETQ