2009-05-27 23:09:47 +02:00
|
|
|
/** @file
|
2020-02-07 02:08:29 +01:00
|
|
|
C based implementation of IA32 interrupt handling only
|
2009-05-27 23:09:47 +02:00
|
|
|
requiring a minimal assembly interrupt entry point.
|
|
|
|
|
2015-10-30 18:32:27 +01:00
|
|
|
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:07:22 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2009-05-27 23:09:47 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "CpuDxe.h"
|
2014-11-13 19:25:10 +01:00
|
|
|
#include "CpuGdt.h"
|
2009-05-27 23:09:47 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Global descriptor table (GDT) Template
|
|
|
|
//
|
|
|
|
STATIC GDT_ENTRIES GdtTemplate = {
|
|
|
|
//
|
|
|
|
// NULL_SEL
|
|
|
|
//
|
|
|
|
{
|
|
|
|
0x0, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x0, // type
|
|
|
|
0x0, // limit 19:16, flags
|
|
|
|
0x0, // base 31:24
|
|
|
|
},
|
|
|
|
//
|
|
|
|
// LINEAR_SEL
|
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x092, // present, ring 0, data, read/write
|
2009-05-27 23:09:47 +02:00
|
|
|
0x0CF, // page-granular, 32-bit
|
|
|
|
0x0,
|
|
|
|
},
|
|
|
|
//
|
|
|
|
// LINEAR_CODE_SEL
|
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x09F, // present, ring 0, code, execute/read, conforming, accessed
|
2009-05-27 23:09:47 +02:00
|
|
|
0x0CF, // page-granular, 32-bit
|
|
|
|
0x0,
|
|
|
|
},
|
|
|
|
//
|
|
|
|
// SYS_DATA_SEL
|
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x093, // present, ring 0, data, read/write, accessed
|
2009-05-27 23:09:47 +02:00
|
|
|
0x0CF, // page-granular, 32-bit
|
|
|
|
0x0,
|
|
|
|
},
|
|
|
|
//
|
|
|
|
// SYS_CODE_SEL
|
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x09A, // present, ring 0, code, execute/read
|
2009-05-27 23:09:47 +02:00
|
|
|
0x0CF, // page-granular, 32-bit
|
|
|
|
0x0,
|
|
|
|
},
|
|
|
|
//
|
2015-10-30 18:32:27 +01:00
|
|
|
// SPARE4_SEL
|
2009-05-27 23:09:47 +02:00
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x0, // type
|
|
|
|
0x0, // limit 19:16, flags
|
|
|
|
0x0, // base 31:24
|
2009-05-27 23:09:47 +02:00
|
|
|
},
|
|
|
|
//
|
2015-10-30 18:32:27 +01:00
|
|
|
// LINEAR_DATA64_SEL
|
2009-05-27 23:09:47 +02:00
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x092, // present, ring 0, data, read/write
|
|
|
|
0x0CF, // page-granular, 32-bit
|
2009-05-27 23:09:47 +02:00
|
|
|
0x0,
|
|
|
|
},
|
|
|
|
//
|
2015-10-30 18:32:27 +01:00
|
|
|
// LINEAR_CODE64_SEL
|
|
|
|
//
|
|
|
|
{
|
|
|
|
0x0FFFF, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x09A, // present, ring 0, code, execute/read
|
|
|
|
0x0AF, // page-granular, 64-bit code
|
|
|
|
0x0, // base (high)
|
|
|
|
},
|
|
|
|
//
|
2009-05-27 23:09:47 +02:00
|
|
|
// SPARE5_SEL
|
|
|
|
//
|
|
|
|
{
|
2015-10-30 18:32:27 +01:00
|
|
|
0x0, // limit 15:0
|
|
|
|
0x0, // base 15:0
|
|
|
|
0x0, // base 23:16
|
|
|
|
0x0, // type
|
|
|
|
0x0, // limit 19:16, flags
|
|
|
|
0x0, // base 31:24
|
2009-05-27 23:09:47 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-07-13 05:08:54 +02:00
|
|
|
Initialize Global Descriptor Table.
|
2009-05-27 23:09:47 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
InitGlobalDescriptorTable (
|
2010-07-13 05:08:54 +02:00
|
|
|
VOID
|
2009-05-27 23:09:47 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
GDT_ENTRIES *gdt;
|
|
|
|
IA32_DESCRIPTOR gdtPtr;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate Runtime Data for the GDT
|
|
|
|
//
|
|
|
|
gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
|
|
|
|
ASSERT (gdt != NULL);
|
|
|
|
gdt = ALIGN_POINTER (gdt, 8);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize all GDT entries
|
|
|
|
//
|
|
|
|
CopyMem (gdt, &GdtTemplate, sizeof (GdtTemplate));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Write GDT register
|
|
|
|
//
|
|
|
|
gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;
|
2010-08-10 08:57:32 +02:00
|
|
|
gdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 1);
|
2009-05-27 23:09:47 +02:00
|
|
|
AsmWriteGdtr (&gdtPtr);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update selector (segment) registers base on new GDT
|
|
|
|
//
|
|
|
|
SetCodeSelector ((UINT16)CPU_CODE_SEL);
|
|
|
|
SetDataSelectors ((UINT16)CPU_DATA_SEL);
|
|
|
|
}
|
|
|
|
|