VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/Instructions/env-common.mac@ 100725

Last change on this file since 100725 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1; $Id: env-common.mac 98103 2023-01-17 14:15:46Z vboxsync $
2;; @file
3; Instruction Test Environment - Common Bits.
4;
5
6;
7; Copyright (C) 2006-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%ifndef ___env_common_mac
29%define ___env_common_mac
30
31%include "iprt/x86.mac"
32
33;*******************************************************************************
34;* Defined Constants And Macros *
35;*******************************************************************************
36%ifdef RT_ARCH_AMD64
37 %define MY_PUSH_FLAGS pushfq
38 %define MY_POP_FLAGS popfq
39 %define MY_PUSH_FLAGS_SIZE 8
40
41 %macro MY_PUSH_ALL 0
42 push rbp
43 mov rbp, rsp
44 push rax
45 push rbx
46 push rcx
47 push rdx
48 push rsi
49 push rdi
50 push r8
51 push r9
52 push r10
53 push r11
54 push r12
55 push r13
56 push r14
57 push r15
58 pushfq
59 %endm
60 %macro MY_POP_ALL 0
61 popfq
62 pop r15
63 pop r14
64 pop r13
65 pop r12
66 pop r11
67 pop r10
68 pop r9
69 pop r8
70 pop rdi
71 pop rsi
72 pop rdx
73 pop rcx
74 pop rbx
75 pop rax
76 pop rbp
77 %endm
78
79%else
80 %define MY_PUSH_FLAGS pushfd
81 %define MY_POP_FLAGS popfd
82 %define MY_PUSH_FLAGS_SIZE 4
83
84 %macro MY_PUSH_ALL 0
85 push eBP
86 mov xBP, xSP
87 push eax
88 push ebx
89 push ecx
90 push edx
91 push esi
92 push edi
93 pushfd
94 %endm
95 %macro MY_POP_ALL 0
96 popfd
97 pop edi
98 pop esi
99 pop edx
100 pop ecx
101 pop ebx
102 pop eax
103 pop ebp
104 %endm
105%endif
106
107
108
109;*******************************************************************************
110;* Internal Functions *
111;*******************************************************************************
112
113VBINSTST_BEGINCODE
114
115;;
116; Report bad register value.
117;
118; Primary purpose is save all registers and convert from our stack-based to
119; the correct calling convention for the environment.
120;
121; This function will clean up the stack upon return (to save space in the caller).
122;
123; @param uExpected
124; @param uActual
125; @param uRegisterNo
126;
127VBINSTST_BEGINPROC Common_BadValue
128 MY_PUSH_ALL
129 mov xAX, xSP ; 16-byte align the stack and reserve space for arguments and stuff.
130 sub xSP, 40h
131 and xSP, ~15
132 mov [xSP + 38h], xAX
133
134%ifdef ASM_CALL64_GCC
135 mov r8d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
136 mov rcx, [rbp + 10h] ; expected
137 mov rdx, [rbp + 18h] ; actual
138 mov rsi, [rbp + 20h] ; reg#
139 lea rdi, [.szFmt wrt rip]
140 VBINSTST_CALL_FN_FAILURE_4
141
142%elifdef ASM_CALL64_MSC
143 mov r10d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
144 mov [rsp + 20h], r10
145 mov r9, [rbp + 10h] ; expected
146 mov r8, [rbp + 18h] ; actual
147 mov rdx, [rbp + 20h] ; reg#
148 lea rcx, [.szFmt wrt rip]
149 VBINSTST_CALL_FN_FAILURE_4
150
151%elifdef ASM_CALL64_BS2
152 mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) xWrtRIP]
153 mov sCX, [xBP + xCB + xCB] ; expected
154 mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
155 mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
156 lea sSI, [.szFmt xWrtRIP]
157 mov qword [xSP + xCB + 3*sCB], sBX
158 mov qword [xSP + xCB + 2*sCB], sCX
159 mov qword [xSP + xCB + 1*sCB], sAX
160 mov qword [xSP + xCB], sDX
161 mov [xSP], sSI
162 VBINSTST_CALL_FN_FAILURE_4
163
164%else
165 mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator)]
166 mov sCX, [xBP + xCB + xCB] ; expected
167 mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
168 mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
169 mov [xSP + xCB + 3*sCB], sBX
170 mov [xSP + xCB + 2*sCB], sCX
171 mov [xSP + xCB + 1*sCB], sAX
172 mov [xSP + xCB], sDX
173 mov [xSP], RTCCPTR_PRE .szFmt
174 VBINSTST_CALL_FN_FAILURE_4
175%endif
176
177 mov xSP, [xSP + 38h]
178 MY_POP_ALL
179 ret 3*sCB
180%if ARCH_BITS == 64
181.szFmt: db 'Bad register 0x%RX32 value 0x%RX64, expected 0x%RX64 (line %RU64)', 13, 0
182%else
183.szFmt: db 'Bad register 0x%RX32 value 0x%RX32, expected 0x%RX32 (line %RU32)', 13, 0
184%endif
185VBINSTST_ENDPROC Common_BadValue
186
187
188%ifdef VBINSTST_CAN_DO_TRAPS
189
190;;
191; Report a missing TRAP.
192;
193; Primary purpose is save all registers and convert from our stack-based to
194; the correct calling convention for the environment.
195;
196; This function will clean up the stack upon return (to save space in the caller).
197;
198; @param uExpected
199;
200VBINSTST_BEGINPROC Common_MissingTrap
201 MY_PUSH_ALL
202 mov xAX, xSP ; 16-byte align the stack and reserve space for arguments and stuff.
203 sub xSP, 40h
204 and xSP, ~15
205 mov [xSP + 38h], xAX
206
207 %ifdef ASM_CALL64_GCC
208 mov rdx, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
209 movzx rsi, byte [rbp + 10h] ; expected
210 lea rdi, [.szFmt wrt rip]
211 VBINSTST_CALL_FN_FAILURE_2
212
213 %elifdef ASM_CALL64_MSC
214 mov r8d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
215 movzx rdx, byte [rbp + 10h] ; expected
216 lea rcx, [.szFmt wrt rip]
217 VBINSTST_CALL_FN_FAILURE_2
218
219 %elifdef ASM_CALL64_BS2
220 mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) xWrtRIP]
221 mov sDX, [xBP + xCB + xCB] ; expected
222 lea sSI, [.szFmt xWrtRIP]
223 mov qword [xSP + xCB + 1*sCB], sBX
224 mov qword [xSP + xCB], sDX
225 mov [xSP], sSI
226 VBINSTST_CALL_FN_FAILURE_2
227
228 %else
229 mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator)]
230 mov sDX, [xBP + xCB + xCB] ; expected
231 mov [xSP + xCB + 1*sCB], sBX
232 mov [xSP + xCB], sDX
233 mov [xSP], RTCCPTR_PRE .szFmt
234 VBINSTST_CALL_FN_FAILURE_2
235 %endif
236
237 mov xSP, [xSP + 38h]
238 MY_POP_ALL
239 ret 1*sCB
240 %if ARCH_BITS == 64
241.szFmt: db 'Missing trap %RX8 (line %RU64)', 13, 0
242 %else
243.szFmt: db 'Missing trap %RX8 (line %RU32)', 13, 0
244 %endif
245VBINSTST_ENDPROC Common_MissingTrap
246
247 %macro Common_MissingTrapTemplate 1
248 VBINSTST_BEGINPROC Common_MissingTrap_%1
249 push %1
250 call VBINSTST_NAME(Common_MissingTrap)
251 ret
252 VBINSTST_ENDPROC Common_MissingTrap_%1
253 %endmacro
254 Common_MissingTrapTemplate X86_XCPT_DE
255 Common_MissingTrapTemplate X86_XCPT_DB
256 Common_MissingTrapTemplate X86_XCPT_NMI
257 Common_MissingTrapTemplate X86_XCPT_BP
258 Common_MissingTrapTemplate X86_XCPT_OF
259 Common_MissingTrapTemplate X86_XCPT_BR
260 Common_MissingTrapTemplate X86_XCPT_UD
261 Common_MissingTrapTemplate X86_XCPT_NM
262 ;Common_MissingTrapTemplate X86_XCPT_DF
263 ;Common_MissingTrapTemplate X86_XCPT_CO_SEG_OVERRUN
264 Common_MissingTrapTemplate X86_XCPT_TS
265 Common_MissingTrapTemplate X86_XCPT_NP
266 Common_MissingTrapTemplate X86_XCPT_SS
267 Common_MissingTrapTemplate X86_XCPT_GP
268 Common_MissingTrapTemplate X86_XCPT_PF
269 Common_MissingTrapTemplate X86_XCPT_MF
270 Common_MissingTrapTemplate X86_XCPT_AC
271 ;Common_MissingTrapTemplate X86_XCPT_MC
272 Common_MissingTrapTemplate X86_XCPT_XF
273
274%endif ; VBINSTST_CAN_DO_TRAPS
275
276
277;
278; Global data variables used by Common_SetupMemReadUxx.
279; For address calculation reasons, these must be qword aligned.
280;
281VBINSTST_BEGINDATA
282 align 64
283 dd 09d8af498h, 09ab3e5f8h
284VBINSTST_GLOBALNAME_EX g_u64Data, data hidden
285 dq 0
286 dd 07d7af797h, 096b36562h
287VBINSTST_GLOBALNAME_EX g_u32Data, data hidden
288 dd 0
289 dd 012305987h
290VBINSTST_GLOBALNAME_EX g_u16Data, data hidden
291 dw 0
292 dw 05865h
293 dw 03863h
294 dw 02679h
295VBINSTST_GLOBALNAME_EX g_u8Data, data hidden
296 db 0
297 db 90h
298 dw 0865ah
299 dd 058daffe2h
300
301VBINSTST_BEGINCODE
302
303;;
304; Sets up g_u8Data.
305; @param uValue
306VBINSTST_BEGINPROC Common_SetupMemReadU8
307 push sAX
308 mov ax, [xSP + sCB + xCB]
309 mov [VBINSTST_NAME(g_u8Data) xWrtRIP], ax
310 pop sAX
311 ret sCB
312VBINSTST_ENDPROC Common_SetupMemReadU8
313
314;;
315; Sets up g_u16Data.
316; @param uValue
317VBINSTST_BEGINPROC Common_SetupMemReadU16
318 push sAX
319 mov ax, [xSP + sCB + xCB]
320 mov [VBINSTST_NAME(g_u16Data) xWrtRIP], ax
321 pop sAX
322 ret sCB
323VBINSTST_ENDPROC Common_SetupMemReadU16
324
325;;
326; Sets up g_u32Data.
327; @param uValue
328VBINSTST_BEGINPROC Common_SetupMemReadU32
329 push sAX
330 mov eax, [xSP + sCB + xCB]
331 mov [VBINSTST_NAME(g_u32Data) xWrtRIP], eax
332 pop sAX
333 ret sCB
334VBINSTST_ENDPROC Common_SetupMemReadU32
335
336;;
337; Sets up g_u64Data.
338; @param uValue
339VBINSTST_BEGINPROC Common_SetupMemReadU64
340 push sAX
341%ifdef RT_ARCH_AMD64
342 mov rax, [xSP + sCB + xCB]
343 mov [VBINSTST_NAME(g_u64Data) xWrtRIP], rax
344%else
345 mov eax, [xSP + sCB + xCB]
346 mov [VBINSTST_NAME(g_u64Data) xWrtRIP], eax
347 mov eax, [xSP + sCB + xCB + 4]
348 mov [VBINSTST_NAME(g_u64Data) + 4 xWrtRIP], eax
349%endif
350 pop sAX
351 ret sCB
352VBINSTST_ENDPROC Common_SetupMemReadU64
353
354
355%endif
356
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