1 | ; $Id: IEMAllN8veHlpA.asm 103376 2024-02-15 01:09:23Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IEM - Native Recompiler Assembly Helpers.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2023 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | ;
|
---|
27 |
|
---|
28 | ;*********************************************************************************************************************************
|
---|
29 | ;* Header Files *
|
---|
30 | ;*********************************************************************************************************************************
|
---|
31 | %define RT_ASM_WITH_SEH64
|
---|
32 | %include "VBox/asmdefs.mac"
|
---|
33 |
|
---|
34 |
|
---|
35 | BEGINCODE
|
---|
36 |
|
---|
37 | extern NAME(iemThreadedFunc_BltIn_LogCpuStateWorker)
|
---|
38 | extern NAME(iemNativeHlpCheckTlbLookup)
|
---|
39 |
|
---|
40 |
|
---|
41 | ;;
|
---|
42 | ; This does the epilogue of a TB, given the RBP for the frame and eax value to return.
|
---|
43 | ;
|
---|
44 | ; @param pFrame (gcc:rdi, msc:rcx) The frame pointer.
|
---|
45 | ; @param rc (gcc:esi, msc:edx) The return value.
|
---|
46 | ;
|
---|
47 | ; @note This doesn't really work for MSC since xmm6 thru xmm15 are non-volatile
|
---|
48 | ; and since we don't save them in the TB prolog we'll potentially return
|
---|
49 | ; with different values if any functions on the calling stack uses them
|
---|
50 | ; as they're unlikely to restore them till they return.
|
---|
51 | ;
|
---|
52 | ; For the GCC calling convention all xmm registers are volatile and the
|
---|
53 | ; only worry would be someone fiddling the control bits of MXCSR or FCW
|
---|
54 | ; without restoring them. This is highly unlikely, unless we're doing
|
---|
55 | ; it ourselves, I think.
|
---|
56 | ;
|
---|
57 | BEGINPROC iemNativeTbLongJmp
|
---|
58 | %ifdef ASM_CALL64_MSC
|
---|
59 | mov rbp, rcx
|
---|
60 | mov eax, edx
|
---|
61 | %else
|
---|
62 | mov rbp, rdi
|
---|
63 | mov eax, esi
|
---|
64 | %endif
|
---|
65 | SEH64_PUSH_xBP ; non-sense, but whatever.
|
---|
66 | SEH64_END_PROLOGUE
|
---|
67 |
|
---|
68 | ;
|
---|
69 | ; This must exactly match what iemNativeEmitEpilog does.
|
---|
70 | ;
|
---|
71 | %ifdef ASM_CALL64_MSC
|
---|
72 | lea rsp, [rbp - 5 * 8]
|
---|
73 | %else
|
---|
74 | lea rsp, [rbp - 7 * 8]
|
---|
75 | %endif
|
---|
76 | pop r15
|
---|
77 | pop r14
|
---|
78 | pop r13
|
---|
79 | pop r12
|
---|
80 | %ifdef ASM_CALL64_MSC
|
---|
81 | pop rdi
|
---|
82 | pop rsi
|
---|
83 | %endif
|
---|
84 | pop rbx
|
---|
85 | leave
|
---|
86 | ret
|
---|
87 | ENDPROC iemNativeTbLongJmp
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | ;;
|
---|
92 | ; This is wrapper function that saves and restores all volatile registers
|
---|
93 | ; so the impact of inserting LogCpuState is minimal to the other TB code.
|
---|
94 | ;
|
---|
95 | BEGINPROC iemNativeHlpAsmSafeWrapLogCpuState
|
---|
96 | push xBP
|
---|
97 | SEH64_PUSH_xBP
|
---|
98 | mov xBP, xSP
|
---|
99 | SEH64_SET_FRAME_xBP 0
|
---|
100 | SEH64_END_PROLOGUE
|
---|
101 |
|
---|
102 | ;
|
---|
103 | ; Save all volatile registers.
|
---|
104 | ;
|
---|
105 | push xAX
|
---|
106 | push xCX
|
---|
107 | push xDX
|
---|
108 | %ifdef RT_OS_WINDOWS
|
---|
109 | push xSI
|
---|
110 | push xDI
|
---|
111 | %endif
|
---|
112 | push r8
|
---|
113 | push r9
|
---|
114 | push r10
|
---|
115 | push r11
|
---|
116 | sub rsp, 8+20h
|
---|
117 |
|
---|
118 | ;
|
---|
119 | ; Call C function to do the actual work.
|
---|
120 | ;
|
---|
121 | %ifdef RT_OS_WINDOWS
|
---|
122 | mov rcx, rbx ; IEMNATIVE_REG_FIXED_PVMCPU
|
---|
123 | mov rdx, [rbp + 10h] ; Just in case we decide to put something there.
|
---|
124 | xor r8, r8
|
---|
125 | xor r9, r9
|
---|
126 | %else
|
---|
127 | mov rdi, rbx ; IEMNATIVE_REG_FIXED_PVMCPU
|
---|
128 | mov rsi, [rbp + 10h] ; Just in case we decide to put something there.
|
---|
129 | xor ecx, ecx
|
---|
130 | xor edx, edx
|
---|
131 | %endif
|
---|
132 | call NAME(iemThreadedFunc_BltIn_LogCpuStateWorker)
|
---|
133 |
|
---|
134 | ;
|
---|
135 | ; Restore volatile registers and return to the TB code.
|
---|
136 | ;
|
---|
137 | add rsp, 8+20h
|
---|
138 | pop r11
|
---|
139 | pop r10
|
---|
140 | pop r9
|
---|
141 | pop r8
|
---|
142 | %ifdef RT_OS_WINDOWS
|
---|
143 | pop xDI
|
---|
144 | pop xSI
|
---|
145 | %endif
|
---|
146 | pop xDX
|
---|
147 | pop xCX
|
---|
148 | pop xAX
|
---|
149 | leave
|
---|
150 | ret
|
---|
151 | ENDPROC iemNativeHlpAsmSafeWrapLogCpuState
|
---|
152 |
|
---|
153 |
|
---|
154 | ;;
|
---|
155 | ; This is wrapper function that saves and restores all volatile registers
|
---|
156 | ; so the impact of inserting CheckTlbLookup is minimal to the other TB code.
|
---|
157 | ;
|
---|
158 | BEGINPROC iemNativeHlpAsmSafeWrapCheckTlbLookup
|
---|
159 | push xBP
|
---|
160 | SEH64_PUSH_xBP
|
---|
161 | mov xBP, xSP
|
---|
162 | SEH64_SET_FRAME_xBP 0
|
---|
163 | SEH64_END_PROLOGUE
|
---|
164 |
|
---|
165 | ;
|
---|
166 | ; Save all volatile registers.
|
---|
167 | ;
|
---|
168 | push xAX
|
---|
169 | push xCX
|
---|
170 | push xDX
|
---|
171 | %ifdef RT_OS_WINDOWS
|
---|
172 | push xSI
|
---|
173 | push xDI
|
---|
174 | %endif
|
---|
175 | push r8
|
---|
176 | push r9
|
---|
177 | push r10
|
---|
178 | push r11
|
---|
179 | sub rsp, 8+20h
|
---|
180 |
|
---|
181 | ;
|
---|
182 | ; Call C function to do the actual work.
|
---|
183 | ;
|
---|
184 | %ifdef RT_OS_WINDOWS
|
---|
185 | mov rcx, [rbp + 10h]
|
---|
186 | mov rdx, [rbp + 18h]
|
---|
187 | mov r8, [rbp + 20h]
|
---|
188 | mov r9, [rbp + 28h]
|
---|
189 | %else
|
---|
190 | mov rdi, [rbp + 10h]
|
---|
191 | mov rsi, [rbp + 18h]
|
---|
192 | mov ecx, [rbp + 20h]
|
---|
193 | mov edx, [rbp + 28h]
|
---|
194 | %endif
|
---|
195 | call NAME(iemNativeHlpCheckTlbLookup)
|
---|
196 |
|
---|
197 | ;
|
---|
198 | ; Restore volatile registers and return to the TB code.
|
---|
199 | ;
|
---|
200 | add rsp, 8+20h
|
---|
201 | pop r11
|
---|
202 | pop r10
|
---|
203 | pop r9
|
---|
204 | pop r8
|
---|
205 | %ifdef RT_OS_WINDOWS
|
---|
206 | pop xDI
|
---|
207 | pop xSI
|
---|
208 | %endif
|
---|
209 | pop xDX
|
---|
210 | pop xCX
|
---|
211 | pop xAX
|
---|
212 | leave
|
---|
213 | ret 20h
|
---|
214 | ENDPROC iemNativeHlpAsmSafeWrapCheckTlbLookup
|
---|
215 |
|
---|