misc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include <linux/compiler.h> /* for inline */
  20. #include <linux/types.h>
  21. #include <linux/linkage.h>
  22. static void putstr(const char *ptr);
  23. extern void error(char *x);
  24. #ifdef CONFIG_ARCH_MULTIPLATFORM
  25. static inline void putc(int c) {}
  26. static inline void flush(void) {}
  27. static inline void arch_decomp_setup(void) {}
  28. #else
  29. #include <mach/uncompress.h>
  30. #endif
  31. #ifdef CONFIG_DEBUG_ICEDCC
  32. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  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_XSCALE)
  44. static void icedcc_putc(int ch)
  45. {
  46. int status, i = 0x4000000;
  47. do {
  48. if (--i < 0)
  49. return;
  50. asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
  51. } while (status & (1 << 28));
  52. asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
  53. }
  54. #else
  55. static void icedcc_putc(int ch)
  56. {
  57. int status, i = 0x4000000;
  58. do {
  59. if (--i < 0)
  60. return;
  61. asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
  62. } while (status & 2);
  63. asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
  64. }
  65. #endif
  66. #define putc(ch) icedcc_putc(ch)
  67. #endif
  68. static void putstr(const char *ptr)
  69. {
  70. char c;
  71. while ((c = *ptr++) != '\0') {
  72. if (c == '\n')
  73. putc('\r');
  74. putc(c);
  75. }
  76. flush();
  77. }
  78. /*
  79. * gzip declarations
  80. */
  81. extern char input_data[];
  82. extern char input_data_end[];
  83. unsigned char *output_data;
  84. unsigned long free_mem_ptr;
  85. unsigned long free_mem_end_ptr;
  86. #ifndef arch_error
  87. #define arch_error(x)
  88. #endif
  89. void error(char *x)
  90. {
  91. arch_error(x);
  92. putstr("\n\n");
  93. putstr(x);
  94. putstr("\n\n -- System halted");
  95. while(1); /* Halt */
  96. }
  97. asmlinkage void __div0(void)
  98. {
  99. error("Attempting division by 0!");
  100. }
  101. extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
  102. void
  103. decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
  104. unsigned long free_mem_ptr_end_p,
  105. int arch_id)
  106. {
  107. int ret;
  108. output_data = (unsigned char *)output_start;
  109. free_mem_ptr = free_mem_ptr_p;
  110. free_mem_end_ptr = free_mem_ptr_end_p;
  111. __machine_arch_type = arch_id;
  112. arch_decomp_setup();
  113. putstr("Uncompressing Linux...");
  114. ret = do_decompress(input_data, input_data_end - input_data,
  115. output_data, error);
  116. if (ret)
  117. error("decompressor returned an error");
  118. else
  119. putstr(" done, booting the kernel.\n");
  120. }