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>
16 /* FUNCTIONS **************************************************************/
18 /* Arch-specific addresses translation implementation */
22 return (PVOID
)((ULONG_PTR
)Va
& ~KSEG0_BASE
);
28 return (PVOID
)((ULONG_PTR
)Pa
| KSEG0_BASE
);
32 List_PaToVa(LIST_ENTRY
*ListEntry
)
34 LIST_ENTRY
*ListHead
= ListEntry
;
35 LIST_ENTRY
*Next
= ListEntry
->Flink
;
38 //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next);
40 // Walk through the whole list
44 while (Next
!= PaToVa(ListHead
))
46 NextPA
= VaToPa(Next
);
47 //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink);
49 NextPA
->Flink
= PaToVa((PVOID
)NextPA
->Flink
);
50 NextPA
->Blink
= PaToVa((PVOID
)NextPA
->Blink
);
52 //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink);
58 // Finally convert first Flink/Blink
60 ListEntry
->Flink
= PaToVa((PVOID
)ListEntry
->Flink
);
62 ListEntry
->Blink
= PaToVa((PVOID
)ListEntry
->Blink
);
66 // This function converts only Child->Child, and calls itself for each Sibling
68 ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start
)
70 PCONFIGURATION_COMPONENT_DATA Child
;
71 PCONFIGURATION_COMPONENT_DATA Sibling
;
73 DbgPrint((DPRINT_WINDOWS
, "ConvertConfigToVA(Start 0x%X)\n", Start
));
78 if (Child
->ConfigurationData
)
79 Child
->ConfigurationData
= PaToVa(Child
->ConfigurationData
);
82 Child
->Child
= PaToVa(Child
->Child
);
85 Child
->Parent
= PaToVa(Child
->Parent
);
88 Child
->Sibling
= PaToVa(Child
->Sibling
);
90 if (Child
->ComponentEntry
.Identifier
)
91 Child
->ComponentEntry
.Identifier
= PaToVa(Child
->ComponentEntry
.Identifier
);
93 DbgPrint((DPRINT_WINDOWS
, "Device 0x%X class %d type %d id '%s', parent %p\n", Child
,
94 Child
->ComponentEntry
.Class
, Child
->ComponentEntry
.Type
, VaToPa(Child
->ComponentEntry
.Identifier
), Child
->Parent
));
96 // Go through siblings list
97 Sibling
= VaToPa(Child
->Sibling
);
98 while (Sibling
!= NULL
)
100 if (Sibling
->ConfigurationData
)
101 Sibling
->ConfigurationData
= PaToVa(Sibling
->ConfigurationData
);
104 Sibling
->Child
= PaToVa(Sibling
->Child
);
107 Sibling
->Parent
= PaToVa(Sibling
->Parent
);
109 if (Sibling
->Sibling
)
110 Sibling
->Sibling
= PaToVa(Sibling
->Sibling
);
112 if (Sibling
->ComponentEntry
.Identifier
)
113 Sibling
->ComponentEntry
.Identifier
= PaToVa(Sibling
->ComponentEntry
.Identifier
);
115 DbgPrint((DPRINT_WINDOWS
, "Device 0x%X class %d type %d id '%s', parent %p\n", Sibling
,
116 Sibling
->ComponentEntry
.Class
, Sibling
->ComponentEntry
.Type
, VaToPa(Sibling
->ComponentEntry
.Identifier
), Sibling
->Parent
));
118 // Recurse into the Child tree
119 if (VaToPa(Sibling
->Child
) != NULL
)
120 ConvertConfigToVA(VaToPa(Sibling
->Child
));
122 Sibling
= VaToPa(Sibling
->Sibling
);
125 // Go to the next child
126 Child
= VaToPa(Child
->Child
);