Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


email notification test
[palacios.git] / palacios / src / palacios / svm_lowlevel.S
1 #;  -*- fundamental -*-
2
3 .text
4 .align 4
5
6 .globl v3_svm_launch
7 .globl v3_stgi
8 .globl v3_clgi
9
10 #define SVM_ERROR .dword 0xffffffff
11 #define SVM_SUCCESS .dword 0x00000000
12
13 #define vmrun .byte 0x0f,0x01,0xd8
14 #define vmload .byte 0x0F,0x01,0xDA
15 #define vmsave .byte 0x0F,0x01,0xDB
16 #define stgi   .byte 0x0F,0x01,0xDC
17 #define clgi   .byte 0x0F,0x01,0xDD
18
19
20 #define SVM_VM_HSAVE_PA_MSR .dword 0xc0010117
21
22
23 #ifdef __V3_32BIT__
24
25 #define Save_SVM_Registers(location)    \
26         pushl   %eax;                   \
27         movl    location, %eax;         \
28         movl    %edi, (%eax);           \
29         movl    %esi, 8(%eax);          \
30         movl    %ebp, 16(%eax);         \
31         movl    $0, 24(%eax);           \
32         movl    %ebx, 32(%eax);         \
33         movl    %edx, 40(%eax);         \
34         movl    %ecx, 48(%eax);         \
35         pushl   %ebx;                   \
36         movl    8(%esp), %ebx;          \
37         movl    %ebx, 56(%eax);         \
38         popl    %ebx;                   \
39         popl    %eax;                   
40         
41
42 #define Restore_SVM_Registers(location) \
43         pushl   %eax;                   \
44         movl    location, %eax;         \
45         movl    (%eax), %edi;           \
46         movl    8(%eax), %esi;          \
47         movl    16(%eax), %ebp;         \
48         movl    32(%eax), %ebx;         \
49         movl    40(%eax), %edx;         \
50         movl    48(%eax), %ecx;         \
51         popl    %eax;
52
53
54 // 32 bit GCC passes arguments via stack
55
56 v3_svm_launch:
57         push    %ebp;
58         movl    %esp, %ebp;
59         pushf;
60         pusha;
61
62         movl    16(%ebp), %eax;
63         vmsave;
64
65         pushl   12(%ebp);
66         pushl   8(%ebp);
67
68         Restore_SVM_Registers(8(%esp));
69         popl    %eax;
70
71         vmload;
72         vmrun;
73         vmsave;
74
75         Save_SVM_Registers(4(%esp));
76
77         addl    $4, %esp;
78
79
80         movl    16(%ebp), %eax;
81         vmload;
82
83         popa;
84         popf;
85         pop     %ebp;
86         ret
87
88
89
90 #elif __V3_64BIT__
91
92 #define Save_SVM_Registers(location)    \
93         pushq   %rax;                   \
94         movq    location, %rax;         \
95         movq    %rdi, (%rax);           \
96         movq    %rsi, 8(%rax);          \
97         movq    %rbp, 16(%rax);         \
98         movq    $0, 24(%rax);           \
99         movq    %rbx, 32(%rax);         \
100         movq    %rdx, 40(%rax);         \
101         movq    %rcx, 48(%rax);         \
102         pushq   %rbx;                   \
103         movq    16(%rsp), %rbx;         \
104         movq    %rbx, 56(%rax);         \
105         popq    %rbx;                   \
106                                         \
107         movq    %r8, 64(%rax);          \
108         movq    %r9, 72(%rax);          \
109         movq    %r10, 80(%rax);         \
110         movq    %r11, 88(%rax);         \
111         movq    %r12, 96(%rax);         \
112         movq    %r13, 104(%rax);        \
113         movq    %r14, 112(%rax);        \
114         movq    %r15, 120(%rax);        \
115         popq    %rax;                   
116         
117
118 #define Restore_SVM_Registers(location) \
119         push    %rax;                   \
120         mov     location, %rax;         \
121         mov     (%rax), %rdi;           \
122         mov     8(%rax), %rsi;          \
123         mov     16(%rax), %rbp;         \
124         mov     32(%rax), %rbx;         \
125         mov     40(%rax), %rdx;         \
126         mov     48(%rax), %rcx;         \
127                                         \
128         mov     64(%rax), %r8;          \
129         mov     72(%rax), %r9;          \
130         mov     80(%rax), %r10;         \
131         mov     88(%rax), %r11;         \
132         mov     96(%rax), %r12;         \
133         mov     104(%rax), %r13;        \
134         mov     112(%rax), %r14;        \
135         mov     120(%rax), %r15;        \
136         pop     %rax;
137
138
139
140
141 #define PUSHA                           \
142         pushq %rbp;                     \
143         pushq %rbx;                     \
144         pushq %r8;                      \
145         pushq %r9;                      \
146         pushq %r10;                     \
147         pushq %r11;                     \
148         pushq %r12;                     \
149         pushq %r13;                     \
150         pushq %r14;                     \
151         pushq %r15;                     
152
153
154 #define POPA                            \
155         popq %r15;                      \
156         popq %r14;                      \
157         popq %r13;                      \
158         popq %r12;                      \
159         popq %r11;                      \
160         popq %r10;                      \
161         popq %r9;                       \
162         popq %r8;                       \
163         popq %rbx;                      \
164         popq %rbp;                      
165
166
167 // Note that this is only for 64 bit GCC, 32 bit GCC passes via stack
168 // VMCB => RDI
169 // vm_regs => RSI
170 // HOST VMCB => RDX
171
172 v3_svm_launch:
173         pushf;
174         PUSHA
175         
176         pushq   %rdx;
177         movq    %rdx, %rax;
178         vmsave;
179
180         pushq   %rsi
181
182         movq    %rdi, %rax
183         Restore_SVM_Registers(%rsi);
184
185
186         vmload;
187         vmrun;
188         vmsave;
189
190
191         Save_SVM_Registers(8(%rsp));
192
193         addq $8, %rsp
194
195
196         popq %rax;
197         vmload;
198
199         POPA
200         popf;
201         ret
202
203
204 #endif
205
206
207 v3_stgi:
208         stgi;
209         ret;
210
211 v3_clgi:
212         clgi;
213         ret;
214         
215