misc.c 3.7 KB

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