misc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include "misc.h"
  18. /*
  19. * gzip declarations
  20. */
  21. #define STATIC static
  22. #undef memset
  23. #undef memcpy
  24. #define memzero(s, n) memset ((s), 0, (n))
  25. extern char input_data[];
  26. extern int input_len;
  27. static unsigned char *output;
  28. static void error(char *m);
  29. int puts(const char *);
  30. extern int _text; /* Defined in vmlinux.lds.S */
  31. extern int _end;
  32. static unsigned long free_mem_ptr;
  33. static unsigned long free_mem_end_ptr;
  34. #ifdef CONFIG_HAVE_KERNEL_BZIP2
  35. #define HEAP_SIZE 0x400000
  36. #else
  37. #define HEAP_SIZE 0x10000
  38. #endif
  39. #ifdef CONFIG_KERNEL_GZIP
  40. #include "../../../../lib/decompress_inflate.c"
  41. #endif
  42. #ifdef CONFIG_KERNEL_BZIP2
  43. #include "../../../../lib/decompress_bunzip2.c"
  44. #endif
  45. #ifdef CONFIG_KERNEL_LZMA
  46. #include "../../../../lib/decompress_unlzma.c"
  47. #endif
  48. #ifdef CONFIG_KERNEL_XZ
  49. #include "../../../../lib/decompress_unxz.c"
  50. #endif
  51. #ifdef CONFIG_KERNEL_LZO
  52. #include "../../../../lib/decompress_unlzo.c"
  53. #endif
  54. int puts(const char *s)
  55. {
  56. /* This should be updated to use the sh-sci routines */
  57. return 0;
  58. }
  59. void* memset(void* s, int c, size_t n)
  60. {
  61. int i;
  62. char *ss = (char*)s;
  63. for (i=0;i<n;i++) ss[i] = c;
  64. return s;
  65. }
  66. void* memcpy(void* __dest, __const void* __src,
  67. size_t __n)
  68. {
  69. int i;
  70. char *d = (char *)__dest, *s = (char *)__src;
  71. for (i=0;i<__n;i++) d[i] = s[i];
  72. return __dest;
  73. }
  74. static void error(char *x)
  75. {
  76. puts("\n\n");
  77. puts(x);
  78. puts("\n\n -- System halted");
  79. while(1); /* Halt */
  80. }
  81. const unsigned long __stack_chk_guard = 0x000a0dff;
  82. void __stack_chk_fail(void)
  83. {
  84. error("stack-protector: Kernel stack is corrupted\n");
  85. }
  86. /* Needed because vmlinux.lds.h references this */
  87. void ftrace_stub(void)
  88. {
  89. }
  90. void arch_ftrace_ops_list_func(void)
  91. {
  92. }
  93. #define stackalign 4
  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. output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
  101. #if defined(CONFIG_29BIT)
  102. output_addr |= P2SEG;
  103. #endif
  104. output = (unsigned char *)output_addr;
  105. free_mem_ptr = (unsigned long)&_end;
  106. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  107. puts("Uncompressing Linux... ");
  108. __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
  109. puts("Ok, booting the kernel.\n");
  110. }