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.


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