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.


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