-
Notifications
You must be signed in to change notification settings - Fork 47
/
vdebug64.asm
130 lines (100 loc) · 1.49 KB
/
vdebug64.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
segment V
USE16
firstcall db 0
ve:
mov ax,DATA16
mov ds,ax
mov ax,[bbb.sp]
mov sp,ax
mov ax,[bbb.ss]
mov ss,ax
mov ax,[bbb.ip]
push ax
mov ax,[bbb.cs]
push ax
vmcall ; first call
retf
segment STACK64
USE64
stx dq 1024 dup(0)
ste:
nop
rspsave dq 0
exitreason db 0
vregs dq 50 dup (0)
segment CODE64
USE64
include 'vdisplay.asm'
start64:
; interrupts
lidt [eax]
linear rsp,ste,STACK64
mov ax,0
int 0xF0
; Prepare the virtualization structures
mov ax,0x801
linear r8,hr,CODE64
mov r9,V
mov r10,ve
int 0xF0
vmlaunch
hr:
; Save all volatile registers
push r15
linear r15,vregs,STACK64
mov [r15 + 0x00],rax
mov [r15 + 0x08],rbx
mov [r15 + 0x10],rcx
mov [r15 + 0x18],rdx
mov [r15 + 0x20],rsi
mov [r15 + 0x28],rdi
mov [r15 + 0x30],rbp
pop r15
; check exit reason
vmr rax,0x4402
cmp al,18
jnz DebugInterface
linear rax,firstcall,V
cmp byte [rax],1
je VmFinalCall
mov byte [rax],1
; rip +3
vmr rax,0x681E
add rax,3
vmw64 0x681E,rax
mov al,18
jmp DebugInterface
VmFinalCall:
; Disable VMX
mov ax,0x800
int 0xF0
; Back to real mode
cli
xor rcx,rcx
mov cx,CODE16
shl rcx,16
add ecx,back16
mov ax,0x0900
int 0xF0
DebugInterface:
; al = reason
; Just resume yet, not ready
if VDEBUG = 0
jmp DebugResume
end if
linear rdx,exitreason,STACK64
mov byte [rdx],al
call ShowDisplay
jmp DebugResume
DebugResume:
push r15
linear r15,vregs,STACK64
mov rax,[r15 + 0x00]
mov rbx,[r15 + 0x08]
mov rcx,[r15 + 0x10]
mov rdx,[r15 + 0x18]
mov rsi,[r15 + 0x20]
mov rdi,[r15 + 0x28]
mov rbp,[r15 + 0x30]
pop r15
vmresume