misc.c 3.6 KB

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