xref: /aosp_15_r20/prebuilts/clang-tools/linux-x86/clang-headers/uintrintrin.h (revision bed243d3d9cd544cfb038bfa7be843dedc6e6bf7)
1*bed243d3SAndroid Build Coastguard Worker /*===------------------ uintrintrin.h - UINTR intrinsics -------------------===
2*bed243d3SAndroid Build Coastguard Worker  *
3*bed243d3SAndroid Build Coastguard Worker  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bed243d3SAndroid Build Coastguard Worker  * See https://llvm.org/LICENSE.txt for license information.
5*bed243d3SAndroid Build Coastguard Worker  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bed243d3SAndroid Build Coastguard Worker  *
7*bed243d3SAndroid Build Coastguard Worker  *===-----------------------------------------------------------------------===
8*bed243d3SAndroid Build Coastguard Worker  */
9*bed243d3SAndroid Build Coastguard Worker 
10*bed243d3SAndroid Build Coastguard Worker #ifndef __X86GPRINTRIN_H
11*bed243d3SAndroid Build Coastguard Worker #error "Never use <uintrintrin.h> directly; include <x86gprintrin.h> instead."
12*bed243d3SAndroid Build Coastguard Worker #endif
13*bed243d3SAndroid Build Coastguard Worker 
14*bed243d3SAndroid Build Coastguard Worker #ifndef __UINTRINTRIN_H
15*bed243d3SAndroid Build Coastguard Worker #define __UINTRINTRIN_H
16*bed243d3SAndroid Build Coastguard Worker 
17*bed243d3SAndroid Build Coastguard Worker /* Define the default attributes for the functions in this file */
18*bed243d3SAndroid Build Coastguard Worker #define __DEFAULT_FN_ATTRS \
19*bed243d3SAndroid Build Coastguard Worker   __attribute__((__always_inline__, __nodebug__, __target__("uintr")))
20*bed243d3SAndroid Build Coastguard Worker 
21*bed243d3SAndroid Build Coastguard Worker #ifdef __x86_64__
22*bed243d3SAndroid Build Coastguard Worker 
23*bed243d3SAndroid Build Coastguard Worker struct __uintr_frame
24*bed243d3SAndroid Build Coastguard Worker {
25*bed243d3SAndroid Build Coastguard Worker   unsigned long long rip;
26*bed243d3SAndroid Build Coastguard Worker   unsigned long long rflags;
27*bed243d3SAndroid Build Coastguard Worker   unsigned long long rsp;
28*bed243d3SAndroid Build Coastguard Worker };
29*bed243d3SAndroid Build Coastguard Worker 
30*bed243d3SAndroid Build Coastguard Worker /// Clears the user interrupt flag (UIF). Its effect takes place immediately: a
31*bed243d3SAndroid Build Coastguard Worker ///    user interrupt cannot be delivered on the instruction boundary following
32*bed243d3SAndroid Build Coastguard Worker ///    CLUI. Can be executed only if CR4.UINT = 1, the logical processor is in
33*bed243d3SAndroid Build Coastguard Worker ///    64-bit mode, and software is not executing inside an enclave; otherwise,
34*bed243d3SAndroid Build Coastguard Worker ///    each causes an invalid-opcode exception. Causes a transactional abort if
35*bed243d3SAndroid Build Coastguard Worker ///    executed inside a transactional region; the abort loads EAX as it would
36*bed243d3SAndroid Build Coastguard Worker ///    had it been due to an execution of CLI.
37*bed243d3SAndroid Build Coastguard Worker ///
38*bed243d3SAndroid Build Coastguard Worker /// \headerfile <x86gprintrin.h>
39*bed243d3SAndroid Build Coastguard Worker ///
40*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the <c> CLUI </c> instruction.
41*bed243d3SAndroid Build Coastguard Worker ///
42*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
43*bed243d3SAndroid Build Coastguard Worker ///   UIF := 0
44*bed243d3SAndroid Build Coastguard Worker /// \endcode
45*bed243d3SAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
_clui(void)46*bed243d3SAndroid Build Coastguard Worker _clui (void)
47*bed243d3SAndroid Build Coastguard Worker {
48*bed243d3SAndroid Build Coastguard Worker   __builtin_ia32_clui();
49*bed243d3SAndroid Build Coastguard Worker }
50*bed243d3SAndroid Build Coastguard Worker 
51*bed243d3SAndroid Build Coastguard Worker /// Sets the user interrupt flag (UIF). Its effect takes place immediately; a
52*bed243d3SAndroid Build Coastguard Worker ///    user interrupt may be delivered on the instruction boundary following
53*bed243d3SAndroid Build Coastguard Worker ///    STUI. Can be executed only if CR4.UINT = 1, the logical processor is in
54*bed243d3SAndroid Build Coastguard Worker ///    64-bit mode, and software is not executing inside an enclave; otherwise,
55*bed243d3SAndroid Build Coastguard Worker ///    each causes an invalid-opcode exception. Causes a transactional abort if
56*bed243d3SAndroid Build Coastguard Worker ///    executed inside a transactional region; the abort loads EAX as it would
57*bed243d3SAndroid Build Coastguard Worker ///    had it been due to an execution of STI.
58*bed243d3SAndroid Build Coastguard Worker ///
59*bed243d3SAndroid Build Coastguard Worker /// \headerfile <x86gprintrin.h>
60*bed243d3SAndroid Build Coastguard Worker ///
61*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the <c> STUI </c> instruction.
62*bed243d3SAndroid Build Coastguard Worker ///
63*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
64*bed243d3SAndroid Build Coastguard Worker ///   UIF := 1
65*bed243d3SAndroid Build Coastguard Worker /// \endcode
66*bed243d3SAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
_stui(void)67*bed243d3SAndroid Build Coastguard Worker _stui (void)
68*bed243d3SAndroid Build Coastguard Worker {
69*bed243d3SAndroid Build Coastguard Worker   __builtin_ia32_stui();
70*bed243d3SAndroid Build Coastguard Worker }
71*bed243d3SAndroid Build Coastguard Worker 
72*bed243d3SAndroid Build Coastguard Worker /// Get the current value of the user interrupt flag (UIF). Can be executed
73*bed243d3SAndroid Build Coastguard Worker ///    regardless of CPL and inside a transactional region. Can be executed only
74*bed243d3SAndroid Build Coastguard Worker ///    if CR4.UINT = 1, the logical processor is in 64-bit mode, and software is
75*bed243d3SAndroid Build Coastguard Worker ///    not executing inside an enclave; otherwise, it causes an invalid-opcode
76*bed243d3SAndroid Build Coastguard Worker ///    exception.
77*bed243d3SAndroid Build Coastguard Worker ///
78*bed243d3SAndroid Build Coastguard Worker /// \headerfile <x86gprintrin.h>
79*bed243d3SAndroid Build Coastguard Worker ///
80*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the <c> TESTUI </c> instruction.
81*bed243d3SAndroid Build Coastguard Worker ///
82*bed243d3SAndroid Build Coastguard Worker /// \returns The current value of the user interrupt flag (UIF).
83*bed243d3SAndroid Build Coastguard Worker ///
84*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
85*bed243d3SAndroid Build Coastguard Worker ///   CF := UIF
86*bed243d3SAndroid Build Coastguard Worker ///   ZF := 0
87*bed243d3SAndroid Build Coastguard Worker ///   AF := 0
88*bed243d3SAndroid Build Coastguard Worker ///   OF := 0
89*bed243d3SAndroid Build Coastguard Worker ///   PF := 0
90*bed243d3SAndroid Build Coastguard Worker ///   SF := 0
91*bed243d3SAndroid Build Coastguard Worker ///   dst := CF
92*bed243d3SAndroid Build Coastguard Worker /// \endcode
93*bed243d3SAndroid Build Coastguard Worker static __inline__ unsigned char __DEFAULT_FN_ATTRS
_testui(void)94*bed243d3SAndroid Build Coastguard Worker _testui (void)
95*bed243d3SAndroid Build Coastguard Worker {
96*bed243d3SAndroid Build Coastguard Worker   return __builtin_ia32_testui();
97*bed243d3SAndroid Build Coastguard Worker }
98*bed243d3SAndroid Build Coastguard Worker 
99*bed243d3SAndroid Build Coastguard Worker /// Send interprocessor user interrupt. Can be executed only if
100*bed243d3SAndroid Build Coastguard Worker ///    CR4.UINT = IA32_UINT_TT[0] = 1, the logical processor is in 64-bit mode,
101*bed243d3SAndroid Build Coastguard Worker ///    and software is not executing inside an enclave; otherwise, it causes an
102*bed243d3SAndroid Build Coastguard Worker ///    invalid-opcode exception. May be executed at any privilege level, all of
103*bed243d3SAndroid Build Coastguard Worker ///    its memory accesses are performed with supervisor privilege.
104*bed243d3SAndroid Build Coastguard Worker ///
105*bed243d3SAndroid Build Coastguard Worker /// \headerfile <x86gprintrin.h>
106*bed243d3SAndroid Build Coastguard Worker ///
107*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the <c> SENDUIPI </c> instruction
108*bed243d3SAndroid Build Coastguard Worker ///
109*bed243d3SAndroid Build Coastguard Worker /// \param __a
110*bed243d3SAndroid Build Coastguard Worker ///    Index of user-interrupt target table entry in user-interrupt target
111*bed243d3SAndroid Build Coastguard Worker ///    table.
112*bed243d3SAndroid Build Coastguard Worker ///
113*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
114*bed243d3SAndroid Build Coastguard Worker ///   IF __a > UITTSZ
115*bed243d3SAndroid Build Coastguard Worker ///     GP (0)
116*bed243d3SAndroid Build Coastguard Worker ///   FI
117*bed243d3SAndroid Build Coastguard Worker ///   tempUITTE := MEM[UITTADDR + (a<<4)]
118*bed243d3SAndroid Build Coastguard Worker ///   // tempUITTE must be valid, and can't have any reserved bit set
119*bed243d3SAndroid Build Coastguard Worker ///   IF (tempUITTE.V == 0 OR tempUITTE[7:1] != 0)
120*bed243d3SAndroid Build Coastguard Worker ///     GP (0)
121*bed243d3SAndroid Build Coastguard Worker ///   FI
122*bed243d3SAndroid Build Coastguard Worker ///   tempUPID := MEM[tempUITTE.UPIDADDR] // under lock
123*bed243d3SAndroid Build Coastguard Worker ///   // tempUPID can't have any reserved bit set
124*bed243d3SAndroid Build Coastguard Worker ///   IF (tempUPID[15:2] != 0 OR tempUPID[31:24] != 0)
125*bed243d3SAndroid Build Coastguard Worker ///     GP (0) // release lock
126*bed243d3SAndroid Build Coastguard Worker ///   FI
127*bed243d3SAndroid Build Coastguard Worker ///   tempUPID.PIR[tempUITTE.UV] := 1;
128*bed243d3SAndroid Build Coastguard Worker ///   IF (tempUPID.SN == 0 AND tempUPID.ON == 0)
129*bed243d3SAndroid Build Coastguard Worker ///     tempUPID.ON := 1
130*bed243d3SAndroid Build Coastguard Worker ///     sendNotify := 1
131*bed243d3SAndroid Build Coastguard Worker ///   ELSE
132*bed243d3SAndroid Build Coastguard Worker ///     sendNotify := 0
133*bed243d3SAndroid Build Coastguard Worker ///   FI
134*bed243d3SAndroid Build Coastguard Worker ///   MEM[tempUITTE.UPIDADDR] := tempUPID // release lock
135*bed243d3SAndroid Build Coastguard Worker ///   IF sendNotify == 1
136*bed243d3SAndroid Build Coastguard Worker ///     IF IA32_APIC_BASE[10] == 1 // local APIC is in x2APIC mode
137*bed243d3SAndroid Build Coastguard Worker ///       // send ordinary IPI with vector tempUPID.NV to 32-bit physical APIC
138*bed243d3SAndroid Build Coastguard Worker ///       // ID tempUPID.NDST
139*bed243d3SAndroid Build Coastguard Worker ///       SendOrdinaryIPI(tempUPID.NV, tempUPID.NDST)
140*bed243d3SAndroid Build Coastguard Worker ///     ELSE
141*bed243d3SAndroid Build Coastguard Worker ///       // send ordinary IPI with vector tempUPID.NV to 8-bit physical APIC
142*bed243d3SAndroid Build Coastguard Worker ///       // ID tempUPID.NDST[15:8]
143*bed243d3SAndroid Build Coastguard Worker ///       SendOrdinaryIPI(tempUPID.NV, tempUPID.NDST[15:8])
144*bed243d3SAndroid Build Coastguard Worker ///     FI
145*bed243d3SAndroid Build Coastguard Worker ///   FI
146*bed243d3SAndroid Build Coastguard Worker /// \endcode
147*bed243d3SAndroid Build Coastguard Worker static __inline__ void __DEFAULT_FN_ATTRS
_senduipi(unsigned long long __a)148*bed243d3SAndroid Build Coastguard Worker _senduipi (unsigned long long __a)
149*bed243d3SAndroid Build Coastguard Worker {
150*bed243d3SAndroid Build Coastguard Worker   __builtin_ia32_senduipi(__a);
151*bed243d3SAndroid Build Coastguard Worker }
152*bed243d3SAndroid Build Coastguard Worker 
153*bed243d3SAndroid Build Coastguard Worker #endif /* __x86_64__ */
154*bed243d3SAndroid Build Coastguard Worker 
155*bed243d3SAndroid Build Coastguard Worker #undef __DEFAULT_FN_ATTRS
156*bed243d3SAndroid Build Coastguard Worker 
157*bed243d3SAndroid Build Coastguard Worker #endif /* __UINTRINTRIN_H */
158