]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
1. Introduced CPU Exception Handler Library to provide the CPU exception handlers...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / X64 / 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 x64 platform
5
6 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
7
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17 #include "ScriptExecute.h"
18 //
19 // INTERRUPT_GATE_DESCRIPTOR and SetIdtEntry () are used to setup IDT to do debug
20 //
21
22 #pragma pack(1)
23
24 typedef struct {
25 UINT16 Offset15To0;
26 UINT16 SegmentSelector;
27 UINT16 Attributes;
28 UINT16 Offset31To16;
29 UINT32 Offset63To32;
30 UINT32 Reserved;
31 } INTERRUPT_GATE_DESCRIPTOR;
32
33 #define INTERRUPT_GATE_ATTRIBUTE 0x8e00
34
35 #pragma pack()
36 /**
37 Set a IDT entry for interrupt vector 3 for debug purpose.
38
39 @param AcpiS3Context a pointer to a structure of ACPI_S3_CONTEXT
40
41 **/
42 VOID
43 SetIdtEntry (
44 IN ACPI_S3_CONTEXT *AcpiS3Context
45 )
46 {
47 INTERRUPT_GATE_DESCRIPTOR *IdtEntry;
48 IA32_DESCRIPTOR *IdtDescriptor;
49 UINTN S3DebugBuffer;
50
51 //
52 // Restore IDT for debug
53 //
54 IdtDescriptor = (IA32_DESCRIPTOR *) (UINTN) (AcpiS3Context->IdtrProfile);
55 AsmWriteIdtr (IdtDescriptor);
56
57 //
58 // Setup the default CPU exception handlers
59 //
60 SetupCpuExceptionHandlers ();
61
62 //
63 // Update IDT entry INT3
64 //
65 IdtEntry = (INTERRUPT_GATE_DESCRIPTOR *)(IdtDescriptor->Base + (3 * sizeof (INTERRUPT_GATE_DESCRIPTOR)));
66 S3DebugBuffer = (UINTN) (AcpiS3Context->S3DebugBufferAddress);
67
68 IdtEntry->Offset15To0 = (UINT16)S3DebugBuffer;
69 IdtEntry->SegmentSelector = (UINT16)AsmReadCs ();;
70 IdtEntry->Attributes = (UINT16)INTERRUPT_GATE_ATTRIBUTE;
71 IdtEntry->Offset31To16 = (UINT16)(S3DebugBuffer >> 16);
72 IdtEntry->Offset63To32 = (UINT32)(S3DebugBuffer >> 32);
73 IdtEntry->Reserved = 0;
74
75 }
76