misc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/unicore32/boot/compressed/misc.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <asm/unaligned.h>
  13. #include <mach/uncompress.h>
  14. /*
  15. * gzip delarations
  16. */
  17. unsigned char *output_data;
  18. unsigned long output_ptr;
  19. unsigned int free_mem_ptr;
  20. unsigned int free_mem_end_ptr;
  21. #define STATIC static
  22. #define STATIC_RW_DATA /* non-static please */
  23. /*
  24. * arch-dependent implementations
  25. */
  26. #ifndef ARCH_HAVE_DECOMP_ERROR
  27. #define arch_decomp_error(x)
  28. #endif
  29. #ifndef ARCH_HAVE_DECOMP_SETUP
  30. #define arch_decomp_setup()
  31. #endif
  32. #ifndef ARCH_HAVE_DECOMP_PUTS
  33. #define arch_decomp_puts(p)
  34. #endif
  35. void *memcpy(void *dest, const void *src, size_t n)
  36. {
  37. int i = 0;
  38. unsigned char *d = (unsigned char *)dest, *s = (unsigned char *)src;
  39. for (i = n >> 3; i > 0; i--) {
  40. *d++ = *s++;
  41. *d++ = *s++;
  42. *d++ = *s++;
  43. *d++ = *s++;
  44. *d++ = *s++;
  45. *d++ = *s++;
  46. *d++ = *s++;
  47. *d++ = *s++;
  48. }
  49. if (n & 1 << 2) {
  50. *d++ = *s++;
  51. *d++ = *s++;
  52. *d++ = *s++;
  53. *d++ = *s++;
  54. }
  55. if (n & 1 << 1) {
  56. *d++ = *s++;
  57. *d++ = *s++;
  58. }
  59. if (n & 1)
  60. *d++ = *s++;
  61. return dest;
  62. }
  63. void error(char *x)
  64. {
  65. arch_decomp_puts("\n\n");
  66. arch_decomp_puts(x);
  67. arch_decomp_puts("\n\n -- System halted");
  68. arch_decomp_error(x);
  69. for (;;)
  70. ; /* Halt */
  71. }
  72. /* Heap size should be adjusted for different decompress method */
  73. #ifdef CONFIG_KERNEL_GZIP
  74. #include "../../../../lib/decompress_inflate.c"
  75. #endif
  76. #ifdef CONFIG_KERNEL_BZIP2
  77. #include "../../../../lib/decompress_bunzip2.c"
  78. #endif
  79. #ifdef CONFIG_KERNEL_LZO
  80. #include "../../../../lib/decompress_unlzo.c"
  81. #endif
  82. #ifdef CONFIG_KERNEL_LZMA
  83. #include "../../../../lib/decompress_unlzma.c"
  84. #endif
  85. unsigned long decompress_kernel(unsigned long output_start,
  86. unsigned long free_mem_ptr_p,
  87. unsigned long free_mem_ptr_end_p)
  88. {
  89. unsigned char *tmp;
  90. output_data = (unsigned char *)output_start;
  91. free_mem_ptr = free_mem_ptr_p;
  92. free_mem_end_ptr = free_mem_ptr_end_p;
  93. arch_decomp_setup();
  94. tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
  95. output_ptr = get_unaligned_le32(tmp);
  96. arch_decomp_puts("Uncompressing Linux...");
  97. decompress(input_data, input_data_end - input_data, NULL, NULL,
  98. output_data, NULL, error);
  99. arch_decomp_puts(" done, booting the kernel.\n");
  100. return output_ptr;
  101. }