2 Initialize GDT for Linux.
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "LoadLinuxLib.h"
19 // Local structure definitions
25 // Global Descriptor Entry structures
28 typedef struct _GDT_ENTRY
{
33 UINT8 Limit19_16_and_flags
;
43 GDT_ENTRY TaskSegment
;
50 STATIC GDT_ENTRIES
*mGdt
= NULL
;
53 // Global descriptor table (GDT) Template
55 STATIC GDT_ENTRIES GdtTemplate
= {
64 0x0, // limit 19:16, flags
75 0x0, // limit 19:16, flags
82 0x0FFFF, // limit 0xFFFFF
85 0x09A, // present, ring 0, data, expand-up, writable
86 0x0CF, // page-granular, 32-bit
93 0x0FFFF, // limit 0xFFFFF
96 0x092, // present, ring 0, data, expand-up, writable
97 0x0CF, // page-granular, 32-bit
118 0x0, // present, ring 0, data, expand-up, writable
119 0x0, // page-granular, 32-bit
129 0x0, // present, ring 0, data, expand-up, writable
130 0x0, // page-granular, 32-bit
136 Initialize Global Descriptor Table.
140 InitLinuxDescriptorTables (
145 // Allocate Runtime Data for the GDT
147 mGdt
= AllocateRuntimePool (sizeof (GdtTemplate
) + 8);
148 ASSERT (mGdt
!= NULL
);
149 mGdt
= ALIGN_POINTER (mGdt
, 8);
152 // Initialize all GDT entries
154 CopyMem (mGdt
, &GdtTemplate
, sizeof (GdtTemplate
));
159 Initialize Global Descriptor Table.
163 SetLinuxDescriptorTables (
167 IA32_DESCRIPTOR GdtPtr
;
168 IA32_DESCRIPTOR IdtPtr
;
171 // Write GDT register
173 GdtPtr
.Base
= (UINT32
)(UINTN
)(VOID
*) mGdt
;
174 GdtPtr
.Limit
= (UINT16
) (sizeof (GdtTemplate
) - 1);
175 AsmWriteGdtr (&GdtPtr
);
177 IdtPtr
.Base
= (UINT32
) 0;
178 IdtPtr
.Limit
= (UINT16
) 0;
179 AsmWriteIdtr (&IdtPtr
);