vm.c 2.3 KB

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