misc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #include <mach/uncompress.h>
  31. #ifdef CONFIG_DEBUG_ICEDCC
  32. #ifdef CONFIG_CPU_V6
  33. static void icedcc_putc(int ch)
  34. {
  35. int status, i = 0x4000000;
  36. do {
  37. if (--i < 0)
  38. return;
  39. asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
  40. } while (status & (1 << 29));
  41. asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
  42. }
  43. #elif defined(CONFIG_CPU_V7)
  44. static void icedcc_putc(int ch)
  45. {
  46. asm(
  47. "wait: mrc p14, 0, pc, c0, c1, 0 \n\
  48. bcs wait \n\
  49. mcr p14, 0, %0, c0, c5, 0 "
  50. : : "r" (ch));
  51. }
  52. #elif defined(CONFIG_CPU_XSCALE)
  53. static void icedcc_putc(int ch)
  54. {
  55. int status, i = 0x4000000;
  56. do {
  57. if (--i < 0)
  58. return;
  59. asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
  60. } while (status & (1 << 28));
  61. asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
  62. }
  63. #else
  64. static void icedcc_putc(int ch)
  65. {
  66. int status, i = 0x4000000;
  67. do {
  68. if (--i < 0)
  69. return;
  70. asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
  71. } while (status & 2);
  72. asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
  73. }
  74. #endif
  75. #define putc(ch) icedcc_putc(ch)
  76. #endif
  77. static void putstr(const char *ptr)
  78. {
  79. char c;
  80. while ((c = *ptr++) != '\0') {
  81. if (c == '\n')
  82. putc('\r');
  83. putc(c);
  84. }
  85. flush();
  86. }
  87. #endif
  88. void *memcpy(void *__dest, __const void *__src, size_t __n)
  89. {
  90. int i = 0;
  91. unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
  92. for (i = __n >> 3; i > 0; i--) {
  93. *d++ = *s++;
  94. *d++ = *s++;
  95. *d++ = *s++;
  96. *d++ = *s++;
  97. *d++ = *s++;
  98. *d++ = *s++;
  99. *d++ = *s++;
  100. *d++ = *s++;
  101. }
  102. if (__n & 1 << 2) {
  103. *d++ = *s++;
  104. *d++ = *s++;
  105. *d++ = *s++;
  106. *d++ = *s++;
  107. }
  108. if (__n & 1 << 1) {
  109. *d++ = *s++;
  110. *d++ = *s++;
  111. }
  112. if (__n & 1)
  113. *d++ = *s++;
  114. return __dest;
  115. }
  116. /*
  117. * gzip delarations
  118. */
  119. extern char input_data[];
  120. extern char input_data_end[];
  121. unsigned char *output_data;
  122. unsigned long output_ptr;
  123. unsigned long free_mem_ptr;
  124. unsigned long free_mem_end_ptr;
  125. #ifndef arch_error
  126. #define arch_error(x)
  127. #endif
  128. void error(char *x)
  129. {
  130. arch_error(x);
  131. putstr("\n\n");
  132. putstr(x);
  133. putstr("\n\n -- System halted");
  134. while(1); /* Halt */
  135. }
  136. asmlinkage void __div0(void)
  137. {
  138. error("Attempting division by 0!");
  139. }
  140. extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
  141. #ifndef STANDALONE_DEBUG
  142. unsigned long
  143. decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
  144. unsigned long free_mem_ptr_end_p,
  145. int arch_id)
  146. {
  147. unsigned char *tmp;
  148. output_data = (unsigned char *)output_start;
  149. free_mem_ptr = free_mem_ptr_p;
  150. free_mem_end_ptr = free_mem_ptr_end_p;
  151. __machine_arch_type = arch_id;
  152. arch_decomp_setup();
  153. tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
  154. output_ptr = get_unaligned_le32(tmp);
  155. putstr("Uncompressing Linux...");
  156. do_decompress(input_data, input_data_end - input_data,
  157. output_data, error);
  158. putstr(" done, booting the kernel.\n");
  159. return output_ptr;
  160. }
  161. #else
  162. char output_buffer[1500*1024];
  163. int main()
  164. {
  165. output_data = output_buffer;
  166. putstr("Uncompressing Linux...");
  167. decompress(input_data, input_data_end - input_data,
  168. NULL, NULL, output_data, NULL, error);
  169. putstr("done.\n");
  170. return 0;
  171. }
  172. #endif