Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.4 KiB

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