1 | ; $Id: fegetexceptflag.asm 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT fegetexceptflag - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2022 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 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 | %define RT_ASM_WITH_SEH64
|
---|
39 | %include "iprt/asmdefs.mac"
|
---|
40 | %include "iprt/x86.mac"
|
---|
41 |
|
---|
42 |
|
---|
43 | BEGINCODE
|
---|
44 |
|
---|
45 | ;;
|
---|
46 | ; Gets the pending exceptions.
|
---|
47 | ;
|
---|
48 | ; @returns eax = 0 on success, non-zero on failure.
|
---|
49 | ; @param pfXcpts 32-bit: [xBP+8]; msc64: rcx; gcc64: rdi; -- Where to store the flags (pointer to fexcept_t (16-bit)).
|
---|
50 | ; @param fXcptMask 32-bit: [xBP+c]; msc64: edx; gcc64: esi; -- The exception flags to get (X86_FSW_XCPT_MASK).
|
---|
51 | ; Accepts X86_FSW_SF and will return it if given as input.
|
---|
52 | ;
|
---|
53 | RT_NOCRT_BEGINPROC fegetexceptflag
|
---|
54 | push xBP
|
---|
55 | SEH64_PUSH_xBP
|
---|
56 | mov xBP, xSP
|
---|
57 | SEH64_SET_FRAME_xBP 0
|
---|
58 | sub xSP, 10h
|
---|
59 | SEH64_ALLOCATE_STACK 10h
|
---|
60 | SEH64_END_PROLOGUE
|
---|
61 |
|
---|
62 | ;
|
---|
63 | ; Load the parameter into rcx (pfXcpts) and edx (fXcptMask).
|
---|
64 | ;
|
---|
65 | %ifdef ASM_CALL64_GCC
|
---|
66 | mov rcx, rdi
|
---|
67 | mov edx, esi
|
---|
68 | %elifdef RT_ARCH_X86
|
---|
69 | mov ecx, [xBP + xCB*2]
|
---|
70 | mov edx, [xBP + xCB*3]
|
---|
71 | %endif
|
---|
72 | %if 0
|
---|
73 | and edx, X86_FSW_XCPT_MASK
|
---|
74 | %else
|
---|
75 | or eax, -1
|
---|
76 | test edx, ~X86_FSW_XCPT_MASK
|
---|
77 | %ifndef RT_STRICT
|
---|
78 | jnz .return
|
---|
79 | %else
|
---|
80 | jz .input_ok
|
---|
81 | int3
|
---|
82 | jmp .return
|
---|
83 | .input_ok:
|
---|
84 | %endif
|
---|
85 | %endif
|
---|
86 |
|
---|
87 | ;
|
---|
88 | ; Get the pending exceptions.
|
---|
89 | ;
|
---|
90 |
|
---|
91 | ; x87.
|
---|
92 | fnstsw ax
|
---|
93 | and ax, dx
|
---|
94 | mov [xCX], ax
|
---|
95 |
|
---|
96 | %ifdef RT_ARCH_X86
|
---|
97 | ; SSE supported (ecx preserved)?
|
---|
98 | extern NAME(rtNoCrtHasSse)
|
---|
99 | call NAME(rtNoCrtHasSse)
|
---|
100 | test al, al
|
---|
101 | jz .return_ok
|
---|
102 | %endif
|
---|
103 |
|
---|
104 | ; Modify the SSE flags.
|
---|
105 | stmxcsr [xBP - 10h]
|
---|
106 | mov ax, [xBP - 10h]
|
---|
107 | and ax, dx
|
---|
108 | and ax, X86_MXCSR_XCPT_FLAGS ; Don't confuse X86_MXCSR_DAZ for X86_FSW_SF.
|
---|
109 | or [xCX], ax
|
---|
110 |
|
---|
111 | .return_ok:
|
---|
112 | xor eax, eax
|
---|
113 | .return:
|
---|
114 | leave
|
---|
115 | ret
|
---|
116 | ENDPROC RT_NOCRT(fegetexceptflag)
|
---|
117 |
|
---|