VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-fpustate-1-template.mac@ 89146

Last change on this file since 89146 was 83318, checked in by vboxsync, 5 years ago

ValKit/bs3-fpustate-1: Check the value we read and also test MOVUPS. skylake fmul FOP value adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1; $Id: bs3-fpustate-1-template.mac 83318 2020-03-18 16:59:45Z vboxsync $
2;; @file
3; BS3Kit - bs3-fpustate-1, assembly template.
4;
5
6;
7; Copyright (C) 2007-2020 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; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27
28;*********************************************************************************************************************************
29;* Header Files *
30;*********************************************************************************************************************************
31%include "bs3kit-template-header.mac" ; setup environment
32
33
34;*********************************************************************************************************************************
35;* External Symbols *
36;*********************************************************************************************************************************
37TMPL_BEGIN_TEXT
38
39
40;;
41; Initializes the FPU state and saves it to pFxState.
42;
43; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_InitState)(X86FXSTATE BS3_FAR *pFxState, void *pvMmioReg);
44;
45BS3_PROC_BEGIN_MODE bs3FpuState1_InitState, BS3_PBC_NEAR
46 BS3_CALL_CONV_PROLOG 2
47 push xBP
48 mov xBP, xSP
49 push xBX
50TONLY16 push ds
51 pushf
52TONLY64 sub xSP, 20h
53
54 ;
55 ; x87 state.
56 ;
57 fninit
58 fld dword [TMPL_DATA16_WRT(g_r32V1)]
59 fld qword [TMPL_DATA16_WRT(g_r64V1)]
60 fld tword [TMPL_DATA16_WRT(g_r80V1)]
61 fld qword [TMPL_DATA16_WRT(g_r64V1)]
62 fld dword [TMPL_DATA16_WRT(g_r32V2)]
63 fld dword [TMPL_DATA16_WRT(g_r80_QNaNMax)]
64 fld tword [TMPL_DATA16_WRT(g_r80_SNaNMax)]
65 fld tword [TMPL_DATA16_WRT(g_r80_ThirtyTwo)]
66
67 ;
68 ; We'll later be using FMUL to test actually using the FPU in RC & R0,
69 ; so for everything to line up correctly with FPU CS:IP and FPU DS:DP,
70 ; we'll call the function here too. This has the benefitial side effect
71 ; of loading correct FPU DS/DS values so we can check that they don't
72 ; get lost either. Also, we now don't have to guess whether the CPU
73 ; emulation sets CS/DS or not.
74 ;
75TONLY16 push xPRE [xBP + xCB + cbCurRetAddr + sCB + 2]
76 push xPRE [xBP + xCB + cbCurRetAddr + sCB]
77 BS3_CALL TMPL_NM(bs3FpuState1_FMul), 1
78 add xSP, sCB
79
80 ;
81 ; SSE state
82 ;
83 movdqu xmm0, [TMPL_DATA16_WRT(g_r32_0dot1)]
84 movdqu xmm1, [TMPL_DATA16_WRT(g_r32_Two)]
85 movdqu xmm2, [TMPL_DATA16_WRT(g_r32_ThirtyTwo)]
86 movdqu xmm3, [TMPL_DATA16_WRT(g_r32_SNaN)]
87 movdqu xmm4, [TMPL_DATA16_WRT(g_r80_ThirtyTwo)]
88 movdqu xmm5, [TMPL_DATA16_WRT(g_r32_NegQNaN)]
89 movdqu xmm6, [TMPL_DATA16_WRT(g_r64_Zero)]
90 movdqu xmm7, [TMPL_DATA16_WRT(g_r64_Two)]
91%if TMPL_BITS == 64
92 movdqu xmm8, [TMPL_DATA16_WRT(g_r64_Ten)]
93 movdqu xmm9, [TMPL_DATA16_WRT(g_r64_ThirtyTwo)]
94 movdqu xmm10, [TMPL_DATA16_WRT(g_r64_Max)]
95 movdqu xmm11, [TMPL_DATA16_WRT(g_r64_SNaN)]
96 movdqu xmm12, [TMPL_DATA16_WRT(g_r64_NegQNaN)]
97 movdqu xmm13, [TMPL_DATA16_WRT(g_r64_QNaNMax)]
98 movdqu xmm14, [TMPL_DATA16_WRT(g_r64_DnMax)]
99 movdqu xmm15, [TMPL_DATA16_WRT(g_r80_Eleven)]
100%endif
101
102 ;; @todo status regs
103
104 ;
105 ; Save it. Note that DS is no longer valid in 16-bit code.
106 ; To be on the safe side, we load and save the state once again.
107 ;
108TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
109 mov xBX, [xBP + xCB + cbCurRetAddr]
110 cli
111%if TMPL_BITS == 64
112 o64 fxsave [xBX]
113 fninit
114 o64 fxrstor [xBX]
115 o64 fxsave [xBX]
116%else
117 fxsave [xBX]
118 fninit
119 fxrstor [xBX]
120 fxsave [xBX]
121%endif
122
123.return:
124TONLY64 add xSP, 20h
125 popf
126TONLY16 pop ds
127 pop xBX
128 mov xSP, xBP
129 pop xBP
130 BS3_CALL_CONV_EPILOG 2
131 BS3_HYBRID_RET
132BS3_PROC_END_MODE bs3FpuState1_InitState
133
134
135;;
136; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_Restore)(X86FXSTATE const BS3_FAR *pFxState);
137;
138BS3_PROC_BEGIN_MODE bs3FpuState1_Restore, BS3_PBC_NEAR
139 push xBP
140 mov xBP, xSP
141
142%if TMPL_BITS == 64
143 o64 fxrstor [rcx]
144
145%elif TMPL_BITS == 32
146 mov eax, [xBP + xCB*2]
147 fxrstor [eax]
148
149%elif TMPL_BITS == 16
150 mov ax, ds
151 mov ds, [xBP + xCB + cbCurRetAddr + 2]
152 mov xBX, [xBP + xCB + cbCurRetAddr]
153 fxrstor [bx]
154 mov ds, ax
155%else
156 %error TMPL_BITS
157%endif
158
159 mov xSP, xBP
160 pop xBP
161 BS3_HYBRID_RET
162BS3_PROC_END_MODE bs3FpuState1_Restore
163
164;;
165; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_Save)(X86FXSTATE BS3_FAR *pFxState);
166;
167BS3_PROC_BEGIN_MODE bs3FpuState1_Save, BS3_PBC_NEAR
168 push xBP
169 mov xBP, xSP
170
171%if TMPL_BITS == 64
172 o64 fxsave [rcx]
173
174%elif TMPL_BITS == 32
175 mov eax, [xBP + xCB*2]
176 fxsave [eax]
177
178%elif TMPL_BITS == 16
179 push bx
180 push ds
181 mov ds, [xBP + xCB + cbCurRetAddr + 2]
182 mov bx, [xBP + xCB + cbCurRetAddr]
183 fxsave [bx]
184 pop ds
185 pop bx
186%else
187 %error TMPL_BITS
188%endif
189
190 mov xSP, xBP
191 pop xBP
192 BS3_HYBRID_RET
193BS3_PROC_END_MODE bs3FpuState1_Save
194
195
196;;
197; Performs a MOVDQU write on the specified memory.
198;
199; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_MovDQU_Write)(void *pvMmioReg);
200;
201BS3_PROC_BEGIN_MODE bs3FpuState1_MovDQU_Write, BS3_PBC_NEAR
202 BS3_CALL_CONV_PROLOG 1
203 push xBP
204 mov xBP, xSP
205 push xBX
206TONLY16 push ds
207
208 ; Load the register pointer.
209 mov xBX, [xBP + xCB + cbCurRetAddr]
210TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
211
212 ; Do read.
213 movdqu [xBX], xmm0
214
215TONLY16 pop ds
216 pop xBX
217 leave
218 BS3_CALL_CONV_EPILOG 1
219 BS3_HYBRID_RET
220BS3_PROC_END_MODE bs3FpuState1_MovDQU_Write
221
222
223;;
224; Performs a MOVDQU write to the specified memory.
225;
226; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_MovDQU_Read)(void *pvMmioReg);
227;
228BS3_PROC_BEGIN_MODE bs3FpuState1_MovDQU_Read, BS3_PBC_NEAR
229 BS3_CALL_CONV_PROLOG 2
230 push xBP
231 mov xBP, xSP
232 push xBX
233TONLY16 push ds
234 sub xSP, 20h
235%if TMPL_BITS == 16
236 movdqu [xBP - xCB - xCB - 2 - 18h], xmm2
237%else
238 movdqu [xSP], xmm2
239%endif
240
241 ; Load the register pointer.
242 mov xBX, [xBP + xCB + cbCurRetAddr]
243TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
244
245
246 ; Do read.
247 movdqu xmm2, [xBX]
248
249 ; Save the result.
250 mov xBX, [xBP + xCB + cbCurRetAddr + sCB]
251TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + sCB + 2]
252 movups [xBX], xmm2
253
254%if TMPL_BITS == 16
255 movdqu xmm2, [xBP - xCB - xCB - 2 - 18h]
256%else
257 movdqu xmm2, [xSP]
258%endif
259 add xSP, 20h
260TONLY16 pop ds
261 pop xBX
262 mov xSP, xBP
263 pop xBP
264 BS3_CALL_CONV_EPILOG 2
265 BS3_HYBRID_RET
266BS3_PROC_END_MODE bs3FpuState1_MovDQU_Read
267
268
269;;
270; Performs a MOVUPS write on the specified memory.
271;
272; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_MovUPS_Write)(void *pvMmioReg);
273;
274BS3_PROC_BEGIN_MODE bs3FpuState1_MovUPS_Write, BS3_PBC_NEAR
275 BS3_CALL_CONV_PROLOG 1
276 push xBP
277 mov xBP, xSP
278 push xBX
279TONLY16 push ds
280
281 ; Load the register pointer.
282 mov xBX, [xBP + xCB + cbCurRetAddr]
283TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
284
285 ; Do read.
286 movups [xBX], xmm3
287
288TONLY16 pop ds
289 pop xBX
290 leave
291 BS3_CALL_CONV_EPILOG 1
292 BS3_HYBRID_RET
293BS3_PROC_END_MODE bs3FpuState1_MovUPS_Write
294
295
296;;
297; Performs a MOVUPS write to the specified memory.
298;
299; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_MovUPS_Read)(void *pvMmioReg, void *pvResult);
300;
301BS3_PROC_BEGIN_MODE bs3FpuState1_MovUPS_Read, BS3_PBC_NEAR
302 BS3_CALL_CONV_PROLOG 2
303 push xBP
304 mov xBP, xSP
305 push xBX
306TONLY16 push ds
307 sub xSP, 20h
308%if TMPL_BITS == 16
309 movups [xBP - xCB - xCB - 2 - 18h], xmm1
310%else
311 movups [xSP], xmm1
312%endif
313
314 ; Load the register pointer.
315 mov xBX, [xBP + xCB + cbCurRetAddr]
316TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
317
318
319 ; Do read.
320 movups xmm1, [xBX]
321
322 ; Save the result.
323 mov xBX, [xBP + xCB + cbCurRetAddr + sCB]
324TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + sCB + 2]
325 movups [xBX], xmm1
326
327%if TMPL_BITS == 16
328 movups xmm1, [xBP - xCB - xCB - 2 - 18h]
329%else
330 movups xmm1, [xSP]
331%endif
332 add xSP, 20h
333TONLY16 pop ds
334 pop xBX
335 mov xSP, xBP
336 pop xBP
337 BS3_CALL_CONV_EPILOG 2
338 BS3_HYBRID_RET
339BS3_PROC_END_MODE bs3FpuState1_MovUPS_Read
340
341
342;;
343; Performs a FNSTENV write on the specified memory.
344;
345; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_FNStEnv)(void *pvMmioReg);
346;
347BS3_PROC_BEGIN_MODE bs3FpuState1_FNStEnv, BS3_PBC_NEAR
348 BS3_CALL_CONV_PROLOG 1
349 push xBP
350 mov xBP, xSP
351 push xBX
352TONLY16 push ds
353
354 ; Load the register pointer.
355 mov xBX, [xBP + xCB + cbCurRetAddr]
356TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
357
358 ; Just write.
359 fnstenv [xBX]
360
361TONLY16 pop ds
362 pop xBX
363 mov xSP, xBP
364 pop xBP
365 BS3_CALL_CONV_EPILOG 1
366 BS3_HYBRID_RET
367BS3_PROC_END_MODE bs3FpuState1_FNStEnv
368
369
370;;
371; Performs a FMUL on the specified memory, after writing a 64-bit value to it first.
372;
373; BS3_DECL_NEAR(void) TMPL_NM(bs3FpuState1_FMul)(void *pvMmioReg, void *pvResultIgnored);
374;
375BS3_PROC_BEGIN_MODE bs3FpuState1_FMul, BS3_PBC_NEAR
376 BS3_CALL_CONV_PROLOG 2
377 push xBP
378 mov xBP, xSP
379 push xBX
380TONLY16 push ds
381
382 ; Load the value we'll be multiplying with into register(s) while ds is DATA16.
383 mov sAX, [TMPL_DATA16_WRT(g_r64_One)]
384TNOT64 mov edx, [4 + TMPL_DATA16_WRT(g_r64_One)]
385
386 ; Load the register pointer.
387 mov xBX, [xBP + xCB + cbCurRetAddr]
388TONLY16 mov ds, [xBP + xCB + cbCurRetAddr + 2]
389
390 ; Just write.
391 mov [xBX], sAX
392TNOT64 mov [xBX + 4], edx
393 call .do_it
394
395TONLY16 pop ds
396 pop xBX
397 mov xSP, xBP
398 pop xBP
399 BS3_CALL_CONV_EPILOG 2
400 BS3_HYBRID_RET
401.do_it:
402 fmul qword [xBX]
403 ret
404BS3_PROC_END_MODE bs3FpuState1_FMul
405
406
407%include "bs3kit-template-footer.mac" ; reset environment
408
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