misc.c 2.6 KB

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