]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Real Mode Thunk Functions for IA32 and X64.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Module Name: x86Thunk.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | /**\r | |
18 | Invokes 16-bit code in big real mode and returns the updated register set.\r | |
19 | \r | |
20 | This function transfers control to the 16-bit code specified by CS:EIP using\r | |
21 | the stack specified by SS:ESP in RegisterSet. The updated registers are saved\r | |
22 | on the real mode stack and the starting address of the save area is returned.\r | |
23 | \r | |
24 | @param RegisterSet Values of registers before invocation of 16-bit code.\r | |
25 | @param Patch Pointer to the area following the 16-bit code.\r | |
26 | \r | |
27 | @return The pointer to a IA32_REGISTER_SET structure containing the updated\r | |
28 | register values.\r | |
29 | \r | |
30 | **/\r | |
31 | IA32_REGISTER_SET *\r | |
32 | InternalAsmThunk16 (\r | |
33 | IN IA32_REGISTER_SET *RegisterSet,\r | |
34 | IN OUT VOID *Patch\r | |
35 | );\r | |
36 | \r | |
37 | /**\r | |
38 | Prepares all structures a code required to use AsmThunk16().\r | |
39 | \r | |
40 | Prepares all structures and code required to use AsmThunk16().\r | |
41 | \r | |
42 | If ThunkContext is NULL, then ASSERT().\r | |
43 | \r | |
44 | @param ThunkContext A pointer to the context structure that describes the\r | |
45 | 16-bit real mode code to call.\r | |
46 | \r | |
47 | **/\r | |
48 | VOID\r | |
49 | EFIAPI\r | |
50 | AsmPrepareThunk16 (\r | |
51 | OUT THUNK_CONTEXT *ThunkContext\r | |
52 | )\r | |
53 | {\r | |
54 | ASSERT (ThunkContext != NULL);\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | Transfers control to a 16-bit real mode entry point and returns the results.\r | |
59 | \r | |
60 | Transfers control to a 16-bit real mode entry point and returns the results.\r | |
61 | AsmPrepareThunk16() must be called with ThunkContext before this function is\r | |
62 | used. This function must be called with interrupts disabled.\r | |
63 | \r | |
64 | If ThunkContext is NULL, then ASSERT().\r | |
65 | If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().\r | |
66 | \r | |
67 | @param ThunkContext A pointer to the context structure that describes the\r | |
68 | 16-bit real mode code to call.\r | |
69 | \r | |
70 | **/\r | |
71 | VOID\r | |
72 | EFIAPI\r | |
73 | AsmThunk16 (\r | |
74 | IN OUT THUNK_CONTEXT *ThunkContext\r | |
75 | )\r | |
76 | {\r | |
77 | UINT16 *Patch;\r | |
78 | \r | |
79 | ASSERT (ThunkContext != NULL);\r | |
80 | \r | |
81 | Patch = (UINT16*)(\r | |
82 | (UINTN)ThunkContext->RealModeCode +\r | |
83 | ThunkContext->RealModeCodeSize\r | |
84 | );\r | |
85 | \r | |
86 | //\r | |
87 | // 0x9a66 is the OpCode of far call with an operand size override.\r | |
88 | //\r | |
89 | *Patch = 0x9a66;\r | |
90 | \r | |
91 | //\r | |
92 | // CopyMem() here copies the updated register values back to RealModeState\r | |
93 | //\r | |
94 | CopyMem (\r | |
95 | &ThunkContext->RealModeState,\r | |
96 | InternalAsmThunk16 (&ThunkContext->RealModeState, Patch + 1),\r | |
97 | sizeof (ThunkContext->RealModeState)\r | |
98 | );\r | |
99 | }\r | |
100 | \r | |
101 | /**\r | |
102 | Prepares all structures and code for a 16-bit real mode thunk, transfers\r | |
103 | control to a 16-bit real mode entry point, and returns the results.\r | |
104 | \r | |
105 | Prepares all structures and code for a 16-bit real mode thunk, transfers\r | |
106 | control to a 16-bit real mode entry point, and returns the results. If the\r | |
107 | caller only need to perform a single 16-bit real mode thunk, then this\r | |
108 | service should be used. If the caller intends to make more than one 16-bit\r | |
109 | real mode thunk, then it is more efficient if AsmPrepareThunk16() is called\r | |
110 | once and AsmThunk16() can be called for each 16-bit real mode thunk. This\r | |
111 | function must be called with interrupts disabled.\r | |
112 | \r | |
113 | If ThunkContext is NULL, then ASSERT().\r | |
114 | \r | |
115 | @param ThunkContext A pointer to the context structure that describes the\r | |
116 | 16-bit real mode code to call.\r | |
117 | \r | |
118 | **/\r | |
119 | VOID\r | |
120 | EFIAPI\r | |
121 | AsmPrepareAndThunk16 (\r | |
122 | IN OUT THUNK_CONTEXT *ThunkContext\r | |
123 | )\r | |
124 | {\r | |
125 | AsmPrepareThunk16 (ThunkContext);\r | |
126 | AsmThunk16 (ThunkContext);\r | |
127 | }\r |