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