]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/IA32/SetIdtEntry.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / IA32 / SetIdtEntry.c
1 /** @file
2 Set a IDT entry for debug purpose
3
4 Set a IDT entry for interrupt vector 3 for debug purpose for IA32 platform
5
6 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11 #include "ScriptExecute.h"
12
13 /**
14 Set a IDT entry for interrupt vector 3 for debug purpose.
15
16 @param AcpiS3Context a pointer to a structure of ACPI_S3_CONTEXT
17
18 **/
19 VOID
20 SetIdtEntry (
21 IN ACPI_S3_CONTEXT *AcpiS3Context
22 )
23 {
24 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
25 IA32_DESCRIPTOR *IdtDescriptor;
26 UINTN S3DebugBuffer;
27 EFI_STATUS Status;
28
29 //
30 // Restore IDT for debug
31 //
32 IdtDescriptor = (IA32_DESCRIPTOR *)(UINTN)(AcpiS3Context->IdtrProfile);
33 AsmWriteIdtr (IdtDescriptor);
34
35 //
36 // Setup the default CPU exception handlers
37 //
38 Status = InitializeCpuExceptionHandlers (NULL);
39 ASSERT_EFI_ERROR (Status);
40
41 DEBUG_CODE_BEGIN ();
42 //
43 // Update IDT entry INT3 if the instruction is valid in it
44 //
45 S3DebugBuffer = (UINTN)(AcpiS3Context->S3DebugBufferAddress);
46 if (*(UINTN *)S3DebugBuffer != (UINTN)-1) {
47 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (IA32_IDT_GATE_DESCRIPTOR)));
48 IdtEntry->Bits.OffsetLow = (UINT16)S3DebugBuffer;
49 IdtEntry->Bits.Selector = (UINT16)AsmReadCs ();
50 IdtEntry->Bits.Reserved_0 = 0;
51 IdtEntry->Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
52 IdtEntry->Bits.OffsetHigh = (UINT16)(S3DebugBuffer >> 16);
53 }
54
55 DEBUG_CODE_END ();
56 }