init.c 4.0 KB

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