misc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * misc.c
  4. *
  5. * This is a collection of several routines from gzip-1.0.3
  6. * adapted for Linux.
  7. *
  8. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  9. *
  10. * Modified for ARM Linux by Russell King
  11. *
  12. * Nicolas Pitre <[email protected]> 1999/04/14 :
  13. * For this code to run directly from Flash, all constant variables must
  14. * be marked with 'const' and all other variables initialized at run-time
  15. * only. This way all non constant variables will end up in the bss segment,
  16. * which should point to addresses in RAM and cleared to 0 on start.
  17. * This allows for a much quicker boot time.
  18. */
  19. unsigned int __machine_arch_type;
  20. #include <linux/compiler.h> /* for inline */
  21. #include <linux/types.h>
  22. #include <linux/linkage.h>
  23. #include "misc.h"
  24. #ifdef CONFIG_ARCH_EP93XX
  25. #include "misc-ep93xx.h"
  26. #endif
  27. static void putstr(const char *ptr);
  28. #include CONFIG_UNCOMPRESS_INCLUDE
  29. #ifdef CONFIG_DEBUG_ICEDCC
  30. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  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_XSCALE)
  42. static void icedcc_putc(int ch)
  43. {
  44. int status, i = 0x4000000;
  45. do {
  46. if (--i < 0)
  47. return;
  48. asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
  49. } while (status & (1 << 28));
  50. asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
  51. }
  52. #else
  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, c0, c0, 0" : "=r" (status));
  60. } while (status & 2);
  61. asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
  62. }
  63. #endif
  64. #define putc(ch) icedcc_putc(ch)
  65. #endif
  66. static void putstr(const char *ptr)
  67. {
  68. char c;
  69. while ((c = *ptr++) != '\0') {
  70. if (c == '\n')
  71. putc('\r');
  72. putc(c);
  73. }
  74. flush();
  75. }
  76. /*
  77. * gzip declarations
  78. */
  79. extern char input_data[];
  80. extern char input_data_end[];
  81. unsigned char *output_data;
  82. unsigned long free_mem_ptr;
  83. unsigned long free_mem_end_ptr;
  84. #ifndef arch_error
  85. #define arch_error(x)
  86. #endif
  87. void error(char *x)
  88. {
  89. arch_error(x);
  90. putstr("\n\n");
  91. putstr(x);
  92. putstr("\n\n -- System halted");
  93. while(1); /* Halt */
  94. }
  95. asmlinkage void __div0(void)
  96. {
  97. error("Attempting division by 0!");
  98. }
  99. extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
  100. void
  101. decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
  102. unsigned long free_mem_ptr_end_p,
  103. int arch_id)
  104. {
  105. int ret;
  106. output_data = (unsigned char *)output_start;
  107. free_mem_ptr = free_mem_ptr_p;
  108. free_mem_end_ptr = free_mem_ptr_end_p;
  109. __machine_arch_type = arch_id;
  110. #ifdef CONFIG_ARCH_EP93XX
  111. ep93xx_decomp_setup();
  112. #endif
  113. arch_decomp_setup();
  114. putstr("Uncompressing Linux...");
  115. ret = do_decompress(input_data, input_data_end - input_data,
  116. output_data, error);
  117. if (ret)
  118. error("decompressor returned an error");
  119. else
  120. putstr(" done, booting the kernel.\n");
  121. }
  122. void fortify_panic(const char *name)
  123. {
  124. error("detected buffer overflow");
  125. }