TianoCore EDK2 master
Loading...
Searching...
No Matches
LinuxGdt.c
Go to the documentation of this file.
1
9#include "LoadLinuxLib.h"
10
11//
12// Local structure definitions
13//
14
15#pragma pack (1)
16
17//
18// Global Descriptor Entry structures
19//
20
21typedef struct _GDT_ENTRY {
22 UINT16 Limit15_0;
23 UINT16 Base15_0;
24 UINT8 Base23_16;
25 UINT8 Type;
26 UINT8 Limit19_16_and_flags;
27 UINT8 Base31_24;
28} GDT_ENTRY;
29
30typedef
31 struct _GDT_ENTRIES {
32 GDT_ENTRY Null;
33 GDT_ENTRY Null2;
34 GDT_ENTRY Linear;
35 GDT_ENTRY LinearCode;
36 GDT_ENTRY TaskSegment;
37 GDT_ENTRY Spare4;
38 GDT_ENTRY Spare5;
40
41#pragma pack ()
42
43STATIC GDT_ENTRIES *mGdt = NULL;
44
45//
46// Global descriptor table (GDT) Template
47//
48STATIC GDT_ENTRIES GdtTemplate = {
49 //
50 // Null
51 //
52 {
53 0x0, // limit 15:0
54 0x0, // base 15:0
55 0x0, // base 23:16
56 0x0, // type
57 0x0, // limit 19:16, flags
58 0x0, // base 31:24
59 },
60 //
61 // Null2
62 //
63 {
64 0x0, // limit 15:0
65 0x0, // base 15:0
66 0x0, // base 23:16
67 0x0, // type
68 0x0, // limit 19:16, flags
69 0x0, // base 31:24
70 },
71 //
72 // Linear
73 //
74 {
75 0x0FFFF, // limit 0xFFFFF
76 0x0, // base 0
77 0x0,
78 0x09A, // present, ring 0, data, expand-up, writable
79 0x0CF, // page-granular, 32-bit
80 0x0,
81 },
82 //
83 // LinearCode
84 //
85 {
86 0x0FFFF, // limit 0xFFFFF
87 0x0, // base 0
88 0x0,
89 0x092, // present, ring 0, data, expand-up, writable
90 0x0CF, // page-granular, 32-bit
91 0x0,
92 },
93 //
94 // TaskSegment
95 //
96 {
97 0x0, // limit 0
98 0x0, // base 0
99 0x0,
100 0x089, // ?
101 0x080, // ?
102 0x0,
103 },
104 //
105 // Spare4
106 //
107 {
108 0x0, // limit 0
109 0x0, // base 0
110 0x0,
111 0x0, // present, ring 0, data, expand-up, writable
112 0x0, // page-granular, 32-bit
113 0x0,
114 },
115 //
116 // Spare5
117 //
118 {
119 0x0, // limit 0
120 0x0, // base 0
121 0x0,
122 0x0, // present, ring 0, data, expand-up, writable
123 0x0, // page-granular, 32-bit
124 0x0,
125 },
126};
127
132VOID
134 VOID
135 )
136{
137 //
138 // Allocate Runtime Data for the GDT
139 //
140 mGdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
141 ASSERT (mGdt != NULL);
142 mGdt = ALIGN_POINTER (mGdt, 8);
143
144 //
145 // Initialize all GDT entries
146 //
147 CopyMem (mGdt, &GdtTemplate, sizeof (GdtTemplate));
148}
149
154VOID
156 VOID
157 )
158{
159 IA32_DESCRIPTOR GdtPtr;
160 IA32_DESCRIPTOR IdtPtr;
161
162 //
163 // Write GDT register
164 //
165 GdtPtr.Base = (UINT32)(UINTN)(VOID *)mGdt;
166 GdtPtr.Limit = (UINT16)(sizeof (GdtTemplate) - 1);
167 AsmWriteGdtr (&GdtPtr);
168
169 IdtPtr.Base = (UINT32)0;
170 IdtPtr.Limit = (UINT16)0;
171 AsmWriteIdtr (&IdtPtr);
172}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateRuntimePool(IN UINTN AllocationSize)
VOID InitLinuxDescriptorTables(VOID)
Definition: LinuxGdt.c:133
VOID SetLinuxDescriptorTables(VOID)
Definition: LinuxGdt.c:155
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define ALIGN_POINTER(Pointer, Alignment)
Definition: Base.h:963
VOID EFIAPI AsmWriteGdtr(IN CONST IA32_DESCRIPTOR *Gdtr)
VOID EFIAPI AsmWriteIdtr(IN CONST IA32_DESCRIPTOR *Idtr)