efirtlib.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. EfiRtLib.h
  5. Abstract:
  6. EFI Runtime library functions
  7. Revision History
  8. --*/
  9. #include "efi.h"
  10. #include "efilib.h"
  11. #include "efirtlib.h"
  12. #ifndef __GNUC__
  13. #pragma RUNTIME_CODE(RtZeroMem)
  14. #endif
  15. VOID
  16. RUNTIMEFUNCTION
  17. RtZeroMem (
  18. IN VOID *Buffer,
  19. IN UINTN Size
  20. )
  21. {
  22. INT8 *pt;
  23. pt = Buffer;
  24. while (Size--) {
  25. *(pt++) = 0;
  26. }
  27. }
  28. #ifndef __GNUC__
  29. #pragma RUNTIME_CODE(RtSetMem)
  30. #endif
  31. VOID
  32. RUNTIMEFUNCTION
  33. RtSetMem (
  34. IN VOID *Buffer,
  35. IN UINTN Size,
  36. IN UINT8 Value
  37. )
  38. {
  39. INT8 *pt;
  40. pt = Buffer;
  41. while (Size--) {
  42. *(pt++) = Value;
  43. }
  44. }
  45. #ifndef __GNUC__
  46. #pragma RUNTIME_CODE(RtCopyMem)
  47. #endif
  48. VOID
  49. RUNTIMEFUNCTION
  50. RtCopyMem (
  51. IN VOID *Dest,
  52. IN CONST VOID *Src,
  53. IN UINTN len
  54. )
  55. {
  56. CHAR8 *d = (CHAR8*)Dest;
  57. CHAR8 *s = (CHAR8*)Src;
  58. if (d == NULL || s == NULL || s == d)
  59. return;
  60. // If the beginning of the destination range overlaps with the end of
  61. // the source range, make sure to start the copy from the end so that
  62. // we don't end up overwriting source data that we need for the copy.
  63. if ((d > s) && (d < s + len)) {
  64. for (d += len, s += len; len--; )
  65. *--d = *--s;
  66. } else {
  67. while (len--)
  68. *d++ = *s++;
  69. }
  70. }
  71. #ifndef __GNUC__
  72. #pragma RUNTIME_CODE(RtCompareMem)
  73. #endif
  74. INTN
  75. RUNTIMEFUNCTION
  76. RtCompareMem (
  77. IN CONST VOID *Dest,
  78. IN CONST VOID *Src,
  79. IN UINTN len
  80. )
  81. {
  82. CONST CHAR8 *d = Dest, *s = Src;
  83. while (len--) {
  84. if (*d != *s) {
  85. return *d - *s;
  86. }
  87. d += 1;
  88. s += 1;
  89. }
  90. return 0;
  91. }
  92. #ifndef __GNUC__
  93. #pragma RUNTIME_CODE(RtCompareGuid)
  94. #endif
  95. INTN
  96. RUNTIMEFUNCTION
  97. RtCompareGuid (
  98. IN EFI_GUID *Guid1,
  99. IN EFI_GUID *Guid2
  100. )
  101. /*++
  102. Routine Description:
  103. Compares to GUIDs
  104. Arguments:
  105. Guid1 - guid to compare
  106. Guid2 - guid to compare
  107. Returns:
  108. = 0 if Guid1 == Guid2
  109. --*/
  110. {
  111. INT32 *g1, *g2, r;
  112. //
  113. // Compare 32 bits at a time
  114. //
  115. g1 = (INT32 *) Guid1;
  116. g2 = (INT32 *) Guid2;
  117. r = g1[0] - g2[0];
  118. r |= g1[1] - g2[1];
  119. r |= g1[2] - g2[2];
  120. r |= g1[3] - g2[3];
  121. return r;
  122. }