init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. Abstract:
  5. Revision History
  6. --*/
  7. #include "lib.h"
  8. VOID
  9. EFIDebugVariable (
  10. VOID
  11. );
  12. VOID
  13. InitializeLib (
  14. IN EFI_HANDLE ImageHandle,
  15. IN EFI_SYSTEM_TABLE *SystemTable
  16. )
  17. /*++
  18. Routine Description:
  19. Initializes EFI library for use
  20. Arguments:
  21. Firmware's EFI system table
  22. Returns:
  23. None
  24. --*/
  25. {
  26. EFI_LOADED_IMAGE *LoadedImage;
  27. EFI_STATUS Status;
  28. CHAR8 *LangCode;
  29. if (!LibInitialized) {
  30. LibInitialized = TRUE;
  31. LibFwInstance = FALSE;
  32. //
  33. // Set up global pointer to the system table, boot services table,
  34. // and runtime services table
  35. //
  36. ST = SystemTable;
  37. BS = SystemTable->BootServices;
  38. RT = SystemTable->RuntimeServices;
  39. // ASSERT (CheckCrc(0, &ST->Hdr));
  40. // ASSERT (CheckCrc(0, &BS->Hdr));
  41. // ASSERT (CheckCrc(0, &RT->Hdr));
  42. //
  43. // Initialize pool allocation type
  44. //
  45. if (ImageHandle) {
  46. Status = uefi_call_wrapper(
  47. BS->HandleProtocol,
  48. 3,
  49. ImageHandle,
  50. &LoadedImageProtocol,
  51. (VOID*)&LoadedImage
  52. );
  53. if (!EFI_ERROR(Status)) {
  54. PoolAllocationType = LoadedImage->ImageDataType;
  55. }
  56. EFIDebugVariable ();
  57. }
  58. //
  59. // Initialize Guid table
  60. //
  61. InitializeGuid();
  62. InitializeLibPlatform(ImageHandle,SystemTable);
  63. }
  64. //
  65. //
  66. //
  67. if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) {
  68. LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable);
  69. InitializeUnicodeSupport (LangCode);
  70. if (LangCode) {
  71. FreePool (LangCode);
  72. }
  73. }
  74. }
  75. VOID
  76. InitializeUnicodeSupport (
  77. CHAR8 *LangCode
  78. )
  79. {
  80. EFI_UNICODE_COLLATION_INTERFACE *Ui;
  81. EFI_STATUS Status;
  82. CHAR8 *Languages;
  83. UINTN Index, Position, Length;
  84. UINTN NoHandles;
  85. EFI_HANDLE *Handles;
  86. //
  87. // If we don't know it, lookup the current language code
  88. //
  89. LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles);
  90. if (!LangCode || !NoHandles) {
  91. goto Done;
  92. }
  93. //
  94. // Check all driver's for a matching language code
  95. //
  96. for (Index=0; Index < NoHandles; Index++) {
  97. Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui);
  98. if (EFI_ERROR(Status)) {
  99. continue;
  100. }
  101. //
  102. // Check for a matching language code
  103. //
  104. Languages = Ui->SupportedLanguages;
  105. Length = strlena(Languages);
  106. for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) {
  107. //
  108. // If this code matches, use this driver
  109. //
  110. if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) {
  111. UnicodeInterface = Ui;
  112. goto Done;
  113. }
  114. }
  115. }
  116. Done:
  117. //
  118. // Cleanup
  119. //
  120. if (Handles) {
  121. FreePool (Handles);
  122. }
  123. }
  124. VOID
  125. EFIDebugVariable (
  126. VOID
  127. )
  128. {
  129. EFI_STATUS Status;
  130. UINT32 Attributes;
  131. UINTN DataSize;
  132. UINTN NewEFIDebug;
  133. DataSize = sizeof(EFIDebug);
  134. Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug);
  135. if (!EFI_ERROR(Status)) {
  136. EFIDebug = NewEFIDebug;
  137. }
  138. }