summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/NestedInterruptTplLib/Iret.c
blob: 4ab274d69be50fafb6cc5a5d590491f73a8d295e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** @file
  Force interrupt handler to return with interrupts still disabled.

  Copyright (C) 2022, Fen Systems Ltd.

  SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Library/BaseLib.h>
#include <Library/DebugLib.h>

#include "Iret.h"

/**
  Force interrupt handler to return with interrupts still disabled.

  @param SystemContext         A pointer to the system context when the
                               interrupt occurred.
**/
VOID
DisableInterruptsOnIret (
  IN OUT EFI_SYSTEM_CONTEXT  SystemContext
  )
{
 #if defined (MDE_CPU_X64)

  IA32_EFLAGS32  Rflags;

  //
  // Get flags from system context.
  //
  Rflags.UintN = SystemContext.SystemContextX64->Rflags;
  ASSERT (Rflags.Bits.IF);

  //
  // Clear interrupts-enabled flag.
  //
  Rflags.Bits.IF                         = 0;
  SystemContext.SystemContextX64->Rflags = Rflags.UintN;

 #else

  #error "Unsupported CPU"

 #endif
}