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.


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