TianoCore EDK2 master
Loading...
Searching...
No Matches
DispatchExecute.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <Library/BaseLib.h>
13#include <FspEas.h>
14
23typedef
25(EFIAPI *FSP_FUNCTION)(
26 IN VOID *Param1,
27 IN VOID *Param2
28 );
29
30#pragma pack(1)
31typedef union {
32 struct {
33 UINT32 LimitLow : 16;
34 UINT32 BaseLow : 16;
35 UINT32 BaseMid : 8;
36 UINT32 Type : 4;
37 UINT32 System : 1;
38 UINT32 Dpl : 2;
39 UINT32 Present : 1;
40 UINT32 LimitHigh : 4;
41 UINT32 Software : 1;
42 UINT32 Reserved : 1;
43 UINT32 DefaultSize : 1;
44 UINT32 Granularity : 1;
45 UINT32 BaseHigh : 8;
46 } Bits;
47 UINT64 Uint64;
48} IA32_GDT;
49#pragma pack()
50
52 {
53 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
54 }, /* 0x0: reserve */
55 {
56 { 0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 0, 1, 1, 0 }
57 }, /* 0x8: compatibility mode */
58 {
59 { 0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 1, 0, 1, 0 }
60 }, /* 0x10: for long mode */
61 {
62 { 0xFFFF, 0, 0, 0x3, 1, 0, 1, 0xF, 0, 0, 1, 1, 0 }
63 }, /* 0x18: data */
64 {
65 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
66 }, /* 0x20: reserve */
67};
68
69//
70// IA32 Gdt register
71//
72GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = {
73 sizeof (mGdtEntries) - 1,
74 (UINTN)mGdtEntries
75};
76
88UINT32
89EFIAPI
91 IN UINT64 Function,
92 IN UINT64 Param1,
93 IN UINT64 Param2,
94 IN IA32_DESCRIPTOR *InternalGdtr
95 );
96
109 IN UINT64 Function,
110 IN UINT64 Param1,
111 IN UINT64 Param2
112 )
113{
114 EFI_STATUS Status;
115 IA32_DESCRIPTOR Idtr;
116
117 //
118 // Idtr might be changed inside of FSP. 32bit FSP only knows the <4G address.
119 // If IDTR.Base is >4G, FSP can not handle. So we need save/restore IDTR here for X64 only.
120 // Interrupt is already disabled here, so it is safety to update IDTR.
121 //
122 AsmReadIdtr (&Idtr);
123 Status = AsmExecute32BitCode (Function, Param1, Param2, &mGdt);
124 //
125 // Convert FSP Status code from 32bit to 64bit to match caller expectation.
126 //
127 Status = (Status & ~(BIT31 + BIT30)) | LShiftU64 (Status & (BIT31 + BIT30), 32);
128 AsmWriteIdtr (&Idtr);
129
130 return Status;
131}
132
144 IN UINT64 Function,
145 IN UINT64 Param1,
146 IN UINT64 Param2
147 )
148{
149 FSP_FUNCTION EntryFunc;
150 EFI_STATUS Status;
151
152 EntryFunc = (FSP_FUNCTION)(UINTN)(Function);
153 Status = EntryFunc ((VOID *)(UINTN)Param1, (VOID *)(UINTN)Param2);
154
155 return Status;
156}
UINT64 UINTN
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
EFI_STATUS Execute32BitCode(IN UINT64 Function, IN UINT64 Param1, IN UINT64 Param2)
EFI_STATUS Execute64BitCode(IN UINT64 Function, IN UINT64 Param1, IN UINT64 Param2)
EFI_STATUS(EFIAPI * FSP_FUNCTION)(IN VOID *Param1, IN VOID *Param2)
#define IN
Definition: Base.h:279
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINT32 EFIAPI AsmExecute32BitCode(IN UINT64 Function, IN UINT64 Param1, IN UINT64 Param2, IN IA32_DESCRIPTOR *InternalGdtr)
VOID EFIAPI AsmReadIdtr(OUT IA32_DESCRIPTOR *Idtr)
Definition: X86ReadIdtr.c:24
VOID EFIAPI AsmWriteIdtr(IN CONST IA32_DESCRIPTOR *Idtr)