SetIdtEntry.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /** @file
  2. Set a IDT entry for debug purpose
  3. Set a IDT entry for interrupt vector 3 for debug purpose for IA32 platform
  4. Copyright (c) 2013-2015 Intel Corporation.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "ScriptExecute.h"
  8. //
  9. // INTERRUPT_GATE_DESCRIPTOR and SetIdtEntry () are used to setup IDT to do debug
  10. //
  11. #pragma pack(1)
  12. typedef struct {
  13. UINT16 OffsetLow;
  14. UINT16 SegmentSelector;
  15. UINT16 Attributes;
  16. UINT16 OffsetHigh;
  17. } INTERRUPT_GATE_DESCRIPTOR;
  18. #define INTERRUPT_GATE_ATTRIBUTE 0x8e00
  19. #pragma pack()
  20. /**
  21. Set a IDT entry for interrupt vector 3 for debug purpose.
  22. @param AcpiS3Context a pointer to a structure of ACPI_S3_CONTEXT
  23. **/
  24. VOID
  25. SetIdtEntry (
  26. IN ACPI_S3_CONTEXT *AcpiS3Context
  27. )
  28. {
  29. INTERRUPT_GATE_DESCRIPTOR *IdtEntry;
  30. IA32_DESCRIPTOR *IdtDescriptor;
  31. UINTN S3DebugBuffer;
  32. //
  33. // Restore IDT for debug
  34. //
  35. IdtDescriptor = (IA32_DESCRIPTOR *) (UINTN) (AcpiS3Context->IdtrProfile);
  36. IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
  37. S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);
  38. IdtEntry->OffsetLow = (UINT16)S3DebugBuffer;
  39. IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();
  40. IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE;
  41. IdtEntry->OffsetHigh = (UINT16)(S3DebugBuffer >> 16);
  42. AsmWriteIdtr (IdtDescriptor);
  43. }