~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/arch/x86/hvm/svm/entry.S

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * entry.S: SVM architecture-specific entry/exit handling.
 
3
 * Copyright (c) 2005-2007, Advanced Micro Devices, Inc.
 
4
 * Copyright (c) 2004, Intel Corporation.
 
5
 * Copyright (c) 2008, Citrix Systems, Inc.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify it
 
8
 * under the terms and conditions of the GNU General Public License,
 
9
 * version 2, as published by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
 * more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along with
 
17
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
18
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 
19
 */
 
20
 
 
21
#include <xen/config.h>
 
22
#include <xen/errno.h>
 
23
#include <xen/softirq.h>
 
24
#include <asm/types.h>
 
25
#include <asm/asm_defns.h>
 
26
#include <asm/apicdef.h>
 
27
#include <asm/page.h>
 
28
#include <public/xen.h>
 
29
 
 
30
#define VMRUN  .byte 0x0F,0x01,0xD8
 
31
#define STGI   .byte 0x0F,0x01,0xDC
 
32
#define CLGI   .byte 0x0F,0x01,0xDD
 
33
 
 
34
#define get_current(reg)                        \
 
35
        mov $STACK_SIZE-BYTES_PER_LONG, r(reg); \
 
36
        or  r(sp), r(reg);                      \
 
37
        and $~(BYTES_PER_LONG-1),r(reg);        \
 
38
        mov (r(reg)),r(reg);
 
39
 
 
40
#if defined(__x86_64__)
 
41
#define r(reg) %r##reg
 
42
#define addr_of(lbl) lbl(%rip)
 
43
#define call_with_regs(fn)                      \
 
44
        mov  %rsp,%rdi;                         \
 
45
        call fn;
 
46
#else /* defined(__i386__) */
 
47
#define r(reg) %e##reg
 
48
#define addr_of(lbl) lbl
 
49
#define UREGS_rax UREGS_eax
 
50
#define UREGS_rip UREGS_eip
 
51
#define UREGS_rsp UREGS_esp
 
52
#define call_with_regs(fn)                      \
 
53
        mov  %esp,%eax;                         \
 
54
        push %eax;                              \
 
55
        call fn;                                \
 
56
        add  $4,%esp;
 
57
#endif
 
58
 
 
59
ENTRY(svm_asm_do_resume)
 
60
        call svm_intr_assist
 
61
 
 
62
        get_current(bx)
 
63
        CLGI
 
64
 
 
65
        mov  VCPU_processor(r(bx)),%eax
 
66
        shl  $IRQSTAT_shift,r(ax)
 
67
        lea  addr_of(irq_stat),r(dx)
 
68
        testl $~0,(r(dx),r(ax),1)
 
69
        jnz  .Lsvm_process_softirqs
 
70
 
 
71
        call svm_asid_handle_vmrun
 
72
 
 
73
        cmpb $0,addr_of(tb_init_done)
 
74
        jnz  .Lsvm_trace
 
75
.Lsvm_trace_done:
 
76
 
 
77
        mov  VCPU_svm_vmcb(r(bx)),r(cx)
 
78
        mov  UREGS_rax(r(sp)),r(ax)
 
79
        mov  r(ax),VMCB_rax(r(cx))
 
80
        mov  UREGS_rip(r(sp)),r(ax)
 
81
        mov  r(ax),VMCB_rip(r(cx))
 
82
        mov  UREGS_rsp(r(sp)),r(ax)
 
83
        mov  r(ax),VMCB_rsp(r(cx))
 
84
        mov  UREGS_eflags(r(sp)),r(ax)
 
85
        mov  r(ax),VMCB_rflags(r(cx))
 
86
 
 
87
        mov  VCPU_svm_vmcb_pa(r(bx)),r(ax)
 
88
 
 
89
#if defined(__x86_64__)
 
90
        pop  %r15
 
91
        pop  %r14
 
92
        pop  %r13
 
93
        pop  %r12
 
94
        pop  %rbp
 
95
        pop  %rbx
 
96
        pop  %r11
 
97
        pop  %r10
 
98
        pop  %r9
 
99
        pop  %r8
 
100
        add  $8,%rsp /* Skip %rax: restored by VMRUN. */
 
101
        pop  %rcx
 
102
        pop  %rdx
 
103
        pop  %rsi
 
104
        pop  %rdi
 
105
#else /* defined(__i386__) */
 
106
        pop  %ebx
 
107
        pop  %ecx
 
108
        pop  %edx
 
109
        pop  %esi
 
110
        pop  %edi
 
111
        pop  %ebp
 
112
#endif
 
113
 
 
114
        VMRUN
 
115
 
 
116
#if defined(__x86_64__)
 
117
        push %rdi
 
118
        push %rsi
 
119
        push %rdx
 
120
        push %rcx
 
121
        push %rax
 
122
        push %r8
 
123
        push %r9
 
124
        push %r10
 
125
        push %r11
 
126
        push %rbx
 
127
        push %rbp
 
128
        push %r12
 
129
        push %r13
 
130
        push %r14
 
131
        push %r15
 
132
#else /* defined(__i386__) */
 
133
        push %ebp
 
134
        push %edi
 
135
        push %esi
 
136
        push %edx
 
137
        push %ecx
 
138
        push %ebx
 
139
#endif
 
140
 
 
141
        get_current(bx)
 
142
        movb $0,VCPU_svm_vmcb_in_sync(r(bx))
 
143
        mov  VCPU_svm_vmcb(r(bx)),r(cx)
 
144
        mov  VMCB_rax(r(cx)),r(ax)
 
145
        mov  r(ax),UREGS_rax(r(sp))
 
146
        mov  VMCB_rip(r(cx)),r(ax)
 
147
        mov  r(ax),UREGS_rip(r(sp))
 
148
        mov  VMCB_rsp(r(cx)),r(ax)
 
149
        mov  r(ax),UREGS_rsp(r(sp))
 
150
        mov  VMCB_rflags(r(cx)),r(ax)
 
151
        mov  r(ax),UREGS_eflags(r(sp))
 
152
 
 
153
#ifndef NDEBUG
 
154
        mov  $0xbeef,%ax
 
155
        mov  %ax,UREGS_error_code(r(sp))
 
156
        mov  %ax,UREGS_entry_vector(r(sp))
 
157
        mov  %ax,UREGS_saved_upcall_mask(r(sp))
 
158
        mov  %ax,UREGS_cs(r(sp))
 
159
        mov  %ax,UREGS_ds(r(sp))
 
160
        mov  %ax,UREGS_es(r(sp))
 
161
        mov  %ax,UREGS_fs(r(sp))
 
162
        mov  %ax,UREGS_gs(r(sp))
 
163
        mov  %ax,UREGS_ss(r(sp))
 
164
#endif
 
165
 
 
166
        STGI
 
167
.globl svm_stgi_label
 
168
svm_stgi_label:
 
169
        call_with_regs(svm_vmexit_handler)
 
170
        jmp  svm_asm_do_resume
 
171
 
 
172
.Lsvm_process_softirqs:
 
173
        STGI
 
174
        call do_softirq
 
175
        jmp  svm_asm_do_resume
 
176
 
 
177
.Lsvm_trace:
 
178
        call svm_trace_vmentry
 
179
        jmp  .Lsvm_trace_done