xref: /DragonStub/lib/runtime/vm.c (revision e7db4418b1fe6ea0220974b77c3b10918ab9b7a0)
1 /*++
2 
3 Copyright (c) 1998  Intel Corporation
4 
5 Module Name:
6 
7     vm.c
8 
9 Abstract:
10 
11     EFI Hell to remap runtime address into the new virual address space
12     that was registered by the OS for RT calls.
13 
14     So the code image needs to be relocated. All pointers need to be
15     manually fixed up since the address map changes.
16 
17     GOOD LUCK NOT HAVING BUGS IN YOUR CODE! PLEASE TEST A LOT. MAKE SURE
18     EXIT BOOTSERVICES OVER WRITES ALL BOOTSERVICE MEMORY & DATA SPACES WHEN
19     YOU TEST.
20 
21 Revision History
22 
23 --*/
24 
25 #include "lib.h"
26 
27 #ifndef __GNUC__
28 #pragma RUNTIME_CODE(RtLibEnableVirtualMappings)
29 #endif
30 VOID
31 RUNTIMEFUNCTION
32 RtLibEnableVirtualMappings (
33     VOID
34     )
35 {
36     EFI_CONVERT_POINTER     ConvertPointer;
37 
38     //
39     // If this copy of the lib is linked into the firmware, then
40     // do not update the pointers yet.
41     //
42 
43     if (!LibFwInstance) {
44 
45         //
46         // Different components are updating to the new virtual
47         // mappings at differnt times.  The only function that
48         // is safe to call at this notification is ConvertAddress
49         //
50 
51         ConvertPointer = RT->ConvertPointer;
52 
53         //
54         // Fix any pointers that the lib created, that may be needed
55         // during runtime.
56         //
57 
58         ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&RT);
59         ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&LibRuntimeDebugOut);
60 
61         ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRaiseTPL);
62         ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRestoreTPL);
63 
64         // that was it :^)
65     }
66 }
67 
68 
69 #ifndef __GNUC__
70 #pragma RUNTIME_CODE(RtConvertList)
71 #endif
72 VOID
73 RUNTIMEFUNCTION
74 RtConvertList (
75     IN UINTN                DebugDisposition,
76     IN OUT LIST_ENTRY       *ListHead
77     )
78 {
79     LIST_ENTRY              *Link;
80     LIST_ENTRY              *NextLink;
81     EFI_CONVERT_POINTER     ConvertPointer;
82 
83     ConvertPointer = RT->ConvertPointer;
84 
85     //
86     // Convert all the Flink & Blink pointers in the list
87     //
88 
89     Link = ListHead;
90     do {
91         NextLink = Link->Flink;
92 
93         ConvertPointer (
94             Link->Flink == ListHead ? DebugDisposition : 0,
95             (VOID **)&Link->Flink
96             );
97 
98         ConvertPointer (
99             Link->Blink == ListHead ? DebugDisposition : 0,
100             (VOID **)&Link->Blink
101             );
102 
103         Link = NextLink;
104     } while (Link != ListHead);
105 }
106