2 C based implemention of IA32 interrupt handling only
3 requiring a minimal assembly interrupt entry point.
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
14 // Global descriptor table (GDT) Template
16 STATIC GDT_ENTRIES GdtTemplate
= {
25 0x0, // limit 19:16, flags
32 0x0FFFF, // limit 15:0
35 0x092, // present, ring 0, data, read/write
36 0x0CF, // page-granular, 32-bit
43 0x0FFFF, // limit 15:0
46 0x09F, // present, ring 0, code, execute/read, conforming, accessed
47 0x0CF, // page-granular, 32-bit
54 0x0FFFF, // limit 15:0
57 0x093, // present, ring 0, data, read/write, accessed
58 0x0CF, // page-granular, 32-bit
65 0x0FFFF, // limit 15:0
68 0x09A, // present, ring 0, code, execute/read
69 0x0CF, // page-granular, 32-bit
80 0x0, // limit 19:16, flags
87 0x0FFFF, // limit 15:0
90 0x092, // present, ring 0, data, read/write
91 0x0CF, // page-granular, 32-bit
98 0x0FFFF, // limit 15:0
101 0x09A, // present, ring 0, code, execute/read
102 0x0AF, // page-granular, 64-bit code
113 0x0, // limit 19:16, flags
119 Initialize Global Descriptor Table.
123 InitGlobalDescriptorTable (
128 IA32_DESCRIPTOR gdtPtr
;
131 // Allocate Runtime Data for the GDT
133 gdt
= AllocateRuntimePool (sizeof (GdtTemplate
) + 8);
134 ASSERT (gdt
!= NULL
);
135 gdt
= ALIGN_POINTER (gdt
, 8);
138 // Initialize all GDT entries
140 CopyMem (gdt
, &GdtTemplate
, sizeof (GdtTemplate
));
143 // Write GDT register
145 gdtPtr
.Base
= (UINT32
)(UINTN
)(VOID
*) gdt
;
146 gdtPtr
.Limit
= (UINT16
) (sizeof (GdtTemplate
) - 1);
147 AsmWriteGdtr (&gdtPtr
);
150 // Update selector (segment) registers base on new GDT
152 SetCodeSelector ((UINT16
)CPU_CODE_SEL
);
153 SetDataSelectors ((UINT16
)CPU_DATA_SEL
);