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