misc.c 3.1 KB

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