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.


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