VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/TRPMR0A.asm@ 1995

Last change on this file since 1995 was 1570, checked in by vboxsync, 18 years ago

pushfq, not pushfd. (hope the old yasm doesn't mind...)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1; $Id: TRPMR0A.asm 1570 2007-03-20 04:45:47Z vboxsync $
2;; @file
3; TRPM - Host Context Ring-0
4;
5
6;
7; Copyright (C) 2006 InnoTek Systemberatung GmbH
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License as published by the Free Software Foundation,
13; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14; distribution. VirtualBox OSE is distributed in the hope that it will
15; be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; If you received this file as part of a commercial VirtualBox
18; distribution, then only the terms of your commercial VirtualBox
19; license agreement apply instead of the previous paragraph.
20;
21
22;*******************************************************************************
23;* Header Files *
24;*******************************************************************************
25%include "VBox/asmdefs.mac"
26%include "VBox/x86.mac"
27
28
29BEGINCODE
30 align 16
31
32;;
33; Calls the interrupt gate as if we received an interrupt while in Ring-0.
34;
35; @param uIP x86:[ebp+8] msc:rcx gcc:rdi The interrupt gate IP.
36; @param SelCS x86:[ebp+12] msc:dx gcc:si The interrupt gate CS.
37; @param RSP msc:r8 gcc:rdx The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
38;DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
39BEGINPROC trpmR0DispatchHostInterrupt
40 push xBP
41 mov xBP, xSP
42
43%ifdef __AMD64__
44 mov r11, rsp ; save the RSP for the iret frame.
45 and rsp, 0fffffffffffffff0h ; align the stack. (do it unconditionally saves some jump mess)
46
47 ; switch stack?
48 %ifdef ASM_CALL64_MSC
49 cmp r8, 0ffffffffffffffffh
50 je .no_stack_switch
51 mov rsp, r8
52 %else
53 cmp rdx, 0ffffffffffffffffh
54 je .no_stack_switch
55 mov rsp, rdx
56 %endif
57.no_stack_switch:
58
59 ; create the iret frame
60 push 0 ; SS
61 push r11 ; RSP
62 pushfq ; RFLAGS
63 and dword [rsp], ~X86_EFL_IF
64 mov ax, cs
65 push rax ; CS
66 lea r10, [.return wrt rip] ; RIP
67 push r10
68
69 ; create the retf frame
70 %ifdef ASM_CALL64_MSC
71 movzx rdx, dx
72 cmp rdx, r11
73 je .dir_jump
74 push rdx
75 push rcx
76 %else
77 movzx rsi, si
78 cmp rsi, r11
79 je .dir_jump
80 push rsi
81 push rdi
82 %endif
83
84 ; dispatch it
85 db 048h
86 retf
87
88 ; dispatch it by a jmp (don't mess up the IST stack)
89.dir_jump:
90 %ifdef ASM_CALL64_MSC
91 jmp rcx
92 %else
93 jmp rdi
94 %endif
95
96%else ; 32-bit:
97 mov ecx, [ebp + 8] ; uIP
98 movzx edx, word [ebp + 12] ; SelCS
99
100 ; create the iret frame
101 pushfd ; EFLAGS
102 and dword [esp], ~X86_EFL_IF
103 push cs ; CS
104 push .return ; EIP
105
106 ; create the retf frame
107 push edx
108 push ecx
109
110 ; dispatch it!
111 retf
112%endif
113.return:
114 cli
115
116 leave
117 ret
118ENDPROC trpmR0DispatchHostInterrupt
119
120
121%ifndef VBOX_WITHOUT_IDT_PATCHING
122
123 align 16
124;;
125; This is the alternative return from VMMR0Entry() used when
126; we need to dispatch an interrupt to the Host (we received it in GC).
127;
128; As seen in TRPMR0SetupInterruptDispatcherFrame() the stack is different
129; than for the normal VMMR0Entry() return.
130;
131; 32-bit:
132; 18 iret frame
133; 14 retf selector (interrupt handler)
134; 10 retf offset (interrupt handler)
135; c es
136; 8 fs
137; 4 ds
138; 0 pVM (esp here)
139;
140; 64-bit:
141; 24 iret frame
142; 18 retf selector (interrupt handler)
143; 10 retf offset (interrupt handler)
144; 8 uOperation
145; 0 pVM (rsp here)
146;
147BEGINPROC trpmR0InterruptDispatcher
148%ifdef __AMD64__
149 lea rsp, [rsp + 10h] ; skip pVM and uOperation
150 swapgs
151 db 48h
152 retf
153%else ; !__AMD64__
154 add esp, byte 4 ; skip pVM
155 pop ds
156 pop fs
157 pop es
158 retf
159%endif ; !__AMD64__
160ENDPROC trpmR0InterruptDispatcher
161
162%endif ; !VBOX_WITHOUT_IDT_PATCHING
163
164
165;;
166; Issues a software interrupt to the specified interrupt vector.
167;
168; @param uActiveVector x86:[esp+4] msc:rcx gcc:rdi The vector number.
169;
170;DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
171BEGINPROC trpmR0DispatchHostInterruptSimple
172%ifdef __X86__
173 mov eax, [esp + 4]
174 jmp dword [.jmp_table + eax * 4]
175%else
176 lea r9, [.jmp_table wrt rip]
177 %ifdef ASM_CALL64_MSC
178 jmp qword [r9 + rcx * 8]
179 %else
180 jmp qword [r9 + rdi * 8]
181 %endif
182%endif
183
184.jmp_table:
185%assign i 0
186%rep 256
187RTCCPTR_DEF .int_ %+ i
188%assign i i+1
189%endrep
190
191%assign i 0
192%rep 256
193 ALIGNCODE(4)
194.int_ %+ i:
195 int i
196 ret
197%assign i i+1
198%endrep
199
200ENDPROC trpmR0DispatchHostInterruptSimple
201
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette