misc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/boot/compressed/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. * Adapted for SH by Stuart Menefy, Aug 1999
  11. *
  12. * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
  13. */
  14. #include <linux/uaccess.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/page.h>
  17. /*
  18. * gzip declarations
  19. */
  20. #define STATIC static
  21. #undef memset
  22. #undef memcpy
  23. #define memzero(s, n) memset ((s), 0, (n))
  24. /* cache.c */
  25. #define CACHE_ENABLE 0
  26. #define CACHE_DISABLE 1
  27. int cache_control(unsigned int command);
  28. extern char input_data[];
  29. extern int input_len;
  30. static unsigned char *output;
  31. static void error(char *m);
  32. int puts(const char *);
  33. extern int _text; /* Defined in vmlinux.lds.S */
  34. extern int _end;
  35. static unsigned long free_mem_ptr;
  36. static unsigned long free_mem_end_ptr;
  37. #ifdef CONFIG_HAVE_KERNEL_BZIP2
  38. #define HEAP_SIZE 0x400000
  39. #else
  40. #define HEAP_SIZE 0x10000
  41. #endif
  42. #ifdef CONFIG_KERNEL_GZIP
  43. #include "../../../../lib/decompress_inflate.c"
  44. #endif
  45. #ifdef CONFIG_KERNEL_BZIP2
  46. #include "../../../../lib/decompress_bunzip2.c"
  47. #endif
  48. #ifdef CONFIG_KERNEL_LZMA
  49. #include "../../../../lib/decompress_unlzma.c"
  50. #endif
  51. #ifdef CONFIG_KERNEL_XZ
  52. #include "../../../../lib/decompress_unxz.c"
  53. #endif
  54. #ifdef CONFIG_KERNEL_LZO
  55. #include "../../../../lib/decompress_unlzo.c"
  56. #endif
  57. int puts(const char *s)
  58. {
  59. /* This should be updated to use the sh-sci routines */
  60. return 0;
  61. }
  62. void* memset(void* s, int c, size_t n)
  63. {
  64. int i;
  65. char *ss = (char*)s;
  66. for (i=0;i<n;i++) ss[i] = c;
  67. return s;
  68. }
  69. void* memcpy(void* __dest, __const void* __src,
  70. size_t __n)
  71. {
  72. int i;
  73. char *d = (char *)__dest, *s = (char *)__src;
  74. for (i=0;i<__n;i++) d[i] = s[i];
  75. return __dest;
  76. }
  77. static void error(char *x)
  78. {
  79. puts("\n\n");
  80. puts(x);
  81. puts("\n\n -- System halted");
  82. while(1); /* Halt */
  83. }
  84. const unsigned long __stack_chk_guard = 0x000a0dff;
  85. void __stack_chk_fail(void)
  86. {
  87. error("stack-protector: Kernel stack is corrupted\n");
  88. }
  89. #ifdef CONFIG_SUPERH64
  90. #define stackalign 8
  91. #else
  92. #define stackalign 4
  93. #endif
  94. #define STACK_SIZE (4096)
  95. long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
  96. long *stack_start = &user_stack[STACK_SIZE];
  97. void decompress_kernel(void)
  98. {
  99. unsigned long output_addr;
  100. #ifdef CONFIG_SUPERH64
  101. output_addr = (CONFIG_MEMORY_START + 0x2000);
  102. #else
  103. output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
  104. #if defined(CONFIG_29BIT)
  105. output_addr |= P2SEG;
  106. #endif
  107. #endif
  108. output = (unsigned char *)output_addr;
  109. free_mem_ptr = (unsigned long)&_end;
  110. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  111. puts("Uncompressing Linux... ");
  112. cache_control(CACHE_ENABLE);
  113. __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
  114. cache_control(CACHE_DISABLE);
  115. puts("Ok, booting the kernel.\n");
  116. }