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.


added full io support
[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 SVM_ERROR equ 0xFFFFFFFF
11 SVM_SUCCESS equ 0x00000000
12
13 EXPORT DisableInts
14
15 EXPORT GetGDTR
16 EXPORT GetIDTR
17 EXPORT GetTR
18
19 EXPORT exit_test
20
21 EXTERN handle_svm_exit
22
23 EXPORT launch_svm
24 EXPORT safe_svm_launch
25
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 ;VMRUN  equ db 0Fh, 01h, D8h
85 ;VMLOAD equ db 0x0F,0x01,0xDA
86 ;VMSAVE equ db 0x0F,0x01,0xDB
87 ;STGI   equ db 0x0F,0x01,0xDC
88 ;CLGI   equ db 0x0F,0x01,0xDD
89
90
91 align 8
92 DisableInts:
93         cli
94         ret
95
96
97 align 8
98 GetGDTR:
99         push    ebp
100         mov     ebp, esp
101         pusha   
102         mov     ebx, [ebp + 8]
103         sgdt    [ebx]
104         
105         popa
106         pop     ebp
107         ret
108
109
110 align 8
111 GetIDTR:
112         push    ebp
113         mov     ebp, esp
114         pusha   
115
116         mov     ebx, [ebp + 8]
117         sidt    [ebx]
118         
119         popa
120         pop     ebp
121         ret
122
123
124
125 align 8
126 GetTR:
127         push    ebp
128         mov     ebp, esp
129         pusha   
130         mov     ebx, [ebp + 8]
131         str     [ebx]
132         
133         popa
134         pop     ebp
135         ret
136
137
138
139 ; I think its safe to say that there are some pretty serious register issues...
140 align 8
141 launch_svm:
142         push    ebp
143         mov     ebp, esp
144         pusha
145         
146         mov     eax, [ebp + 8]
147         vmrun
148 ;       db      00fh, 001h, 0d8h
149         popa
150         pop     ebp
151         ret
152
153
154
155
156 exit_test: 
157         mov     cr4, eax
158         ret
159
160
161 ;; Need to check this..
162 ;; save_svm_launch(rax, struct guest_gprs * regs)
163 align 8
164 safe_svm_launch:
165         push    ebp
166         mov     ebp, esp
167         pushf
168         pusha                                   ;; Save Host state
169
170
171         push    dword [ebp + 12]                ;; pointer to the guest GPR save area
172         push    dword [ebp + 8]                 ;; pointer to the VMCB pointer
173
174 ;;      mov     eax, [esp + 4]                  ;; mov guest GPR pointer to eax
175
176         ;; this is plus 8 because we push eax in the macro
177         Restore_SVM_Registers [esp + 8]         ;; Restore Guest GPR state
178         pop     eax                             ;; pop VMCB pointer into eax
179
180         vmload
181         vmrun
182         vmsave
183
184 ;;      pop     eax                             ;; pop Guest GPR pointer into eax
185         ;; this is plus 4 because we push eax in the macro NEED TO CHANGE
186         Save_SVM_Registers  [esp+4]             ;; save guest GPRs
187         
188         add     esp, 4                          ;; skip past the gpr ptr
189         
190         popa                                    ;; Restore Host state
191         popf
192         pop     ebp
193         ret
194
195
196
197 %endif
198
199