1 | ; $Id: env-common.mac 46954 2013-07-03 21:11:02Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Instruction Test Environment - Common Bits.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2013 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 |
|
---|
18 | %ifndef ___env_common_mac
|
---|
19 | %define ___env_common_mac
|
---|
20 |
|
---|
21 |
|
---|
22 | ;*******************************************************************************
|
---|
23 | ;* Defined Constants And Macros *
|
---|
24 | ;*******************************************************************************
|
---|
25 | %ifdef RT_ARCH_AMD64
|
---|
26 | %define MY_PUSH_FLAGS pushfq
|
---|
27 | %define MY_POP_FLAGS popfq
|
---|
28 | %define MY_PUSH_FLAGS_SIZE 8
|
---|
29 |
|
---|
30 | %macro MY_PUSH_ALL 0
|
---|
31 | push rbp
|
---|
32 | mov rbp, rsp
|
---|
33 | push rax
|
---|
34 | push rbx
|
---|
35 | push rcx
|
---|
36 | push rdx
|
---|
37 | push rsi
|
---|
38 | push rdi
|
---|
39 | push r8
|
---|
40 | push r9
|
---|
41 | push r10
|
---|
42 | push r11
|
---|
43 | push r12
|
---|
44 | push r13
|
---|
45 | push r14
|
---|
46 | push r15
|
---|
47 | pushfq
|
---|
48 | %endm
|
---|
49 | %macro MY_POP_ALL 0
|
---|
50 | popfq
|
---|
51 | pop r15
|
---|
52 | pop r14
|
---|
53 | pop r13
|
---|
54 | pop r12
|
---|
55 | pop r11
|
---|
56 | pop r10
|
---|
57 | pop r9
|
---|
58 | pop r8
|
---|
59 | pop rdi
|
---|
60 | pop rsi
|
---|
61 | pop rdx
|
---|
62 | pop rcx
|
---|
63 | pop rbx
|
---|
64 | pop rax
|
---|
65 | pop rbp
|
---|
66 | %endm
|
---|
67 |
|
---|
68 | %else
|
---|
69 | %define MY_PUSH_FLAGS pushfd
|
---|
70 | %define MY_POP_FLAGS popfd
|
---|
71 | %define MY_PUSH_FLAGS_SIZE 4
|
---|
72 |
|
---|
73 | %macro MY_PUSH_ALL 0
|
---|
74 | push eBP
|
---|
75 | mov xBP, xSP
|
---|
76 | push eax
|
---|
77 | push ebx
|
---|
78 | push ecx
|
---|
79 | push edx
|
---|
80 | push esi
|
---|
81 | push edi
|
---|
82 | pushfd
|
---|
83 | %endm
|
---|
84 | %macro MY_POP_ALL 0
|
---|
85 | popfd
|
---|
86 | pop edi
|
---|
87 | pop esi
|
---|
88 | pop edx
|
---|
89 | pop ecx
|
---|
90 | pop ebx
|
---|
91 | pop eax
|
---|
92 | pop ebp
|
---|
93 | %endm
|
---|
94 | %endif
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 | ;*******************************************************************************
|
---|
99 | ;* Internal Functions *
|
---|
100 | ;*******************************************************************************
|
---|
101 |
|
---|
102 | VBINSTST_BEGINCODE
|
---|
103 |
|
---|
104 | ;;
|
---|
105 | ; Report bad register value.
|
---|
106 | ;
|
---|
107 | ; Primary purpose is save all registers and convert from our stack-based to
|
---|
108 | ; the correct calling convention for the environment.
|
---|
109 | ;
|
---|
110 | ; This function will clean up the stack upon return (to save space in the caller).
|
---|
111 | ;
|
---|
112 | ; @param uExpected
|
---|
113 | ; @param uActual
|
---|
114 | ; @param uRegisterNo
|
---|
115 | ;
|
---|
116 | VBINSTST_BEGINPROC Common_BadValue
|
---|
117 | MY_PUSH_ALL
|
---|
118 | mov xAX, xSP ; 16-byte align the stack and reserve space for arguments and stuff.
|
---|
119 | sub xSP, 40h
|
---|
120 | and xSP, ~15
|
---|
121 | mov [xSP + 38h], xAX
|
---|
122 |
|
---|
123 | %ifdef ASM_CALL64_GCC
|
---|
124 | mov r8d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
|
---|
125 | mov rcx, [rbp + 10h] ; expected
|
---|
126 | mov rdx, [rbp + 18h] ; actual
|
---|
127 | mov rsi, [rbp + 20h] ; reg#
|
---|
128 | lea rdi, [.szFmt wrt rip]
|
---|
129 | VBINSTST_CALL_FN_FAILURE_4
|
---|
130 |
|
---|
131 | %elifdef ASM_CALL64_MSC
|
---|
132 | mov r10d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
|
---|
133 | mov [rsp + 20h], r10
|
---|
134 | mov r9, [rbp + 10h] ; expected
|
---|
135 | mov r8, [rbp + 18h] ; actual
|
---|
136 | mov rdx, [rbp + 20h] ; reg#
|
---|
137 | lea rcx, [.szFmt wrt rip]
|
---|
138 | VBINSTST_CALL_FN_FAILURE_4
|
---|
139 |
|
---|
140 | %elifdef ASM_CALL64_BS2
|
---|
141 | mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) xWrtRIP]
|
---|
142 | mov sCX, [xBP + xCB + xCB] ; expected
|
---|
143 | mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
|
---|
144 | mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
|
---|
145 | lea sSI, [.szFmt xWrtRIP]
|
---|
146 | mov qword [xSP + xCB + 3*sCB], sBX
|
---|
147 | mov qword [xSP + xCB + 2*sCB], sCX
|
---|
148 | mov qword [xSP + xCB + 1*sCB], sAX
|
---|
149 | mov qword [xSP + xCB], sDX
|
---|
150 | mov [xSP], sSI
|
---|
151 | VBINSTST_CALL_FN_FAILURE_4
|
---|
152 |
|
---|
153 | %else
|
---|
154 | mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator)]
|
---|
155 | mov sCX, [xBP + xCB + xCB] ; expected
|
---|
156 | mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
|
---|
157 | mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
|
---|
158 | mov [xSP + xCB + 3*sCB], sBX
|
---|
159 | mov [xSP + xCB + 2*sCB], sCX
|
---|
160 | mov [xSP + xCB + 1*sCB], sAX
|
---|
161 | mov [xSP + xCB], sDX
|
---|
162 | mov [xSP], RTCCPTR_PRE .szFmt
|
---|
163 | VBINSTST_CALL_FN_FAILURE_4
|
---|
164 | %endif
|
---|
165 |
|
---|
166 | mov xSP, [xSP + 38h]
|
---|
167 | MY_POP_ALL
|
---|
168 | ret 3*sCB
|
---|
169 | %if ARCH_BITS == 64
|
---|
170 | .szFmt: db 'Bad register 0x%RX32 value 0x%RX64, expected 0x%RX64 (line %RU64)', 13, 0
|
---|
171 | %else
|
---|
172 | .szFmt: db 'Bad register 0x%RX32 value 0x%RX32, expected 0x%RX32 (line %RU32)', 13, 0
|
---|
173 | %endif
|
---|
174 | VBINSTST_ENDPROC Common_BadValue
|
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 | ;
|
---|
179 | ; Global data variables used by Common_SetupMemReadUxx.
|
---|
180 | ; For address calculation reasons, these must be qword aligned.
|
---|
181 | ;
|
---|
182 | VBINSTST_BEGINDATA
|
---|
183 | align 64
|
---|
184 | dd 09d8af498h, 09ab3e5f8h
|
---|
185 | VBINSTST_GLOBALNAME_EX g_u64Data, data hidden
|
---|
186 | dq 0
|
---|
187 | dd 07d7af797h, 096b36562h
|
---|
188 | VBINSTST_GLOBALNAME_EX g_u32Data, data hidden
|
---|
189 | dd 0
|
---|
190 | dd 012305987h
|
---|
191 | VBINSTST_GLOBALNAME_EX g_u16Data, data hidden
|
---|
192 | dw 0
|
---|
193 | dw 05865h
|
---|
194 | dw 03863h
|
---|
195 | dw 02679h
|
---|
196 | VBINSTST_GLOBALNAME_EX g_u8Data, data hidden
|
---|
197 | db 0
|
---|
198 | db 90h
|
---|
199 | dw 0865ah
|
---|
200 | dd 058daffe2h
|
---|
201 |
|
---|
202 | VBINSTST_BEGINCODE
|
---|
203 |
|
---|
204 | ;;
|
---|
205 | ; Sets up g_u8Data.
|
---|
206 | ; @param uValue
|
---|
207 | VBINSTST_BEGINPROC Common_SetupMemReadU8
|
---|
208 | push sAX
|
---|
209 | mov ax, [xSP + sCB + xCB]
|
---|
210 | mov [VBINSTST_NAME(g_u8Data) xWrtRIP], ax
|
---|
211 | pop sAX
|
---|
212 | ret sCB
|
---|
213 | VBINSTST_ENDPROC Common_SetupMemReadU8
|
---|
214 |
|
---|
215 | ;;
|
---|
216 | ; Sets up g_u16Data.
|
---|
217 | ; @param uValue
|
---|
218 | VBINSTST_BEGINPROC Common_SetupMemReadU16
|
---|
219 | push sAX
|
---|
220 | mov ax, [xSP + sCB + xCB]
|
---|
221 | mov [VBINSTST_NAME(g_u16Data) xWrtRIP], ax
|
---|
222 | pop sAX
|
---|
223 | ret sCB
|
---|
224 | VBINSTST_ENDPROC Common_SetupMemReadU16
|
---|
225 |
|
---|
226 | ;;
|
---|
227 | ; Sets up g_u32Data.
|
---|
228 | ; @param uValue
|
---|
229 | VBINSTST_BEGINPROC Common_SetupMemReadU32
|
---|
230 | push sAX
|
---|
231 | mov eax, [xSP + sCB + xCB]
|
---|
232 | mov [VBINSTST_NAME(g_u32Data) xWrtRIP], eax
|
---|
233 | pop sAX
|
---|
234 | ret sCB
|
---|
235 | VBINSTST_ENDPROC Common_SetupMemReadU32
|
---|
236 |
|
---|
237 | ;;
|
---|
238 | ; Sets up g_u64Data.
|
---|
239 | ; @param uValue
|
---|
240 | VBINSTST_BEGINPROC Common_SetupMemReadU64
|
---|
241 | push sAX
|
---|
242 | %ifdef RT_ARCH_AMD64
|
---|
243 | mov rax, [xSP + sCB + xCB]
|
---|
244 | mov [VBINSTST_NAME(g_u64Data) xWrtRIP], rax
|
---|
245 | %else
|
---|
246 | mov eax, [xSP + sCB + xCB]
|
---|
247 | mov [VBINSTST_NAME(g_u64Data) xWrtRIP], eax
|
---|
248 | mov eax, [xSP + sCB + xCB + 4]
|
---|
249 | mov [VBINSTST_NAME(g_u64Data) + 4 xWrtRIP], eax
|
---|
250 | %endif
|
---|
251 | pop sAX
|
---|
252 | ret sCB
|
---|
253 | VBINSTST_ENDPROC Common_SetupMemReadU64
|
---|
254 |
|
---|
255 |
|
---|
256 | %endif
|
---|
257 |
|
---|