2 * PROJECT: EFI Windows Loader
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: freeldr/winldr/conversion.c
5 * PURPOSE: Physical <-> Virtual addressing mode conversions
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
9 /* INCLUDES ***************************************************************/
13 //#include <ndk/ldrtypes.h>
18 /* FUNCTIONS **************************************************************/
20 /* Arch-specific addresses translation implementation */
24 return (PVOID
)((ULONG_PTR
)Va
& ~KSEG0_BASE
);
30 return (PVOID
)((ULONG_PTR
)Pa
| KSEG0_BASE
);
34 List_PaToVa(LIST_ENTRY
*ListEntry
)
36 LIST_ENTRY
*ListHead
= ListEntry
;
37 LIST_ENTRY
*Next
= ListEntry
->Flink
;
40 //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next);
42 // Walk through the whole list
46 while (Next
!= PaToVa(ListHead
))
48 NextPA
= VaToPa(Next
);
49 //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink);
51 NextPA
->Flink
= PaToVa((PVOID
)NextPA
->Flink
);
52 NextPA
->Blink
= PaToVa((PVOID
)NextPA
->Blink
);
54 //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink);
60 // Finally convert first Flink/Blink
62 ListEntry
->Flink
= PaToVa((PVOID
)ListEntry
->Flink
);
64 ListEntry
->Blink
= PaToVa((PVOID
)ListEntry
->Blink
);
68 // This function converts only Child->Child, and calls itself for each Sibling
70 ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start
)
72 PCONFIGURATION_COMPONENT_DATA Child
;
73 PCONFIGURATION_COMPONENT_DATA Sibling
;
75 DbgPrint((DPRINT_WINDOWS
, "ConvertConfigToVA(Start 0x%X)", Start
));
80 if (Child
->ConfigurationData
)
81 Child
->ConfigurationData
= PaToVa(Child
->ConfigurationData
);
84 Child
->Child
= PaToVa(Child
->Child
);
87 Child
->Parent
= PaToVa(Child
->Parent
);
90 Child
->Sibling
= PaToVa(Child
->Sibling
);
92 DbgPrint((DPRINT_WINDOWS
, "Device 0x%X class %d", Child
, Child
->ComponentEntry
.Class
));
94 // If the child has a sibling list, then search the sibling list
95 // for an entry that matches the specified class, type, and key.
96 Sibling
= Child
->Sibling
;
97 while (Sibling
!= NULL
)
99 if (Sibling
->ConfigurationData
)
100 Sibling
->ConfigurationData
= PaToVa(Sibling
->ConfigurationData
);
103 Sibling
->Child
= PaToVa(Sibling
->Child
);
106 Sibling
->Parent
= PaToVa(Sibling
->Parent
);
108 if (Sibling
->Sibling
)
109 Sibling
->Sibling
= PaToVa(Sibling
->Sibling
);
111 DbgPrint((DPRINT_WINDOWS
, "Device 0x%X class %d", Sibling
, Sibling
->ComponentEntry
.Class
));
113 // If the sibling has a child tree, then search the child tree
114 // for an entry that matches the specified class, type, and key.
115 if (VaToPa(Sibling
->Child
) != NULL
)
116 ConvertConfigToVA(VaToPa(Sibling
->Child
));
118 Sibling
= VaToPa(Sibling
->Sibling
);
121 Child
= VaToPa(Child
->Child
);