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.


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