Debian Codegraph @

grub-core/boot/decompressor/minilib.c

raw
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <grub/types.h>
20 #include <grub/misc.h>
21 #include <grub/decompressor.h>
22
23 void *
24 grub_memset (void *s, int c, grub_size_t len)
25 {
26 grub_uint8_t *ptr;
27 for (ptr = s; len; ptr++, len--)
28 *ptr = c;
29 return s;
30 }
31
32 void *
33 grub_memmove (void *dest, const void *src, grub_size_t n)
34 {
35 char *d = (char *) dest;
36 const char *s = (const char *) src;
37
38 if (d < s)
39 while (n--)
40 *d++ = *s++;
41 else
42 {
43 d += n;
44 s += n;
45
46 while (n--)
47 *--d = *--s;
48 }
49
50 return dest;
51 }
52
53 void *
54 grub_memcpy (void *dest, const void *src, grub_size_t n)
55 {
56 return grub_memmove (dest, src, n);
57 }
58
59 int
60 grub_memcmp (const void *s1, const void *s2, grub_size_t n)
61 {
62 const unsigned char *t1 = s1;
63 const unsigned char *t2 = s2;
64
65 while (n--)
66 {
67 if (*t1 != *t2)
68 return (int) *t1 - (int) *t2;
69
70 t1++;
71 t2++;
72 }
73
74 return 0;
75 }
76
77 void *grub_decompressor_scratch;
78
79 void
80 find_scratch (void *src, void *dst, unsigned long srcsize,
81 unsigned long dstsize)
82 {
83 #ifdef _mips
84 /* Decoding from ROM. */
85 if (((grub_addr_t) src & 0x10000000))
86 {
87 grub_decompressor_scratch = (void *) ALIGN_UP((grub_addr_t) dst + dstsize,
88 256);
89 return;
90 }
91 #endif
92 if ((char *) src + srcsize > (char *) dst + dstsize)
93 grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) src + srcsize,
94 256);
95 else
96 grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) dst + dstsize,
97 256);
98 return;
99 }