misc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <nico@visuaide.com> 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. static void putstr(const char *ptr);
  25. #include CONFIG_UNCOMPRESS_INCLUDE
  26. #ifdef CONFIG_DEBUG_ICEDCC
  27. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  28. static void icedcc_putc(int ch)
  29. {
  30. int status, i = 0x4000000;
  31. do {
  32. if (--i < 0)
  33. return;
  34. asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
  35. } while (status & (1 << 29));
  36. asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
  37. }
  38. #elif defined(CONFIG_CPU_XSCALE)
  39. static void icedcc_putc(int ch)
  40. {
  41. int status, i = 0x4000000;
  42. do {
  43. if (--i < 0)
  44. return;
  45. asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
  46. } while (status & (1 << 28));
  47. asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
  48. }
  49. #else
  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, c0, c0, 0" : "=r" (status));
  57. } while (status & 2);
  58. asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
  59. }
  60. #endif
  61. #define putc(ch) icedcc_putc(ch)
  62. #endif
  63. static void putstr(const char *ptr)
  64. {
  65. char c;
  66. while ((c = *ptr++) != '\0') {
  67. if (c == '\n')
  68. putc('\r');
  69. putc(c);
  70. }
  71. flush();
  72. }
  73. /*
  74. * gzip declarations
  75. */
  76. extern char input_data[];
  77. extern char input_data_end[];
  78. unsigned char *output_data;
  79. unsigned long free_mem_ptr;
  80. unsigned long free_mem_end_ptr;
  81. #ifndef arch_error
  82. #define arch_error(x)
  83. #endif
  84. void error(char *x)
  85. {
  86. arch_error(x);
  87. putstr("\n\n");
  88. putstr(x);
  89. putstr("\n\n -- System halted");
  90. while(1); /* Halt */
  91. }
  92. asmlinkage void __div0(void)
  93. {
  94. error("Attempting division by 0!");
  95. }
  96. const unsigned long __stack_chk_guard = 0x000a0dff;
  97. void __stack_chk_fail(void)
  98. {
  99. error("stack-protector: Kernel stack is corrupted\n");
  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. }
  121. void fortify_panic(const char *name)
  122. {
  123. error("detected buffer overflow");
  124. }