minilib.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include <grub/types.h>
  19. #include <grub/misc.h>
  20. #include <grub/decompressor.h>
  21. void *
  22. grub_memset (void *s, int c, grub_size_t len)
  23. {
  24. grub_uint8_t *ptr;
  25. for (ptr = s; len; ptr++, len--)
  26. *ptr = c;
  27. return s;
  28. }
  29. void *
  30. grub_memmove (void *dest, const void *src, grub_size_t n)
  31. {
  32. char *d = (char *) dest;
  33. const char *s = (const char *) src;
  34. if (d < s)
  35. while (n--)
  36. *d++ = *s++;
  37. else
  38. {
  39. d += n;
  40. s += n;
  41. while (n--)
  42. *--d = *--s;
  43. }
  44. return dest;
  45. }
  46. int
  47. grub_memcmp (const void *s1, const void *s2, grub_size_t n)
  48. {
  49. const unsigned char *t1 = s1;
  50. const unsigned char *t2 = s2;
  51. while (n--)
  52. {
  53. if (*t1 != *t2)
  54. return (int) *t1 - (int) *t2;
  55. t1++;
  56. t2++;
  57. }
  58. return 0;
  59. }
  60. void *grub_decompressor_scratch;
  61. void
  62. find_scratch (void *src, void *dst, unsigned long srcsize,
  63. unsigned long dstsize)
  64. {
  65. #ifdef _mips
  66. /* Decoding from ROM. */
  67. if (((grub_addr_t) src & 0x10000000))
  68. {
  69. grub_decompressor_scratch = (void *) ALIGN_UP((grub_addr_t) dst + dstsize,
  70. 256);
  71. return;
  72. }
  73. #endif
  74. if ((char *) src + srcsize > (char *) dst + dstsize)
  75. grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) src + srcsize,
  76. 256);
  77. else
  78. grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) dst + dstsize,
  79. 256);
  80. return;
  81. }