misc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_LZO
  51. #include "../../../../lib/decompress_unlzo.c"
  52. #endif
  53. int puts(const char *s)
  54. {
  55. /* This should be updated to use the sh-sci routines */
  56. return 0;
  57. }
  58. void* memset(void* s, int c, size_t n)
  59. {
  60. int i;
  61. char *ss = (char*)s;
  62. for (i=0;i<n;i++) ss[i] = c;
  63. return s;
  64. }
  65. void* memcpy(void* __dest, __const void* __src,
  66. size_t __n)
  67. {
  68. int i;
  69. char *d = (char *)__dest, *s = (char *)__src;
  70. for (i=0;i<__n;i++) d[i] = s[i];
  71. return __dest;
  72. }
  73. static void error(char *x)
  74. {
  75. puts("\n\n");
  76. puts(x);
  77. puts("\n\n -- System halted");
  78. while(1); /* Halt */
  79. }
  80. #ifdef CONFIG_SUPERH64
  81. #define stackalign 8
  82. #else
  83. #define stackalign 4
  84. #endif
  85. #define STACK_SIZE (4096)
  86. long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
  87. long *stack_start = &user_stack[STACK_SIZE];
  88. void decompress_kernel(void)
  89. {
  90. unsigned long output_addr;
  91. #ifdef CONFIG_SUPERH64
  92. output_addr = (CONFIG_MEMORY_START + 0x2000);
  93. #else
  94. output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
  95. #if defined(CONFIG_29BIT)
  96. output_addr |= P2SEG;
  97. #endif
  98. #endif
  99. output = (unsigned char *)output_addr;
  100. free_mem_ptr = (unsigned long)&_end;
  101. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  102. puts("Uncompressing Linux... ");
  103. cache_control(CACHE_ENABLE);
  104. decompress(input_data, input_len, NULL, NULL, output, NULL, error);
  105. cache_control(CACHE_DISABLE);
  106. puts("Ok, booting the kernel.\n");
  107. }