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.


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