1 | ; $Id: feupdateenv.asm 96205 2022-08-14 23:40:55Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT feupdateenv - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2022 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 | %define RT_ASM_WITH_SEH64
|
---|
29 | %include "iprt/asmdefs.mac"
|
---|
30 | %include "iprt/x86.mac"
|
---|
31 |
|
---|
32 |
|
---|
33 | BEGINCODE
|
---|
34 | extern NAME(RT_NOCRT(fesetenv))
|
---|
35 | extern NAME(RT_NOCRT(feraiseexcept))
|
---|
36 |
|
---|
37 |
|
---|
38 | ;;
|
---|
39 | ; Updates the FPU+SSE environment.
|
---|
40 | ;
|
---|
41 | ; This will restore @a pEnv and merge in pending exception flags.
|
---|
42 | ;
|
---|
43 | ; @returns eax = 0 on success, -1 on failure.
|
---|
44 | ; @param pEnv 32-bit: [xBP+8] msc64: rcx gcc64: rdi - Saved enviornment.
|
---|
45 | ;
|
---|
46 | RT_NOCRT_BEGINPROC feupdateenv
|
---|
47 | push xBP
|
---|
48 | SEH64_PUSH_xBP
|
---|
49 | mov xBP, xSP
|
---|
50 | SEH64_SET_FRAME_xBP 0
|
---|
51 | sub xSP, 30h
|
---|
52 | SEH64_ALLOCATE_STACK 30h
|
---|
53 | SEH64_END_PROLOGUE
|
---|
54 |
|
---|
55 | ;
|
---|
56 | ; Load the parameter into rcx.
|
---|
57 | ;
|
---|
58 | %ifdef ASM_CALL64_GCC
|
---|
59 | mov rcx, rdi
|
---|
60 | %elifdef RT_ARCH_X86
|
---|
61 | mov ecx, [xBP + xCB*2]
|
---|
62 | %endif
|
---|
63 |
|
---|
64 | ;
|
---|
65 | ; Save the pending exceptions.
|
---|
66 | ;
|
---|
67 | %ifdef RT_ARCH_X86
|
---|
68 | extern NAME(rtNoCrtHasSse)
|
---|
69 | call NAME(rtNoCrtHasSse) ; Preserves all except xAX.
|
---|
70 | xor edx, edx
|
---|
71 | test al, al
|
---|
72 | jz .no_sse
|
---|
73 | %endif
|
---|
74 | stmxcsr [xBP - 10h]
|
---|
75 | mov edx, [xBP - 10h]
|
---|
76 | .no_sse:
|
---|
77 | fnstsw ax
|
---|
78 | or edx, eax
|
---|
79 | mov [xBP - 8h], edx ; save the pending exceptions here (will apply mask later).
|
---|
80 |
|
---|
81 | ;
|
---|
82 | ; Call fesetenv to update the environment.
|
---|
83 | ; Note! We have not yet modified the parameter registers for calling
|
---|
84 | ; convensions using them. So, parameters only needs to be loaded
|
---|
85 | ; for the stacked based convention.
|
---|
86 | ;
|
---|
87 | %ifdef RT_ARCH_X86
|
---|
88 | mov [xSP], ecx
|
---|
89 | %endif
|
---|
90 | call NAME(RT_NOCRT(fesetenv))
|
---|
91 |
|
---|
92 | ;
|
---|
93 | ; Raise exceptions if any are pending.
|
---|
94 | ;
|
---|
95 | %ifdef ASM_CALL64_GCC
|
---|
96 | mov edi, [xBP - 8h]
|
---|
97 | and edi, X86_FCW_XCPT_MASK
|
---|
98 | %elifdef ASM_CALL64_MSC
|
---|
99 | mov ecx, [xBP - 8h]
|
---|
100 | and ecx, X86_FCW_XCPT_MASK
|
---|
101 | %else
|
---|
102 | mov ecx, [xBP - 8h]
|
---|
103 | and ecx, X86_FCW_XCPT_MASK
|
---|
104 | mov [xSP], ecx
|
---|
105 | %endif
|
---|
106 | jz .no_exceptions_to_raise
|
---|
107 | call NAME(RT_NOCRT(feraiseexcept))
|
---|
108 | .no_exceptions_to_raise:
|
---|
109 |
|
---|
110 | ;
|
---|
111 | ; Return success.
|
---|
112 | ;
|
---|
113 | xor eax, eax
|
---|
114 | leave
|
---|
115 | ret
|
---|
116 | ENDPROC RT_NOCRT(feupdateenv)
|
---|
117 |
|
---|