misc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * misc.c
  3. *
  4. * This is a collection of several routines from gzip-1.0.3
  5. * adapted for Linux.
  6. *
  7. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  8. *
  9. * Modified for ARM Linux by Russell King
  10. *
  11. * Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
  12. * For this code to run directly from Flash, all constant variables must
  13. * be marked with 'const' and all other variables initialized at run-time
  14. * only. This way all non constant variables will end up in the bss segment,
  15. * which should point to addresses in RAM and cleared to 0 on start.
  16. * This allows for a much quicker boot time.
  17. */
  18. unsigned int __machine_arch_type;
  19. #define _LINUX_STRING_H_
  20. #include <linux/compiler.h> /* for inline */
  21. #include <linux/types.h> /* for size_t */
  22. #include <linux/stddef.h> /* for NULL */
  23. #include <linux/linkage.h>
  24. #include <asm/string.h>
  25. #include <asm/unaligned.h>
  26. #ifdef STANDALONE_DEBUG
  27. #define putstr printf
  28. #else
  29. static void putstr(const char *ptr);
  30. extern void error(char *x);
  31. #include <mach/uncompress.h>
  32. #ifdef CONFIG_DEBUG_ICEDCC
  33. #ifdef CONFIG_CPU_V6
  34. static void icedcc_putc(int ch)
  35. {
  36. int status, i = 0x4000000;
  37. do {
  38. if (--i < 0)
  39. return;
  40. asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
  41. } while (status & (1 << 29));
  42. asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
  43. }
  44. #elif defined(CONFIG_CPU_V7)
  45. static void icedcc_putc(int ch)
  46. {
  47. asm(
  48. "wait: mrc p14, 0, pc, c0, c1, 0 \n\
  49. bcs wait \n\
  50. mcr p14, 0, %0, c0, c5, 0 "
  51. : : "r" (ch));
  52. }
  53. #elif defined(CONFIG_CPU_XSCALE)
  54. static void icedcc_putc(int ch)
  55. {
  56. int status, i = 0x4000000;
  57. do {
  58. if (--i < 0)
  59. return;
  60. asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
  61. } while (status & (1 << 28));
  62. asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
  63. }
  64. #else
  65. static void icedcc_putc(int ch)
  66. {
  67. int status, i = 0x4000000;
  68. do {
  69. if (--i < 0)
  70. return;
  71. asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
  72. } while (status & 2);
  73. asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
  74. }
  75. #endif
  76. #define putc(ch) icedcc_putc(ch)
  77. #endif
  78. static void putstr(const char *ptr)
  79. {
  80. char c;
  81. while ((c = *ptr++) != '\0') {
  82. if (c == '\n')
  83. putc('\r');
  84. putc(c);
  85. }
  86. flush();
  87. }
  88. #endif
  89. void *memcpy(void *__dest, __const void *__src, size_t __n)
  90. {
  91. int i = 0;
  92. unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
  93. for (i = __n >> 3; i > 0; i--) {
  94. *d++ = *s++;
  95. *d++ = *s++;
  96. *d++ = *s++;
  97. *d++ = *s++;
  98. *d++ = *s++;
  99. *d++ = *s++;
  100. *d++ = *s++;
  101. *d++ = *s++;
  102. }
  103. if (__n & 1 << 2) {
  104. *d++ = *s++;
  105. *d++ = *s++;
  106. *d++ = *s++;
  107. *d++ = *s++;
  108. }
  109. if (__n & 1 << 1) {
  110. *d++ = *s++;
  111. *d++ = *s++;
  112. }
  113. if (__n & 1)
  114. *d++ = *s++;
  115. return __dest;
  116. }
  117. /*
  118. * gzip delarations
  119. */
  120. extern char input_data[];
  121. extern char input_data_end[];
  122. unsigned char *output_data;
  123. unsigned long output_ptr;
  124. unsigned long free_mem_ptr;
  125. unsigned long free_mem_end_ptr;
  126. #ifndef arch_error
  127. #define arch_error(x)
  128. #endif
  129. void error(char *x)
  130. {
  131. arch_error(x);
  132. putstr("\n\n");
  133. putstr(x);
  134. putstr("\n\n -- System halted");
  135. while(1); /* Halt */
  136. }
  137. asmlinkage void __div0(void)
  138. {
  139. error("Attempting division by 0!");
  140. }
  141. extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
  142. #ifndef STANDALONE_DEBUG
  143. unsigned long
  144. decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
  145. unsigned long free_mem_ptr_end_p,
  146. int arch_id)
  147. {
  148. unsigned char *tmp;
  149. output_data = (unsigned char *)output_start;
  150. free_mem_ptr = free_mem_ptr_p;
  151. free_mem_end_ptr = free_mem_ptr_end_p;
  152. __machine_arch_type = arch_id;
  153. arch_decomp_setup();
  154. tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
  155. output_ptr = get_unaligned_le32(tmp);
  156. putstr("Uncompressing Linux...");
  157. do_decompress(input_data, input_data_end - input_data,
  158. output_data, error);
  159. putstr(" done, booting the kernel.\n");
  160. return output_ptr;
  161. }
  162. #else
  163. char output_buffer[1500*1024];
  164. int main()
  165. {
  166. output_data = output_buffer;
  167. putstr("Uncompressing Linux...");
  168. decompress(input_data, input_data_end - input_data,
  169. NULL, NULL, output_data, NULL, error);
  170. putstr("done.\n");
  171. return 0;
  172. }
  173. #endif