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.


*** empty log message ***
[palacios.git] / palacios / src / palacios / svm_lowlevel.asm
1 ;  -*- fundamental -*-
2
3
4 %ifndef SVM_ASM
5 %define SVM_ASM
6
7 ;%include "defs.asm"
8 %include "vmm_symbol.asm"
9
10 SVM_ERROR equ 0xFFFFFFFF
11 SVM_SUCCESS equ 0x00000000
12
13 EXPORT DisableInts
14 EXPORT EnableInts
15
16
17 EXPORT exit_test
18
19 EXTERN handle_svm_exit
20
21 EXPORT launch_svm
22 EXPORT safe_svm_launch
23
24 EXPORT STGI
25 EXPORT CLGI
26
27
28
29 ;; These need to be kept similar with the svm return values in svm.h
30 SVM_HANDLER_SUCCESS  equ 0x00
31 SVM_HANDLER_ERROR equ  0x1
32 SVM_HANDLER_HALT equ 0x2
33
34 [BITS 32]
35
36
37 ; Save and restore registers needed by SVM
38 %macro Save_SVM_Registers 1
39         push    eax
40         mov     eax, dword %1
41         mov     [eax], edi
42         mov     [eax + 8], esi
43         mov     [eax + 16], ebp
44         mov     [eax + 24], dword 0             ;; esp
45         mov     [eax + 32], ebx
46         mov     [eax + 40], edx
47         mov     [eax + 48], ecx
48
49         push    ebx
50         mov     ebx, [esp + 4]
51         mov     [eax + 56], ebx         ;; eax
52         pop     ebx
53
54         pop     eax
55 %endmacro
56
57
58 %macro Restore_SVM_Registers 1
59         push    eax
60         mov     eax, dword %1
61         mov     edi, [eax]
62         mov     esi, [eax + 8]
63         mov     ebp, [eax + 16]
64 ;;      mov     esp, [eax + 24]
65         mov     ebx, [eax + 32]
66         mov     edx, [eax + 40]
67         mov     ecx, [eax + 48]
68 ;;      mov     eax, [eax + 56]
69         pop     eax
70 %endmacro
71
72 %macro vmrun 0
73         db      00fh, 001h, 0d8h
74 %endmacro
75
76 %macro vmsave 0
77         db      00fh, 001h, 0dbh
78 %endmacro
79
80 %macro vmload 0
81         db      00fh, 001h, 0dah
82 %endmacro
83
84 %macro stgi 0
85         db      00fh, 001h, 0dch
86 %endmacro
87
88 %macro clgi 0
89         db      00fh, 001h, 0ddh
90 %endmacro
91
92 ;VMRUN  equ db 0Fh, 01h, D8h
93 ;VMLOAD equ db 0x0F,0x01,0xDA
94 ;VMSAVE equ db 0x0F,0x01,0xDB
95 ;STGI   equ db 0x0F,0x01,0xDC
96 ;CLGI   equ db 0x0F,0x01,0xDD
97
98
99 align 8
100 DisableInts:
101         cli
102         ret
103
104 align 8
105 EnableInts:
106         sti
107         ret
108
109
110 align 8
111 CLGI:
112         clgi
113         ret
114
115 align 8
116 STGI:
117         stgi
118         ret
119
120
121
122 ; I think its safe to say that there are some pretty serious register issues...
123 align 8
124 launch_svm:
125         push    ebp
126         mov     ebp, esp
127         pusha
128         
129         mov     eax, [ebp + 8]
130         vmrun
131 ;       db      00fh, 001h, 0d8h
132         popa
133         pop     ebp
134         ret
135
136
137
138
139 exit_test: 
140         mov     cr4, eax
141         ret
142
143
144 ;; Need to check this..
145 ;; save_svm_launch(rax, struct guest_gprs * regs)
146 align 8
147 safe_svm_launch:
148         push    ebp
149         mov     ebp, esp
150         pushf
151         push    fs
152         push    gs
153         pusha                                   ;; Save Host state
154
155
156         push    dword [ebp + 12]                ;; pointer to the guest GPR save area
157         push    dword [ebp + 8]                 ;; pointer to the VMCB pointer
158
159 ;;      mov     eax, [esp + 4]                  ;; mov guest GPR pointer to eax
160
161         ;; this is plus 8 because we push eax in the macro
162         Restore_SVM_Registers [esp + 8]         ;; Restore Guest GPR state
163         pop     eax                             ;; pop VMCB pointer into eax
164
165         vmload
166         vmrun
167         vmsave
168
169 ;;      pop     eax                             ;; pop Guest GPR pointer into eax
170         ;; this is plus 4 because we push eax in the macro NEED TO CHANGE
171         Save_SVM_Registers  [esp+4]             ;; save guest GPRs
172         
173         add     esp, 4                          ;; skip past the gpr ptr
174         
175         popa                                    ;; Restore Host state
176         pop     gs
177         pop     fs
178         popf
179         pop     ebp
180         ret
181
182
183
184 %endif
185
186