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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 // Global descriptor table (GDT) Template
22 STATIC GDT_ENTRIES GdtTemplate
= {
31 0x0, // limit 19:16, flags
38 0x0FFFF, // limit 15:0
41 0x092, // present, ring 0, data, read/write
42 0x0CF, // page-granular, 32-bit
49 0x0FFFF, // limit 15:0
52 0x09F, // present, ring 0, code, execute/read, conforming, accessed
53 0x0CF, // page-granular, 32-bit
60 0x0FFFF, // limit 15:0
63 0x093, // present, ring 0, data, read/write, accessed
64 0x0CF, // page-granular, 32-bit
71 0x0FFFF, // limit 15:0
74 0x09A, // present, ring 0, code, execute/read
75 0x0CF, // page-granular, 32-bit
86 0x0, // limit 19:16, flags
93 0x0FFFF, // limit 15:0
96 0x092, // present, ring 0, data, read/write
97 0x0CF, // page-granular, 32-bit
104 0x0FFFF, // limit 15:0
107 0x09A, // present, ring 0, code, execute/read
108 0x0AF, // page-granular, 64-bit code
119 0x0, // limit 19:16, flags
125 Initialize Global Descriptor Table.
129 InitGlobalDescriptorTable (
134 IA32_DESCRIPTOR gdtPtr
;
137 // Allocate Runtime Data for the GDT
139 gdt
= AllocateRuntimePool (sizeof (GdtTemplate
) + 8);
140 ASSERT (gdt
!= NULL
);
141 gdt
= ALIGN_POINTER (gdt
, 8);
144 // Initialize all GDT entries
146 CopyMem (gdt
, &GdtTemplate
, sizeof (GdtTemplate
));
149 // Write GDT register
151 gdtPtr
.Base
= (UINT32
)(UINTN
)(VOID
*) gdt
;
152 gdtPtr
.Limit
= (UINT16
) (sizeof (GdtTemplate
) - 1);
153 AsmWriteGdtr (&gdtPtr
);
156 // Update selector (segment) registers base on new GDT
158 SetCodeSelector ((UINT16
)CPU_CODE_SEL
);
159 SetDataSelectors ((UINT16
)CPU_DATA_SEL
);