init.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. LibImageHandle = ImageHandle;
  33. //
  34. // Set up global pointer to the system table, boot services table,
  35. // and runtime services table
  36. //
  37. ST = SystemTable;
  38. BS = SystemTable->BootServices;
  39. RT = SystemTable->RuntimeServices;
  40. // ASSERT (CheckCrc(0, &ST->Hdr));
  41. // ASSERT (CheckCrc(0, &BS->Hdr));
  42. // ASSERT (CheckCrc(0, &RT->Hdr));
  43. //
  44. // Initialize pool allocation type
  45. //
  46. if (ImageHandle) {
  47. Status = uefi_call_wrapper(
  48. BS->HandleProtocol,
  49. 3,
  50. ImageHandle,
  51. &LoadedImageProtocol,
  52. (VOID*)&LoadedImage
  53. );
  54. if (!EFI_ERROR(Status)) {
  55. PoolAllocationType = LoadedImage->ImageDataType;
  56. }
  57. EFIDebugVariable ();
  58. }
  59. //
  60. // Initialize Guid table
  61. //
  62. InitializeGuid();
  63. InitializeLibPlatform(ImageHandle,SystemTable);
  64. }
  65. //
  66. //
  67. //
  68. if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) {
  69. LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable);
  70. InitializeUnicodeSupport (LangCode);
  71. if (LangCode) {
  72. FreePool (LangCode);
  73. }
  74. }
  75. }
  76. VOID
  77. InitializeUnicodeSupport (
  78. CHAR8 *LangCode
  79. )
  80. {
  81. EFI_UNICODE_COLLATION_INTERFACE *Ui;
  82. EFI_STATUS Status;
  83. CHAR8 *Languages;
  84. UINTN Index, Position, Length;
  85. UINTN NoHandles;
  86. EFI_HANDLE *Handles;
  87. //
  88. // If we don't know it, lookup the current language code
  89. //
  90. LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles);
  91. if (!LangCode || !NoHandles) {
  92. goto Done;
  93. }
  94. //
  95. // Check all driver's for a matching language code
  96. //
  97. for (Index=0; Index < NoHandles; Index++) {
  98. Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui);
  99. if (EFI_ERROR(Status)) {
  100. continue;
  101. }
  102. //
  103. // Check for a matching language code
  104. //
  105. Languages = Ui->SupportedLanguages;
  106. Length = strlena(Languages);
  107. for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) {
  108. //
  109. // If this code matches, use this driver
  110. //
  111. if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) {
  112. UnicodeInterface = Ui;
  113. goto Done;
  114. }
  115. }
  116. }
  117. Done:
  118. //
  119. // Cleanup
  120. //
  121. if (Handles) {
  122. FreePool (Handles);
  123. }
  124. }
  125. VOID
  126. EFIDebugVariable (
  127. VOID
  128. )
  129. {
  130. EFI_STATUS Status;
  131. UINT32 Attributes;
  132. UINTN DataSize;
  133. UINTN NewEFIDebug;
  134. DataSize = sizeof(EFIDebug);
  135. Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug);
  136. if (!EFI_ERROR(Status)) {
  137. EFIDebug = NewEFIDebug;
  138. }
  139. }
  140. /*
  141. * Calls to memset/memcpy may be emitted implicitly by GCC or MSVC
  142. * even when -ffreestanding or /NODEFAULTLIB are in effect.
  143. */
  144. #ifndef __SIZE_TYPE__
  145. #define __SIZE_TYPE__ UINTN
  146. #endif
  147. void *memset(void *s, int c, __SIZE_TYPE__ n)
  148. {
  149. unsigned char *p = s;
  150. while (n--)
  151. *p++ = c;
  152. return s;
  153. }
  154. void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
  155. {
  156. const unsigned char *q = src;
  157. unsigned char *p = dest;
  158. while (n--)
  159. *p++ = *q++;
  160. return dest;
  161. }