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