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